]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/MicroBlazeV8/portmacro.h
Add additional critical section to the default tickless implementations.
[freertos] / FreeRTOS / Source / portable / GCC / MicroBlazeV8 / portmacro.h
1 /*\r
2     FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
5 \r
6     ***************************************************************************\r
7      *                                                                       *\r
8      *    FreeRTOS provides completely free yet professionally developed,    *\r
9      *    robust, strictly quality controlled, supported, and cross          *\r
10      *    platform software that has become a de facto standard.             *\r
11      *                                                                       *\r
12      *    Help yourself get started quickly and support the FreeRTOS         *\r
13      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
14      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
15      *                                                                       *\r
16      *    Thank you!                                                         *\r
17      *                                                                       *\r
18     ***************************************************************************\r
19 \r
20     This file is part of the FreeRTOS distribution.\r
21 \r
22     FreeRTOS is free software; you can redistribute it and/or modify it under\r
23     the terms of the GNU General Public License (version 2) as published by the\r
24     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
25 \r
26     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
27     >>! a combined work that includes FreeRTOS without being obliged to provide\r
28     >>! the source code for proprietary components outside of the FreeRTOS\r
29     >>! kernel.\r
30 \r
31     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
32     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
33     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
34     link: http://www.freertos.org/a00114.html\r
35 \r
36     1 tab == 4 spaces!\r
37 \r
38     ***************************************************************************\r
39      *                                                                       *\r
40      *    Having a problem?  Start by reading the FAQ "My application does   *\r
41      *    not run, what could be wrong?"                                     *\r
42      *                                                                       *\r
43      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
44      *                                                                       *\r
45     ***************************************************************************\r
46 \r
47     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
48     license and Real Time Engineers Ltd. contact details.\r
49 \r
50     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
51     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
52     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
53 \r
54     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
55     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
56     licenses offer ticketed support, indemnification and middleware.\r
57 \r
58     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
59     engineered and independently SIL3 certified version for use in safety and\r
60     mission critical applications that require provable dependability.\r
61 \r
62     1 tab == 4 spaces!\r
63 */\r
64 \r
65 #ifndef PORTMACRO_H\r
66 #define PORTMACRO_H\r
67 \r
68 #ifdef __cplusplus\r
69 extern "C" {\r
70 #endif\r
71 \r
72 /* BSP includes. */\r
73 #include <mb_interface.h>\r
74 #include <xparameters.h>\r
75 \r
76 /*-----------------------------------------------------------\r
77  * Port specific definitions.  \r
78  *\r
79  * The settings in this file configure FreeRTOS correctly for the\r
80  * given hardware and compiler.\r
81  *\r
82  * These settings should not be altered.\r
83  *-----------------------------------------------------------\r
84  */\r
85 \r
86 /* Type definitions. */\r
87 #define portCHAR                char\r
88 #define portFLOAT               float\r
89 #define portDOUBLE              double\r
90 #define portLONG                long\r
91 #define portSHORT               short\r
92 #define portSTACK_TYPE  unsigned long\r
93 #define portBASE_TYPE   long\r
94 \r
95 #if( configUSE_16_BIT_TICKS == 1 )\r
96         typedef unsigned portSHORT portTickType;\r
97         #define portMAX_DELAY ( portTickType ) 0xffff\r
98 #else\r
99         typedef unsigned portLONG portTickType;\r
100         #define portMAX_DELAY ( portTickType ) 0xffffffff\r
101 #endif\r
102 /*-----------------------------------------------------------*/ \r
103 \r
104 /* Interrupt control macros and functions. */\r
105 void microblaze_disable_interrupts( void );\r
106 void microblaze_enable_interrupts( void );\r
107 #define portDISABLE_INTERRUPTS()        microblaze_disable_interrupts()\r
108 #define portENABLE_INTERRUPTS()         microblaze_enable_interrupts()\r
109 \r
110 /*-----------------------------------------------------------*/\r
111 \r
112 /* Critical section macros. */\r
113 void vPortEnterCritical( void );\r
114 void vPortExitCritical( void );\r
115 #define portENTER_CRITICAL()            {                                                                                                                               \\r
116                                                                                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
117                                                                                 microblaze_disable_interrupts();                                                        \\r
118                                                                                 uxCriticalNesting++;                                                                            \\r
119                                                                         }\r
120 \r
121 #define portEXIT_CRITICAL()                     {                                                                                                                               \\r
122                                                                                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
123                                                                                 /* Interrupts are disabled, so we can */                                        \\r
124                                                                                 /* access the variable directly. */                                                     \\r
125                                                                                 uxCriticalNesting--;                                                                            \\r
126                                                                                 if( uxCriticalNesting == 0 )                                                            \\r
127                                                                                 {                                                                                                                       \\r
128                                                                                         /* The nesting has unwound and we                                               \\r
129                                                                                         can enable interrupts again. */                                                 \\r
130                                                                                         portENABLE_INTERRUPTS();                                                                \\r
131                                                                                 }                                                                                                                       \\r
132                                                                         }\r
133 \r
134 /*-----------------------------------------------------------*/\r
135 \r
136 /* The yield macro maps directly to the vPortYield() function. */\r
137 void vPortYield( void );\r
138 #define portYIELD() vPortYield()\r
139 \r
140 /* portYIELD_FROM_ISR() does not directly call vTaskSwitchContext(), but instead\r
141 sets a flag to say that a yield has been requested.  The interrupt exit code\r
142 then checks this flag, and calls vTaskSwitchContext() before restoring a task\r
143 context, if the flag is not false.  This is done to prevent multiple calls to\r
144 vTaskSwitchContext() being made from a single interrupt, as a single interrupt\r
145 can result in multiple peripherals being serviced. */\r
146 extern volatile unsigned long ulTaskSwitchRequested;\r
147 #define portYIELD_FROM_ISR( x ) if( x != pdFALSE ) ulTaskSwitchRequested = 1\r
148 /*-----------------------------------------------------------*/\r
149 \r
150 /* Hardware specifics. */\r
151 #define portBYTE_ALIGNMENT                      4\r
152 #define portSTACK_GROWTH                        ( -1 )\r
153 #define portTICK_RATE_MS                        ( ( portTickType ) 1000 / configTICK_RATE_HZ )\r
154 #define portNOP()                                       asm volatile ( "NOP" )\r
155 /*-----------------------------------------------------------*/\r
156 \r
157 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
158 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
159 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
160 /*-----------------------------------------------------------*/\r
161 \r
162 /* The following structure is used by the FreeRTOS exception handler.  It is\r
163 filled with the MicroBlaze context as it was at the time the exception occurred.\r
164 This is done as an aid to debugging exception occurrences. */\r
165 typedef struct PORT_REGISTER_DUMP\r
166 {\r
167         /* The following structure members hold the values of the MicroBlaze\r
168         registers at the time the exception was raised. */\r
169         unsigned long ulR1_SP;\r
170         unsigned long ulR2_small_data_area;\r
171         unsigned long ulR3;\r
172         unsigned long ulR4;\r
173         unsigned long ulR5;\r
174         unsigned long ulR6;\r
175         unsigned long ulR7;\r
176         unsigned long ulR8;\r
177         unsigned long ulR9;\r
178         unsigned long ulR10;\r
179         unsigned long ulR11;\r
180         unsigned long ulR12;\r
181         unsigned long ulR13_read_write_small_data_area;\r
182         unsigned long ulR14_return_address_from_interrupt;\r
183         unsigned long ulR15_return_address_from_subroutine;\r
184         unsigned long ulR16_return_address_from_trap;\r
185         unsigned long 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
186         unsigned long ulR18;\r
187         unsigned long ulR19;\r
188         unsigned long ulR20;\r
189         unsigned long ulR21;\r
190         unsigned long ulR22;\r
191         unsigned long ulR23;\r
192         unsigned long ulR24;\r
193         unsigned long ulR25;\r
194         unsigned long ulR26;\r
195         unsigned long ulR27;\r
196         unsigned long ulR28;\r
197         unsigned long ulR29;\r
198         unsigned long ulR30;\r
199         unsigned long ulR31;\r
200         unsigned long ulPC;\r
201         unsigned long ulESR;\r
202         unsigned long ulMSR;\r
203         unsigned long ulEAR;\r
204         unsigned long ulFSR;\r
205         unsigned long ulEDR;\r
206 \r
207         /* A human readable description of the exception cause.  The strings used\r
208         are the same as the #define constant names found in the\r
209         microblaze_exceptions_i.h header file */\r
210         signed char *pcExceptionCause;\r
211 \r
212         /* The human readable name of the task that was running at the time the\r
213         exception occurred.  This is the name that was given to the task when the\r
214         task was created using the FreeRTOS xTaskCreate() API function. */\r
215         signed char *pcCurrentTaskName;\r
216 \r
217         /* The handle of the task that was running a the time the exception\r
218         occurred. */\r
219         void * xCurrentTaskHandle;\r
220 \r
221 } xPortRegisterDump;\r
222 \r
223 \r
224 /*\r
225  * Installs pxHandler as the interrupt handler for the peripheral specified by \r
226  * the ucInterruptID parameter.\r
227  *\r
228  * ucInterruptID:\r
229  * \r
230  * The ID of the peripheral that will have pxHandler assigned as its interrupt\r
231  * handler.  Peripheral IDs are defined in the xparameters.h header file, which \r
232  * is itself part of the BSP project.  For example, in the official demo \r
233  * application for this port, xparameters.h defines the following IDs for the \r
234  * four possible interrupt sources:\r
235  *\r
236  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.\r
237  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.\r
238  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.\r
239  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.\r
240  *\r
241  *\r
242  * pxHandler:\r
243  * \r
244  * A pointer to the interrupt handler function itself.  This must be a void\r
245  * function that takes a (void *) parameter.\r
246  *\r
247  *\r
248  * pvCallBackRef:\r
249  *\r
250  * The parameter passed into the handler function.  In many cases this will not\r
251  * be used and can be NULL.  Some times it is used to pass in a reference to\r
252  * the peripheral instance variable, so it can be accessed from inside the\r
253  * handler function.\r
254  *\r
255  * \r
256  * pdPASS is returned if the function executes successfully.  Any other value\r
257  * being returned indicates that the function did not execute correctly.\r
258  */\r
259 portBASE_TYPE xPortInstallInterruptHandler( unsigned char ucInterruptID, XInterruptHandler pxHandler, 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( unsigned char 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( unsigned char 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
372 \r