2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
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.
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 ***************************************************************************
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
25 ***************************************************************************
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. *
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 *
37 ***************************************************************************
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()?
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.
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.
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.
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.
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.
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.
78 #include <mb_interface.h>
79 #include <xparameters.h>
81 /*-----------------------------------------------------------
82 * Port specific definitions.
84 * The settings in this file configure FreeRTOS correctly for the
85 * given hardware and compiler.
87 * These settings should not be altered.
88 *-----------------------------------------------------------
91 /* Type definitions. */
93 #define portFLOAT float
94 #define portDOUBLE double
96 #define portSHORT short
97 #define portSTACK_TYPE uint32_t
98 #define portBASE_TYPE long
100 typedef portSTACK_TYPE StackType_t;
101 typedef long BaseType_t;
102 typedef unsigned long UBaseType_t;
104 #if( configUSE_16_BIT_TICKS == 1 )
105 typedef uint16_t TickType_t;
106 #define portMAX_DELAY ( TickType_t ) 0xffff
108 typedef uint32_t TickType_t;
109 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
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
115 /*-----------------------------------------------------------*/
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 /*-----------------------------------------------------------*/
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++; \
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 ) \
140 /* The nesting has unwound and we \
141 can enable interrupts again. */ \
142 portENABLE_INTERRUPTS(); \
146 /*-----------------------------------------------------------*/
148 /* The yield macro maps directly to the vPortYield() function. */
149 void vPortYield( void );
150 #define portYIELD() vPortYield()
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
161 #if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )
163 /* Generic helper function. */
164 __attribute__( ( always_inline ) ) static inline uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap )
168 __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) );
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.
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 ) )
181 /*-----------------------------------------------------------*/
183 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) ucPortCountLeadingZeros( ( uxReadyPriorities ) ) )
185 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
187 /*-----------------------------------------------------------*/
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 /*-----------------------------------------------------------*/
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 /*-----------------------------------------------------------*/
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
206 /* The following structure members hold the values of the MicroBlaze
207 registers at the time the exception was raised. */
209 uint32_t ulR2_small_data_area;
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. */
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;
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;
256 /* The handle of the task that was running a the time the exception
258 void * xCurrentTaskHandle;
264 * Installs pxHandler as the interrupt handler for the peripheral specified by
265 * the ucInterruptID parameter.
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:
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.
283 * A pointer to the interrupt handler function itself. This must be a void
284 * function that takes a (void *) parameter.
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
295 * pdPASS is returned if the function executes successfully. Any other value
296 * being returned indicates that the function did not execute correctly.
298 BaseType_t xPortInstallInterruptHandler( uint8_t ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef );
302 * Enables the interrupt, within the interrupt controller, for the peripheral
303 * specified by the ucInterruptID parameter.
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:
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.
319 void vPortEnableInterrupt( uint8_t ucInterruptID );
322 * Disables the interrupt, within the interrupt controller, for the peripheral
323 * specified by the ucInterruptID parameter.
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:
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.
339 void vPortDisableInterrupt( uint8_t ucInterruptID );
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.
351 void vApplicationSetupTimerInterrupt( void );
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.
364 void vApplicationClearTimerInterrupt( void );
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.
371 * vPortExceptionsInstallHandlers() installs the FreeRTOS exception handler
372 * for every possible exception cause.
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().
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.
384 * See the description of vApplicationExceptionRegisterDump() for information
385 * on the processing performed by the FreeRTOS exception handler.
387 void vPortExceptionsInstallHandlers( void );
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.
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.
403 void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump );
410 #endif /* PORTMACRO_H */