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
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 uint32_t
\r
53 #define portBASE_TYPE portLONG
\r
55 typedef portSTACK_TYPE StackType_t;
\r
56 typedef long BaseType_t;
\r
57 typedef unsigned long UBaseType_t;
\r
59 #if( configUSE_16_BIT_TICKS == 1 )
\r
60 typedef uint16_t TickType_t;
\r
61 #define portMAX_DELAY ( TickType_t ) 0xffff
\r
63 typedef uint32_t TickType_t;
\r
64 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
\r
66 /*-----------------------------------------------------------*/
\r
68 /* Architecture specifics. */
\r
69 #define portSTACK_GROWTH ( -1 )
\r
70 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
\r
71 #define portBYTE_ALIGNMENT 8
\r
72 #define portNOP() __asm volatile ( "NOP" );
\r
73 /*-----------------------------------------------------------*/
\r
76 /* Scheduler utilities. */
\r
79 * portRESTORE_CONTEXT, portRESTORE_CONTEXT, portENTER_SWITCHING_ISR
\r
80 * and portEXIT_SWITCHING_ISR can only be called from ARM mode, but
\r
81 * are included here for efficiency. An attempt to call one from
\r
82 * THUMB mode code will result in a compile time error.
\r
85 #define portRESTORE_CONTEXT() \
\r
87 extern volatile void * volatile pxCurrentTCB; \
\r
88 extern volatile uint32_t ulCriticalNesting; \
\r
90 /* Set the LR to the task stack. */ \
\r
92 "LDR R0, =pxCurrentTCB \n\t" \
\r
93 "LDR R0, [R0] \n\t" \
\r
94 "LDR LR, [R0] \n\t" \
\r
96 /* The critical nesting depth is the first item on the stack. */ \
\r
97 /* Load it into the ulCriticalNesting variable. */ \
\r
98 "LDR R0, =ulCriticalNesting \n\t" \
\r
99 "LDMFD LR!, {R1} \n\t" \
\r
100 "STR R1, [R0] \n\t" \
\r
102 /* Get the SPSR from the stack. */ \
\r
103 "LDMFD LR!, {R0} \n\t" \
\r
104 "MSR SPSR, R0 \n\t" \
\r
106 /* Restore all system mode registers for the task. */ \
\r
107 "LDMFD LR, {R0-R14}^ \n\t" \
\r
110 /* Restore the return address. */ \
\r
111 "LDR LR, [LR, #+60] \n\t" \
\r
113 /* And return - correcting the offset in the LR to obtain the */ \
\r
114 /* correct address. */ \
\r
115 "SUBS PC, LR, #4 \n\t" \
\r
117 ( void ) ulCriticalNesting; \
\r
118 ( void ) pxCurrentTCB; \
\r
120 /*-----------------------------------------------------------*/
\r
122 #define portSAVE_CONTEXT() \
\r
124 extern volatile void * volatile pxCurrentTCB; \
\r
125 extern volatile uint32_t ulCriticalNesting; \
\r
127 /* Push R0 as we are going to use the register. */ \
\r
129 "STMDB SP!, {R0} \n\t" \
\r
131 /* Set R0 to point to the task stack pointer. */ \
\r
132 "STMDB SP,{SP}^ \n\t" \
\r
134 "SUB SP, SP, #4 \n\t" \
\r
135 "LDMIA SP!,{R0} \n\t" \
\r
137 /* Push the return address onto the stack. */ \
\r
138 "STMDB R0!, {LR} \n\t" \
\r
140 /* Now we have saved LR we can use it instead of R0. */ \
\r
141 "MOV LR, R0 \n\t" \
\r
143 /* Pop R0 so we can save it onto the system mode stack. */ \
\r
144 "LDMIA SP!, {R0} \n\t" \
\r
146 /* Push all the system mode registers onto the task stack. */ \
\r
147 "STMDB LR,{R0-LR}^ \n\t" \
\r
149 "SUB LR, LR, #60 \n\t" \
\r
151 /* Push the SPSR onto the task stack. */ \
\r
152 "MRS R0, SPSR \n\t" \
\r
153 "STMDB LR!, {R0} \n\t" \
\r
155 "LDR R0, =ulCriticalNesting \n\t" \
\r
156 "LDR R0, [R0] \n\t" \
\r
157 "STMDB LR!, {R0} \n\t" \
\r
159 /* Store the new top of stack for the task. */ \
\r
160 "LDR R0, =pxCurrentTCB \n\t" \
\r
161 "LDR R0, [R0] \n\t" \
\r
162 "STR LR, [R0] \n\t" \
\r
164 ( void ) ulCriticalNesting; \
\r
165 ( void ) pxCurrentTCB; \
\r
168 extern void vTaskSwitchContext( void );
\r
169 #define portYIELD_FROM_ISR() vTaskSwitchContext()
\r
170 #define portYIELD() __asm volatile ( "SWI 0" )
\r
171 /*-----------------------------------------------------------*/
\r
174 /* Critical section management. */
\r
177 * The interrupt management utilities can only be called from ARM mode. When
\r
178 * THUMB_INTERWORK is defined the utilities are defined as functions in
\r
179 * portISR.c to ensure a switch to ARM mode. When THUMB_INTERWORK is not
\r
180 * defined then the utilities are defined as macros here - as per other ports.
\r
183 #ifdef THUMB_INTERWORK
\r
185 extern void vPortDisableInterruptsFromThumb( void ) __attribute__ ((naked));
\r
186 extern void vPortEnableInterruptsFromThumb( void ) __attribute__ ((naked));
\r
188 #define portDISABLE_INTERRUPTS() vPortDisableInterruptsFromThumb()
\r
189 #define portENABLE_INTERRUPTS() vPortEnableInterruptsFromThumb()
\r
193 #define portDISABLE_INTERRUPTS() \
\r
195 "STMDB SP!, {R0} \n\t" /* Push R0. */ \
\r
196 "MRS R0, CPSR \n\t" /* Get CPSR. */ \
\r
197 "ORR R0, R0, #0xC0 \n\t" /* Disable IRQ, FIQ. */ \
\r
198 "MSR CPSR, R0 \n\t" /* Write back modified value. */ \
\r
199 "LDMIA SP!, {R0} " ) /* Pop R0. */
\r
201 #define portENABLE_INTERRUPTS() \
\r
203 "STMDB SP!, {R0} \n\t" /* Push R0. */ \
\r
204 "MRS R0, CPSR \n\t" /* Get CPSR. */ \
\r
205 "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */ \
\r
206 "MSR CPSR, R0 \n\t" /* Write back modified value. */ \
\r
207 "LDMIA SP!, {R0} " ) /* Pop R0. */
\r
209 #endif /* THUMB_INTERWORK */
\r
211 extern void vPortEnterCritical( void );
\r
212 extern void vPortExitCritical( void );
\r
214 #define portENTER_CRITICAL() vPortEnterCritical();
\r
215 #define portEXIT_CRITICAL() vPortExitCritical();
\r
216 /*-----------------------------------------------------------*/
\r
218 /* Task function macros as described on the FreeRTOS.org WEB site. */
\r
219 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
\r
220 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
\r
226 #endif /* PORTMACRO_H */
\r