2 * FreeRTOS Kernel V10.2.0
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
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.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
36 #include <mb_interface.h>
37 #include <xparameters.h>
39 /*-----------------------------------------------------------
40 * Port specific definitions.
42 * The settings in this file configure FreeRTOS correctly for the
43 * given hardware and compiler.
45 * These settings should not be altered.
46 *-----------------------------------------------------------
49 /* Type definitions. */
51 #define portFLOAT float
52 #define portDOUBLE double
54 #define portSHORT short
55 #define portSTACK_TYPE uint32_t
56 #define portBASE_TYPE long
58 typedef portSTACK_TYPE StackType_t;
59 typedef long BaseType_t;
60 typedef unsigned long UBaseType_t;
62 #if( configUSE_16_BIT_TICKS == 1 )
63 typedef uint16_t TickType_t;
64 #define portMAX_DELAY ( TickType_t ) 0xffff
66 typedef uint32_t TickType_t;
67 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
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
73 /*-----------------------------------------------------------*/
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 /*-----------------------------------------------------------*/
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++; \
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 ) \
98 /* The nesting has unwound and we \
99 can enable interrupts again. */ \
100 portENABLE_INTERRUPTS(); \
104 /*-----------------------------------------------------------*/
106 /* The yield macro maps directly to the vPortYield() function. */
107 void vPortYield( void );
108 #define portYIELD() vPortYield()
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
119 #if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )
121 /* Generic helper function. */
122 __attribute__( ( always_inline ) ) static inline uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap )
126 __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) );
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.
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 ) )
139 /*-----------------------------------------------------------*/
141 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) ucPortCountLeadingZeros( ( uxReadyPriorities ) ) )
143 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
145 /*-----------------------------------------------------------*/
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 /*-----------------------------------------------------------*/
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 /*-----------------------------------------------------------*/
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
164 /* The following structure members hold the values of the MicroBlaze
165 registers at the time the exception was raised. */
167 uint32_t ulR2_small_data_area;
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. */
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;
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;
214 /* The handle of the task that was running a the time the exception
216 void * xCurrentTaskHandle;
222 * Installs pxHandler as the interrupt handler for the peripheral specified by
223 * the ucInterruptID parameter.
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:
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.
241 * A pointer to the interrupt handler function itself. This must be a void
242 * function that takes a (void *) parameter.
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
253 * pdPASS is returned if the function executes successfully. Any other value
254 * being returned indicates that the function did not execute correctly.
256 BaseType_t xPortInstallInterruptHandler( uint8_t ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef );
260 * Enables the interrupt, within the interrupt controller, for the peripheral
261 * specified by the ucInterruptID parameter.
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:
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.
277 void vPortEnableInterrupt( uint8_t ucInterruptID );
280 * Disables the interrupt, within the interrupt controller, for the peripheral
281 * specified by the ucInterruptID parameter.
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:
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.
297 void vPortDisableInterrupt( uint8_t ucInterruptID );
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.
309 void vApplicationSetupTimerInterrupt( void );
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.
322 void vApplicationClearTimerInterrupt( void );
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.
329 * vPortExceptionsInstallHandlers() installs the FreeRTOS exception handler
330 * for every possible exception cause.
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().
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.
342 * See the description of vApplicationExceptionRegisterDump() for information
343 * on the processing performed by the FreeRTOS exception handler.
345 void vPortExceptionsInstallHandlers( void );
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.
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.
361 void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump );
368 #endif /* PORTMACRO_H */