]> begriffs open source - cmsis-freertos/blob - Source/portable/GCC/MicroBlazeV8/portmacro.h
Initial commit
[cmsis-freertos] / Source / portable / GCC / MicroBlazeV8 / portmacro.h
1 /*
2     FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70 #ifndef PORTMACRO_H
71 #define PORTMACRO_H
72
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76
77 /* BSP includes. */
78 #include <mb_interface.h>
79 #include <xparameters.h>
80
81 /*-----------------------------------------------------------
82  * Port specific definitions.
83  *
84  * The settings in this file configure FreeRTOS correctly for the
85  * given hardware and compiler.
86  *
87  * These settings should not be altered.
88  *-----------------------------------------------------------
89  */
90
91 /* Type definitions. */
92 #define portCHAR                char
93 #define portFLOAT               float
94 #define portDOUBLE              double
95 #define portLONG                long
96 #define portSHORT               short
97 #define portSTACK_TYPE  uint32_t
98 #define portBASE_TYPE   long
99
100 typedef portSTACK_TYPE StackType_t;
101 typedef long BaseType_t;
102 typedef unsigned long UBaseType_t;
103
104 #if( configUSE_16_BIT_TICKS == 1 )
105         typedef uint16_t TickType_t;
106         #define portMAX_DELAY ( TickType_t ) 0xffff
107 #else
108         typedef uint32_t TickType_t;
109         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
110
111         /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
112         not need to be guarded with a critical section. */
113         #define portTICK_TYPE_IS_ATOMIC 1
114 #endif
115 /*-----------------------------------------------------------*/
116
117 /* Interrupt control macros and functions. */
118 void microblaze_disable_interrupts( void );
119 void microblaze_enable_interrupts( void );
120 #define portDISABLE_INTERRUPTS()        microblaze_disable_interrupts()
121 #define portENABLE_INTERRUPTS()         microblaze_enable_interrupts()
122 /*-----------------------------------------------------------*/
123
124 /* Critical section macros. */
125 void vPortEnterCritical( void );
126 void vPortExitCritical( void );
127 #define portENTER_CRITICAL()            {                                                                                                                               \
128                                                                                 extern volatile UBaseType_t uxCriticalNesting;                          \
129                                                                                 microblaze_disable_interrupts();                                                        \
130                                                                                 uxCriticalNesting++;                                                                            \
131                                                                         }
132
133 #define portEXIT_CRITICAL()                     {                                                                                                                               \
134                                                                                 extern volatile UBaseType_t uxCriticalNesting;                          \
135                                                                                 /* Interrupts are disabled, so we can */                                        \
136                                                                                 /* access the variable directly. */                                                     \
137                                                                                 uxCriticalNesting--;                                                                            \
138                                                                                 if( uxCriticalNesting == 0 )                                                            \
139                                                                                 {                                                                                                                       \
140                                                                                         /* The nesting has unwound and we                                               \
141                                                                                         can enable interrupts again. */                                                 \
142                                                                                         portENABLE_INTERRUPTS();                                                                \
143                                                                                 }                                                                                                                       \
144                                                                         }
145
146 /*-----------------------------------------------------------*/
147
148 /* The yield macro maps directly to the vPortYield() function. */
149 void vPortYield( void );
150 #define portYIELD() vPortYield()
151
152 /* portYIELD_FROM_ISR() does not directly call vTaskSwitchContext(), but instead
153 sets a flag to say that a yield has been requested.  The interrupt exit code
154 then checks this flag, and calls vTaskSwitchContext() before restoring a task
155 context, if the flag is not false.  This is done to prevent multiple calls to
156 vTaskSwitchContext() being made from a single interrupt, as a single interrupt
157 can result in multiple peripherals being serviced. */
158 extern volatile uint32_t ulTaskSwitchRequested;
159 #define portYIELD_FROM_ISR( x ) if( ( x ) != pdFALSE ) ulTaskSwitchRequested = 1
160
161 #if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )
162
163         /* Generic helper function. */
164         __attribute__( ( always_inline ) ) static inline uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap )
165         {
166         uint8_t ucReturn;
167
168                 __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) );
169                 return ucReturn;
170         }
171
172         /* Check the configuration. */
173         #if( configMAX_PRIORITIES > 32 )
174                 #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.
175         #endif
176
177         /* Store/clear the ready priorities in a bit map. */
178         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
179         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
180
181         /*-----------------------------------------------------------*/
182
183         #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) ucPortCountLeadingZeros( ( uxReadyPriorities ) ) )
184
185 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
186
187 /*-----------------------------------------------------------*/
188
189 /* Hardware specifics. */
190 #define portBYTE_ALIGNMENT                      4
191 #define portSTACK_GROWTH                        ( -1 )
192 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
193 #define portNOP()                                       asm volatile ( "NOP" )
194 /*-----------------------------------------------------------*/
195
196 /* Task function macros as described on the FreeRTOS.org WEB site. */
197 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
198 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
199 /*-----------------------------------------------------------*/
200
201 /* The following structure is used by the FreeRTOS exception handler.  It is
202 filled with the MicroBlaze context as it was at the time the exception occurred.
203 This is done as an aid to debugging exception occurrences. */
204 typedef struct PORT_REGISTER_DUMP
205 {
206         /* The following structure members hold the values of the MicroBlaze
207         registers at the time the exception was raised. */
208         uint32_t ulR1_SP;
209         uint32_t ulR2_small_data_area;
210         uint32_t ulR3;
211         uint32_t ulR4;
212         uint32_t ulR5;
213         uint32_t ulR6;
214         uint32_t ulR7;
215         uint32_t ulR8;
216         uint32_t ulR9;
217         uint32_t ulR10;
218         uint32_t ulR11;
219         uint32_t ulR12;
220         uint32_t ulR13_read_write_small_data_area;
221         uint32_t ulR14_return_address_from_interrupt;
222         uint32_t ulR15_return_address_from_subroutine;
223         uint32_t ulR16_return_address_from_trap;
224         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. */
225         uint32_t ulR18;
226         uint32_t ulR19;
227         uint32_t ulR20;
228         uint32_t ulR21;
229         uint32_t ulR22;
230         uint32_t ulR23;
231         uint32_t ulR24;
232         uint32_t ulR25;
233         uint32_t ulR26;
234         uint32_t ulR27;
235         uint32_t ulR28;
236         uint32_t ulR29;
237         uint32_t ulR30;
238         uint32_t ulR31;
239         uint32_t ulPC;
240         uint32_t ulESR;
241         uint32_t ulMSR;
242         uint32_t ulEAR;
243         uint32_t ulFSR;
244         uint32_t ulEDR;
245
246         /* A human readable description of the exception cause.  The strings used
247         are the same as the #define constant names found in the
248         microblaze_exceptions_i.h header file */
249         int8_t *pcExceptionCause;
250
251         /* The human readable name of the task that was running at the time the
252         exception occurred.  This is the name that was given to the task when the
253         task was created using the FreeRTOS xTaskCreate() API function. */
254         char *pcCurrentTaskName;
255
256         /* The handle of the task that was running a the time the exception
257         occurred. */
258         void * xCurrentTaskHandle;
259
260 } xPortRegisterDump;
261
262
263 /*
264  * Installs pxHandler as the interrupt handler for the peripheral specified by
265  * the ucInterruptID parameter.
266  *
267  * ucInterruptID:
268  *
269  * The ID of the peripheral that will have pxHandler assigned as its interrupt
270  * handler.  Peripheral IDs are defined in the xparameters.h header file, which
271  * is itself part of the BSP project.  For example, in the official demo
272  * application for this port, xparameters.h defines the following IDs for the
273  * four possible interrupt sources:
274  *
275  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.
276  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.
277  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.
278  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.
279  *
280  *
281  * pxHandler:
282  *
283  * A pointer to the interrupt handler function itself.  This must be a void
284  * function that takes a (void *) parameter.
285  *
286  *
287  * pvCallBackRef:
288  *
289  * The parameter passed into the handler function.  In many cases this will not
290  * be used and can be NULL.  Some times it is used to pass in a reference to
291  * the peripheral instance variable, so it can be accessed from inside the
292  * handler function.
293  *
294  *
295  * pdPASS is returned if the function executes successfully.  Any other value
296  * being returned indicates that the function did not execute correctly.
297  */
298 BaseType_t xPortInstallInterruptHandler( uint8_t ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef );
299
300
301 /*
302  * Enables the interrupt, within the interrupt controller, for the peripheral
303  * specified by the ucInterruptID parameter.
304  *
305  * ucInterruptID:
306  *
307  * The ID of the peripheral that will have its interrupt enabled in the
308  * interrupt controller.  Peripheral IDs are defined in the xparameters.h header
309  * file, which is itself part of the BSP project.  For example, in the official
310  * demo application for this port, xparameters.h defines the following IDs for
311  * the four possible interrupt sources:
312  *
313  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.
314  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.
315  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.
316  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.
317  *
318  */
319 void vPortEnableInterrupt( uint8_t ucInterruptID );
320
321 /*
322  * Disables the interrupt, within the interrupt controller, for the peripheral
323  * specified by the ucInterruptID parameter.
324  *
325  * ucInterruptID:
326  *
327  * The ID of the peripheral that will have its interrupt disabled in the
328  * interrupt controller.  Peripheral IDs are defined in the xparameters.h header
329  * file, which is itself part of the BSP project.  For example, in the official
330  * demo application for this port, xparameters.h defines the following IDs for
331  * the four possible interrupt sources:
332  *
333  * XPAR_INTC_0_UARTLITE_1_VEC_ID  -  for the UARTlite peripheral.
334  * XPAR_INTC_0_TMRCTR_0_VEC_ID    -  for the AXI Timer 0 peripheral.
335  * XPAR_INTC_0_EMACLITE_0_VEC_ID  -  for the Ethernet lite peripheral.
336  * XPAR_INTC_0_GPIO_1_VEC_ID      -  for the button inputs.
337  *
338  */
339 void vPortDisableInterrupt( uint8_t ucInterruptID );
340
341 /*
342  * This is an application defined callback function used to install the tick
343  * interrupt handler.  It is provided as an application callback because the
344  * kernel will run on lots of different MicroBlaze and FPGA configurations - not
345  * all of which will have the same timer peripherals defined or available.  This
346  * example uses the AXI Timer 0.  If that is available on your hardware platform
347  * then this example callback implementation should not require modification.
348  * The name of the interrupt handler that should be installed is vPortTickISR(),
349  * which the function below declares as an extern.
350  */
351 void vApplicationSetupTimerInterrupt( void );
352
353 /*
354  * This is an application defined callback function used to clear whichever
355  * interrupt was installed by the the vApplicationSetupTimerInterrupt() callback
356  * function - in this case the interrupt generated by the AXI timer.  It is
357  * provided as an application callback because the kernel will run on lots of
358  * different MicroBlaze and FPGA configurations - not all of which will have the
359  * same timer peripherals defined or available.  This example uses the AXI Timer 0.
360  * If that is available on your hardware platform then this example callback
361  * implementation should not require modification provided the example definition
362  * of vApplicationSetupTimerInterrupt() is also not modified.
363  */
364 void vApplicationClearTimerInterrupt( void );
365
366 /*
367  * vPortExceptionsInstallHandlers() is only available when the MicroBlaze
368  * is configured to include exception functionality, and
369  * configINSTALL_EXCEPTION_HANDLERS is set to 1 in FreeRTOSConfig.h.
370  *
371  * vPortExceptionsInstallHandlers() installs the FreeRTOS exception handler
372  * for every possible exception cause.
373  *
374  * vPortExceptionsInstallHandlers() can be called explicitly from application
375  * code.  After that is done, the default FreeRTOS exception handler that will
376  * have been installed can be replaced for any specific exception cause by using
377  * the standard Xilinx library function microblaze_register_exception_handler().
378  *
379  * If vPortExceptionsInstallHandlers() is not called explicitly by the
380  * application, it will be called automatically by the kernel the first time
381  * xPortInstallInterruptHandler() is called.  At that time, any exception
382  * handlers that may have already been installed will be replaced.
383  *
384  * See the description of vApplicationExceptionRegisterDump() for information
385  * on the processing performed by the FreeRTOS exception handler.
386  */
387 void vPortExceptionsInstallHandlers( void );
388
389 /*
390  * The FreeRTOS exception handler fills an xPortRegisterDump structure (defined
391  * in portmacro.h) with the MicroBlaze context, as it was at the time the
392  * exception occurred.  The exception handler then calls
393  * vApplicationExceptionRegisterDump(), passing in the completed
394  * xPortRegisterDump structure as its parameter.
395  *
396  * The FreeRTOS kernel provides its own implementation of
397  * vApplicationExceptionRegisterDump(), but the kernel provided implementation
398  * is declared as being 'weak'.  The weak definition allows the application
399  * writer to provide their own implementation, should they wish to use the
400  * register dump information.  For example, an implementation could be provided
401  * that wrote the register dump data to a display, or a UART port.
402  */
403 void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump );
404
405
406 #ifdef __cplusplus
407 }
408 #endif
409
410 #endif /* PORTMACRO_H */
411