]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/RVDS/ARM_CM4_MPU/portmacro.h
First Official Release of ARMV8M Support. This release removes Pre-Release from all...
[freertos] / FreeRTOS / Source / portable / RVDS / ARM_CM4_MPU / portmacro.h
1 /*\r
2  * FreeRTOS Kernel V10.2.0\r
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 \r
29 #ifndef PORTMACRO_H\r
30 #define PORTMACRO_H\r
31 \r
32 #ifdef __cplusplus\r
33 extern "C" {\r
34 #endif\r
35 \r
36 /*-----------------------------------------------------------\r
37  * Port specific definitions.\r
38  *\r
39  * The settings in this file configure FreeRTOS correctly for the\r
40  * given hardware and compiler.\r
41  *\r
42  * These settings should not be altered.\r
43  *-----------------------------------------------------------\r
44  */\r
45 \r
46 /* Type definitions. */\r
47 #define portCHAR                char\r
48 #define portFLOAT               float\r
49 #define portDOUBLE              double\r
50 #define portLONG                long\r
51 #define portSHORT               short\r
52 #define portSTACK_TYPE  uint32_t\r
53 #define portBASE_TYPE   long\r
54 \r
55 typedef portSTACK_TYPE StackType_t;\r
56 typedef long BaseType_t;\r
57 typedef unsigned long UBaseType_t;\r
58 \r
59 #if( configUSE_16_BIT_TICKS == 1 )\r
60         typedef uint16_t TickType_t;\r
61         #define portMAX_DELAY ( TickType_t ) 0xffff\r
62 #else\r
63         typedef uint32_t TickType_t;\r
64         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\r
65 \r
66         /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do\r
67         not need to be guarded with a critical section. */\r
68         #define portTICK_TYPE_IS_ATOMIC 1\r
69 #endif\r
70 /*-----------------------------------------------------------*/\r
71 \r
72 /* MPU specific constants. */\r
73 #define portUSING_MPU_WRAPPERS          1\r
74 #define portPRIVILEGE_BIT                       ( 0x80000000UL )\r
75 \r
76 #define portMPU_REGION_READ_WRITE                               ( 0x03UL << 24UL )\r
77 #define portMPU_REGION_PRIVILEGED_READ_ONLY             ( 0x05UL << 24UL )\r
78 #define portMPU_REGION_READ_ONLY                                ( 0x06UL << 24UL )\r
79 #define portMPU_REGION_PRIVILEGED_READ_WRITE    ( 0x01UL << 24UL )\r
80 #define portMPU_REGION_CACHEABLE_BUFFERABLE             ( 0x07UL << 16UL )\r
81 #define portMPU_REGION_EXECUTE_NEVER                    ( 0x01UL << 28UL )\r
82 \r
83 #define portUNPRIVILEGED_FLASH_REGION           ( 0UL )\r
84 #define portPRIVILEGED_FLASH_REGION                     ( 1UL )\r
85 #define portPRIVILEGED_RAM_REGION                       ( 2UL )\r
86 #define portGENERAL_PERIPHERALS_REGION          ( 3UL )\r
87 #define portSTACK_REGION                                        ( 4UL )\r
88 #define portFIRST_CONFIGURABLE_REGION           ( 5UL )\r
89 #define portLAST_CONFIGURABLE_REGION            ( 7UL )\r
90 #define portNUM_CONFIGURABLE_REGIONS            ( ( portLAST_CONFIGURABLE_REGION - portFIRST_CONFIGURABLE_REGION ) + 1 )\r
91 #define portTOTAL_NUM_REGIONS                           ( portNUM_CONFIGURABLE_REGIONS + 1 ) /* Plus one to make space for the stack region. */\r
92 \r
93 void vPortSwitchToUserMode( void );\r
94 #define portSWITCH_TO_USER_MODE()       vPortSwitchToUserMode()\r
95 \r
96 typedef struct MPU_REGION_REGISTERS\r
97 {\r
98         uint32_t ulRegionBaseAddress;\r
99         uint32_t ulRegionAttribute;\r
100 } xMPU_REGION_REGISTERS;\r
101 \r
102 /* Plus 1 to create space for the stack region. */\r
103 typedef struct MPU_SETTINGS\r
104 {\r
105         xMPU_REGION_REGISTERS xRegion[ portTOTAL_NUM_REGIONS ];\r
106 } xMPU_SETTINGS;\r
107 \r
108 /* Architecture specifics. */\r
109 #define portSTACK_GROWTH                        ( -1 )\r
110 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
111 #define portBYTE_ALIGNMENT                      8\r
112 \r
113 /* Constants used with memory barrier intrinsics. */\r
114 #define portSY_FULL_READ_WRITE          ( 15 )\r
115 \r
116 /*-----------------------------------------------------------*/\r
117 \r
118 /* SVC numbers for various services. */\r
119 #define portSVC_START_SCHEDULER                         0\r
120 #define portSVC_YIELD                                           1\r
121 #define portSVC_RAISE_PRIVILEGE                         2\r
122 \r
123 /* Scheduler utilities. */\r
124 \r
125 #define portYIELD()                             __asm{ SVC portSVC_YIELD }\r
126 #define portYIELD_WITHIN_API()                                                                                                  \\r
127 {                                                                                                                                                               \\r
128         /* Set a PendSV to request a context switch. */                                                         \\r
129         portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;                                                         \\r
130                                                                                                                                                                 \\r
131         /* Barriers are normally not required but do ensure the code is completely      \\r
132         within the specified behaviour for the architecture. */                                         \\r
133         __dsb( portSY_FULL_READ_WRITE );                                                                                        \\r
134         __isb( portSY_FULL_READ_WRITE );                                                                                        \\r
135 }\r
136 /*-----------------------------------------------------------*/\r
137 \r
138 #define portNVIC_INT_CTRL_REG           ( * ( ( volatile uint32_t * ) 0xe000ed04 ) )\r
139 #define portNVIC_PENDSVSET_BIT          ( 1UL << 28UL )\r
140 #define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT\r
141 #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 /* Critical section management. */\r
145 extern void vPortEnterCritical( void );\r
146 extern void vPortExitCritical( void );\r
147 \r
148 #define portDISABLE_INTERRUPTS()                                vPortRaiseBASEPRI()\r
149 #define portENABLE_INTERRUPTS()                                 vPortSetBASEPRI(0)\r
150 #define portENTER_CRITICAL()                                    vPortEnterCritical()\r
151 #define portEXIT_CRITICAL()                                             vPortExitCritical()\r
152 #define portSET_INTERRUPT_MASK_FROM_ISR()               ulPortRaiseBASEPRI()\r
153 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x)    vPortSetBASEPRI(x)\r
154 \r
155 /*-----------------------------------------------------------*/\r
156 \r
157 /* Architecture specific optimisations. */\r
158 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION\r
159         #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1\r
160 #endif\r
161 \r
162 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
163 \r
164         /* Check the configuration. */\r
165         #if( configMAX_PRIORITIES > 32 )\r
166                 #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
167         #endif\r
168 \r
169         /* Store/clear the ready priorities in a bit map. */\r
170         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
171         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
172 \r
173         /*-----------------------------------------------------------*/\r
174 \r
175         #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __clz( ( uxReadyPriorities ) ) )\r
176 \r
177 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
178 /*-----------------------------------------------------------*/\r
179 \r
180 /* Task function macros as described on the FreeRTOS.org WEB site.  These are\r
181 not necessary for to use this port.  They are defined so the common demo files\r
182 (which build with all the ports) will build. */\r
183 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
184 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
185 /*-----------------------------------------------------------*/\r
186 \r
187 #ifdef configASSERT\r
188         void vPortValidateInterruptPriority( void );\r
189         #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID()      vPortValidateInterruptPriority()\r
190 #endif\r
191 \r
192 /* portNOP() is not required by this port. */\r
193 #define portNOP()\r
194 \r
195 #define portINLINE __inline\r
196 \r
197 #ifndef portFORCE_INLINE\r
198         #define portFORCE_INLINE __forceinline\r
199 #endif\r
200 /*-----------------------------------------------------------*/\r
201 \r
202 extern BaseType_t xIsPrivileged( void );\r
203 extern void vResetPrivilege( void );\r
204 \r
205 /**\r
206  * @brief Checks whether or not the processor is privileged.\r
207  *\r
208  * @return 1 if the processor is already privileged, 0 otherwise.\r
209  */\r
210 #define portIS_PRIVILEGED()                     xIsPrivileged()\r
211 \r
212 /**\r
213  * @brief Raise an SVC request to raise privilege.\r
214  */\r
215 #define portRAISE_PRIVILEGE()           __asm { svc portSVC_RAISE_PRIVILEGE }\r
216 \r
217 /**\r
218  * @brief Lowers the privilege level by setting the bit 0 of the CONTROL\r
219  * register.\r
220  */\r
221 #define portRESET_PRIVILEGE()           vResetPrivilege()\r
222 /*-----------------------------------------------------------*/\r
223 \r
224 static portFORCE_INLINE void vPortSetBASEPRI( uint32_t ulBASEPRI )\r
225 {\r
226         __asm\r
227         {\r
228                 /* Barrier instructions are not used as this function is only used to\r
229                 lower the BASEPRI value. */\r
230                 msr basepri, ulBASEPRI\r
231         }\r
232 }\r
233 /*-----------------------------------------------------------*/\r
234 \r
235 static portFORCE_INLINE void vPortRaiseBASEPRI( void )\r
236 {\r
237 uint32_t ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY;\r
238 \r
239         __asm\r
240         {\r
241                 /* Set BASEPRI to the max syscall priority to effect a critical\r
242                 section. */\r
243                 msr basepri, ulNewBASEPRI\r
244                 dsb\r
245                 isb\r
246         }\r
247 }\r
248 /*-----------------------------------------------------------*/\r
249 \r
250 static portFORCE_INLINE void vPortClearBASEPRIFromISR( void )\r
251 {\r
252         __asm\r
253         {\r
254                 /* Set BASEPRI to 0 so no interrupts are masked.  This function is only\r
255                 used to lower the mask in an interrupt, so memory barriers are not\r
256                 used. */\r
257                 msr basepri, #0\r
258         }\r
259 }\r
260 /*-----------------------------------------------------------*/\r
261 \r
262 static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void )\r
263 {\r
264 uint32_t ulReturn, ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY;\r
265 \r
266         __asm\r
267         {\r
268                 /* Set BASEPRI to the max syscall priority to effect a critical\r
269                 section. */\r
270                 mrs ulReturn, basepri\r
271                 msr basepri, ulNewBASEPRI\r
272                 dsb\r
273                 isb\r
274         }\r
275 \r
276         return ulReturn;\r
277 }\r
278 /*-----------------------------------------------------------*/\r
279 \r
280 static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void )\r
281 {\r
282 uint32_t ulCurrentInterrupt;\r
283 BaseType_t xReturn;\r
284 \r
285         /* Obtain the number of the currently executing interrupt. */\r
286         __asm\r
287         {\r
288                 mrs ulCurrentInterrupt, ipsr\r
289         }\r
290 \r
291         if( ulCurrentInterrupt == 0 )\r
292         {\r
293                 xReturn = pdFALSE;\r
294         }\r
295         else\r
296         {\r
297                 xReturn = pdTRUE;\r
298         }\r
299 \r
300         return xReturn;\r
301 }\r
302 /*-----------------------------------------------------------*/\r
303 \r
304 #ifdef __cplusplus\r
305 }\r
306 #endif\r
307 \r
308 #endif /* PORTMACRO_H */\r