]> begriffs open source - freertos/blob - portable/RVDS/ARM_CM3/portmacro.h
[AUTO][RELEASE]: Bump file header version to "10.5.1"
[freertos] / portable / RVDS / ARM_CM3 / portmacro.h
1 /*\r
2  * FreeRTOS Kernel V10.5.1\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 /* 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
57 \r
58     typedef portSTACK_TYPE   StackType_t;\r
59     typedef long             BaseType_t;\r
60     typedef unsigned long    UBaseType_t;\r
61 \r
62     #if ( configUSE_16_BIT_TICKS == 1 )\r
63         typedef uint16_t     TickType_t;\r
64         #define portMAX_DELAY              ( TickType_t ) 0xffff\r
65     #else\r
66         typedef uint32_t     TickType_t;\r
67         #define portMAX_DELAY              ( TickType_t ) 0xffffffffUL\r
68 \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
72     #endif\r
73 /*-----------------------------------------------------------*/\r
74 \r
75 /* Architecture specifics. */\r
76     #define portSTACK_GROWTH          ( -1 )\r
77     #define portTICK_PERIOD_MS        ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
78     #define portBYTE_ALIGNMENT        8\r
79 \r
80 /* Constants used with memory barrier intrinsics. */\r
81     #define portSY_FULL_READ_WRITE    ( 15 )\r
82 \r
83 /*-----------------------------------------------------------*/\r
84 \r
85 /* Scheduler utilities. */\r
86     #define portYIELD()                                 \\r
87     {                                                   \\r
88         /* Set a PendSV to request a context switch. */ \\r
89         portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; \\r
90                                                         \\r
91         /* Barriers are normally not required but do ensure the code is completely \\r
92          * within the specified behaviour for the architecture. */ \\r
93         __dsb( portSY_FULL_READ_WRITE );                           \\r
94         __isb( portSY_FULL_READ_WRITE );                           \\r
95     }\r
96 /*-----------------------------------------------------------*/\r
97 \r
98     #define portNVIC_INT_CTRL_REG     ( *( ( volatile uint32_t * ) 0xe000ed04 ) )\r
99     #define portNVIC_PENDSVSET_BIT    ( 1UL << 28UL )\r
100     #define portEND_SWITCHING_ISR( xSwitchRequired )    do { if( xSwitchRequired != pdFALSE ) portYIELD(); } while( 0 )\r
101     #define portYIELD_FROM_ISR( x )                     portEND_SWITCHING_ISR( x )\r
102 /*-----------------------------------------------------------*/\r
103 \r
104 /* Critical section management. */\r
105     extern void vPortEnterCritical( void );\r
106     extern void vPortExitCritical( void );\r
107 \r
108     #define portDISABLE_INTERRUPTS()                  vPortRaiseBASEPRI()\r
109     #define portENABLE_INTERRUPTS()                   vPortSetBASEPRI( 0 )\r
110     #define portENTER_CRITICAL()                      vPortEnterCritical()\r
111     #define portEXIT_CRITICAL()                       vPortExitCritical()\r
112     #define portSET_INTERRUPT_MASK_FROM_ISR()         ulPortRaiseBASEPRI()\r
113     #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x )    vPortSetBASEPRI( x )\r
114 \r
115 /*-----------------------------------------------------------*/\r
116 \r
117 /* Tickless idle/low power functionality. */\r
118     #ifndef portSUPPRESS_TICKS_AND_SLEEP\r
119         extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime );\r
120         #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime )    vPortSuppressTicksAndSleep( xExpectedIdleTime )\r
121     #endif\r
122 /*-----------------------------------------------------------*/\r
123 \r
124 /* Port specific optimisations. */\r
125     #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION\r
126         #define configUSE_PORT_OPTIMISED_TASK_SELECTION    1\r
127     #endif\r
128 \r
129     #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
130 \r
131 /* Check the configuration. */\r
132         #if ( configMAX_PRIORITIES > 32 )\r
133             #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
134         #endif\r
135 \r
136 /* Store/clear the ready priorities in a bit map. */\r
137         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities )    ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
138         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities )     ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
139 \r
140 /*-----------------------------------------------------------*/\r
141 \r
142         #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities )    uxTopPriority = ( 31UL - ( uint32_t ) __clz( ( uxReadyPriorities ) ) )\r
143 \r
144     #endif /* taskRECORD_READY_PRIORITY */\r
145 /*-----------------------------------------------------------*/\r
146 \r
147 /* Task function macros as described on the FreeRTOS.org WEB site.  These are\r
148  * not necessary for to use this port.  They are defined so the common demo files\r
149  * (which build with all the ports) will build. */\r
150     #define portTASK_FUNCTION_PROTO( vFunction, pvParameters )    void vFunction( void * pvParameters )\r
151     #define portTASK_FUNCTION( vFunction, pvParameters )          void vFunction( void * pvParameters )\r
152 /*-----------------------------------------------------------*/\r
153 \r
154     #ifdef configASSERT\r
155         void vPortValidateInterruptPriority( void );\r
156         #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID()    vPortValidateInterruptPriority()\r
157     #endif\r
158 \r
159 /* portNOP() is not required by this port. */\r
160     #define portNOP()\r
161 \r
162     #define portINLINE              __inline\r
163 \r
164     #ifndef portFORCE_INLINE\r
165         #define portFORCE_INLINE    __forceinline\r
166     #endif\r
167 \r
168 /*-----------------------------------------------------------*/\r
169 \r
170     static portFORCE_INLINE void vPortSetBASEPRI( uint32_t ulBASEPRI )\r
171     {\r
172         __asm\r
173         {\r
174             /* Barrier instructions are not used as this function is only used to\r
175              * lower the BASEPRI value. */\r
176 /* *INDENT-OFF* */\r
177             msr basepri, ulBASEPRI\r
178 /* *INDENT-ON* */\r
179         }\r
180     }\r
181 /*-----------------------------------------------------------*/\r
182 \r
183     static portFORCE_INLINE void vPortRaiseBASEPRI( void )\r
184     {\r
185         uint32_t ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY;\r
186 \r
187         __asm\r
188         {\r
189             /* Set BASEPRI to the max syscall priority to effect a critical\r
190              * section. */\r
191 /* *INDENT-OFF* */\r
192             msr basepri, ulNewBASEPRI\r
193             dsb\r
194             isb\r
195 /* *INDENT-ON* */\r
196         }\r
197     }\r
198 /*-----------------------------------------------------------*/\r
199 \r
200     static portFORCE_INLINE void vPortClearBASEPRIFromISR( void )\r
201     {\r
202         __asm\r
203         {\r
204             /* Set BASEPRI to 0 so no interrupts are masked.  This function is only\r
205              * used to lower the mask in an interrupt, so memory barriers are not\r
206              * used. */\r
207 /* *INDENT-OFF* */\r
208             msr basepri, # 0\r
209 /* *INDENT-ON* */\r
210         }\r
211     }\r
212 /*-----------------------------------------------------------*/\r
213 \r
214     static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void )\r
215     {\r
216         uint32_t ulReturn, ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY;\r
217 \r
218         __asm\r
219         {\r
220             /* Set BASEPRI to the max syscall priority to effect a critical\r
221              * section. */\r
222 /* *INDENT-OFF* */\r
223             mrs ulReturn, basepri\r
224             msr basepri, ulNewBASEPRI\r
225             dsb\r
226             isb\r
227 /* *INDENT-ON* */\r
228         }\r
229 \r
230         return ulReturn;\r
231     }\r
232 /*-----------------------------------------------------------*/\r
233 \r
234     static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void )\r
235     {\r
236         uint32_t ulCurrentInterrupt;\r
237         BaseType_t xReturn;\r
238 \r
239         /* Obtain the number of the currently executing interrupt. */\r
240         __asm\r
241         {\r
242 /* *INDENT-OFF* */\r
243             mrs ulCurrentInterrupt, ipsr\r
244 /* *INDENT-ON* */\r
245         }\r
246 \r
247         if( ulCurrentInterrupt == 0 )\r
248         {\r
249             xReturn = pdFALSE;\r
250         }\r
251         else\r
252         {\r
253             xReturn = pdTRUE;\r
254         }\r
255 \r
256         return xReturn;\r
257     }\r
258 \r
259 \r
260 /* *INDENT-OFF* */\r
261 #ifdef __cplusplus\r
262     }\r
263 #endif\r
264 /* *INDENT-ON* */\r
265 \r
266 #endif /* PORTMACRO_H */\r