]> begriffs open source - freertos/blob - portable/GCC/MicroBlazeV9/portmacro.h
Style: uncrusitfy
[freertos] / portable / GCC / MicroBlazeV9 / portmacro.h
1 /*\r
2  * FreeRTOS Kernel V10.3.1\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  */\r
26 \r
27 #ifndef PORTMACRO_H\r
28     #define PORTMACRO_H\r
29 \r
30     #ifdef __cplusplus\r
31         extern "C" {\r
32     #endif\r
33 \r
34 /* BSP includes. */\r
35     #include <mb_interface.h>\r
36     #include <xparameters.h>\r
37 \r
38 /*-----------------------------------------------------------\r
39  * Port specific definitions.\r
40  *\r
41  * The settings in this file configure FreeRTOS correctly for the\r
42  * given hardware and compiler.\r
43  *\r
44  * These settings should not be altered.\r
45  *-----------------------------------------------------------\r
46  */\r
47 \r
48 /* Type definitions. */\r
49     #define portCHAR          char\r
50     #define portFLOAT         float\r
51     #define portDOUBLE        double\r
52     #define portLONG          long\r
53     #define portSHORT         short\r
54     #define portSTACK_TYPE    uint32_t\r
55     #define portBASE_TYPE     long\r
56 \r
57     typedef portSTACK_TYPE   StackType_t;\r
58     typedef long             BaseType_t;\r
59     typedef unsigned long    UBaseType_t;\r
60 \r
61     #if ( configUSE_16_BIT_TICKS == 1 )\r
62         typedef uint16_t     TickType_t;\r
63         #define portMAX_DELAY              ( TickType_t ) 0xffff\r
64     #else\r
65         typedef uint32_t     TickType_t;\r
66         #define portMAX_DELAY              ( TickType_t ) 0xffffffffUL\r
67 \r
68 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do\r
69  * not need to be guarded with a critical section. */\r
70         #define portTICK_TYPE_IS_ATOMIC    1\r
71     #endif\r
72 /*-----------------------------------------------------------*/\r
73 \r
74 /* Interrupt control macros and functions. */\r
75     void microblaze_disable_interrupts( void );\r
76     void microblaze_enable_interrupts( void );\r
77     #define portDISABLE_INTERRUPTS()    microblaze_disable_interrupts()\r
78     #define portENABLE_INTERRUPTS()     microblaze_enable_interrupts()\r
79 /*-----------------------------------------------------------*/\r
80 \r
81 /* Critical section macros. */\r
82     void vPortEnterCritical( void );\r
83     void vPortExitCritical( void );\r
84     #define portENTER_CRITICAL()                       \\r
85     {                                                  \\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     {                                                  \\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 \r
129             return ucReturn;\r
130         }\r
131 \r
132 /* Check the configuration. */\r
133         #if ( configMAX_PRIORITIES > 32 )\r
134             #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
135         #endif\r
136 \r
137 /* Store/clear the ready priorities in a bit map. */\r
138         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities )    ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
139         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities )     ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
140 \r
141 /*-----------------------------------------------------------*/\r
142 \r
143         #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities )    uxTopPriority        = ( 31UL - ( uint32_t ) ucPortCountLeadingZeros( ( uxReadyPriorities ) ) )\r
144 \r
145     #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
146 \r
147 /*-----------------------------------------------------------*/\r
148 \r
149 /* Hardware specifics. */\r
150     #define portBYTE_ALIGNMENT    4\r
151     #define portSTACK_GROWTH      ( -1 )\r
152     #define portTICK_PERIOD_MS    ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
153     #define portNOP()    asm volatile ( "NOP" )\r
154 /*-----------------------------------------------------------*/\r
155 \r
156 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
157     #define portTASK_FUNCTION_PROTO( vFunction, pvParameters )    void vFunction( void * pvParameters )\r
158     #define portTASK_FUNCTION( vFunction, pvParameters )          void vFunction( void * pvParameters )\r
159 /*-----------------------------------------------------------*/\r
160 \r
161 /* The following structure is used by the FreeRTOS exception handler.  It is\r
162  * filled with the MicroBlaze context as it was at the time the exception occurred.\r
163  * This is done as an aid to debugging exception occurrences. */\r
164     typedef struct PORT_REGISTER_DUMP\r
165     {\r
166         /* The following structure members hold the values of the MicroBlaze\r
167          * registers at the time the exception was raised. */\r
168         uint32_t ulR1_SP;\r
169         uint32_t ulR2_small_data_area;\r
170         uint32_t ulR3;\r
171         uint32_t ulR4;\r
172         uint32_t ulR5;\r
173         uint32_t ulR6;\r
174         uint32_t ulR7;\r
175         uint32_t ulR8;\r
176         uint32_t ulR9;\r
177         uint32_t ulR10;\r
178         uint32_t ulR11;\r
179         uint32_t ulR12;\r
180         uint32_t ulR13_read_write_small_data_area;\r
181         uint32_t ulR14_return_address_from_interrupt;\r
182         uint32_t ulR15_return_address_from_subroutine;\r
183         uint32_t ulR16_return_address_from_trap;\r
184         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
185         uint32_t ulR18;\r
186         uint32_t ulR19;\r
187         uint32_t ulR20;\r
188         uint32_t ulR21;\r
189         uint32_t ulR22;\r
190         uint32_t ulR23;\r
191         uint32_t ulR24;\r
192         uint32_t ulR25;\r
193         uint32_t ulR26;\r
194         uint32_t ulR27;\r
195         uint32_t ulR28;\r
196         uint32_t ulR29;\r
197         uint32_t ulR30;\r
198         uint32_t ulR31;\r
199         uint32_t ulPC;\r
200         uint32_t ulESR;\r
201         uint32_t ulMSR;\r
202         uint32_t ulEAR;\r
203         uint32_t ulFSR;\r
204         uint32_t ulEDR;\r
205 \r
206         /* A human readable description of the exception cause.  The strings used\r
207          * are the same as the #define constant names found in the\r
208          * microblaze_exceptions_i.h header file */\r
209         int8_t * pcExceptionCause;\r
210 \r
211         /* The human readable name of the task that was running at the time the\r
212          * exception occurred.  This is the name that was given to the task when the\r
213          * task was created using the FreeRTOS xTaskCreate() API function. */\r
214         char * pcCurrentTaskName;\r
215 \r
216         /* The handle of the task that was running a the time the exception\r
217          * occurred. */\r
218         void * xCurrentTaskHandle;\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,\r
258                                              XInterruptHandler pxHandler,\r
259                                              void * pvCallBackRef );\r
260 \r
261 \r
262 /*\r
263  * Enables the interrupt, within the interrupt controller, for the peripheral\r
264  * specified by the ucInterruptID parameter.\r
265  *\r
266  * ucInterruptID:\r
267  *\r
268  * The ID of the peripheral that will have its interrupt enabled in the\r
269  * interrupt controller.  Peripheral IDs are defined in the xparameters.h header\r
270  * file, which is itself part of the BSP project.  For example, in the official\r
271  * demo application for this port, xparameters.h defines the following IDs for\r
272  * the four possible interrupt sources:\r
273  *\r
274  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.\r
275  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.\r
276  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.\r
277  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.\r
278  *\r
279  */\r
280     void vPortEnableInterrupt( uint8_t ucInterruptID );\r
281 \r
282 /*\r
283  * Disables the interrupt, within the interrupt controller, for the peripheral\r
284  * specified by the ucInterruptID parameter.\r
285  *\r
286  * ucInterruptID:\r
287  *\r
288  * The ID of the peripheral that will have its interrupt disabled in the\r
289  * interrupt controller.  Peripheral IDs are defined in the xparameters.h header\r
290  * file, which is itself part of the BSP project.  For example, in the official\r
291  * demo application for this port, xparameters.h defines the following IDs for\r
292  * the four possible interrupt sources:\r
293  *\r
294  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.\r
295  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.\r
296  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.\r
297  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.\r
298  *\r
299  */\r
300     void vPortDisableInterrupt( uint8_t ucInterruptID );\r
301 \r
302 /*\r
303  * This is an application defined callback function used to install the tick\r
304  * interrupt handler.  It is provided as an application callback because the\r
305  * kernel will run on lots of different MicroBlaze and FPGA configurations - not\r
306  * all of which will have the same timer peripherals defined or available.  This\r
307  * example uses the AXI Timer 0.  If that is available on your hardware platform\r
308  * then this example callback implementation should not require modification.\r
309  * The name of the interrupt handler that should be installed is vPortTickISR(),\r
310  * which the function below declares as an extern.\r
311  */\r
312     void vApplicationSetupTimerInterrupt( void );\r
313 \r
314 /*\r
315  * This is an application defined callback function used to clear whichever\r
316  * interrupt was installed by the the vApplicationSetupTimerInterrupt() callback\r
317  * function - in this case the interrupt generated by the AXI timer.  It is\r
318  * provided as an application callback because the kernel will run on lots of\r
319  * different MicroBlaze and FPGA configurations - not all of which will have the\r
320  * same timer peripherals defined or available.  This example uses the AXI Timer 0.\r
321  * If that is available on your hardware platform then this example callback\r
322  * implementation should not require modification provided the example definition\r
323  * of vApplicationSetupTimerInterrupt() is also not modified.\r
324  */\r
325     void vApplicationClearTimerInterrupt( void );\r
326 \r
327 /*\r
328  * vPortExceptionsInstallHandlers() is only available when the MicroBlaze\r
329  * is configured to include exception functionality, and\r
330  * configINSTALL_EXCEPTION_HANDLERS is set to 1 in FreeRTOSConfig.h.\r
331  *\r
332  * vPortExceptionsInstallHandlers() installs the FreeRTOS exception handler\r
333  * for every possible exception cause.\r
334  *\r
335  * vPortExceptionsInstallHandlers() can be called explicitly from application\r
336  * code.  After that is done, the default FreeRTOS exception handler that will\r
337  * have been installed can be replaced for any specific exception cause by using\r
338  * the standard Xilinx library function microblaze_register_exception_handler().\r
339  *\r
340  * If vPortExceptionsInstallHandlers() is not called explicitly by the\r
341  * application, it will be called automatically by the kernel the first time\r
342  * xPortInstallInterruptHandler() is called.  At that time, any exception\r
343  * handlers that may have already been installed will be replaced.\r
344  *\r
345  * See the description of vApplicationExceptionRegisterDump() for information\r
346  * on the processing performed by the FreeRTOS exception handler.\r
347  */\r
348     void vPortExceptionsInstallHandlers( void );\r
349 \r
350 /*\r
351  * The FreeRTOS exception handler fills an xPortRegisterDump structure (defined\r
352  * in portmacro.h) with the MicroBlaze context, as it was at the time the\r
353  * exception occurred.  The exception handler then calls\r
354  * vApplicationExceptionRegisterDump(), passing in the completed\r
355  * xPortRegisterDump structure as its parameter.\r
356  *\r
357  * The FreeRTOS kernel provides its own implementation of\r
358  * vApplicationExceptionRegisterDump(), but the kernel provided implementation\r
359  * is declared as being 'weak'.  The weak definition allows the application\r
360  * writer to provide their own implementation, should they wish to use the\r
361  * register dump information.  For example, an implementation could be provided\r
362  * that wrote the register dump data to a display, or a UART port.\r
363  */\r
364     void vApplicationExceptionRegisterDump( xPortRegisterDump * xRegisterDump );\r
365 \r
366 \r
367     #ifdef __cplusplus\r
368         }\r
369     #endif\r
370 \r
371 #endif /* PORTMACRO_H */\r