]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/MicroBlazeV9/portmacro.h
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Source / portable / GCC / MicroBlazeV9 / portmacro.h
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 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. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\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 /* BSP includes. */\r
37 #include <mb_interface.h>\r
38 #include <xparameters.h>\r
39 \r
40 /*-----------------------------------------------------------\r
41  * Port specific definitions.\r
42  *\r
43  * The settings in this file configure FreeRTOS correctly for the\r
44  * given hardware and compiler.\r
45  *\r
46  * These settings should not be altered.\r
47  *-----------------------------------------------------------\r
48  */\r
49 \r
50 /* Type definitions. */\r
51 #define portCHAR                char\r
52 #define portFLOAT               float\r
53 #define portDOUBLE              double\r
54 #define portLONG                long\r
55 #define portSHORT               short\r
56 #define portSTACK_TYPE  uint32_t\r
57 #define portBASE_TYPE   long\r
58 \r
59 typedef portSTACK_TYPE StackType_t;\r
60 typedef long BaseType_t;\r
61 typedef unsigned long UBaseType_t;\r
62 \r
63 #if( configUSE_16_BIT_TICKS == 1 )\r
64         typedef uint16_t TickType_t;\r
65         #define portMAX_DELAY ( TickType_t ) 0xffff\r
66 #else\r
67         typedef uint32_t TickType_t;\r
68         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\r
69 \r
70         /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do\r
71         not need to be guarded with a critical section. */\r
72         #define portTICK_TYPE_IS_ATOMIC 1\r
73 #endif\r
74 /*-----------------------------------------------------------*/\r
75 \r
76 /* Interrupt control macros and functions. */\r
77 void microblaze_disable_interrupts( void );\r
78 void microblaze_enable_interrupts( void );\r
79 #define portDISABLE_INTERRUPTS()        microblaze_disable_interrupts()\r
80 #define portENABLE_INTERRUPTS()         microblaze_enable_interrupts()\r
81 /*-----------------------------------------------------------*/\r
82 \r
83 /* Critical section macros. */\r
84 void vPortEnterCritical( void );\r
85 void vPortExitCritical( void );\r
86 #define portENTER_CRITICAL()            {                                                                                                                               \\r
87                                                                                 extern volatile UBaseType_t uxCriticalNesting;                          \\r
88                                                                                 microblaze_disable_interrupts();                                                        \\r
89                                                                                 uxCriticalNesting++;                                                                            \\r
90                                                                         }\r
91 \r
92 #define portEXIT_CRITICAL()                     {                                                                                                                               \\r
93                                                                                 extern volatile UBaseType_t uxCriticalNesting;                          \\r
94                                                                                 /* Interrupts are disabled, so we can */                                        \\r
95                                                                                 /* access the variable directly. */                                                     \\r
96                                                                                 uxCriticalNesting--;                                                                            \\r
97                                                                                 if( uxCriticalNesting == 0 )                                                            \\r
98                                                                                 {                                                                                                                       \\r
99                                                                                         /* The nesting has unwound and we                                               \\r
100                                                                                         can enable interrupts again. */                                                 \\r
101                                                                                         portENABLE_INTERRUPTS();                                                                \\r
102                                                                                 }                                                                                                                       \\r
103                                                                         }\r
104 \r
105 /*-----------------------------------------------------------*/\r
106 \r
107 /* The yield macro maps directly to the vPortYield() function. */\r
108 void vPortYield( void );\r
109 #define portYIELD() vPortYield()\r
110 \r
111 /* portYIELD_FROM_ISR() does not directly call vTaskSwitchContext(), but instead\r
112 sets a flag to say that a yield has been requested.  The interrupt exit code\r
113 then checks this flag, and calls vTaskSwitchContext() before restoring a task\r
114 context, if the flag is not false.  This is done to prevent multiple calls to\r
115 vTaskSwitchContext() being made from a single interrupt, as a single interrupt\r
116 can result in multiple peripherals being serviced. */\r
117 extern volatile uint32_t ulTaskSwitchRequested;\r
118 #define portYIELD_FROM_ISR( x ) if( ( x ) != pdFALSE ) ulTaskSwitchRequested = 1\r
119 \r
120 #if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )\r
121 \r
122         /* Generic helper function. */\r
123         __attribute__( ( always_inline ) ) static inline uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap )\r
124         {\r
125         uint8_t ucReturn;\r
126 \r
127                 __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) );\r
128                 return ucReturn;\r
129         }\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 ) ucPortCountLeadingZeros( ( uxReadyPriorities ) ) )\r
143 \r
144 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
145 \r
146 /*-----------------------------------------------------------*/\r
147 \r
148 /* Hardware specifics. */\r
149 #define portBYTE_ALIGNMENT                      4\r
150 #define portSTACK_GROWTH                        ( -1 )\r
151 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
152 #define portNOP()                                       asm volatile ( "NOP" )\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
156 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
157 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
158 /*-----------------------------------------------------------*/\r
159 \r
160 /* The following structure is used by the FreeRTOS exception handler.  It is\r
161 filled with the MicroBlaze context as it was at the time the exception occurred.\r
162 This is done as an aid to debugging exception occurrences. */\r
163 typedef struct PORT_REGISTER_DUMP\r
164 {\r
165         /* The following structure members hold the values of the MicroBlaze\r
166         registers at the time the exception was raised. */\r
167         uint32_t ulR1_SP;\r
168         uint32_t ulR2_small_data_area;\r
169         uint32_t ulR3;\r
170         uint32_t ulR4;\r
171         uint32_t ulR5;\r
172         uint32_t ulR6;\r
173         uint32_t ulR7;\r
174         uint32_t ulR8;\r
175         uint32_t ulR9;\r
176         uint32_t ulR10;\r
177         uint32_t ulR11;\r
178         uint32_t ulR12;\r
179         uint32_t ulR13_read_write_small_data_area;\r
180         uint32_t ulR14_return_address_from_interrupt;\r
181         uint32_t ulR15_return_address_from_subroutine;\r
182         uint32_t ulR16_return_address_from_trap;\r
183         uint32_t ulR17_return_address_from_exceptions; /* The exception entry code will copy the BTR into R17 if the exception occurred in the delay slot of a branch instruction. */\r
184         uint32_t ulR18;\r
185         uint32_t ulR19;\r
186         uint32_t ulR20;\r
187         uint32_t ulR21;\r
188         uint32_t ulR22;\r
189         uint32_t ulR23;\r
190         uint32_t ulR24;\r
191         uint32_t ulR25;\r
192         uint32_t ulR26;\r
193         uint32_t ulR27;\r
194         uint32_t ulR28;\r
195         uint32_t ulR29;\r
196         uint32_t ulR30;\r
197         uint32_t ulR31;\r
198         uint32_t ulPC;\r
199         uint32_t ulESR;\r
200         uint32_t ulMSR;\r
201         uint32_t ulEAR;\r
202         uint32_t ulFSR;\r
203         uint32_t ulEDR;\r
204 \r
205         /* A human readable description of the exception cause.  The strings used\r
206         are the same as the #define constant names found in the\r
207         microblaze_exceptions_i.h header file */\r
208         int8_t *pcExceptionCause;\r
209 \r
210         /* The human readable name of the task that was running at the time the\r
211         exception occurred.  This is the name that was given to the task when the\r
212         task was created using the FreeRTOS xTaskCreate() API function. */\r
213         char *pcCurrentTaskName;\r
214 \r
215         /* The handle of the task that was running a the time the exception\r
216         occurred. */\r
217         void * xCurrentTaskHandle;\r
218 \r
219 } xPortRegisterDump;\r
220 \r
221 \r
222 /*\r
223  * Installs pxHandler as the interrupt handler for the peripheral specified by\r
224  * the ucInterruptID parameter.\r
225  *\r
226  * ucInterruptID:\r
227  *\r
228  * The ID of the peripheral that will have pxHandler assigned as its interrupt\r
229  * handler.  Peripheral IDs are defined in the xparameters.h header file, which\r
230  * is itself part of the BSP project.  For example, in the official demo\r
231  * application for this port, xparameters.h defines the following IDs for the\r
232  * four possible interrupt sources:\r
233  *\r
234  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.\r
235  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.\r
236  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.\r
237  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.\r
238  *\r
239  *\r
240  * pxHandler:\r
241  *\r
242  * A pointer to the interrupt handler function itself.  This must be a void\r
243  * function that takes a (void *) parameter.\r
244  *\r
245  *\r
246  * pvCallBackRef:\r
247  *\r
248  * The parameter passed into the handler function.  In many cases this will not\r
249  * be used and can be NULL.  Some times it is used to pass in a reference to\r
250  * the peripheral instance variable, so it can be accessed from inside the\r
251  * handler function.\r
252  *\r
253  *\r
254  * pdPASS is returned if the function executes successfully.  Any other value\r
255  * being returned indicates that the function did not execute correctly.\r
256  */\r
257 BaseType_t xPortInstallInterruptHandler( uint8_t ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef );\r
258 \r
259 \r
260 /*\r
261  * Enables the interrupt, within the interrupt controller, for the peripheral\r
262  * specified by the ucInterruptID parameter.\r
263  *\r
264  * ucInterruptID:\r
265  *\r
266  * The ID of the peripheral that will have its interrupt enabled in the\r
267  * interrupt controller.  Peripheral IDs are defined in the xparameters.h header\r
268  * file, which is itself part of the BSP project.  For example, in the official\r
269  * demo application for this port, xparameters.h defines the following IDs for\r
270  * the four possible interrupt sources:\r
271  *\r
272  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.\r
273  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.\r
274  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.\r
275  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.\r
276  *\r
277  */\r
278 void vPortEnableInterrupt( uint8_t ucInterruptID );\r
279 \r
280 /*\r
281  * Disables the interrupt, within the interrupt controller, for the peripheral\r
282  * specified by the ucInterruptID parameter.\r
283  *\r
284  * ucInterruptID:\r
285  *\r
286  * The ID of the peripheral that will have its interrupt disabled in the\r
287  * interrupt controller.  Peripheral IDs are defined in the xparameters.h header\r
288  * file, which is itself part of the BSP project.  For example, in the official\r
289  * demo application for this port, xparameters.h defines the following IDs for\r
290  * the four possible interrupt sources:\r
291  *\r
292  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.\r
293  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.\r
294  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.\r
295  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.\r
296  *\r
297  */\r
298 void vPortDisableInterrupt( uint8_t ucInterruptID );\r
299 \r
300 /*\r
301  * This is an application defined callback function used to install the tick\r
302  * interrupt handler.  It is provided as an application callback because the\r
303  * kernel will run on lots of different MicroBlaze and FPGA configurations - not\r
304  * all of which will have the same timer peripherals defined or available.  This\r
305  * example uses the AXI Timer 0.  If that is available on your hardware platform\r
306  * then this example callback implementation should not require modification.\r
307  * The name of the interrupt handler that should be installed is vPortTickISR(),\r
308  * which the function below declares as an extern.\r
309  */\r
310 void vApplicationSetupTimerInterrupt( void );\r
311 \r
312 /*\r
313  * This is an application defined callback function used to clear whichever\r
314  * interrupt was installed by the the vApplicationSetupTimerInterrupt() callback\r
315  * function - in this case the interrupt generated by the AXI timer.  It is\r
316  * provided as an application callback because the kernel will run on lots of\r
317  * different MicroBlaze and FPGA configurations - not all of which will have the\r
318  * same timer peripherals defined or available.  This example uses the AXI Timer 0.\r
319  * If that is available on your hardware platform then this example callback\r
320  * implementation should not require modification provided the example definition\r
321  * of vApplicationSetupTimerInterrupt() is also not modified.\r
322  */\r
323 void vApplicationClearTimerInterrupt( void );\r
324 \r
325 /*\r
326  * vPortExceptionsInstallHandlers() is only available when the MicroBlaze\r
327  * is configured to include exception functionality, and\r
328  * configINSTALL_EXCEPTION_HANDLERS is set to 1 in FreeRTOSConfig.h.\r
329  *\r
330  * vPortExceptionsInstallHandlers() installs the FreeRTOS exception handler\r
331  * for every possible exception cause.\r
332  *\r
333  * vPortExceptionsInstallHandlers() can be called explicitly from application\r
334  * code.  After that is done, the default FreeRTOS exception handler that will\r
335  * have been installed can be replaced for any specific exception cause by using\r
336  * the standard Xilinx library function microblaze_register_exception_handler().\r
337  *\r
338  * If vPortExceptionsInstallHandlers() is not called explicitly by the\r
339  * application, it will be called automatically by the kernel the first time\r
340  * xPortInstallInterruptHandler() is called.  At that time, any exception\r
341  * handlers that may have already been installed will be replaced.\r
342  *\r
343  * See the description of vApplicationExceptionRegisterDump() for information\r
344  * on the processing performed by the FreeRTOS exception handler.\r
345  */\r
346 void vPortExceptionsInstallHandlers( void );\r
347 \r
348 /*\r
349  * The FreeRTOS exception handler fills an xPortRegisterDump structure (defined\r
350  * in portmacro.h) with the MicroBlaze context, as it was at the time the\r
351  * exception occurred.  The exception handler then calls\r
352  * vApplicationExceptionRegisterDump(), passing in the completed\r
353  * xPortRegisterDump structure as its parameter.\r
354  *\r
355  * The FreeRTOS kernel provides its own implementation of\r
356  * vApplicationExceptionRegisterDump(), but the kernel provided implementation\r
357  * is declared as being 'weak'.  The weak definition allows the application\r
358  * writer to provide their own implementation, should they wish to use the\r
359  * register dump information.  For example, an implementation could be provided\r
360  * that wrote the register dump data to a display, or a UART port.\r
361  */\r
362 void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump );\r
363 \r
364 \r
365 #ifdef __cplusplus\r
366 }\r
367 #endif\r
368 \r
369 #endif /* PORTMACRO_H */\r
370 \r