]> begriffs open source - cmsis-freertos/blob - Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h
Sources updated to FreeRTOS 10.2.0
[cmsis-freertos] / Source / portable / GCC / ARM7_AT91SAM7S / portmacro.h
1 /*
2  * FreeRTOS Kernel V10.2.0
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
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.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /*
29         Changes from V3.2.3
30
31         + Modified portENTER_SWITCHING_ISR() to allow use with GCC V4.0.1.
32
33         Changes from V3.2.4
34
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.
39
40         + The assembler statements are now included in a single asm block rather
41           than each line having its own asm block.
42
43         Changes from V4.5.0
44
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.
49 */
50
51 #ifndef PORTMACRO_H
52 #define PORTMACRO_H
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 /*-----------------------------------------------------------
59  * Port specific definitions.
60  *
61  * The settings in this file configure FreeRTOS correctly for the
62  * given hardware and compiler.
63  *
64  * These settings should not be altered.
65  *-----------------------------------------------------------
66  */
67
68 /* Type definitions. */
69 #define portCHAR                char
70 #define portFLOAT               float
71 #define portDOUBLE              double
72 #define portLONG                long
73 #define portSHORT               short
74 #define portSTACK_TYPE  uint32_t
75 #define portBASE_TYPE   portLONG
76
77 typedef portSTACK_TYPE StackType_t;
78 typedef long BaseType_t;
79 typedef unsigned long UBaseType_t;
80
81 #if( configUSE_16_BIT_TICKS == 1 )
82         typedef uint16_t TickType_t;
83         #define portMAX_DELAY ( TickType_t ) 0xffff
84 #else
85         typedef uint32_t TickType_t;
86         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
87 #endif
88 /*-----------------------------------------------------------*/
89
90 /* Architecture specifics. */
91 #define portSTACK_GROWTH                        ( -1 )
92 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
93 #define portBYTE_ALIGNMENT                      8
94 #define portNOP()                                       __asm volatile ( "NOP" );
95 /*-----------------------------------------------------------*/
96
97
98 /* Scheduler utilities. */
99
100 /*
101  * portRESTORE_CONTEXT, portRESTORE_CONTEXT, portENTER_SWITCHING_ISR
102  * and portEXIT_SWITCHING_ISR can only be called from ARM mode, but
103  * are included here for efficiency.  An attempt to call one from
104  * THUMB mode code will result in a compile time error.
105  */
106
107 #define portRESTORE_CONTEXT()                                                                                   \
108 {                                                                                                                                               \
109 extern volatile void * volatile pxCurrentTCB;                                                   \
110 extern volatile uint32_t ulCriticalNesting;                                     \
111                                                                                                                                                 \
112         /* Set the LR to the task stack. */                                                                     \
113         __asm volatile (                                                                                                        \
114         "LDR            R0, =pxCurrentTCB                                                               \n\t"   \
115         "LDR            R0, [R0]                                                                                \n\t"   \
116         "LDR            LR, [R0]                                                                                \n\t"   \
117                                                                                                                                                 \
118         /* The critical nesting depth is the first item on the stack. */        \
119         /* Load it into the ulCriticalNesting variable. */                                      \
120         "LDR            R0, =ulCriticalNesting                                                  \n\t"   \
121         "LDMFD  LR!, {R1}                                                                                       \n\t"   \
122         "STR            R1, [R0]                                                                                \n\t"   \
123                                                                                                                                                 \
124         /* Get the SPSR from the stack. */                                                                      \
125         "LDMFD  LR!, {R0}                                                                                       \n\t"   \
126         "MSR            SPSR, R0                                                                                \n\t"   \
127                                                                                                                                                 \
128         /* Restore all system mode registers for the task. */                           \
129         "LDMFD  LR, {R0-R14}^                                                                           \n\t"   \
130         "NOP                                                                                                            \n\t"   \
131                                                                                                                                                 \
132         /* Restore the return address. */                                                                       \
133         "LDR            LR, [LR, #+60]                                                                  \n\t"   \
134                                                                                                                                                 \
135         /* And return - correcting the offset in the LR to obtain the */        \
136         /* correct address. */                                                                                          \
137         "SUBS   PC, LR, #4                                                                                      \n\t"   \
138         );                                                                                                                                      \
139         ( void ) ulCriticalNesting;                                                                                     \
140         ( void ) pxCurrentTCB;                                                                                          \
141 }
142 /*-----------------------------------------------------------*/
143
144 #define portSAVE_CONTEXT()                                                                                              \
145 {                                                                                                                                               \
146 extern volatile void * volatile pxCurrentTCB;                                                   \
147 extern volatile uint32_t ulCriticalNesting;                                     \
148                                                                                                                                                 \
149         /* Push R0 as we are going to use the register. */                                      \
150         __asm volatile (                                                                                                        \
151         "STMDB  SP!, {R0}                                                                                       \n\t"   \
152                                                                                                                                                 \
153         /* Set R0 to point to the task stack pointer. */                                        \
154         "STMDB  SP,{SP}^                                                                                        \n\t"   \
155         "NOP                                                                                                            \n\t"   \
156         "SUB    SP, SP, #4                                                                                      \n\t"   \
157         "LDMIA  SP!,{R0}                                                                                        \n\t"   \
158                                                                                                                                                 \
159         /* Push the return address onto the stack. */                                           \
160         "STMDB  R0!, {LR}                                                                                       \n\t"   \
161                                                                                                                                                 \
162         /* Now we have saved LR we can use it instead of R0. */                         \
163         "MOV    LR, R0                                                                                          \n\t"   \
164                                                                                                                                                 \
165         /* Pop R0 so we can save it onto the system mode stack. */                      \
166         "LDMIA  SP!, {R0}                                                                                       \n\t"   \
167                                                                                                                                                 \
168         /* Push all the system mode registers onto the task stack. */           \
169         "STMDB  LR,{R0-LR}^                                                                                     \n\t"   \
170         "NOP                                                                                                            \n\t"   \
171         "SUB    LR, LR, #60                                                                                     \n\t"   \
172                                                                                                                                                 \
173         /* Push the SPSR onto the task stack. */                                                        \
174         "MRS    R0, SPSR                                                                                        \n\t"   \
175         "STMDB  LR!, {R0}                                                                                       \n\t"   \
176                                                                                                                                                 \
177         "LDR    R0, =ulCriticalNesting                                                          \n\t"   \
178         "LDR    R0, [R0]                                                                                        \n\t"   \
179         "STMDB  LR!, {R0}                                                                                       \n\t"   \
180                                                                                                                                                 \
181         /* Store the new top of stack for the task. */                                          \
182         "LDR    R0, =pxCurrentTCB                                                                       \n\t"   \
183         "LDR    R0, [R0]                                                                                        \n\t"   \
184         "STR    LR, [R0]                                                                                        \n\t"   \
185         );                                                                                                                                      \
186         ( void ) ulCriticalNesting;                                                                                     \
187         ( void ) pxCurrentTCB;                                                                                          \
188 }
189
190
191 #define portYIELD_FROM_ISR()            vTaskSwitchContext()
192 #define portYIELD()                                     __asm volatile ( "SWI 0" )
193 /*-----------------------------------------------------------*/
194
195
196 /* Critical section management. */
197
198 /*
199  * The interrupt management utilities can only be called from ARM mode.  When
200  * THUMB_INTERWORK is defined the utilities are defined as functions in
201  * portISR.c to ensure a switch to ARM mode.  When THUMB_INTERWORK is not
202  * defined then the utilities are defined as macros here - as per other ports.
203  */
204
205 #ifdef THUMB_INTERWORK
206
207         extern void vPortDisableInterruptsFromThumb( void ) __attribute__ ((naked));
208         extern void vPortEnableInterruptsFromThumb( void ) __attribute__ ((naked));
209
210         #define portDISABLE_INTERRUPTS()        vPortDisableInterruptsFromThumb()
211         #define portENABLE_INTERRUPTS()         vPortEnableInterruptsFromThumb()
212
213 #else
214
215         #define portDISABLE_INTERRUPTS()                                                                                        \
216                 __asm volatile (                                                                                                                \
217                         "STMDB  SP!, {R0}               \n\t"   /* Push R0.                                             */      \
218                         "MRS    R0, CPSR                \n\t"   /* Get CPSR.                                    */      \
219                         "ORR    R0, R0, #0xC0   \n\t"   /* Disable IRQ, FIQ.                    */      \
220                         "MSR    CPSR, R0                \n\t"   /* Write back modified value.   */      \
221                         "LDMIA  SP!, {R0}                       " )     /* Pop R0.                                              */
222
223         #define portENABLE_INTERRUPTS()                                                                                         \
224                 __asm volatile (                                                                                                                \
225                         "STMDB  SP!, {R0}               \n\t"   /* Push R0.                                             */      \
226                         "MRS    R0, CPSR                \n\t"   /* Get CPSR.                                    */      \
227                         "BIC    R0, R0, #0xC0   \n\t"   /* Enable IRQ, FIQ.                             */      \
228                         "MSR    CPSR, R0                \n\t"   /* Write back modified value.   */      \
229                         "LDMIA  SP!, {R0}                       " )     /* Pop R0.                                              */
230
231 #endif /* THUMB_INTERWORK */
232
233 extern void vPortEnterCritical( void );
234 extern void vPortExitCritical( void );
235
236 #define portENTER_CRITICAL()            vPortEnterCritical();
237 #define portEXIT_CRITICAL()                     vPortExitCritical();
238 /*-----------------------------------------------------------*/
239
240 /* Task function macros as described on the FreeRTOS.org WEB site. */
241 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
242 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
243
244 #ifdef __cplusplus
245 }
246 #endif
247
248 #endif /* PORTMACRO_H */
249