2 * FreeRTOS Kernel V10.4.3
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
31 + Modified portENTER_SWITCHING_ISR() to allow use with GCC V4.0.1.
35 + Removed the use of the %0 parameter within the assembler macros and
36 replaced them with hard coded registers. This will ensure the
37 assembler does not select the link register as the temp register as
38 was occasionally happening previously.
40 + The assembler statements are now included in a single asm block rather
41 than each line having its own asm block.
45 + Removed the portENTER_SWITCHING_ISR() and portEXIT_SWITCHING_ISR() macros
46 and replaced them with portYIELD_FROM_ISR() macro. Application code
47 should now make use of the portSAVE_CONTEXT() and portRESTORE_CONTEXT()
48 macros as per the V4.5.1 demo code.
58 /*-----------------------------------------------------------
59 * Port specific definitions.
61 * The settings in this file configure FreeRTOS correctly for the
62 * given hardware and compiler.
64 * These settings should not be altered.
65 *-----------------------------------------------------------
68 /* Type definitions. */
70 #define portFLOAT float
71 #define portDOUBLE double
73 #define portSHORT short
74 #define portSTACK_TYPE uint32_t
75 #define portBASE_TYPE long
77 typedef portSTACK_TYPE StackType_t;
78 typedef long BaseType_t;
79 typedef unsigned long UBaseType_t;
81 #if( configUSE_16_BIT_TICKS == 1 )
82 typedef uint16_t TickType_t;
83 #define portMAX_DELAY ( TickType_t ) 0xffff
85 typedef uint32_t TickType_t;
86 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
88 /*-----------------------------------------------------------*/
90 /* Hardware specifics. */
91 #define portSTACK_GROWTH ( -1 )
92 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
93 #define portBYTE_ALIGNMENT 8
94 #define portYIELD() asm volatile ( "SWI 0" )
95 #define portNOP() asm volatile ( "NOP" )
98 * These define the timer to use for generating the tick interrupt.
99 * They are put in this file so they can be shared between "port.c"
102 #define portTIMER_REG_BASE_PTR AT91C_BASE_TC0
103 #define portTIMER_CLK_ENABLE_BIT AT91C_PS_TC0
104 #define portTIMER_AIC_CHANNEL ( ( uint32_t ) 4 )
105 /*-----------------------------------------------------------*/
107 /* Task utilities. */
110 * portRESTORE_CONTEXT, portRESTORE_CONTEXT, portENTER_SWITCHING_ISR
111 * and portEXIT_SWITCHING_ISR can only be called from ARM mode, but
112 * are included here for efficiency. An attempt to call one from
113 * THUMB mode code will result in a compile time error.
116 #define portRESTORE_CONTEXT() \
118 extern volatile void * volatile pxCurrentTCB; \
119 extern volatile uint32_t ulCriticalNesting; \
121 /* Set the LR to the task stack. */ \
123 "LDR R0, =pxCurrentTCB \n\t" \
124 "LDR R0, [R0] \n\t" \
125 "LDR LR, [R0] \n\t" \
127 /* The critical nesting depth is the first item on the stack. */ \
128 /* Load it into the ulCriticalNesting variable. */ \
129 "LDR R0, =ulCriticalNesting \n\t" \
130 "LDMFD LR!, {R1} \n\t" \
131 "STR R1, [R0] \n\t" \
133 /* Get the SPSR from the stack. */ \
134 "LDMFD LR!, {R0} \n\t" \
135 "MSR SPSR, R0 \n\t" \
137 /* Restore all system mode registers for the task. */ \
138 "LDMFD LR, {R0-R14}^ \n\t" \
141 /* Restore the return address. */ \
142 "LDR LR, [LR, #+60] \n\t" \
144 /* And return - correcting the offset in the LR to obtain the */ \
145 /* correct address. */ \
146 "SUBS PC, LR, #4 \n\t" \
148 ( void ) ulCriticalNesting; \
149 ( void ) pxCurrentTCB; \
151 /*-----------------------------------------------------------*/
153 #define portSAVE_CONTEXT() \
155 extern volatile void * volatile pxCurrentTCB; \
156 extern volatile uint32_t ulCriticalNesting; \
158 /* Push R0 as we are going to use the register. */ \
160 "STMDB SP!, {R0} \n\t" \
162 /* Set R0 to point to the task stack pointer. */ \
163 "STMDB SP,{SP}^ \n\t" \
165 "SUB SP, SP, #4 \n\t" \
166 "LDMIA SP!,{R0} \n\t" \
168 /* Push the return address onto the stack. */ \
169 "STMDB R0!, {LR} \n\t" \
171 /* Now we have saved LR we can use it instead of R0. */ \
174 /* Pop R0 so we can save it onto the system mode stack. */ \
175 "LDMIA SP!, {R0} \n\t" \
177 /* Push all the system mode registers onto the task stack. */ \
178 "STMDB LR,{R0-LR}^ \n\t" \
180 "SUB LR, LR, #60 \n\t" \
182 /* Push the SPSR onto the task stack. */ \
183 "MRS R0, SPSR \n\t" \
184 "STMDB LR!, {R0} \n\t" \
186 "LDR R0, =ulCriticalNesting \n\t" \
187 "LDR R0, [R0] \n\t" \
188 "STMDB LR!, {R0} \n\t" \
190 /* Store the new top of stack for the task. */ \
191 "LDR R0, =pxCurrentTCB \n\t" \
192 "LDR R0, [R0] \n\t" \
193 "STR LR, [R0] \n\t" \
195 ( void ) ulCriticalNesting; \
196 ( void ) pxCurrentTCB; \
199 #define portYIELD_FROM_ISR() vTaskSwitchContext()
201 /* Critical section handling. */
204 * The interrupt management utilities can only be called from ARM mode. When
205 * THUMB_INTERWORK is defined the utilities are defined as functions in
206 * portISR.c to ensure a switch to ARM mode. When THUMB_INTERWORK is not
207 * defined then the utilities are defined as macros here - as per other ports.
210 #ifdef THUMB_INTERWORK
212 extern void vPortDisableInterruptsFromThumb( void ) __attribute__ ((naked));
213 extern void vPortEnableInterruptsFromThumb( void ) __attribute__ ((naked));
215 #define portDISABLE_INTERRUPTS() vPortDisableInterruptsFromThumb()
216 #define portENABLE_INTERRUPTS() vPortEnableInterruptsFromThumb()
220 #define portDISABLE_INTERRUPTS() \
222 "STMDB SP!, {R0} \n\t" /* Push R0. */ \
223 "MRS R0, CPSR \n\t" /* Get CPSR. */ \
224 "ORR R0, R0, #0xC0 \n\t" /* Disable IRQ, FIQ. */ \
225 "MSR CPSR, R0 \n\t" /* Write back modified value. */ \
226 "LDMIA SP!, {R0} " ) /* Pop R0. */
228 #define portENABLE_INTERRUPTS() \
230 "STMDB SP!, {R0} \n\t" /* Push R0. */ \
231 "MRS R0, CPSR \n\t" /* Get CPSR. */ \
232 "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */ \
233 "MSR CPSR, R0 \n\t" /* Write back modified value. */ \
234 "LDMIA SP!, {R0} " ) /* Pop R0. */
236 #endif /* THUMB_INTERWORK */
238 extern void vPortEnterCritical( void );
239 extern void vPortExitCritical( void );
241 #define portENTER_CRITICAL() vPortEnterCritical();
242 #define portEXIT_CRITICAL() vPortExitCritical();
244 /*-----------------------------------------------------------*/
246 /* Task function macros as described on the FreeRTOS.org WEB site. */
247 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
248 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
254 #endif /* PORTMACRO_H */