1 #ifndef FREERTOS_CONFIG_H
2 #define FREERTOS_CONFIG_H
4 // NDEBUG ("not debug"), can be specified by the
5 // programmer. It's honored by the C standard
8 // "not not debug" mode is...debug mode
10 /* FreeRTOS internals call configASSERT() if it's
11 * defined. We'll delegate to picolibc assert(),
12 * and also disable interrupts on failure so it's
13 * clear in a debugger how the assert() function
15 #define configASSERT(x) ((x) \
17 : (taskDISABLE_INTERRUPTS(), assert(x)))
18 // also detect stack overflow in debug mode,
19 // which adds a little overhead
20 #define configCHECK_FOR_STACK_OVERFLOW 2
23 /* Size of stack for the idle task.
25 * Quite honestly, I don't know the optimal value
26 * for this. I copied the following from the most
27 * similar FreeRTOS demo: CORTEX_M4F_STM32F407ZG-SK.
28 * Many other demos use 128, so we should be safe. */
29 #define configMINIMAL_STACK_SIZE @MIN_STACK_SIZE@
31 #define configSUPPORT_DYNAMIC_ALLOCATION 1
32 #define configSUPPORT_STATIC_ALLOCATION 0
34 // We'll use only one task, and it constantly yields
35 // by calling a delay function, so no need to involve
36 // a preemptive scheduler on each tick interrupt
37 #define configUSE_PREEMPTION @USE_PREEMPTION@
38 // Our app doesn't need callbacks for these events
39 #define configUSE_IDLE_HOOK @USE_IDLE_HOOK@
40 #define configUSE_TICK_HOOK @USE_TICK_HOOK@
41 // the linker will remove it if not needed
42 #define INCLUDE_vTaskDelay 1
44 /* Record the frequency of the peripheral used to
45 * generate the SysTick interrupt.
47 * Our chosen port, GCC/ARM_CM4F/port.c, sets
48 * the CLKSOURCE bit in the STK_CTL register, meaning
49 * the processor clock (AHB) is the source for SysTick,
50 * as described in PM0214 §4.5.1.
52 * If the processor clock and systick clock differ,
53 * FreeRTOS provides configSYSTICK_CLOCK_HZ that you
54 * can set independently of configCPU_CLOCK_HZ.
56 * We can use the global variable SystemCoreClock
57 * managed by CMSIS, rather than hard-coding a value
58 * in this header file. */
60 extern uint32_t SystemCoreClock;
61 #define configCPU_CLOCK_HZ (SystemCoreClock)
63 /* Set the time slice size of the scheduler. We'll
64 * choose 10 ms, using a 100 Hz tick rate. The time
65 * slice determines the resolution of pdMS_TO_TICKS(),
66 * and a value greater than 1000 breaks that macro. */
67 #define configTICK_RATE_HZ @TICK_RATE_HZ@
68 // we're not on a restrictive 8- or 16-bit chip
69 #define configUSE_16_BIT_TICKS 0
71 /* The three interrupts used by FreeRTOS on Cortex-M4.
73 * Map the FreeRTOS interrupt handlers to the names set
74 * up by picolibc in its interrupt vector table. */
76 // used to start the scheduler
77 #define vPortSVCHandler arm_svc_isr
78 // used for context switches
79 #define xPortPendSVHandler arm_pendsv_isr
81 #define xPortSysTickHandler arm_systick_isr
83 /*****************************************************
84 * Interrupt priority details below.
86 * Macros required by our FreeRTOS GCC/ARM_CM4F port.
87 *****************************************************/
89 /* Number of bits available to express interrupt
90 * priority on our MCU. ARMv7-M chips support between
91 * 3 and 8 priority bits (Architecture Reference Manual
92 * §B1.5.4). We'll get the value from CMSIS.
94 * FreeRTOS consults this macro to do internal sanity
95 * checks using configASSERT(), and we use it below */
96 #include CMSIS_device_header
97 #define configPRIO_BITS __NVIC_PRIO_BITS
99 // Tasks can be assigned a priority from zero, which is
100 // most urgent, to (configMAX_PRIORITIES - 1), which is
102 #define configMAX_PRIORITIES (1 << configPRIO_BITS)
104 /* Set priority for interrupts used by the kernel port.
106 * We're using the highest value (lowest urgency),
107 * shifted to the most significant bits of the byte.
109 #define configKERNEL_INTERRUPT_PRIORITY \
110 ( (configMAX_PRIORITIES - 1) << (8 - configPRIO_BITS) )
112 /* Divide interrupts into two kinds based on priority:
114 * 1. Those which can call FreeRTOS functions, and
115 * which FreeRTOS critical sections can mask.
116 * 2. Those which can't call FreeRTOS, and whose
117 * latency is essentially unaffected by FreeRTOS.
119 * We pick a dividing line, a "max interrupt priority
120 * for FreeRTOS API calls," where interrupts with
121 * greater or equal priority to the divider (less or
122 * equal urgency) become type 1, and lower priority
123 * valued (more urgent) interrupts become type 2.
125 * We pick priority 5, because even the most limited
126 * Cortex-M has 3 prio bits, giving at least the ranges
127 * (0-4) and (5-7) in each category. Our MCU, the
128 * Cortex-M4F, has more: 4 prio bits (RM0383 §10.1.1). */
129 #define configMAX_SYSCALL_INTERRUPT_PRIORITY \
130 ( 5 << (8 - configPRIO_BITS) )