2 * FreeRTOS Kernel V10.3.1
\r
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
35 #include <mb_interface.h>
\r
36 #include <xparameters.h>
\r
38 /*-----------------------------------------------------------
\r
39 * Port specific definitions.
\r
41 * The settings in this file configure FreeRTOS correctly for the
\r
42 * given hardware and compiler.
\r
44 * These settings should not be altered.
\r
45 *-----------------------------------------------------------
\r
48 /* Type definitions. */
\r
49 #define portCHAR char
\r
50 #define portFLOAT float
\r
51 #define portDOUBLE double
\r
52 #define portLONG long
\r
53 #define portSHORT short
\r
54 #define portSTACK_TYPE uint32_t
\r
55 #define portBASE_TYPE long
\r
57 typedef portSTACK_TYPE StackType_t;
\r
58 typedef long BaseType_t;
\r
59 typedef unsigned long UBaseType_t;
\r
61 #if ( configUSE_16_BIT_TICKS == 1 )
\r
62 typedef uint16_t TickType_t;
\r
63 #define portMAX_DELAY ( TickType_t ) 0xffff
\r
65 typedef uint32_t TickType_t;
\r
66 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
\r
68 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
\r
69 * not need to be guarded with a critical section. */
\r
70 #define portTICK_TYPE_IS_ATOMIC 1
\r
72 /*-----------------------------------------------------------*/
\r
74 /* Interrupt control macros and functions. */
\r
75 void microblaze_disable_interrupts( void );
\r
76 void microblaze_enable_interrupts( void );
\r
77 #define portDISABLE_INTERRUPTS() microblaze_disable_interrupts()
\r
78 #define portENABLE_INTERRUPTS() microblaze_enable_interrupts()
\r
79 /*-----------------------------------------------------------*/
\r
81 /* Critical section macros. */
\r
82 void vPortEnterCritical( void );
\r
83 void vPortExitCritical( void );
\r
84 #define portENTER_CRITICAL() \
\r
86 extern volatile UBaseType_t uxCriticalNesting; \
\r
87 microblaze_disable_interrupts(); \
\r
88 uxCriticalNesting++; \
\r
91 #define portEXIT_CRITICAL() \
\r
93 extern volatile UBaseType_t uxCriticalNesting; \
\r
94 /* Interrupts are disabled, so we can */ \
\r
95 /* access the variable directly. */ \
\r
96 uxCriticalNesting--; \
\r
97 if( uxCriticalNesting == 0 ) \
\r
99 /* The nesting has unwound and we \
\r
100 * can enable interrupts again. */ \
\r
101 portENABLE_INTERRUPTS(); \
\r
105 /*-----------------------------------------------------------*/
\r
107 /* The yield macro maps directly to the vPortYield() function. */
\r
108 void vPortYield( void );
\r
109 #define portYIELD() vPortYield()
\r
111 /* portYIELD_FROM_ISR() does not directly call vTaskSwitchContext(), but instead
\r
112 * sets a flag to say that a yield has been requested. The interrupt exit code
\r
113 * then checks this flag, and calls vTaskSwitchContext() before restoring a task
\r
114 * context, if the flag is not false. This is done to prevent multiple calls to
\r
115 * vTaskSwitchContext() being made from a single interrupt, as a single interrupt
\r
116 * can result in multiple peripherals being serviced. */
\r
117 extern volatile uint32_t ulTaskSwitchRequested;
\r
118 #define portYIELD_FROM_ISR( x ) if( ( x ) != pdFALSE ) ulTaskSwitchRequested = 1
\r
120 #if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )
\r
122 /* Generic helper function. */
\r
123 __attribute__( ( always_inline ) ) static inline uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap )
\r
127 __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) );
\r
132 /* Check the configuration. */
\r
133 #if ( configMAX_PRIORITIES > 32 )
\r
134 #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.
\r
137 /* Store/clear the ready priorities in a bit map. */
\r
138 #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
\r
139 #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
\r
141 /*-----------------------------------------------------------*/
\r
143 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) ucPortCountLeadingZeros( ( uxReadyPriorities ) ) )
\r
145 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
\r
147 /*-----------------------------------------------------------*/
\r
149 /* Hardware specifics. */
\r
150 #define portBYTE_ALIGNMENT 4
\r
151 #define portSTACK_GROWTH ( -1 )
\r
152 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
\r
153 #define portNOP() asm volatile ( "NOP" )
\r
154 /*-----------------------------------------------------------*/
\r
156 /* Task function macros as described on the FreeRTOS.org WEB site. */
\r
157 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
\r
158 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
\r
159 /*-----------------------------------------------------------*/
\r
161 /* The following structure is used by the FreeRTOS exception handler. It is
\r
162 * filled with the MicroBlaze context as it was at the time the exception occurred.
\r
163 * This is done as an aid to debugging exception occurrences. */
\r
164 typedef struct PORT_REGISTER_DUMP
\r
166 /* The following structure members hold the values of the MicroBlaze
\r
167 * registers at the time the exception was raised. */
\r
169 uint32_t ulR2_small_data_area;
\r
180 uint32_t ulR13_read_write_small_data_area;
\r
181 uint32_t ulR14_return_address_from_interrupt;
\r
182 uint32_t ulR15_return_address_from_subroutine;
\r
183 uint32_t ulR16_return_address_from_trap;
\r
184 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. */
\r
206 /* A human readable description of the exception cause. The strings used
\r
207 * are the same as the #define constant names found in the
\r
208 * microblaze_exceptions_i.h header file */
\r
209 int8_t * pcExceptionCause;
\r
211 /* The human readable name of the task that was running at the time the
\r
212 * exception occurred. This is the name that was given to the task when the
\r
213 * task was created using the FreeRTOS xTaskCreate() API function. */
\r
214 char * pcCurrentTaskName;
\r
216 /* The handle of the task that was running a the time the exception
\r
218 void * xCurrentTaskHandle;
\r
219 } xPortRegisterDump;
\r
223 * Installs pxHandler as the interrupt handler for the peripheral specified by
\r
224 * the ucInterruptID parameter.
\r
228 * The ID of the peripheral that will have pxHandler assigned as its interrupt
\r
229 * handler. Peripheral IDs are defined in the xparameters.h header file, which
\r
230 * is itself part of the BSP project. For example, in the official demo
\r
231 * application for this port, xparameters.h defines the following IDs for the
\r
232 * four possible interrupt sources:
\r
234 * XPAR_INTC_0_UARTLITE_1_VEC_ID - for the UARTlite peripheral.
\r
235 * XPAR_INTC_0_TMRCTR_0_VEC_ID - for the AXI Timer 0 peripheral.
\r
236 * XPAR_INTC_0_EMACLITE_0_VEC_ID - for the Ethernet lite peripheral.
\r
237 * XPAR_INTC_0_GPIO_1_VEC_ID - for the button inputs.
\r
242 * A pointer to the interrupt handler function itself. This must be a void
\r
243 * function that takes a (void *) parameter.
\r
248 * The parameter passed into the handler function. In many cases this will not
\r
249 * be used and can be NULL. Some times it is used to pass in a reference to
\r
250 * the peripheral instance variable, so it can be accessed from inside the
\r
251 * handler function.
\r
254 * pdPASS is returned if the function executes successfully. Any other value
\r
255 * being returned indicates that the function did not execute correctly.
\r
257 BaseType_t xPortInstallInterruptHandler( uint8_t ucInterruptID,
\r
258 XInterruptHandler pxHandler,
\r
259 void * pvCallBackRef );
\r
263 * Enables the interrupt, within the interrupt controller, for the peripheral
\r
264 * specified by the ucInterruptID parameter.
\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
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
280 void vPortEnableInterrupt( uint8_t ucInterruptID );
\r
283 * Disables the interrupt, within the interrupt controller, for the peripheral
\r
284 * specified by the ucInterruptID parameter.
\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
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
300 void vPortDisableInterrupt( uint8_t ucInterruptID );
\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
312 void vApplicationSetupTimerInterrupt( void );
\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
325 void vApplicationClearTimerInterrupt( void );
\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
332 * vPortExceptionsInstallHandlers() installs the FreeRTOS exception handler
\r
333 * for every possible exception cause.
\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
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
345 * See the description of vApplicationExceptionRegisterDump() for information
\r
346 * on the processing performed by the FreeRTOS exception handler.
\r
348 void vPortExceptionsInstallHandlers( void );
\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
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
364 void vApplicationExceptionRegisterDump( xPortRegisterDump * xRegisterDump );
\r
371 #endif /* PORTMACRO_H */
\r