2 * FreeRTOS 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
32 /*-----------------------------------------------------------
33 * Port specific definitions.
35 * The settings in this file configure FreeRTOS correctly for the
36 * given hardware and compiler.
38 * These settings should not be altered.
39 *-----------------------------------------------------------
42 /* Type definitions. */
44 #define portFLOAT float
45 #define portDOUBLE double
47 #define portSHORT short
48 #define portSTACK_TYPE uint8_t
49 #define portBASE_TYPE char
51 typedef portSTACK_TYPE StackType_t;
52 typedef signed char BaseType_t;
53 typedef unsigned char UBaseType_t;
55 #if( configUSE_16_BIT_TICKS == 1 )
56 typedef uint16_t TickType_t;
57 #define portMAX_DELAY ( TickType_t ) 0xffff
59 typedef uint32_t TickType_t;
60 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
62 /*-----------------------------------------------------------*/
64 /* Hardware specifics. */
65 #define portBYTE_ALIGNMENT 1
66 #define portSTACK_GROWTH ( -1 )
67 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
68 #define portYIELD() __asm( "swi" );
69 #define portNOP() __asm( "nop" );
70 /*-----------------------------------------------------------*/
72 /* Critical section handling. */
73 #define portENABLE_INTERRUPTS() __asm( "cli" )
74 #define portDISABLE_INTERRUPTS() __asm( "sei" )
77 * Disable interrupts before incrementing the count of critical section nesting.
78 * The nesting count is maintained so we know when interrupts should be
79 * re-enabled. Once interrupts are disabled the nesting count can be accessed
80 * directly. Each task maintains its own nesting count.
82 #define portENTER_CRITICAL() \
84 extern volatile UBaseType_t uxCriticalNesting; \
86 portDISABLE_INTERRUPTS(); \
87 uxCriticalNesting++; \
91 * Interrupts are disabled so we can access the nesting count directly. If the
92 * nesting is found to be 0 (no nesting) then we are leaving the critical
93 * section and interrupts can be re-enabled.
95 #define portEXIT_CRITICAL() \
97 extern volatile UBaseType_t uxCriticalNesting; \
99 uxCriticalNesting--; \
100 if( uxCriticalNesting == 0 ) \
102 portENABLE_INTERRUPTS(); \
105 /*-----------------------------------------------------------*/
107 /* Task utilities. */
110 * These macros are very simple as the processor automatically saves and
111 * restores its registers as interrupts are entered and exited. In
112 * addition to the (automatically stacked) registers we also stack the
113 * critical nesting count. Each task maintains its own critical nesting
114 * count as it is legitimate for a task to yield from within a critical
115 * section. If the banked memory model is being used then the PPAGE
116 * register is also stored as part of the tasks context.
121 * Load the stack pointer for the task, then pull the critical nesting
122 * count and PPAGE register from the stack. The remains of the
123 * context are restored by the RTI instruction.
125 #define portRESTORE_CONTEXT() \
127 extern volatile void * pxCurrentTCB; \
128 extern volatile UBaseType_t uxCriticalNesting; \
130 __asm( "ldx pxCurrentTCB" ); \
131 __asm( "lds 0, x" ); \
133 __asm( "staa uxCriticalNesting" ); \
135 __asm( "staa 0x30" ); /* 0x30 = PPAGE */ \
139 * By the time this macro is called the processor has already stacked the
140 * registers. Simply stack the nesting count and PPAGE value, then save
141 * the task stack pointer.
143 #define portSAVE_CONTEXT() \
145 extern volatile void * pxCurrentTCB; \
146 extern volatile UBaseType_t uxCriticalNesting; \
148 __asm( "ldaa 0x30" ); /* 0x30 = PPAGE */ \
150 __asm( "ldaa uxCriticalNesting" ); \
152 __asm( "ldx pxCurrentTCB" ); \
153 __asm( "sts 0, x" ); \
158 * These macros are as per the BANKED versions above, but without saving
159 * and restoring the PPAGE register.
162 #define portRESTORE_CONTEXT() \
164 extern volatile void * pxCurrentTCB; \
165 extern volatile UBaseType_t uxCriticalNesting; \
167 __asm( "ldx pxCurrentTCB" ); \
168 __asm( "lds 0, x" ); \
170 __asm( "staa uxCriticalNesting" ); \
173 #define portSAVE_CONTEXT() \
175 extern volatile void * pxCurrentTCB; \
176 extern volatile UBaseType_t uxCriticalNesting; \
178 __asm( "ldaa uxCriticalNesting" ); \
180 __asm( "ldx pxCurrentTCB" ); \
181 __asm( "sts 0, x" ); \
186 * Utility macro to call macros above in correct order in order to perform a
187 * task switch from within a standard ISR. This macro can only be used if
188 * the ISR does not use any local (stack) variables. If the ISR uses stack
189 * variables portYIELD() should be used in it's place.
191 #define portTASK_SWITCH_FROM_ISR() \
192 portSAVE_CONTEXT(); \
193 vTaskSwitchContext(); \
194 portRESTORE_CONTEXT();
197 /* Task function macros as described on the FreeRTOS.org WEB site. */
198 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
199 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
201 #endif /* PORTMACRO_H */