2 * FreeRTOS Kernel V10.1.0
\r
3 * Copyright (C) 2018 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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
36 /*-----------------------------------------------------------
\r
37 * Port specific definitions.
\r
39 * The settings in this file configure FreeRTOS correctly for the
\r
40 * given hardware and compiler.
\r
42 * These settings should not be altered.
\r
43 *-----------------------------------------------------------
\r
46 /* Type definitions. */
\r
47 #define portCHAR char
\r
48 #define portFLOAT float
\r
49 #define portDOUBLE double
\r
50 #define portLONG long
\r
51 #define portSHORT short
\r
52 #define portSTACK_TYPE uint8_t
\r
53 #define portBASE_TYPE char
\r
55 typedef portSTACK_TYPE StackType_t;
\r
56 typedef signed char BaseType_t;
\r
57 typedef unsigned char UBaseType_t;
\r
60 #if( configUSE_16_BIT_TICKS == 1 )
\r
61 typedef uint16_t TickType_t;
\r
62 #define portMAX_DELAY ( TickType_t ) 0xffff
\r
64 typedef uint32_t TickType_t;
\r
65 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
\r
67 /*-----------------------------------------------------------*/
\r
69 /* Hardware specifics. */
\r
70 #define portBYTE_ALIGNMENT 1
\r
71 #define portSTACK_GROWTH ( -1 )
\r
72 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
\r
73 #define portYIELD() __asm( "swi" );
\r
74 /*-----------------------------------------------------------*/
\r
76 /* Critical section handling. */
\r
77 #define portENABLE_INTERRUPTS() __asm( "cli" )
\r
78 #define portDISABLE_INTERRUPTS() __asm( "sei" )
\r
81 * Disable interrupts before incrementing the count of critical section nesting.
\r
82 * The nesting count is maintained so we know when interrupts should be
\r
83 * re-enabled. Once interrupts are disabled the nesting count can be accessed
\r
84 * directly. Each task maintains its own nesting count.
\r
86 #define portENTER_CRITICAL() \
\r
88 extern volatile UBaseType_t uxCriticalNesting; \
\r
90 portDISABLE_INTERRUPTS(); \
\r
91 uxCriticalNesting++; \
\r
95 * Interrupts are disabled so we can access the nesting count directly. If the
\r
96 * nesting is found to be 0 (no nesting) then we are leaving the critical
\r
97 * section and interrupts can be re-enabled.
\r
99 #define portEXIT_CRITICAL() \
\r
101 extern volatile UBaseType_t uxCriticalNesting; \
\r
103 uxCriticalNesting--; \
\r
104 if( uxCriticalNesting == 0 ) \
\r
106 portENABLE_INTERRUPTS(); \
\r
109 /*-----------------------------------------------------------*/
\r
111 /* Task utilities. */
\r
114 * These macros are very simple as the processor automatically saves and
\r
115 * restores its registers as interrupts are entered and exited. In
\r
116 * addition to the (automatically stacked) registers we also stack the
\r
117 * critical nesting count. Each task maintains its own critical nesting
\r
118 * count as it is legitimate for a task to yield from within a critical
\r
119 * section. If the banked memory model is being used then the PPAGE
\r
120 * register is also stored as part of the tasks context.
\r
123 #ifdef BANKED_MODEL
\r
125 * Load the stack pointer for the task, then pull the critical nesting
\r
126 * count and PPAGE register from the stack. The remains of the
\r
127 * context are restored by the RTI instruction.
\r
129 #define portRESTORE_CONTEXT() \
\r
132 .globl pxCurrentTCB ; void * \n\
\r
133 .globl uxCriticalNesting ; char \n\
\r
135 ldx pxCurrentTCB \n\
\r
136 lds 0,x ; Stack \n\
\r
138 movb 1,sp+,uxCriticalNesting \n\
\r
139 movb 1,sp+,0x30 ; PPAGE \n\
\r
144 * By the time this macro is called the processor has already stacked the
\r
145 * registers. Simply stack the nesting count and PPAGE value, then save
\r
146 * the task stack pointer.
\r
148 #define portSAVE_CONTEXT() \
\r
151 .globl pxCurrentTCB ; void * \n\
\r
152 .globl uxCriticalNesting ; char \n\
\r
154 movb 0x30, 1,-sp ; PPAGE \n\
\r
155 movb uxCriticalNesting, 1,-sp \n\
\r
157 ldx pxCurrentTCB \n\
\r
158 sts 0,x ; Stack \n\
\r
164 * These macros are as per the BANKED versions above, but without saving
\r
165 * and restoring the PPAGE register.
\r
168 #define portRESTORE_CONTEXT() \
\r
171 .globl pxCurrentTCB ; void * \n\
\r
172 .globl uxCriticalNesting ; char \n\
\r
174 ldx pxCurrentTCB \n\
\r
175 lds 0,x ; Stack \n\
\r
177 movb 1,sp+,uxCriticalNesting \n\
\r
181 #define portSAVE_CONTEXT() \
\r
184 .globl pxCurrentTCB ; void * \n\
\r
185 .globl uxCriticalNesting ; char \n\
\r
187 movb uxCriticalNesting, 1,-sp \n\
\r
189 ldx pxCurrentTCB \n\
\r
190 sts 0,x ; Stack \n\
\r
196 * Utility macros to save/restore correct software registers for GCC. This is
\r
197 * useful when GCC does not generate appropriate ISR head/tail code.
\r
199 #define portISR_HEAD() \
\r
202 movw _.frame, 2,-sp \n\
\r
203 movw _.tmp, 2,-sp \n\
\r
204 movw _.z, 2,-sp \n\
\r
205 movw _.xy, 2,-sp \n\
\r
206 ;movw _.d2, 2,-sp \n\
\r
207 ;movw _.d1, 2,-sp \n\
\r
211 #define portISR_TAIL() \
\r
214 movw 2,sp+, _.xy \n\
\r
215 movw 2,sp+, _.z \n\
\r
216 movw 2,sp+, _.tmp \n\
\r
217 movw 2,sp+, _.frame \n\
\r
218 ;movw 2,sp+, _.d1 \n\
\r
219 ;movw 2,sp+, _.d2 \n\
\r
225 * Utility macro to call macros above in correct order in order to perform a
\r
226 * task switch from within a standard ISR. This macro can only be used if
\r
227 * the ISR does not use any local (stack) variables. If the ISR uses stack
\r
228 * variables portYIELD() should be used in it's place.
\r
231 #define portTASK_SWITCH_FROM_ISR() \
\r
232 portSAVE_CONTEXT(); \
\r
233 vTaskSwitchContext(); \
\r
234 portRESTORE_CONTEXT();
\r
237 /* Task function macros as described on the FreeRTOS.org WEB site. */
\r
238 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
\r
239 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
\r
245 #endif /* PORTMACRO_H */
\r