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