]> git.sur5r.net Git - freertos/blob - Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h
First version under SVN is V4.0.1
[freertos] / Source / portable / GCC / ARM7_AT91SAM7S / portmacro.h
1 /*\r
2         FreeRTOS V4.0.1 - Copyright (C) 2003-2006 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS distribution.\r
5 \r
6         FreeRTOS is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section \r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26         ***************************************************************************\r
27         See http://www.FreeRTOS.org for documentation, latest information, license \r
28         and contact details.  Please ensure to read the configuration and relevant \r
29         port sections of the online documentation.\r
30         ***************************************************************************\r
31 */\r
32 \r
33 /*\r
34         Changes from V3.2.3\r
35         \r
36         + Modified portENTER_SWITCHING_ISR() to allow use with GCC V4.0.1.\r
37 \r
38         Changes from V3.2.4\r
39 \r
40         + Removed the use of the %0 parameter within the assembler macros and \r
41           replaced them with hard coded registers.  This will ensure the\r
42           assembler does not select the link register as the temp register as\r
43           was occasionally happening previously.\r
44 \r
45         + The assembler statements are now included in a single asm block rather\r
46           than each line having its own asm block.\r
47 */\r
48 \r
49 #ifndef PORTMACRO_H\r
50 #define PORTMACRO_H\r
51 \r
52 /*-----------------------------------------------------------\r
53  * Port specific definitions.  \r
54  *\r
55  * The settings in this file configure FreeRTOS correctly for the\r
56  * given hardware and compiler.\r
57  *\r
58  * These settings should not be altered.\r
59  *-----------------------------------------------------------\r
60  */\r
61 \r
62 /* Type definitions. */\r
63 #define portCHAR                char\r
64 #define portFLOAT               float\r
65 #define portDOUBLE              double\r
66 #define portLONG                long\r
67 #define portSHORT               short\r
68 #define portSTACK_TYPE  unsigned portLONG\r
69 #define portBASE_TYPE   portLONG\r
70 \r
71 #if( configUSE_16_BIT_TICKS == 1 )\r
72         typedef unsigned portSHORT portTickType;\r
73         #define portMAX_DELAY ( portTickType ) 0xffff\r
74 #else\r
75         typedef unsigned portLONG portTickType;\r
76         #define portMAX_DELAY ( portTickType ) 0xffffffff\r
77 #endif\r
78 /*-----------------------------------------------------------*/ \r
79 \r
80 /* Architecture specifics. */\r
81 #define portSTACK_GROWTH                        ( -1 )\r
82 #define portTICK_RATE_MS                        ( ( portTickType ) 1000 / configTICK_RATE_HZ )          \r
83 #define portBYTE_ALIGNMENT                      4\r
84 #define portNOP()                                       asm volatile ( "NOP" );\r
85 /*-----------------------------------------------------------*/ \r
86 \r
87 \r
88 /* Scheduler utilities. */\r
89 \r
90 /*\r
91  * portRESTORE_CONTEXT, portRESTORE_CONTEXT, portENTER_SWITCHING_ISR\r
92  * and portEXIT_SWITCHING_ISR can only be called from ARM mode, but\r
93  * are included here for efficiency.  An attempt to call one from\r
94  * THUMB mode code will result in a compile time error.\r
95  */\r
96 \r
97 #define portRESTORE_CONTEXT()                                                                                   \\r
98 {                                                                                                                                               \\r
99 extern volatile void * volatile pxCurrentTCB;                                                   \\r
100 extern volatile unsigned portLONG ulCriticalNesting;                                    \\r
101                                                                                                                                                 \\r
102         /* Set the LR to the task stack. */                                                                     \\r
103         asm volatile (                                                                                                          \\r
104         "LDR            R0, =pxCurrentTCB                                                               \n\t"   \\r
105         "LDR            R0, [R0]                                                                                \n\t"   \\r
106         "LDR            LR, [R0]                                                                                \n\t"   \\r
107                                                                                                                                                 \\r
108         /* The critical nesting depth is the first item on the stack. */        \\r
109         /* Load it into the ulCriticalNesting variable. */                                      \\r
110         "LDR            R0, =ulCriticalNesting                                                  \n\t"   \\r
111         "LDMFD  LR!, {R1}                                                                                       \n\t"   \\r
112         "STR            R1, [R0]                                                                                \n\t"   \\r
113                                                                                                                                                 \\r
114         /* Get the SPSR from the stack. */                                                                      \\r
115         "LDMFD  LR!, {R0}                                                                                       \n\t"   \\r
116         "MSR            SPSR, R0                                                                                \n\t"   \\r
117                                                                                                                                                 \\r
118         /* Restore all system mode registers for the task. */                           \\r
119         "LDMFD  LR, {R0-R14}^                                                                           \n\t"   \\r
120         "NOP                                                                                                            \n\t"   \\r
121                                                                                                                                                 \\r
122         /* Restore the return address. */                                                                       \\r
123         "LDR            LR, [LR, #+60]                                                                  \n\t"   \\r
124                                                                                                                                                 \\r
125         /* And return - correcting the offset in the LR to obtain the */        \\r
126         /* correct address. */                                                                                          \\r
127         "SUBS   PC, LR, #4                                                                                      \n\t"   \\r
128         );                                                                                                                                      \\r
129         ( void ) ulCriticalNesting;                                                                                     \\r
130         ( void ) pxCurrentTCB;                                                                                          \\r
131 }\r
132 /*-----------------------------------------------------------*/\r
133 \r
134 #define portSAVE_CONTEXT()                                                                                              \\r
135 {                                                                                                                                               \\r
136 extern volatile void * volatile pxCurrentTCB;                                                   \\r
137 extern volatile unsigned portLONG ulCriticalNesting;                                    \\r
138                                                                                                                                                 \\r
139         /* Push R0 as we are going to use the register. */                                      \\r
140         asm volatile (                                                                                                          \\r
141         "STMDB  SP!, {R0}                                                                                       \n\t"   \\r
142                                                                                                                                                 \\r
143         /* Set R0 to point to the task stack pointer. */                                        \\r
144         "STMDB  SP,{SP}^                                                                                        \n\t"   \\r
145         "NOP                                                                                                            \n\t"   \\r
146         "SUB    SP, SP, #4                                                                                      \n\t"   \\r
147         "LDMIA  SP!,{R0}                                                                                        \n\t"   \\r
148                                                                                                                                                 \\r
149         /* Push the return address onto the stack. */                                           \\r
150         "STMDB  R0!, {LR}                                                                                       \n\t"   \\r
151                                                                                                                                                 \\r
152         /* Now we have saved LR we can use it instead of R0. */                         \\r
153         "MOV    LR, R0                                                                                          \n\t"   \\r
154                                                                                                                                                 \\r
155         /* Pop R0 so we can save it onto the system mode stack. */                      \\r
156         "LDMIA  SP!, {R0}                                                                                       \n\t"   \\r
157                                                                                                                                                 \\r
158         /* Push all the system mode registers onto the task stack. */           \\r
159         "STMDB  LR,{R0-LR}^                                                                                     \n\t"   \\r
160         "NOP                                                                                                            \n\t"   \\r
161         "SUB    LR, LR, #60                                                                                     \n\t"   \\r
162                                                                                                                                                 \\r
163         /* Push the SPSR onto the task stack. */                                                        \\r
164         "MRS    R0, SPSR                                                                                        \n\t"   \\r
165         "STMDB  LR!, {R0}                                                                                       \n\t"   \\r
166                                                                                                                                                 \\r
167         "LDR    R0, =ulCriticalNesting                                                          \n\t"   \\r
168         "LDR    R0, [R0]                                                                                        \n\t"   \\r
169         "STMDB  LR!, {R0}                                                                                       \n\t"   \\r
170                                                                                                                                                 \\r
171         /* Store the new top of stack for the task. */                                          \\r
172         "LDR    R0, =pxCurrentTCB                                                                       \n\t"   \\r
173         "LDR    R0, [R0]                                                                                        \n\t"   \\r
174         "STR    LR, [R0]                                                                                        \n\t"   \\r
175         );                                                                                                                                      \\r
176         ( void ) ulCriticalNesting;                                                                                     \\r
177         ( void ) pxCurrentTCB;                                                                                          \\r
178 }\r
179 \r
180 \r
181 /*-----------------------------------------------------------\r
182  * ISR entry and exit macros.  These are only required if a task switch\r
183  * is required from the ISR.\r
184  *----------------------------------------------------------*/\r
185 \r
186 \r
187 #define portENTER_SWITCHING_ISR()                                                                               \\r
188         /* Save the context of the interrupted task. */                                         \\r
189         portSAVE_CONTEXT();                                                                                                     \\r
190                                                                                                                                                 \\r
191         /* We don't know the stack requirements for the ISR, so the frame */\\r
192         /* pointer will be set to the top of the task stack, and the stack*/\\r
193         /* pointer left where it is.  The IRQ stack will get used for any */\\r
194         /* functions calls made by this ISR. */                                                         \\r
195         asm volatile ( "SUB             R11, LR, #4" );                                                 \\r
196         {\r
197 \r
198 #define portEXIT_SWITCHING_ISR( SwitchRequired )                                                \\r
199                 /* If a switch is required then we just need to call */                 \\r
200                 /* vTaskSwitchContext() as the context has already been */              \\r
201                 /* saved. */                                                                                                    \\r
202                 if( SwitchRequired )                                                                                    \\r
203                 {                                                                                                                               \\r
204                         vTaskSwitchContext();                                                                           \\r
205                 }                                                                                                                               \\r
206         }                                                                                                                                       \\r
207         /* Restore the context of which ever task is now the highest */         \\r
208         /* priority that is ready to run. */                                                            \\r
209         portRESTORE_CONTEXT();\r
210 \r
211 #define portYIELD()                                     asm volatile ( "SWI" ); \r
212 /*-----------------------------------------------------------*/\r
213 \r
214 \r
215 /* Critical section management. */\r
216 \r
217 /*\r
218  * The interrupt management utilities can only be called from ARM mode.  When\r
219  * THUMB_INTERWORK is defined the utilities are defined as functions in \r
220  * portISR.c to ensure a switch to ARM mode.  When THUMB_INTERWORK is not \r
221  * defined then the utilities are defined as macros here - as per other ports.\r
222  */\r
223 \r
224 #ifdef THUMB_INTERWORK\r
225 \r
226         extern void vPortDisableInterruptsFromThumb( void ) __attribute__ ((naked));\r
227         extern void vPortEnableInterruptsFromThumb( void ) __attribute__ ((naked));\r
228 \r
229         #define portDISABLE_INTERRUPTS()        vPortDisableInterruptsFromThumb()\r
230         #define portENABLE_INTERRUPTS()         vPortEnableInterruptsFromThumb()\r
231         \r
232 #else\r
233 \r
234         #define portDISABLE_INTERRUPTS()                                                                                                                                \\r
235         #define portDISABLE_INTERRUPTS()                                                                                        \\r
236                 asm volatile (                                                                                                                  \\r
237                         "STMDB  SP!, {R0}               \n\t"   /* Push R0.                                             */      \\r
238                         "MRS    R0, CPSR                \n\t"   /* Get CPSR.                                    */      \\r
239                         "ORR    R0, R0, #0xC0   \n\t"   /* Disable IRQ, FIQ.                    */      \\r
240                         "MSR    CPSR, R0                \n\t"   /* Write back modified value.   */      \\r
241                         "LDMIA  SP!, {R0}                       " )     /* Pop R0.                                              */\r
242                         \r
243         #define portENABLE_INTERRUPTS()                                                                                         \\r
244                 asm volatile (                                                                                                                  \\r
245                         "STMDB  SP!, {R0}               \n\t"   /* Push R0.                                             */      \\r
246                         "MRS    R0, CPSR                \n\t"   /* Get CPSR.                                    */      \\r
247                         "BIC    R0, R0, #0xC0   \n\t"   /* Enable IRQ, FIQ.                             */      \\r
248                         "MSR    CPSR, R0                \n\t"   /* Write back modified value.   */      \\r
249                         "LDMIA  SP!, {R0}                       " )     /* Pop R0.                                              */\r
250 \r
251 #endif /* THUMB_INTERWORK */\r
252 \r
253 extern void vPortEnterCritical( void );\r
254 extern void vPortExitCritical( void );\r
255 \r
256 #define portENTER_CRITICAL()            vPortEnterCritical();\r
257 #define portEXIT_CRITICAL()                     vPortExitCritical();\r
258 /*-----------------------------------------------------------*/\r
259 \r
260 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
261 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
262 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
263 \r
264 #endif /* PORTMACRO_H */\r
265 \r