2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
33 /*-----------------------------------------------------------
\r
34 * Port specific definitions.
\r
36 * The settings in this file configure FreeRTOS correctly for the
\r
37 * given hardware and compiler.
\r
39 * These settings should not be altered.
\r
40 *-----------------------------------------------------------
\r
43 /* Type definitions. */
\r
44 #define portCHAR char
\r
45 #define portFLOAT float
\r
46 #define portDOUBLE double
\r
47 #define portLONG long
\r
48 #define portSHORT short
\r
49 #define portSTACK_TYPE uint8_t
\r
50 #define portBASE_TYPE char
\r
52 typedef portSTACK_TYPE StackType_t;
\r
53 typedef signed char BaseType_t;
\r
54 typedef unsigned char UBaseType_t;
\r
56 #if( configUSE_16_BIT_TICKS == 1 )
\r
57 typedef uint16_t TickType_t;
\r
58 #define portMAX_DELAY ( TickType_t ) 0xffff
\r
60 typedef uint32_t TickType_t;
\r
61 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
\r
63 /*-----------------------------------------------------------*/
\r
65 /* Hardware specifics. */
\r
66 #define portBYTE_ALIGNMENT 1
\r
67 #define portSTACK_GROWTH ( -1 )
\r
68 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
\r
69 #define portYIELD() __asm( "swi" );
\r
70 #define portNOP() __asm( "nop" );
\r
71 /*-----------------------------------------------------------*/
\r
73 /* Critical section handling. */
\r
74 #define portENABLE_INTERRUPTS() __asm( "cli" )
\r
75 #define portDISABLE_INTERRUPTS() __asm( "sei" )
\r
78 * Disable interrupts before incrementing the count of critical section nesting.
\r
79 * The nesting count is maintained so we know when interrupts should be
\r
80 * re-enabled. Once interrupts are disabled the nesting count can be accessed
\r
81 * directly. Each task maintains its own nesting count.
\r
83 #define portENTER_CRITICAL() \
\r
85 extern volatile UBaseType_t uxCriticalNesting; \
\r
87 portDISABLE_INTERRUPTS(); \
\r
88 uxCriticalNesting++; \
\r
92 * Interrupts are disabled so we can access the nesting count directly. If the
\r
93 * nesting is found to be 0 (no nesting) then we are leaving the critical
\r
94 * section and interrupts can be re-enabled.
\r
96 #define portEXIT_CRITICAL() \
\r
98 extern volatile UBaseType_t uxCriticalNesting; \
\r
100 uxCriticalNesting--; \
\r
101 if( uxCriticalNesting == 0 ) \
\r
103 portENABLE_INTERRUPTS(); \
\r
106 /*-----------------------------------------------------------*/
\r
108 /* Task utilities. */
\r
111 * These macros are very simple as the processor automatically saves and
\r
112 * restores its registers as interrupts are entered and exited. In
\r
113 * addition to the (automatically stacked) registers we also stack the
\r
114 * critical nesting count. Each task maintains its own critical nesting
\r
115 * count as it is legitimate for a task to yield from within a critical
\r
116 * section. If the banked memory model is being used then the PPAGE
\r
117 * register is also stored as part of the tasks context.
\r
120 #ifdef BANKED_MODEL
\r
122 * Load the stack pointer for the task, then pull the critical nesting
\r
123 * count and PPAGE register from the stack. The remains of the
\r
124 * context are restored by the RTI instruction.
\r
126 #define portRESTORE_CONTEXT() \
\r
128 extern volatile void * pxCurrentTCB; \
\r
129 extern volatile UBaseType_t uxCriticalNesting; \
\r
131 __asm( "ldx pxCurrentTCB" ); \
\r
132 __asm( "lds 0, x" ); \
\r
134 __asm( "staa uxCriticalNesting" ); \
\r
136 __asm( "staa 0x30" ); /* 0x30 = PPAGE */ \
\r
140 * By the time this macro is called the processor has already stacked the
\r
141 * registers. Simply stack the nesting count and PPAGE value, then save
\r
142 * the task stack pointer.
\r
144 #define portSAVE_CONTEXT() \
\r
146 extern volatile void * pxCurrentTCB; \
\r
147 extern volatile UBaseType_t uxCriticalNesting; \
\r
149 __asm( "ldaa 0x30" ); /* 0x30 = PPAGE */ \
\r
151 __asm( "ldaa uxCriticalNesting" ); \
\r
153 __asm( "ldx pxCurrentTCB" ); \
\r
154 __asm( "sts 0, x" ); \
\r
159 * These macros are as per the BANKED versions above, but without saving
\r
160 * and restoring the PPAGE register.
\r
163 #define portRESTORE_CONTEXT() \
\r
165 extern volatile void * pxCurrentTCB; \
\r
166 extern volatile UBaseType_t uxCriticalNesting; \
\r
168 __asm( "ldx pxCurrentTCB" ); \
\r
169 __asm( "lds 0, x" ); \
\r
171 __asm( "staa uxCriticalNesting" ); \
\r
174 #define portSAVE_CONTEXT() \
\r
176 extern volatile void * pxCurrentTCB; \
\r
177 extern volatile UBaseType_t uxCriticalNesting; \
\r
179 __asm( "ldaa uxCriticalNesting" ); \
\r
181 __asm( "ldx pxCurrentTCB" ); \
\r
182 __asm( "sts 0, x" ); \
\r
187 * Utility macro to call macros above in correct order in order to perform a
\r
188 * task switch from within a standard ISR. This macro can only be used if
\r
189 * the ISR does not use any local (stack) variables. If the ISR uses stack
\r
190 * variables portYIELD() should be used in it's place.
\r
192 #define portTASK_SWITCH_FROM_ISR() \
\r
193 portSAVE_CONTEXT(); \
\r
194 vTaskSwitchContext(); \
\r
195 portRESTORE_CONTEXT();
\r
198 /* Task function macros as described on the FreeRTOS.org WEB site. */
\r
199 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
\r
200 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
\r
202 #endif /* PORTMACRO_H */
\r