1 // Copyright (c) 2020, XMOS Ltd, All rights reserved
8 /* Inclusion of xc1.h will result in clock being defined as a type.
9 * By default, FreeRTOS will require standard time.h, where clock is a function.
11 #ifndef USE_XCORE_CLOCK_TYPE
12 #define _clock_defined
16 #include "rtos_support.h"
22 /* Type definitions. */
23 #define portSTACK_TYPE uint32_t
24 typedef portSTACK_TYPE StackType_t;
25 typedef double portDOUBLE;
26 typedef int32_t BaseType_t;
27 typedef uint32_t UBaseType_t;
29 #if( configUSE_16_BIT_TICKS == 1 )
30 typedef uint16_t TickType_t;
31 #define portMAX_DELAY ( TickType_t ) 0xffff
33 typedef uint32_t TickType_t;
34 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
36 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
37 not need to be guarded with a critical section. */
38 #define portTICK_TYPE_IS_ATOMIC 1
40 /*-----------------------------------------------------------*/
42 #endif /* __ASSEMBLER__ */
44 /* Architecture specifics. These can be used by assembly files as well. */
45 #define portSTACK_GROWTH ( -1 )
46 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
47 #define portBYTE_ALIGNMENT 8
48 #define portCRITICAL_NESTING_IN_TCB 1
49 #define portMAX_CORE_COUNT 8
50 #ifndef configNUM_CORES
51 #define configNUM_CORES 1
54 /* This may be set to zero in the config file if the rtos_time
55 functions are not needed or if it is incremented elsewhere. */
56 #ifndef configUPDATE_RTOS_TIME_FROM_TICK_ISR
57 #define configUPDATE_RTOS_TIME_FROM_TICK_ISR 1
61 * When entering an ISR we need to grow the stack by one more word than
62 * we actually need to save the thread context. This is because there are
63 * some functions, written in assembly *cough* memcpy() *cough*, that think
64 * it is OK to store words at SP[0]. Therefore the ISR must leave SP[0] alone
65 * even though it is normally not necessary to do so.
67 #define portTHREAD_CONTEXT_STACK_GROWTH RTOS_SUPPORT_INTERRUPT_STACK_GROWTH
71 /* Check validity of number of cores specified in config */
72 #if ( configNUM_CORES < 1 || portMAX_CORE_COUNT < configNUM_CORES )
73 #error "Invalid number of cores specified in config!"
76 #define portMEMORY_BARRIER() RTOS_MEMORY_BARRIER()
77 #define portTASK_STACK_DEPTH(pxTaskCode) RTOS_THREAD_STACK_SIZE(pxTaskCode)
78 /*-----------------------------------------------------------*/
80 /* Scheduler utilities. */
81 #define portYIELD() asm volatile( "KCALLI_lu6 0" ::: "memory" )
83 #define portEND_SWITCHING_ISR( xSwitchRequired ) \
86 if( xSwitchRequired != pdFALSE ) \
88 extern uint32_t ulPortYieldRequired[ portMAX_CORE_COUNT ]; \
89 ulPortYieldRequired[ portGET_CORE_ID() ] = pdTRUE; \
93 #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
94 /*-----------------------------------------------------------*/
97 #define portGET_CORE_ID() rtos_core_id_get()
99 void vPortYieldOtherCore( int xOtherCoreID );
100 #define portYIELD_CORE( x ) vPortYieldOtherCore( x )
101 /*-----------------------------------------------------------*/
103 /* Architecture specific optimisations. */
104 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
105 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
108 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
110 /* Store/clear the ready priorities in a bit map. */
111 #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
112 #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
114 /*-----------------------------------------------------------*/
116 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __builtin_clz( uxReadyPriorities ) )
118 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
119 /*-----------------------------------------------------------*/
121 /* Critical section management. */
123 #define portGET_INTERRUPT_STATE() rtos_interrupt_mask_get()
126 * This differs from the standard portDISABLE_INTERRUPTS()
127 * in that it also returns what the interrupt state was
128 * before it disabling interrupts.
130 #define portDISABLE_INTERRUPTS() rtos_interrupt_mask_all()
132 #define portENABLE_INTERRUPTS() rtos_interrupt_unmask_all()
135 * Will enable interrupts if ulState is non-zero.
137 #define portRESTORE_INTERRUPTS(ulState) rtos_interrupt_mask_set(ulState)
140 * Returns non-zero if currently running in an
141 * ISR or otherwise in kernel mode.
143 #define portCHECK_IF_IN_ISR() rtos_isr_running()
145 #define portASSERT_IF_IN_ISR() configASSERT( portCHECK_IF_IN_ISR() == 0 )
147 #define portGET_ISR_LOCK() rtos_lock_acquire(0)
148 #define portRELEASE_ISR_LOCK() rtos_lock_release(0)
149 #define portGET_TASK_LOCK() rtos_lock_acquire(1)
150 #define portRELEASE_TASK_LOCK() rtos_lock_release(1)
152 void vTaskEnterCritical(void);
153 void vTaskExitCritical(void);
154 #define portENTER_CRITICAL() vTaskEnterCritical()
155 #define portEXIT_CRITICAL() vTaskExitCritical()
158 * vTaskEnterCritical() has been modified to be safe to use
159 * from within ISRs. The previous mask does not need to be
160 * returned since in the xCORE interrupts are always disabled
161 * in ISRs. Effectively this call just grabs the kernel lock
162 * when called from an ISR.
164 #define portSET_INTERRUPT_MASK_FROM_ISR() (vTaskEnterCritical(), 0)
167 * vTaskExitCritical() has been modified to be safe to use
168 * from within ISRs. When the nesting level has reached zero
169 * it releases the lock, but when called from within an ISR
170 * it will *not* re-enable interrupts since it is assumed they
171 * were previously disabled. Thus the previous state in x is
174 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) (vTaskExitCritical(), (void) x)
176 /*-----------------------------------------------------------*/
178 /* Runtime stats support */
179 #if ( configGENERATE_RUN_TIME_STATS == 1 )
180 int xscope_gettime( void );
181 #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() /* nothing needed here */
182 #define portGET_RUN_TIME_COUNTER_VALUE() xscope_gettime()
184 /*-----------------------------------------------------------*/
186 /* Maps sprintf and snprintf to the lite version in lib_rtos_support */
187 #if ( configUSE_DEBUG_SPRINTF == 1 )
188 #define sprintf(...) rtos_sprintf(__VA_ARGS__)
189 #define snprintf(...) rtos_snprintf(__VA_ARGS__)
192 /* Attribute for the pxCallbackFunction member of the Timer_t struct.
193 Required by xcc to calculate stack usage. */
194 #define portTIMER_CALLBACK_ATTRIBUTE __attribute__((fptrgroup("timerCallbackGroup")))
196 /* Timer callback function macros. For xcc this ensures they get added to the timer callback
197 group so that stack usage for certain functions in timers.c can be calculated. */
198 #define portTIMER_CALLBACK_FUNCTION_PROTO( vFunction, xTimer ) void vFunction( TimerHandle_t xTimer )
199 #define portTIMER_CALLBACK_FUNCTION( vFunction, xTimer ) portTIMER_CALLBACK_ATTRIBUTE void vFunction( TimerHandle_t xTimer )
201 /*-----------------------------------------------------------*/
203 /* Task function macros as described on the FreeRTOS.org WEB site. These are
204 not necessary for to use this port. They are defined so the common demo files
205 (which build with all the ports) will build. */
206 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
207 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
208 /*-----------------------------------------------------------*/
215 #endif /* __ASSEMBLER__ */
217 #endif /* PORTMACRO_H */