2 * FreeRTOS SMP Kernel V202110.00
3 * Copyright (C) 2020 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 * https://www.FreeRTOS.org
23 * https://github.com/FreeRTOS
36 /*-----------------------------------------------------------
37 * Port specific definitions.
39 * The settings in this file configure FreeRTOS correctly for the
40 * given hardware and compiler.
42 * These settings should not be altered.
43 *-----------------------------------------------------------
46 /* Type definitions. */
48 #define portFLOAT float
49 #define portDOUBLE double
51 #define portSHORT short
52 #define portSTACK_TYPE uint8_t
53 #define portBASE_TYPE char
55 typedef portSTACK_TYPE StackType_t;
56 typedef signed char BaseType_t;
57 typedef unsigned char UBaseType_t;
60 #if( configUSE_16_BIT_TICKS == 1 )
61 typedef uint16_t TickType_t;
62 #define portMAX_DELAY ( TickType_t ) 0xffff
64 typedef uint32_t TickType_t;
65 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
67 /*-----------------------------------------------------------*/
69 /* Hardware specifics. */
70 #define portBYTE_ALIGNMENT 1
71 #define portSTACK_GROWTH ( -1 )
72 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
73 #define portYIELD() __asm( "swi" );
74 /*-----------------------------------------------------------*/
76 /* Critical section handling. */
77 #define portENABLE_INTERRUPTS() __asm( "cli" )
78 #define portDISABLE_INTERRUPTS() __asm( "sei" )
81 * Disable interrupts before incrementing the count of critical section nesting.
82 * The nesting count is maintained so we know when interrupts should be
83 * re-enabled. Once interrupts are disabled the nesting count can be accessed
84 * directly. Each task maintains its own nesting count.
86 #define portENTER_CRITICAL() \
88 extern volatile UBaseType_t uxCriticalNesting; \
90 portDISABLE_INTERRUPTS(); \
91 uxCriticalNesting++; \
95 * Interrupts are disabled so we can access the nesting count directly. If the
96 * nesting is found to be 0 (no nesting) then we are leaving the critical
97 * section and interrupts can be re-enabled.
99 #define portEXIT_CRITICAL() \
101 extern volatile UBaseType_t uxCriticalNesting; \
103 uxCriticalNesting--; \
104 if( uxCriticalNesting == 0 ) \
106 portENABLE_INTERRUPTS(); \
109 /*-----------------------------------------------------------*/
111 /* Task utilities. */
114 * These macros are very simple as the processor automatically saves and
115 * restores its registers as interrupts are entered and exited. In
116 * addition to the (automatically stacked) registers we also stack the
117 * critical nesting count. Each task maintains its own critical nesting
118 * count as it is legitimate for a task to yield from within a critical
119 * section. If the banked memory model is being used then the PPAGE
120 * register is also stored as part of the tasks context.
125 * Load the stack pointer for the task, then pull the critical nesting
126 * count and PPAGE register from the stack. The remains of the
127 * context are restored by the RTI instruction.
129 #define portRESTORE_CONTEXT() \
132 .globl pxCurrentTCB ; void * \n\
133 .globl uxCriticalNesting ; char \n\
138 movb 1,sp+,uxCriticalNesting \n\
139 movb 1,sp+,0x30 ; PPAGE \n\
144 * By the time this macro is called the processor has already stacked the
145 * registers. Simply stack the nesting count and PPAGE value, then save
146 * the task stack pointer.
148 #define portSAVE_CONTEXT() \
151 .globl pxCurrentTCB ; void * \n\
152 .globl uxCriticalNesting ; char \n\
154 movb 0x30, 1,-sp ; PPAGE \n\
155 movb uxCriticalNesting, 1,-sp \n\
164 * These macros are as per the BANKED versions above, but without saving
165 * and restoring the PPAGE register.
168 #define portRESTORE_CONTEXT() \
171 .globl pxCurrentTCB ; void * \n\
172 .globl uxCriticalNesting ; char \n\
177 movb 1,sp+,uxCriticalNesting \n\
181 #define portSAVE_CONTEXT() \
184 .globl pxCurrentTCB ; void * \n\
185 .globl uxCriticalNesting ; char \n\
187 movb uxCriticalNesting, 1,-sp \n\
196 * Utility macros to save/restore correct software registers for GCC. This is
197 * useful when GCC does not generate appropriate ISR head/tail code.
199 #define portISR_HEAD() \
202 movw _.frame, 2,-sp \n\
203 movw _.tmp, 2,-sp \n\
206 ;movw _.d2, 2,-sp \n\
207 ;movw _.d1, 2,-sp \n\
211 #define portISR_TAIL() \
216 movw 2,sp+, _.tmp \n\
217 movw 2,sp+, _.frame \n\
218 ;movw 2,sp+, _.d1 \n\
219 ;movw 2,sp+, _.d2 \n\
225 * Utility macro to call macros above in correct order in order to perform a
226 * task switch from within a standard ISR. This macro can only be used if
227 * the ISR does not use any local (stack) variables. If the ISR uses stack
228 * variables portYIELD() should be used in it's place.
231 #define portTASK_SWITCH_FROM_ISR() \
232 portSAVE_CONTEXT(); \
233 vTaskSwitchContext(); \
234 portRESTORE_CONTEXT();
237 /* Task function macros as described on the FreeRTOS.org WEB site. */
238 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
239 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
245 #endif /* PORTMACRO_H */