]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/IA32_flat/portmacro.h
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Source / portable / GCC / IA32_flat / portmacro.h
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 #ifndef PORTMACRO_H\r
71 #define PORTMACRO_H\r
72 \r
73 #ifdef __cplusplus\r
74         extern "C" {\r
75 #endif\r
76 \r
77 /*-----------------------------------------------------------\r
78  * Port specific definitions.\r
79  *\r
80  * The settings in this file configure FreeRTOS correctly for the given hardware\r
81  * and compiler.\r
82  *\r
83  * These settings should not be altered.\r
84  *-----------------------------------------------------------\r
85  */\r
86 \r
87 /* Type definitions. */\r
88 #define portCHAR                char\r
89 #define portFLOAT               float\r
90 #define portDOUBLE              double\r
91 #define portLONG                long\r
92 #define portSHORT               short\r
93 #define portSTACK_TYPE  uint32_t\r
94 #define portBASE_TYPE   long\r
95 \r
96 typedef portSTACK_TYPE StackType_t;\r
97 typedef long BaseType_t;\r
98 typedef unsigned long UBaseType_t;\r
99 \r
100 typedef uint32_t TickType_t;\r
101 #define portMAX_DELAY ( ( TickType_t ) 0xffffffffUL )\r
102 \r
103 /*-----------------------------------------------------------*/\r
104 \r
105 /* Hardware specifics. */\r
106 #define portSTACK_GROWTH                        ( -1 )\r
107 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
108 #define portBYTE_ALIGNMENT                      32\r
109 \r
110 /*-----------------------------------------------------------*/\r
111 \r
112 /* Task utilities. */\r
113 \r
114 /* The interrupt priority (for vectors 16 to 255) is determined using vector/16.\r
115 The quotient is rounded to the nearest integer with 1 being the lowest priority\r
116 and 15 is the highest.  Therefore the following two interrupts are at the lowest\r
117 priority.  *NOTE 1* If the yield vector is changed then it must also be changed\r
118 in the portYIELD_INTERRUPT definition immediately below. */\r
119 #define portAPIC_TIMER_INT_VECTOR               ( 0x21 )\r
120 #define portAPIC_YIELD_INT_VECTOR               ( 0x20 )\r
121 \r
122 /* Build yield interrupt instruction. */\r
123 #define portYIELD_INTERRUPT "int $0x20"\r
124 \r
125 /* APIC register addresses. */\r
126 #define portAPIC_EOI                                    ( *( ( volatile uint32_t * ) 0xFEE000B0UL ) )\r
127 \r
128 /* APIC bit definitions. */\r
129 #define portAPIC_ENABLE_BIT                             ( 1UL << 8UL )\r
130 #define portAPIC_TIMER_PERIODIC                 ( 1UL << 17UL )\r
131 #define portAPIC_DISABLE                                ( 1UL << 16UL )\r
132 #define portAPIC_NMI                                    ( 4 << 8)\r
133 #define portAPIC_DIV_16                                 ( 0x03 )\r
134 \r
135 /* Define local API register addresses. */\r
136 #define portAPIC_ID_REGISTER                    ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x20UL  ) ) )\r
137 #define portAPIC_SPURIOUS_INT                   ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0xF0UL  ) ) )\r
138 #define portAPIC_LVT_TIMER                              ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x320UL ) ) )\r
139 #define portAPIC_TIMER_INITIAL_COUNT    ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x380UL ) ) )\r
140 #define portAPIC_TIMER_CURRENT_COUNT    ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x390UL ) ) )\r
141 #define portAPIC_TASK_PRIORITY                  ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x80UL  ) ) )\r
142 #define portAPIC_LVT_ERROR                              ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x370UL ) ) )\r
143 #define portAPIC_ERROR_STATUS                   ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x280UL ) ) )\r
144 #define portAPIC_LDR                                    ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0xD0UL  ) ) )\r
145 #define portAPIC_TMRDIV                                 ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x3E0UL ) ) )\r
146 #define portAPIC_LVT_PERF                               ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x340UL ) ) )\r
147 #define portAPIC_LVT_LINT0                              ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x350UL ) ) )\r
148 #define portAPIC_LVT_LINT1                              ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0x360UL ) ) )\r
149 \r
150 /* Don't yield if inside a critical section - instead hold the yield pending\r
151 so it is performed when the critical section is exited. */\r
152 #define portYIELD()                                                             \\r
153 {                                                                                                       \\r
154 extern volatile uint32_t ulCriticalNesting;                     \\r
155 extern volatile uint32_t ulPortYieldPending;            \\r
156         if( ulCriticalNesting != 0 )                                    \\r
157         {                                                                                               \\r
158                 ulPortYieldPending = pdTRUE;                            \\r
159         }                                                                                               \\r
160         else                                                                                    \\r
161         {                                                                                               \\r
162                 __asm volatile( portYIELD_INTERRUPT );          \\r
163         }                                                                                               \\r
164 }\r
165 \r
166 /* Called at the end of an ISR that can cause a context switch - pend a yield if\r
167 xSwithcRequired is not false. */\r
168 #define portEND_SWITCHING_ISR( xSwitchRequired )        \\r
169 {                                                                                                       \\r
170 extern volatile uint32_t ulPortYieldPending;            \\r
171         if( xSwitchRequired != pdFALSE )                                \\r
172         {                                                                                               \\r
173                 ulPortYieldPending = 1;                                         \\r
174         }                                                                                               \\r
175 }\r
176 \r
177 /* Same as portEND_SWITCHING_ISR() - take your pick which name to use. */\r
178 #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )\r
179 \r
180 /*-----------------------------------------------------------\r
181  * Critical section control\r
182  *----------------------------------------------------------*/\r
183 \r
184 /* Critical sections for use in interrupts. */\r
185 #define portSET_INTERRUPT_MASK_FROM_ISR()               ulPortSetInterruptMask()\r
186 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x)    vPortClearInterruptMask( x )\r
187 \r
188 extern void vPortEnterCritical( void );\r
189 extern void vPortExitCritical( void );\r
190 extern uint32_t ulPortSetInterruptMask( void );\r
191 extern void vPortClearInterruptMask( uint32_t ulNewMaskValue );\r
192 \r
193 /* These macros do not globally disable/enable interrupts.  They do mask off\r
194 interrupts that have a priority below configMAX_API_CALL_INTERRUPT_PRIORITY. */\r
195 #define portENTER_CRITICAL()            vPortEnterCritical()\r
196 #define portEXIT_CRITICAL()                     vPortExitCritical()\r
197 #define portDISABLE_INTERRUPTS()        __asm volatile( "cli" )\r
198 #define portENABLE_INTERRUPTS()         __asm volatile( "sti" )\r
199 \r
200 /*-----------------------------------------------------------*/\r
201 \r
202 /* Task function macros as described on the FreeRTOS.org WEB site.  These are\r
203 not required for this port but included in case common demo code that uses these\r
204 macros is used. */\r
205 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters )      void vFunction( void *pvParameters )\r
206 #define portTASK_FUNCTION( vFunction, pvParameters )    void vFunction( void *pvParameters )\r
207 \r
208 /* Architecture specific optimisations. */\r
209 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
210 \r
211         /* Store/clear the ready priorities in a bit map. */\r
212         #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities )    \\r
213                 __asm volatile( "bsr %1, %0\n\t"                                                                        \\r
214                                                 :"=r"(uxTopPriority) : "rm"(uxReadyPriorities) : "cc" )\r
215 \r
216         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
217         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
218 \r
219 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
220 \r
221 #define portNOP() __asm volatile( "NOP" )\r
222 \r
223 /*-----------------------------------------------------------\r
224  * Misc\r
225  *----------------------------------------------------------*/\r
226 \r
227 #define portNUM_VECTORS         256\r
228 #define portMAX_PRIORITY        15\r
229 typedef void ( *ISR_Handler_t ) ( void );\r
230 \r
231 /* Any task that uses the floating point unit MUST call vPortTaskUsesFPU()\r
232 before any floating point instructions are executed. */\r
233 #ifndef configSUPPORT_FPU\r
234         #define configSUPPORT_FPU 0\r
235 #endif\r
236 \r
237 #if configSUPPORT_FPU == 1\r
238         void vPortTaskUsesFPU( void );\r
239         #define portTASK_USES_FLOATING_POINT() vPortTaskUsesFPU()\r
240 #endif\r
241 \r
242 /* See the comments under the configUSE_COMMON_INTERRUPT_ENTRY_POINT definition\r
243 below. */\r
244 BaseType_t xPortRegisterCInterruptHandler( ISR_Handler_t pxHandler, uint32_t ulVectorNumber );\r
245 BaseType_t xPortInstallInterruptHandler( ISR_Handler_t pxHandler, uint32_t ulVectorNumber );\r
246 \r
247 #ifndef configAPIC_BASE\r
248         /* configAPIC_BASE_ADDRESS sets the base address of the local APIC.  It can\r
249         be overridden in FreeRTOSConfig.h should it not be constant. */\r
250         #define configAPIC_BASE 0xFEE00000UL\r
251 #endif\r
252 \r
253 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION\r
254         /* The FreeRTOS scheduling algorithm selects the task that will enter the\r
255         Running state.  configUSE_PORT_OPTIMISED_TASK_SELECTION is used to set how\r
256         that is done.\r
257 \r
258         If configUSE_PORT_OPTIMISED_TASK_SELECTION is set to 0 then the task to\r
259         enter the Running state is selected using a portable algorithm written in\r
260         C.  This is the slowest method, but the algorithm does not restrict the\r
261         maximum number of unique RTOS task priorities that are available.\r
262 \r
263         If configUSE_PORT_OPTIMISED_TASK_SELECTION is set to 1 then the task to\r
264         enter the Running state is selected using a single assembly instruction.\r
265         This is the fastest method, but restricts the maximum number of unique RTOS\r
266         task priorities to 32 (the same task priority can be assigned to any number\r
267         of RTOS tasks). */\r
268         #warning configUSE_PORT_OPTIMISED_TASK_SELECTION was not defined in FreeRTOSConfig.h and has been defaulted to 1\r
269         #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1\r
270 #endif\r
271 \r
272 #ifndef configUSE_COMMON_INTERRUPT_ENTRY_POINT\r
273         /* There are two ways of implementing interrupt handlers:\r
274 \r
275                 1) As standard C functions -\r
276 \r
277                 This method can only be used if configUSE_COMMON_INTERRUPT_ENTRY_POINT\r
278                 is set to 1.  The C function is installed using\r
279                 xPortRegisterCInterruptHandler().\r
280 \r
281                 This is the simplest of the two methods but incurs a slightly longer\r
282                 interrupt entry time.\r
283 \r
284                 2) By using an assembly stub that wraps the handler in the FreeRTOS\r
285                    portFREERTOS_INTERRUPT_ENTRY and portFREERTOS_INTERRUPT_EXIT macros.\r
286 \r
287                 This method can always be used.  It is slightly more complex than\r
288                 method 1 but benefits from a faster interrupt entry time. */\r
289         #warning config_USE_COMMON_INTERRUPT_ENTRY_POINT was not defined in FreeRTOSConfig.h and has been defaulted to 1.\r
290         #define configUSE_COMMON_INTERRUPT_ENTRY_POINT  1\r
291 #endif\r
292 \r
293 #ifndef configISR_STACK_SIZE\r
294         /* Interrupt entry code will switch the stack in use to a dedicated system \r
295         stack.\r
296 \r
297         configISR_STACK_SIZE defines the number of 32-bit values that can be stored\r
298         on the system stack, and must be large enough to hold a potentially nested\r
299         interrupt stack frame. */\r
300 \r
301         #error configISE_STACK_SIZE was not defined in FreeRTOSConfig.h.\r
302 #endif\r
303 \r
304 #ifndef configMAX_API_CALL_INTERRUPT_PRIORITY\r
305         /* Interrupt safe FreeRTOS functions (those that end in "FromISR" must not\r
306         be called from an interrupt that has a priority above that set by\r
307         configMAX_API_CALL_INTERRUPT_PRIORITY.  */\r
308         #warning configMAX_API_CALL_INTERRUPT_PRIORITY was not defined in FreeRTOSConfig.h and has been defaulted to 10\r
309         #define configMAX_API_CALL_INTERRUPT_PRIORITY 10\r
310 #endif\r
311 \r
312 #ifndef configSUPPORT_FPU\r
313         #warning configSUPPORT_FPU was not defined in FreeRTOSConfig.h and has been defaulted to 0\r
314         #define configSUPPORT_FPU 0\r
315 #endif\r
316 \r
317 /* The value written to the task priority register to raise the interrupt mask\r
318 to the maximum from which FreeRTOS API calls can be made. */\r
319 #define portAPIC_PRIORITY_SHIFT         ( 4UL )\r
320 #define portAPIC_MAX_SUB_PRIORITY       ( 0x0fUL )\r
321 #define portMAX_API_CALL_PRIORITY               ( ( configMAX_API_CALL_INTERRUPT_PRIORITY << portAPIC_PRIORITY_SHIFT ) | portAPIC_MAX_SUB_PRIORITY )\r
322 \r
323 /* Asserts if interrupt safe FreeRTOS functions are called from a priority\r
324 above the max system call interrupt priority. */\r
325 #define portAPIC_PROCESSOR_PRIORITY     ( *( ( volatile uint32_t * ) ( configAPIC_BASE + 0xA0UL  ) ) )\r
326 #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() configASSERT( ( portAPIC_PROCESSOR_PRIORITY ) <= ( portMAX_API_CALL_PRIORITY ) )\r
327 \r
328 #ifdef __cplusplus\r
329         } /* extern C */\r
330 #endif\r
331 \r
332 #endif /* PORTMACRO_H */\r
333 \r