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