]> begriffs open source - freertos/blob - portable/IAR/ARM_CM4F_MPU/portmacro.h
[AUTO][RELEASE]: Bump file header version to "10.5.0"
[freertos] / portable / IAR / ARM_CM4F_MPU / portmacro.h
1 /*\r
2  * FreeRTOS Kernel V10.5.0\r
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * SPDX-License-Identifier: MIT\r
6  *\r
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
8  * this software and associated documentation files (the "Software"), to deal in\r
9  * the Software without restriction, including without limitation the rights to\r
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
11  * the Software, and to permit persons to whom the Software is furnished to do so,\r
12  * subject to the following conditions:\r
13  *\r
14  * The above copyright notice and this permission notice shall be included in all\r
15  * copies or substantial portions of the Software.\r
16  *\r
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
23  *\r
24  * https://www.FreeRTOS.org\r
25  * https://github.com/FreeRTOS\r
26  *\r
27  */\r
28 \r
29 \r
30 #ifndef PORTMACRO_H\r
31 #define PORTMACRO_H\r
32 \r
33 /* *INDENT-OFF* */\r
34 #ifdef __cplusplus\r
35     extern "C" {\r
36 #endif\r
37 /* *INDENT-ON* */\r
38 \r
39 /*-----------------------------------------------------------\r
40  * Port specific definitions.\r
41  *\r
42  * The settings in this file configure FreeRTOS correctly for the\r
43  * given hardware and compiler.\r
44  *\r
45  * These settings should not be altered.\r
46  *-----------------------------------------------------------\r
47  */\r
48 \r
49 /* IAR includes. */\r
50 #include <intrinsics.h>\r
51 \r
52 /* Type definitions. */\r
53 #define portCHAR          char\r
54 #define portFLOAT         float\r
55 #define portDOUBLE        double\r
56 #define portLONG          long\r
57 #define portSHORT         short\r
58 #define portSTACK_TYPE    uint32_t\r
59 #define portBASE_TYPE     long\r
60 \r
61 typedef portSTACK_TYPE   StackType_t;\r
62 typedef long             BaseType_t;\r
63 typedef unsigned long    UBaseType_t;\r
64 \r
65 #if ( configUSE_16_BIT_TICKS == 1 )\r
66     typedef uint16_t     TickType_t;\r
67     #define portMAX_DELAY              ( TickType_t ) 0xffff\r
68 #else\r
69     typedef uint32_t     TickType_t;\r
70     #define portMAX_DELAY              ( TickType_t ) 0xffffffffUL\r
71 \r
72 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do\r
73  * not need to be guarded with a critical section. */\r
74     #define portTICK_TYPE_IS_ATOMIC    1\r
75 #endif\r
76 \r
77 /*-----------------------------------------------------------*/\r
78 \r
79 /* MPU specific constants. */\r
80 #define portUSING_MPU_WRAPPERS                                   1\r
81 #define portPRIVILEGE_BIT                                        ( 0x80000000UL )\r
82 \r
83 #define portMPU_REGION_READ_WRITE                                ( 0x03UL << 24UL )\r
84 #define portMPU_REGION_PRIVILEGED_READ_ONLY                      ( 0x05UL << 24UL )\r
85 #define portMPU_REGION_READ_ONLY                                 ( 0x06UL << 24UL )\r
86 #define portMPU_REGION_PRIVILEGED_READ_WRITE                     ( 0x01UL << 24UL )\r
87 #define portMPU_REGION_PRIVILEGED_READ_WRITE_UNPRIV_READ_ONLY    ( 0x02UL << 24UL )\r
88 #define portMPU_REGION_CACHEABLE_BUFFERABLE                      ( 0x07UL << 16UL )\r
89 #define portMPU_REGION_EXECUTE_NEVER                             ( 0x01UL << 28UL )\r
90 \r
91 /* Location of the TEX,S,C,B bits in the MPU Region Attribute and Size\r
92  * Register (RASR). */\r
93 #define portMPU_RASR_TEX_S_C_B_LOCATION                          ( 16UL )\r
94 #define portMPU_RASR_TEX_S_C_B_MASK                              ( 0x3FUL )\r
95 \r
96 /* MPU settings that can be overriden in FreeRTOSConfig.h. */\r
97 #ifndef configTOTAL_MPU_REGIONS\r
98     /* Define to 8 for backward compatibility. */\r
99     #define configTOTAL_MPU_REGIONS    ( 8UL )\r
100 #endif\r
101 \r
102 /*\r
103  * The TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits define the\r
104  * memory type, and where necessary the cacheable and shareable properties\r
105  * of the memory region.\r
106  *\r
107  * The TEX, C, and B bits together indicate the memory type of the region,\r
108  * and:\r
109  * - For Normal memory, the cacheable properties of the region.\r
110  * - For Device memory, whether the region is shareable.\r
111  *\r
112  * For Normal memory regions, the S bit indicates whether the region is\r
113  * shareable. For Strongly-ordered and Device memory, the S bit is ignored.\r
114  *\r
115  * See the following two tables for setting TEX, S, C and B bits for\r
116  * unprivileged flash, privileged flash and privileged RAM regions.\r
117  *\r
118  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
119  | TEX | C | B | Memory type            |  Description or Normal region cacheability             |  Shareable?             |\r
120  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
121  | 000 | 0 | 0 | Strongly-ordered       |  Strongly ordered                                      |  Shareable              |\r
122  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
123  | 000 | 0 | 1 | Device                 |  Shared device                                         |  Shareable              |\r
124  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
125  | 000 | 1 | 0 | Normal                 |  Outer and inner   write-through; no write allocate    |  S bit                  |\r
126  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
127  | 000 | 1 | 1 | Normal                 |  Outer and inner   write-back; no write allocate       |  S bit                  |\r
128  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
129  | 001 | 0 | 0 | Normal                 |  Outer and inner   Non-cacheable                       |  S bit                  |\r
130  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
131  | 001 | 0 | 1 | Reserved               |  Reserved                                              |  Reserved               |\r
132  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
133  | 001 | 1 | 0 | IMPLEMENTATION DEFINED |  IMPLEMENTATION DEFINED                                |  IMPLEMENTATION DEFINED |\r
134  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
135  | 001 | 1 | 1 | Normal                 |  Outer and inner   write-back; write and read allocate |  S bit                  |\r
136  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
137  | 010 | 0 | 0 | Device                 |  Non-shared device                                     |  Not shareable          |\r
138  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
139  | 010 | 0 | 1 | Reserved               |  Reserved                                              |  Reserved               |\r
140  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
141  | 010 | 1 | X | Reserved               |  Reserved                                              |  Reserved               |\r
142  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
143  | 011 | X | X | Reserved               |  Reserved                                              |  Reserved               |\r
144  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
145  | 1BB | A | A | Normal                 | Cached memory, with AA and BB indicating the inner and |  Reserved               |\r
146  |     |   |   |                        | outer cacheability rules that must be exported on the  |                         |\r
147  |     |   |   |                        | bus. See the table below for the cacheability policy   |                         |\r
148  |     |   |   |                        | encoding. memory, BB=Outer policy, AA=Inner policy.    |                         |\r
149  +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+\r
150  |\r
151  +-----------------------------------------+----------------------------------------+\r
152  | AA or BB subfield of {TEX,C,B} encoding |  Cacheability policy                   |\r
153  +-----------------------------------------+----------------------------------------+\r
154  | 00                                      |  Non-cacheable                         |\r
155  +-----------------------------------------+----------------------------------------+\r
156  | 01                                      |  Write-back, write and   read allocate |\r
157  +-----------------------------------------+----------------------------------------+\r
158  | 10                                      |  Write-through, no write   allocate    |\r
159  +-----------------------------------------+----------------------------------------+\r
160  | 11                                      |  Write-back, no write   allocate       |\r
161  +-----------------------------------------+----------------------------------------+\r
162  */\r
163 \r
164 /* TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits for flash\r
165  * region. */\r
166 #ifndef configTEX_S_C_B_FLASH\r
167     /* Default to TEX=000, S=1, C=1, B=1 for backward compatibility. */\r
168     #define configTEX_S_C_B_FLASH    ( 0x07UL )\r
169 #endif\r
170 \r
171 /* TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits for RAM\r
172  * region. */\r
173 #ifndef configTEX_S_C_B_SRAM\r
174     /* Default to TEX=000, S=1, C=1, B=1 for backward compatibility. */\r
175     #define configTEX_S_C_B_SRAM          ( 0x07UL )\r
176 #endif\r
177 \r
178 #define portGENERAL_PERIPHERALS_REGION    ( configTOTAL_MPU_REGIONS - 5UL )\r
179 #define portSTACK_REGION                  ( configTOTAL_MPU_REGIONS - 4UL )\r
180 #define portUNPRIVILEGED_FLASH_REGION     ( configTOTAL_MPU_REGIONS - 3UL )\r
181 #define portPRIVILEGED_FLASH_REGION       ( configTOTAL_MPU_REGIONS - 2UL )\r
182 #define portPRIVILEGED_RAM_REGION         ( configTOTAL_MPU_REGIONS - 1UL )\r
183 #define portFIRST_CONFIGURABLE_REGION     ( 0UL )\r
184 #define portLAST_CONFIGURABLE_REGION      ( configTOTAL_MPU_REGIONS - 6UL )\r
185 #define portNUM_CONFIGURABLE_REGIONS      ( configTOTAL_MPU_REGIONS - 5UL )\r
186 #define portTOTAL_NUM_REGIONS_IN_TCB      ( portNUM_CONFIGURABLE_REGIONS + 1 ) /* Plus 1 to create space for the stack region. */\r
187 \r
188 #define portSWITCH_TO_USER_MODE()    __asm volatile ( " mrs r0, control \n orr r0, r0, #1 \n msr control, r0 " ::: "r0", "memory" )\r
189 \r
190 typedef struct MPU_REGION_REGISTERS\r
191 {\r
192     uint32_t ulRegionBaseAddress;\r
193     uint32_t ulRegionAttribute;\r
194 } xMPU_REGION_REGISTERS;\r
195 \r
196 typedef struct MPU_SETTINGS\r
197 {\r
198     xMPU_REGION_REGISTERS xRegion[ portTOTAL_NUM_REGIONS_IN_TCB ];\r
199 } xMPU_SETTINGS;\r
200 \r
201 /* Architecture specifics. */\r
202 #define portSTACK_GROWTH      ( -1 )\r
203 #define portTICK_PERIOD_MS    ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
204 #define portBYTE_ALIGNMENT    8\r
205 /*-----------------------------------------------------------*/\r
206 \r
207 /* SVC numbers for various services. */\r
208 #define portSVC_START_SCHEDULER    0\r
209 #define portSVC_YIELD              1\r
210 #define portSVC_RAISE_PRIVILEGE    2\r
211 \r
212 /* Scheduler utilities. */\r
213 \r
214 #define portYIELD()    __asm volatile ( "       SVC     %0      \n"::"i" ( portSVC_YIELD ) : "memory" )\r
215 #define portYIELD_WITHIN_API()                          \\r
216     {                                                   \\r
217         /* Set a PendSV to request a context switch. */ \\r
218         portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; \\r
219         __DSB();                                        \\r
220         __ISB();                                        \\r
221     }\r
222 \r
223 #define portNVIC_INT_CTRL_REG     ( *( ( volatile uint32_t * ) 0xe000ed04 ) )\r
224 #define portNVIC_PENDSVSET_BIT    ( 1UL << 28UL )\r
225 #define portEND_SWITCHING_ISR( xSwitchRequired )    do { if( xSwitchRequired != pdFALSE ) portYIELD_WITHIN_API(); } while( 0 )\r
226 #define portYIELD_FROM_ISR( x )                     portEND_SWITCHING_ISR( x )\r
227 /*-----------------------------------------------------------*/\r
228 \r
229 /* Architecture specific optimisations. */\r
230 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION\r
231     #define configUSE_PORT_OPTIMISED_TASK_SELECTION    1\r
232 #endif\r
233 \r
234 #if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )\r
235 \r
236 /* Check the configuration. */\r
237     #if ( configMAX_PRIORITIES > 32 )\r
238         #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32.  It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.\r
239     #endif\r
240 \r
241 /* Store/clear the ready priorities in a bit map. */\r
242     #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities )    ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
243     #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities )     ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
244 \r
245 /*-----------------------------------------------------------*/\r
246 \r
247     #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities )    uxTopPriority = ( 31UL - ( ( uint32_t ) __CLZ( ( uxReadyPriorities ) ) ) )\r
248 \r
249 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
250 /*-----------------------------------------------------------*/\r
251 \r
252 /* Critical section management. */\r
253 extern void vPortEnterCritical( void );\r
254 extern void vPortExitCritical( void );\r
255 \r
256 #if( configENABLE_ERRATA_837070_WORKAROUND == 1 )\r
257     #define portDISABLE_INTERRUPTS()                               \\r
258         {                                                          \\r
259             __disable_interrupt();                                 \\r
260             __set_BASEPRI( configMAX_SYSCALL_INTERRUPT_PRIORITY ); \\r
261             __DSB();                                               \\r
262             __ISB();                                               \\r
263             __enable_interrupt();                                  \\r
264         }\r
265 #else\r
266     #define portDISABLE_INTERRUPTS()                               \\r
267         {                                                          \\r
268             __set_BASEPRI( configMAX_SYSCALL_INTERRUPT_PRIORITY ); \\r
269             __DSB();                                               \\r
270             __ISB();                                               \\r
271         }\r
272 #endif\r
273 \r
274 #define portENABLE_INTERRUPTS()                   __set_BASEPRI( 0 )\r
275 #define portENTER_CRITICAL()                      vPortEnterCritical()\r
276 #define portEXIT_CRITICAL()                       vPortExitCritical()\r
277 #define portSET_INTERRUPT_MASK_FROM_ISR()         __get_BASEPRI(); portDISABLE_INTERRUPTS()\r
278 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x )    __set_BASEPRI( x )\r
279 /*-----------------------------------------------------------*/\r
280 \r
281 /* Task function macros as described on the FreeRTOS.org WEB site.  These are\r
282  * not necessary for to use this port.  They are defined so the common demo files\r
283  * (which build with all the ports) will build. */\r
284 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters )    void vFunction( void * pvParameters )\r
285 #define portTASK_FUNCTION( vFunction, pvParameters )          void vFunction( void * pvParameters )\r
286 /*-----------------------------------------------------------*/\r
287 \r
288 #ifdef configASSERT\r
289     void vPortValidateInterruptPriority( void );\r
290     #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID()    vPortValidateInterruptPriority()\r
291 #endif\r
292 \r
293 /* portNOP() is not required by this port. */\r
294 #define portNOP()\r
295 \r
296 #define portINLINE              __inline\r
297 \r
298 #ifndef portFORCE_INLINE\r
299     #define portFORCE_INLINE    inline __attribute__( ( always_inline ) )\r
300 #endif\r
301 \r
302 /*-----------------------------------------------------------*/\r
303 \r
304 portFORCE_INLINE static BaseType_t xPortIsInsideInterrupt( void )\r
305 {\r
306     uint32_t ulCurrentInterrupt;\r
307     BaseType_t xReturn;\r
308 \r
309     /* Obtain the number of the currently executing interrupt. */\r
310     __asm volatile ( "mrs %0, ipsr" : "=r" ( ulCurrentInterrupt )::"memory" );\r
311 \r
312     if( ulCurrentInterrupt == 0 )\r
313     {\r
314         xReturn = pdFALSE;\r
315     }\r
316     else\r
317     {\r
318         xReturn = pdTRUE;\r
319     }\r
320 \r
321     return xReturn;\r
322 }\r
323 \r
324 \r
325 /*-----------------------------------------------------------*/\r
326 \r
327 extern BaseType_t xIsPrivileged( void );\r
328 extern void vResetPrivilege( void );\r
329 \r
330 /**\r
331  * @brief Checks whether or not the processor is privileged.\r
332  *\r
333  * @return 1 if the processor is already privileged, 0 otherwise.\r
334  */\r
335 #define portIS_PRIVILEGED()      xIsPrivileged()\r
336 \r
337 /**\r
338  * @brief Raise an SVC request to raise privilege.\r
339  */\r
340 #define portRAISE_PRIVILEGE()    __asm volatile ( "svc %0 \n" ::"i" ( portSVC_RAISE_PRIVILEGE ) : "memory" );\r
341 \r
342 /**\r
343  * @brief Lowers the privilege level by setting the bit 0 of the CONTROL\r
344  * register.\r
345  */\r
346 #define portRESET_PRIVILEGE()    vResetPrivilege()\r
347 /*-----------------------------------------------------------*/\r
348 \r
349 #ifndef configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY\r
350     #warning "configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY is not defined. We recommend defining it to 1 in FreeRTOSConfig.h for better security. https://www.FreeRTOS.org/FreeRTOS-V10.3.x.html"\r
351     #define configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY    0\r
352 #endif\r
353 /*-----------------------------------------------------------*/\r
354 \r
355 /* Suppress warnings that are generated by the IAR tools, but cannot be fixed in\r
356  * the source code because to do so would cause other compilers to generate\r
357  * warnings. */\r
358 #pragma diag_suppress=Pe191\r
359 #pragma diag_suppress=Pa082\r
360 #pragma diag_suppress=Be006\r
361 /*-----------------------------------------------------------*/\r
362 \r
363 /* *INDENT-OFF* */\r
364 #ifdef __cplusplus\r
365     }\r
366 #endif\r
367 /* *INDENT-ON* */\r
368 \r
369 #endif /* PORTMACRO_H */\r