]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/MicroBlazeV8/portmacro.h
f997f2e3d101015b746ba8e83fa3bfee90e834bd
[freertos] / FreeRTOS / Source / portable / GCC / MicroBlazeV8 / portmacro.h
1 /*\r
2     FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43     \r
44     ***************************************************************************\r
45      *                                                                       *\r
46      *    Having a problem?  Start by reading the FAQ "My application does   *\r
47      *    not run, what could be wrong?                                      *\r
48      *                                                                       *\r
49      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
50      *                                                                       *\r
51     ***************************************************************************\r
52 \r
53     \r
54     http://www.FreeRTOS.org - Documentation, training, latest information, \r
55     license and contact details.\r
56     \r
57     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
58     including FreeRTOS+Trace - an indispensable productivity tool.\r
59 \r
60     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
61     the code with commercial support, indemnification, and middleware, under \r
62     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
63     provide a safety engineered and independently SIL3 certified version under \r
64     the SafeRTOS brand: http://www.SafeRTOS.com.\r
65 */\r
66 \r
67 #ifndef PORTMACRO_H\r
68 #define PORTMACRO_H\r
69 \r
70 #ifdef __cplusplus\r
71 extern "C" {\r
72 #endif\r
73 \r
74 /* BSP includes. */\r
75 #include <mb_interface.h>\r
76 #include <xparameters.h>\r
77 \r
78 /*-----------------------------------------------------------\r
79  * Port specific definitions.  \r
80  *\r
81  * The settings in this file configure FreeRTOS correctly for the\r
82  * given hardware and compiler.\r
83  *\r
84  * These settings should not be altered.\r
85  *-----------------------------------------------------------\r
86  */\r
87 \r
88 /* Type definitions. */\r
89 #define portCHAR                char\r
90 #define portFLOAT               float\r
91 #define portDOUBLE              double\r
92 #define portLONG                long\r
93 #define portSHORT               short\r
94 #define portSTACK_TYPE  unsigned long\r
95 #define portBASE_TYPE   long\r
96 \r
97 #if( configUSE_16_BIT_TICKS == 1 )\r
98         typedef unsigned portSHORT portTickType;\r
99         #define portMAX_DELAY ( portTickType ) 0xffff\r
100 #else\r
101         typedef unsigned portLONG portTickType;\r
102         #define portMAX_DELAY ( portTickType ) 0xffffffff\r
103 #endif\r
104 /*-----------------------------------------------------------*/ \r
105 \r
106 /* Interrupt control macros and functions. */\r
107 void microblaze_disable_interrupts( void );\r
108 void microblaze_enable_interrupts( void );\r
109 #define portDISABLE_INTERRUPTS()        microblaze_disable_interrupts()\r
110 #define portENABLE_INTERRUPTS()         microblaze_enable_interrupts()\r
111 \r
112 /*-----------------------------------------------------------*/\r
113 \r
114 /* Critical section macros. */\r
115 void vPortEnterCritical( void );\r
116 void vPortExitCritical( void );\r
117 #define portENTER_CRITICAL()            {                                                                                                                               \\r
118                                                                                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
119                                                                                 microblaze_disable_interrupts();                                                        \\r
120                                                                                 uxCriticalNesting++;                                                                            \\r
121                                                                         }\r
122 \r
123 #define portEXIT_CRITICAL()                     {                                                                                                                               \\r
124                                                                                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
125                                                                                 /* Interrupts are disabled, so we can */                                        \\r
126                                                                                 /* access the variable directly. */                                                     \\r
127                                                                                 uxCriticalNesting--;                                                                            \\r
128                                                                                 if( uxCriticalNesting == 0 )                                                            \\r
129                                                                                 {                                                                                                                       \\r
130                                                                                         /* The nesting has unwound and we                                               \\r
131                                                                                         can enable interrupts again. */                                                 \\r
132                                                                                         portENABLE_INTERRUPTS();                                                                \\r
133                                                                                 }                                                                                                                       \\r
134                                                                         }\r
135 \r
136 /*-----------------------------------------------------------*/\r
137 \r
138 /* The yield macro maps directly to the vPortYield() function. */\r
139 void vPortYield( void );\r
140 #define portYIELD() vPortYield()\r
141 \r
142 /* portYIELD_FROM_ISR() does not directly call vTaskSwitchContext(), but instead\r
143 sets a flag to say that a yield has been requested.  The interrupt exit code\r
144 then checks this flag, and calls vTaskSwitchContext() before restoring a task\r
145 context, if the flag is not false.  This is done to prevent multiple calls to\r
146 vTaskSwitchContext() being made from a single interrupt, as a single interrupt\r
147 can result in multiple peripherals being serviced. */\r
148 extern volatile unsigned long ulTaskSwitchRequested;\r
149 #define portYIELD_FROM_ISR( x ) if( x != pdFALSE ) ulTaskSwitchRequested = 1\r
150 /*-----------------------------------------------------------*/\r
151 \r
152 /* Hardware specifics. */\r
153 #define portBYTE_ALIGNMENT                      4\r
154 #define portSTACK_GROWTH                        ( -1 )\r
155 #define portTICK_RATE_MS                        ( ( portTickType ) 1000 / configTICK_RATE_HZ )\r
156 #define portNOP()                                       asm volatile ( "NOP" )\r
157 /*-----------------------------------------------------------*/\r
158 \r
159 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
160 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
161 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
162 /*-----------------------------------------------------------*/\r
163 \r
164 /* The following structure is used by the FreeRTOS exception handler.  It is\r
165 filled with the MicroBlaze context as it was at the time the exception occurred.\r
166 This is done as an aid to debugging exception occurrences. */\r
167 typedef struct PORT_REGISTER_DUMP\r
168 {\r
169         /* The following structure members hold the values of the MicroBlaze\r
170         registers at the time the exception was raised. */\r
171         unsigned long ulR1_SP;\r
172         unsigned long ulR2_small_data_area;\r
173         unsigned long ulR3;\r
174         unsigned long ulR4;\r
175         unsigned long ulR5;\r
176         unsigned long ulR6;\r
177         unsigned long ulR7;\r
178         unsigned long ulR8;\r
179         unsigned long ulR9;\r
180         unsigned long ulR10;\r
181         unsigned long ulR11;\r
182         unsigned long ulR12;\r
183         unsigned long ulR13_read_write_small_data_area;\r
184         unsigned long ulR14_return_address_from_interrupt;\r
185         unsigned long ulR15_return_address_from_subroutine;\r
186         unsigned long ulR16_return_address_from_trap;\r
187         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
188         unsigned long ulR18;\r
189         unsigned long ulR19;\r
190         unsigned long ulR20;\r
191         unsigned long ulR21;\r
192         unsigned long ulR22;\r
193         unsigned long ulR23;\r
194         unsigned long ulR24;\r
195         unsigned long ulR25;\r
196         unsigned long ulR26;\r
197         unsigned long ulR27;\r
198         unsigned long ulR28;\r
199         unsigned long ulR29;\r
200         unsigned long ulR30;\r
201         unsigned long ulR31;\r
202         unsigned long ulPC;\r
203         unsigned long ulESR;\r
204         unsigned long ulMSR;\r
205         unsigned long ulEAR;\r
206         unsigned long ulFSR;\r
207         unsigned long ulEDR;\r
208 \r
209         /* A human readable description of the exception cause.  The strings used\r
210         are the same as the #define constant names found in the\r
211         microblaze_exceptions_i.h header file */\r
212         signed char *pcExceptionCause;\r
213 \r
214         /* The human readable name of the task that was running at the time the\r
215         exception occurred.  This is the name that was given to the task when the\r
216         task was created using the FreeRTOS xTaskCreate() API function. */\r
217         signed char *pcCurrentTaskName;\r
218 \r
219         /* The handle of the task that was running a the time the exception\r
220         occurred. */\r
221         void * xCurrentTaskHandle;\r
222 \r
223 } xPortRegisterDump;\r
224 \r
225 \r
226 /*\r
227  * Installs pxHandler as the interrupt handler for the peripheral specified by \r
228  * the ucInterruptID parameter.\r
229  *\r
230  * ucInterruptID:\r
231  * \r
232  * The ID of the peripheral that will have pxHandler assigned as its interrupt\r
233  * handler.  Peripheral IDs are defined in the xparameters.h header file, which \r
234  * is itself part of the BSP project.  For example, in the official demo \r
235  * application for this port, xparameters.h defines the following IDs for the \r
236  * four possible interrupt sources:\r
237  *\r
238  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.\r
239  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.\r
240  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.\r
241  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.\r
242  *\r
243  *\r
244  * pxHandler:\r
245  * \r
246  * A pointer to the interrupt handler function itself.  This must be a void\r
247  * function that takes a (void *) parameter.\r
248  *\r
249  *\r
250  * pvCallBackRef:\r
251  *\r
252  * The parameter passed into the handler function.  In many cases this will not\r
253  * be used and can be NULL.  Some times it is used to pass in a reference to\r
254  * the peripheral instance variable, so it can be accessed from inside the\r
255  * handler function.\r
256  *\r
257  * \r
258  * pdPASS is returned if the function executes successfully.  Any other value\r
259  * being returned indicates that the function did not execute correctly.\r
260  */\r
261 portBASE_TYPE xPortInstallInterruptHandler( unsigned char ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef );\r
262 \r
263 \r
264 /*\r
265  * Enables the interrupt, within the interrupt controller, for the peripheral \r
266  * specified by the ucInterruptID parameter.\r
267  *\r
268  * ucInterruptID:\r
269  * \r
270  * The ID of the peripheral that will have its interrupt enabled in the\r
271  * interrupt controller.  Peripheral IDs are defined in the xparameters.h header \r
272  * file, which is itself part of the BSP project.  For example, in the official \r
273  * demo application for this port, xparameters.h defines the following IDs for \r
274  * the four possible interrupt sources:\r
275  *\r
276  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.\r
277  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.\r
278  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.\r
279  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.\r
280  *\r
281  */\r
282 void vPortEnableInterrupt( unsigned char ucInterruptID );\r
283 \r
284 /*\r
285  * Disables the interrupt, within the interrupt controller, for the peripheral \r
286  * specified by the ucInterruptID parameter.\r
287  *\r
288  * ucInterruptID:\r
289  * \r
290  * The ID of the peripheral that will have its interrupt disabled in the\r
291  * interrupt controller.  Peripheral IDs are defined in the xparameters.h header \r
292  * file, which is itself part of the BSP project.  For example, in the official \r
293  * demo application for this port, xparameters.h defines the following IDs for \r
294  * the four possible interrupt sources:\r
295  *\r
296  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.\r
297  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.\r
298  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.\r
299  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.\r
300  *\r
301  */\r
302 void vPortDisableInterrupt( unsigned char ucInterruptID );\r
303 \r
304 /*\r
305  * This is an application defined callback function used to install the tick\r
306  * interrupt handler.  It is provided as an application callback because the \r
307  * kernel will run on lots of different MicroBlaze and FPGA configurations - not \r
308  * all of which will have the same timer peripherals defined or available.  This \r
309  * example uses the AXI Timer 0.  If that is available on your hardware platform \r
310  * then this example callback implementation should not require modification.  \r
311  * The name of the interrupt handler that should be installed is vPortTickISR(), \r
312  * which the function below declares as an extern.\r
313  */ \r
314 void vApplicationSetupTimerInterrupt( void );\r
315 \r
316 /* \r
317  * This is an application defined callback function used to clear whichever\r
318  * interrupt was installed by the the vApplicationSetupTimerInterrupt() callback\r
319  * function - in this case the interrupt generated by the AXI timer.  It is \r
320  * provided as an application callback because the kernel will run on lots of \r
321  * different MicroBlaze and FPGA configurations - not all of which will have the \r
322  * same timer peripherals defined or available.  This example uses the AXI Timer 0.  \r
323  * If that is available on your hardware platform then this example callback \r
324  * implementation should not require modification provided the example definition\r
325  * of vApplicationSetupTimerInterrupt() is also not modified. \r
326  */\r
327 void vApplicationClearTimerInterrupt( void );\r
328 \r
329 /*\r
330  * vPortExceptionsInstallHandlers() is only available when the MicroBlaze\r
331  * is configured to include exception functionality, and \r
332  * configINSTALL_EXCEPTION_HANDLERS is set to 1 in FreeRTOSConfig.h.\r
333  *\r
334  * vPortExceptionsInstallHandlers() installs the FreeRTOS exception handler\r
335  * for every possible exception cause.  \r
336  *\r
337  * vPortExceptionsInstallHandlers() can be called explicitly from application\r
338  * code.  After that is done, the default FreeRTOS exception handler that will\r
339  * have been installed can be replaced for any specific exception cause by using \r
340  * the standard Xilinx library function microblaze_register_exception_handler().\r
341  *\r
342  * If vPortExceptionsInstallHandlers() is not called explicitly by the \r
343  * application, it will be called automatically by the kernel the first time\r
344  * xPortInstallInterruptHandler() is called.  At that time, any exception \r
345  * handlers that may have already been installed will be replaced.\r
346  *\r
347  * See the description of vApplicationExceptionRegisterDump() for information\r
348  * on the processing performed by the FreeRTOS exception handler.\r
349  */\r
350 void vPortExceptionsInstallHandlers( void );\r
351 \r
352 /*\r
353  * The FreeRTOS exception handler fills an xPortRegisterDump structure (defined \r
354  * in portmacro.h) with the MicroBlaze context, as it was at the time the \r
355  * exception occurred.  The exception handler then calls\r
356  * vApplicationExceptionRegisterDump(), passing in the completed\r
357  * xPortRegisterDump structure as its parameter.\r
358  *\r
359  * The FreeRTOS kernel provides its own implementation of\r
360  * vApplicationExceptionRegisterDump(), but the kernel provided implementation \r
361  * is declared as being 'weak'.  The weak definition allows the application \r
362  * writer to provide their own implementation, should they wish to use the \r
363  * register dump information.  For example, an implementation could be provided\r
364  * that wrote the register dump data to a display, or a UART port.\r
365  */\r
366 void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump );\r
367 \r
368 \r
369 #ifdef __cplusplus\r
370 }\r
371 #endif\r
372 \r
373 #endif /* PORTMACRO_H */\r
374 \r