]> begriffs open source - freertos/blob - portable/GCC/IA32_flat/portmacro.h
RP2040: Fix compiler warning and comment (#509)
[freertos] / portable / GCC / IA32_flat / portmacro.h
1 /*
2  * FreeRTOS SMP Kernel V202110.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 #ifndef PORTMACRO_H
29 #define PORTMACRO_H
30
31 #ifdef __cplusplus
32         extern "C" {
33 #endif
34
35 /*-----------------------------------------------------------
36  * Port specific definitions.
37  *
38  * The settings in this file configure FreeRTOS correctly for the given hardware
39  * and compiler.
40  *
41  * These settings should not be altered.
42  *-----------------------------------------------------------
43  */
44
45 /* Type definitions. */
46 #define portCHAR                char
47 #define portFLOAT               float
48 #define portDOUBLE              double
49 #define portLONG                long
50 #define portSHORT               short
51 #define portSTACK_TYPE  uint32_t
52 #define portBASE_TYPE   long
53
54 typedef portSTACK_TYPE StackType_t;
55 typedef long BaseType_t;
56 typedef unsigned long UBaseType_t;
57
58 typedef uint32_t TickType_t;
59 #define portMAX_DELAY ( ( TickType_t ) 0xffffffffUL )
60
61 /*-----------------------------------------------------------*/
62
63 /* Hardware specifics. */
64 #define portSTACK_GROWTH                        ( -1 )
65 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
66 #define portBYTE_ALIGNMENT                      32
67
68 /*-----------------------------------------------------------*/
69
70 /* Task utilities. */
71
72 /* The interrupt priority (for vectors 16 to 255) is determined using vector/16.
73 The quotient is rounded to the nearest integer with 1 being the lowest priority
74 and 15 is the highest.  Therefore the following two interrupts are at the lowest
75 priority.  *NOTE 1* If the yield vector is changed then it must also be changed
76 in the portYIELD_INTERRUPT definition immediately below. */
77 #define portAPIC_TIMER_INT_VECTOR               ( 0x21 )
78 #define portAPIC_YIELD_INT_VECTOR               ( 0x20 )
79
80 /* Build yield interrupt instruction. */
81 #define portYIELD_INTERRUPT "int $0x20"
82
83 /* APIC register addresses. */
84 #define portAPIC_EOI                                    ( *( ( volatile uint32_t * ) 0xFEE000B0UL ) )
85
86 /* APIC bit definitions. */
87 #define portAPIC_ENABLE_BIT                             ( 1UL << 8UL )
88 #define portAPIC_TIMER_PERIODIC                 ( 1UL << 17UL )
89 #define portAPIC_DISABLE                                ( 1UL << 16UL )
90 #define portAPIC_NMI                                    ( 4 << 8)
91 #define portAPIC_DIV_16                                 ( 0x03 )
92
93 /* Define local API register addresses. */
94 #define portAPIC_ID_REGISTER                    ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x20UL  ) ) )
95 #define portAPIC_SPURIOUS_INT                   ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0xF0UL  ) ) )
96 #define portAPIC_LVT_TIMER                              ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x320UL ) ) )
97 #define portAPIC_TIMER_INITIAL_COUNT    ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x380UL ) ) )
98 #define portAPIC_TIMER_CURRENT_COUNT    ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x390UL ) ) )
99 #define portAPIC_TASK_PRIORITY                  ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x80UL  ) ) )
100 #define portAPIC_LVT_ERROR                              ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x370UL ) ) )
101 #define portAPIC_ERROR_STATUS                   ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x280UL ) ) )
102 #define portAPIC_LDR                                    ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0xD0UL  ) ) )
103 #define portAPIC_TMRDIV                                 ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x3E0UL ) ) )
104 #define portAPIC_LVT_PERF                               ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x340UL ) ) )
105 #define portAPIC_LVT_LINT0                              ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x350UL ) ) )
106 #define portAPIC_LVT_LINT1                              ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x360UL ) ) )
107
108 /* Don't yield if inside a critical section - instead hold the yield pending
109 so it is performed when the critical section is exited. */
110 #define portYIELD()                                                             \
111 {                                                                                                       \
112 extern volatile uint32_t ulCriticalNesting;                     \
113 extern volatile uint32_t ulPortYieldPending;            \
114         if( ulCriticalNesting != 0 )                                    \
115         {                                                                                               \
116                 ulPortYieldPending = pdTRUE;                            \
117         }                                                                                               \
118         else                                                                                    \
119         {                                                                                               \
120                 __asm volatile( portYIELD_INTERRUPT );          \
121         }                                                                                               \
122 }
123
124 /* Called at the end of an ISR that can cause a context switch - pend a yield if
125 xSwithcRequired is not false. */
126 #define portEND_SWITCHING_ISR( xSwitchRequired )        \
127 {                                                                                                       \
128 extern volatile uint32_t ulPortYieldPending;            \
129         if( xSwitchRequired != pdFALSE )                                \
130         {                                                                                               \
131                 ulPortYieldPending = 1;                                         \
132         }                                                                                               \
133 }
134
135 /* Same as portEND_SWITCHING_ISR() - take your pick which name to use. */
136 #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
137
138 /*-----------------------------------------------------------
139  * Critical section control
140  *----------------------------------------------------------*/
141
142 /* Critical sections for use in interrupts. */
143 #define portSET_INTERRUPT_MASK_FROM_ISR()               ulPortSetInterruptMask()
144 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x)    vPortClearInterruptMask( x )
145
146 extern void vPortEnterCritical( void );
147 extern void vPortExitCritical( void );
148 extern uint32_t ulPortSetInterruptMask( void );
149 extern void vPortClearInterruptMask( uint32_t ulNewMaskValue );
150
151 /* These macros do not globally disable/enable interrupts.  They do mask off
152 interrupts that have a priority below configMAX_API_CALL_INTERRUPT_PRIORITY. */
153 #define portENTER_CRITICAL()            vPortEnterCritical()
154 #define portEXIT_CRITICAL()                     vPortExitCritical()
155 #define portDISABLE_INTERRUPTS()        __asm volatile( "cli" )
156 #define portENABLE_INTERRUPTS()         __asm volatile( "sti" )
157
158 /*-----------------------------------------------------------*/
159
160 /* Task function macros as described on the FreeRTOS.org WEB site.  These are
161 not required for this port but included in case common demo code that uses these
162 macros is used. */
163 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters )      void vFunction( void *pvParameters )
164 #define portTASK_FUNCTION( vFunction, pvParameters )    void vFunction( void *pvParameters )
165
166 /* Architecture specific optimisations. */
167 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
168
169         /* Store/clear the ready priorities in a bit map. */
170         #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities )    \
171                 __asm volatile( "bsr %1, %0\n\t"                                                                        \
172                                                 :"=r"(uxTopPriority) : "rm"(uxReadyPriorities) : "cc" )
173
174         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
175         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
176
177 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
178
179 #define portNOP() __asm volatile( "NOP" )
180
181 /*-----------------------------------------------------------
182  * Misc
183  *----------------------------------------------------------*/
184
185 #define portNUM_VECTORS         256
186 #define portMAX_PRIORITY        15
187 typedef void ( *ISR_Handler_t ) ( void );
188
189 /* Any task that uses the floating point unit MUST call vPortTaskUsesFPU()
190 before any floating point instructions are executed. */
191 #ifndef configSUPPORT_FPU
192         #define configSUPPORT_FPU 0
193 #endif
194
195 #if configSUPPORT_FPU == 1
196         void vPortTaskUsesFPU( void );
197         #define portTASK_USES_FLOATING_POINT() vPortTaskUsesFPU()
198 #endif
199
200 /* See the comments under the configUSE_COMMON_INTERRUPT_ENTRY_POINT definition
201 below. */
202 BaseType_t xPortRegisterCInterruptHandler( ISR_Handler_t pxHandler, uint32_t ulVectorNumber );
203 BaseType_t xPortInstallInterruptHandler( ISR_Handler_t pxHandler, uint32_t ulVectorNumber );
204
205 #ifndef configAPIC_BASE
206         /* configAPIC_BASE_ADDRESS sets the base address of the local APIC.  It can
207         be overridden in FreeRTOSConfig.h should it not be constant. */
208         #define configAPIC_BASE 0xFEE00000UL
209 #endif
210
211 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
212         /* The FreeRTOS scheduling algorithm selects the task that will enter the
213         Running state.  configUSE_PORT_OPTIMISED_TASK_SELECTION is used to set how
214         that is done.
215
216         If configUSE_PORT_OPTIMISED_TASK_SELECTION is set to 0 then the task to
217         enter the Running state is selected using a portable algorithm written in
218         C.  This is the slowest method, but the algorithm does not restrict the
219         maximum number of unique RTOS task priorities that are available.
220
221         If configUSE_PORT_OPTIMISED_TASK_SELECTION is set to 1 then the task to
222         enter the Running state is selected using a single assembly instruction.
223         This is the fastest method, but restricts the maximum number of unique RTOS
224         task priorities to 32 (the same task priority can be assigned to any number
225         of RTOS tasks). */
226         #warning configUSE_PORT_OPTIMISED_TASK_SELECTION was not defined in FreeRTOSConfig.h and has been defaulted to 1
227         #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
228 #endif
229
230 #ifndef configUSE_COMMON_INTERRUPT_ENTRY_POINT
231         /* There are two ways of implementing interrupt handlers:
232
233                 1) As standard C functions -
234
235                 This method can only be used if configUSE_COMMON_INTERRUPT_ENTRY_POINT
236                 is set to 1.  The C function is installed using
237                 xPortRegisterCInterruptHandler().
238
239                 This is the simplest of the two methods but incurs a slightly longer
240                 interrupt entry time.
241
242                 2) By using an assembly stub that wraps the handler in the FreeRTOS
243                    portFREERTOS_INTERRUPT_ENTRY and portFREERTOS_INTERRUPT_EXIT macros.
244
245                 This method can always be used.  It is slightly more complex than
246                 method 1 but benefits from a faster interrupt entry time. */
247         #warning configUSE_COMMON_INTERRUPT_ENTRY_POINT was not defined in FreeRTOSConfig.h and has been defaulted to 1.
248         #define configUSE_COMMON_INTERRUPT_ENTRY_POINT  1
249 #endif
250
251 #ifndef configISR_STACK_SIZE
252         /* Interrupt entry code will switch the stack in use to a dedicated system
253         stack.
254
255         configISR_STACK_SIZE defines the number of 32-bit values that can be stored
256         on the system stack, and must be large enough to hold a potentially nested
257         interrupt stack frame. */
258
259         #error configISR_STACK_SIZE was not defined in FreeRTOSConfig.h.
260 #endif
261
262 #ifndef configMAX_API_CALL_INTERRUPT_PRIORITY
263         /* Interrupt safe FreeRTOS functions (those that end in "FromISR" must not
264         be called from an interrupt that has a priority above that set by
265         configMAX_API_CALL_INTERRUPT_PRIORITY.  */
266         #warning configMAX_API_CALL_INTERRUPT_PRIORITY was not defined in FreeRTOSConfig.h and has been defaulted to 10
267         #define configMAX_API_CALL_INTERRUPT_PRIORITY 10
268 #endif
269
270 #ifndef configSUPPORT_FPU
271         #warning configSUPPORT_FPU was not defined in FreeRTOSConfig.h and has been defaulted to 0
272         #define configSUPPORT_FPU 0
273 #endif
274
275 /* The value written to the task priority register to raise the interrupt mask
276 to the maximum from which FreeRTOS API calls can be made. */
277 #define portAPIC_PRIORITY_SHIFT         ( 4UL )
278 #define portAPIC_MAX_SUB_PRIORITY       ( 0x0fUL )
279 #define portMAX_API_CALL_PRIORITY               ( ( configMAX_API_CALL_INTERRUPT_PRIORITY << portAPIC_PRIORITY_SHIFT ) | portAPIC_MAX_SUB_PRIORITY )
280
281 /* Asserts if interrupt safe FreeRTOS functions are called from a priority
282 above the max system call interrupt priority. */
283 #define portAPIC_PROCESSOR_PRIORITY     ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0xA0UL  ) ) )
284 #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() configASSERT( ( portAPIC_PROCESSOR_PRIORITY ) <= ( portMAX_API_CALL_PRIORITY ) )
285
286 #ifdef __cplusplus
287         } /* extern C */
288 #endif
289
290 #endif /* PORTMACRO_H */
291