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