2 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
\r
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * SPDX-License-Identifier: MIT
\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
14 * The above copyright notice and this permission notice shall be included in all
\r
15 * copies or substantial portions of the Software.
\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
24 * https://www.FreeRTOS.org
\r
25 * https://github.com/FreeRTOS
\r
39 /*-----------------------------------------------------------
\r
40 * Port specific definitions.
\r
42 * The settings in this file configure FreeRTOS correctly for the
\r
43 * given hardware and compiler.
\r
45 * These settings should not be altered.
\r
46 *-----------------------------------------------------------
\r
49 /* Type definitions. */
\r
50 #define portCHAR char
\r
51 #define portFLOAT float
\r
52 #define portDOUBLE double
\r
53 #define portLONG long
\r
54 #define portSHORT short
\r
55 #define portSTACK_TYPE uint32_t
\r
56 #define portBASE_TYPE long
\r
58 typedef portSTACK_TYPE StackType_t;
\r
59 typedef long BaseType_t;
\r
60 typedef unsigned long UBaseType_t;
\r
62 #if ( configUSE_16_BIT_TICKS == 1 )
\r
63 typedef uint16_t TickType_t;
\r
64 #define portMAX_DELAY ( TickType_t ) 0xffff
\r
66 typedef uint32_t TickType_t;
\r
67 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
\r
69 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
\r
70 * not need to be guarded with a critical section. */
\r
71 #define portTICK_TYPE_IS_ATOMIC 1
\r
73 /*-----------------------------------------------------------*/
\r
75 /* MPU specific constants. */
\r
76 #define portUSING_MPU_WRAPPERS 1
\r
77 #define portPRIVILEGE_BIT ( 0x80000000UL )
\r
79 #define portMPU_REGION_READ_WRITE ( 0x03UL << 24UL )
\r
80 #define portMPU_REGION_PRIVILEGED_READ_ONLY ( 0x05UL << 24UL )
\r
81 #define portMPU_REGION_READ_ONLY ( 0x06UL << 24UL )
\r
82 #define portMPU_REGION_PRIVILEGED_READ_WRITE ( 0x01UL << 24UL )
\r
83 #define portMPU_REGION_PRIVILEGED_READ_WRITE_UNPRIV_READ_ONLY ( 0x02UL << 24UL )
\r
84 #define portMPU_REGION_CACHEABLE_BUFFERABLE ( 0x07UL << 16UL )
\r
85 #define portMPU_REGION_EXECUTE_NEVER ( 0x01UL << 28UL )
\r
87 /* Location of the TEX,S,C,B bits in the MPU Region Attribute and Size
\r
88 * Register (RASR). */
\r
89 #define portMPU_RASR_TEX_S_C_B_LOCATION ( 16UL )
\r
90 #define portMPU_RASR_TEX_S_C_B_MASK ( 0x3FUL )
\r
92 /* MPU settings that can be overriden in FreeRTOSConfig.h. */
\r
93 #ifndef configTOTAL_MPU_REGIONS
\r
94 /* Define to 8 for backward compatibility. */
\r
95 #define configTOTAL_MPU_REGIONS ( 8UL )
\r
99 * The TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits define the
\r
100 * memory type, and where necessary the cacheable and shareable properties
\r
101 * of the memory region.
\r
103 * The TEX, C, and B bits together indicate the memory type of the region,
\r
105 * - For Normal memory, the cacheable properties of the region.
\r
106 * - For Device memory, whether the region is shareable.
\r
108 * For Normal memory regions, the S bit indicates whether the region is
\r
109 * shareable. For Strongly-ordered and Device memory, the S bit is ignored.
\r
111 * See the following two tables for setting TEX, S, C and B bits for
\r
112 * unprivileged flash, privileged flash and privileged RAM regions.
\r
114 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
115 | TEX | C | B | Memory type | Description or Normal region cacheability | Shareable? |
\r
116 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
117 | 000 | 0 | 0 | Strongly-ordered | Strongly ordered | Shareable |
\r
118 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
119 | 000 | 0 | 1 | Device | Shared device | Shareable |
\r
120 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
121 | 000 | 1 | 0 | Normal | Outer and inner write-through; no write allocate | S bit |
\r
122 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
123 | 000 | 1 | 1 | Normal | Outer and inner write-back; no write allocate | S bit |
\r
124 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
125 | 001 | 0 | 0 | Normal | Outer and inner Non-cacheable | S bit |
\r
126 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
127 | 001 | 0 | 1 | Reserved | Reserved | Reserved |
\r
128 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
129 | 001 | 1 | 0 | IMPLEMENTATION DEFINED | IMPLEMENTATION DEFINED | IMPLEMENTATION DEFINED |
\r
130 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
131 | 001 | 1 | 1 | Normal | Outer and inner write-back; write and read allocate | S bit |
\r
132 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
133 | 010 | 0 | 0 | Device | Non-shared device | Not shareable |
\r
134 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
135 | 010 | 0 | 1 | Reserved | Reserved | Reserved |
\r
136 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
137 | 010 | 1 | X | Reserved | Reserved | Reserved |
\r
138 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
139 | 011 | X | X | Reserved | Reserved | Reserved |
\r
140 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
141 | 1BB | A | A | Normal | Cached memory, with AA and BB indicating the inner and | Reserved |
\r
142 | | | | | outer cacheability rules that must be exported on the | |
\r
143 | | | | | bus. See the table below for the cacheability policy | |
\r
144 | | | | | encoding. memory, BB=Outer policy, AA=Inner policy. | |
\r
145 +-----+---+---+------------------------+--------------------------------------------------------+-------------------------+
\r
147 +-----------------------------------------+----------------------------------------+
\r
148 | AA or BB subfield of {TEX,C,B} encoding | Cacheability policy |
\r
149 +-----------------------------------------+----------------------------------------+
\r
150 | 00 | Non-cacheable |
\r
151 +-----------------------------------------+----------------------------------------+
\r
152 | 01 | Write-back, write and read allocate |
\r
153 +-----------------------------------------+----------------------------------------+
\r
154 | 10 | Write-through, no write allocate |
\r
155 +-----------------------------------------+----------------------------------------+
\r
156 | 11 | Write-back, no write allocate |
\r
157 +-----------------------------------------+----------------------------------------+
\r
160 /* TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits for Flash
\r
162 #ifndef configTEX_S_C_B_FLASH
\r
163 /* Default to TEX=000, S=1, C=1, B=1 for backward compatibility. */
\r
164 #define configTEX_S_C_B_FLASH ( 0x07UL )
\r
167 /* TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits for SRAM
\r
169 #ifndef configTEX_S_C_B_SRAM
\r
170 /* Default to TEX=000, S=1, C=1, B=1 for backward compatibility. */
\r
171 #define configTEX_S_C_B_SRAM ( 0x07UL )
\r
174 #define portUNPRIVILEGED_FLASH_REGION ( 0UL )
\r
175 #define portPRIVILEGED_FLASH_REGION ( 1UL )
\r
176 #define portPRIVILEGED_RAM_REGION ( 2UL )
\r
177 #define portGENERAL_PERIPHERALS_REGION ( 3UL )
\r
178 #define portSTACK_REGION ( 4UL )
\r
179 #define portFIRST_CONFIGURABLE_REGION ( 5UL )
\r
180 #define portTOTAL_NUM_REGIONS ( configTOTAL_MPU_REGIONS )
\r
181 #define portNUM_CONFIGURABLE_REGIONS ( portTOTAL_NUM_REGIONS - portFIRST_CONFIGURABLE_REGION )
\r
182 #define portLAST_CONFIGURABLE_REGION ( portTOTAL_NUM_REGIONS - 1 )
\r
184 void vPortSwitchToUserMode( void );
\r
185 #define portSWITCH_TO_USER_MODE() vPortSwitchToUserMode()
\r
187 typedef struct MPU_REGION_REGISTERS
\r
189 uint32_t ulRegionBaseAddress;
\r
190 uint32_t ulRegionAttribute;
\r
191 } xMPU_REGION_REGISTERS;
\r
193 /* Plus 1 to create space for the stack region. */
\r
194 typedef struct MPU_SETTINGS
\r
196 xMPU_REGION_REGISTERS xRegion[ portTOTAL_NUM_REGIONS ];
\r
199 /* Architecture specifics. */
\r
200 #define portSTACK_GROWTH ( -1 )
\r
201 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
\r
202 #define portBYTE_ALIGNMENT 8
\r
204 /* Constants used with memory barrier intrinsics. */
\r
205 #define portSY_FULL_READ_WRITE ( 15 )
\r
207 /*-----------------------------------------------------------*/
\r
209 /* SVC numbers for various services. */
\r
210 #define portSVC_START_SCHEDULER 0
\r
211 #define portSVC_YIELD 1
\r
212 #define portSVC_RAISE_PRIVILEGE 2
\r
214 /* Scheduler utilities. */
\r
216 #define portYIELD() __asm{ SVC portSVC_YIELD }
\r
217 #define portYIELD_WITHIN_API() \
\r
219 /* Set a PendSV to request a context switch. */ \
\r
220 portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; \
\r
222 /* Barriers are normally not required but do ensure the code is completely \
\r
223 * within the specified behaviour for the architecture. */ \
\r
224 __dsb( portSY_FULL_READ_WRITE ); \
\r
225 __isb( portSY_FULL_READ_WRITE ); \
\r
227 /*-----------------------------------------------------------*/
\r
229 #define portNVIC_INT_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000ed04 ) )
\r
230 #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL )
\r
231 #define portEND_SWITCHING_ISR( xSwitchRequired ) do { if( xSwitchRequired ) portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } while( 0 )
\r
232 #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
\r
233 /*-----------------------------------------------------------*/
\r
235 /* Critical section management. */
\r
236 extern void vPortEnterCritical( void );
\r
237 extern void vPortExitCritical( void );
\r
239 #define portDISABLE_INTERRUPTS() vPortRaiseBASEPRI()
\r
240 #define portENABLE_INTERRUPTS() vPortSetBASEPRI( 0 )
\r
241 #define portENTER_CRITICAL() vPortEnterCritical()
\r
242 #define portEXIT_CRITICAL() vPortExitCritical()
\r
243 #define portSET_INTERRUPT_MASK_FROM_ISR() ulPortRaiseBASEPRI()
\r
244 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vPortSetBASEPRI( x )
\r
246 /*-----------------------------------------------------------*/
\r
248 /* Architecture specific optimisations. */
\r
249 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
\r
250 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
\r
253 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
\r
255 /* Check the configuration. */
\r
256 #if ( configMAX_PRIORITIES > 32 )
\r
257 #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
260 /* Store/clear the ready priorities in a bit map. */
\r
261 #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
\r
262 #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
\r
264 /*-----------------------------------------------------------*/
\r
266 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __clz( ( uxReadyPriorities ) ) )
\r
268 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
\r
269 /*-----------------------------------------------------------*/
\r
271 /* Task function macros as described on the FreeRTOS.org WEB site. These are
\r
272 * not necessary for to use this port. They are defined so the common demo files
\r
273 * (which build with all the ports) will build. */
\r
274 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
\r
275 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
\r
276 /*-----------------------------------------------------------*/
\r
278 #ifdef configASSERT
\r
279 void vPortValidateInterruptPriority( void );
\r
280 #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority()
\r
283 /* portNOP() is not required by this port. */
\r
286 #define portINLINE __inline
\r
288 #ifndef portFORCE_INLINE
\r
289 #define portFORCE_INLINE __forceinline
\r
291 /*-----------------------------------------------------------*/
\r
293 extern BaseType_t xIsPrivileged( void );
\r
294 extern void vResetPrivilege( void );
\r
297 * @brief Checks whether or not the processor is privileged.
\r
299 * @return 1 if the processor is already privileged, 0 otherwise.
\r
301 #define portIS_PRIVILEGED() xIsPrivileged()
\r
304 * @brief Raise an SVC request to raise privilege.
\r
306 #define portRAISE_PRIVILEGE() __asm { svc portSVC_RAISE_PRIVILEGE }
\r
309 * @brief Lowers the privilege level by setting the bit 0 of the CONTROL
\r
312 #define portRESET_PRIVILEGE() vResetPrivilege()
\r
313 /*-----------------------------------------------------------*/
\r
315 static portFORCE_INLINE void vPortSetBASEPRI( uint32_t ulBASEPRI )
\r
319 /* Barrier instructions are not used as this function is only used to
\r
320 * lower the BASEPRI value. */
\r
322 msr basepri, ulBASEPRI
\r
326 /*-----------------------------------------------------------*/
\r
328 static portFORCE_INLINE void vPortRaiseBASEPRI( void )
\r
330 uint32_t ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY;
\r
334 /* Set BASEPRI to the max syscall priority to effect a critical
\r
337 msr basepri, ulNewBASEPRI
\r
343 /*-----------------------------------------------------------*/
\r
345 static portFORCE_INLINE void vPortClearBASEPRIFromISR( void )
\r
349 /* Set BASEPRI to 0 so no interrupts are masked. This function is only
\r
350 * used to lower the mask in an interrupt, so memory barriers are not
\r
357 /*-----------------------------------------------------------*/
\r
359 static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void )
\r
361 uint32_t ulReturn, ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY;
\r
365 /* Set BASEPRI to the max syscall priority to effect a critical
\r
368 mrs ulReturn, basepri
\r
369 msr basepri, ulNewBASEPRI
\r
377 /*-----------------------------------------------------------*/
\r
379 static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void )
\r
381 uint32_t ulCurrentInterrupt;
\r
382 BaseType_t xReturn;
\r
384 /* Obtain the number of the currently executing interrupt. */
\r
387 mrs ulCurrentInterrupt, ipsr
\r
390 if( ulCurrentInterrupt == 0 )
\r
401 /*-----------------------------------------------------------*/
\r
403 #ifndef configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY
\r
404 #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
405 #define configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY 0
\r
407 /*-----------------------------------------------------------*/
\r
415 #endif /* PORTMACRO_H */
\r