]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/ARM7_LPC2000/portmacro.h
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Source / portable / GCC / ARM7_LPC2000 / portmacro.h
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 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. 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
15  *\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
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 #ifndef PORTMACRO_H\r
30 #define PORTMACRO_H\r
31 \r
32 #ifdef __cplusplus\r
33 extern "C" {\r
34 #endif\r
35 \r
36 /*-----------------------------------------------------------\r
37  * Port specific definitions.\r
38  *\r
39  * The settings in this file configure FreeRTOS correctly for the\r
40  * given hardware and compiler.\r
41  *\r
42  * These settings should not be altered.\r
43  *-----------------------------------------------------------\r
44  */\r
45 \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
54 \r
55 typedef portSTACK_TYPE StackType_t;\r
56 typedef long BaseType_t;\r
57 typedef unsigned long UBaseType_t;\r
58 \r
59 #if( configUSE_16_BIT_TICKS == 1 )\r
60         typedef uint16_t TickType_t;\r
61         #define portMAX_DELAY ( TickType_t ) 0xffff\r
62 #else\r
63         typedef uint32_t TickType_t;\r
64         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\r
65 #endif\r
66 /*-----------------------------------------------------------*/\r
67 \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
74 \r
75 \r
76 /* Scheduler utilities. */\r
77 \r
78 /*\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
83  */\r
84 \r
85 #define portRESTORE_CONTEXT()                                                                                   \\r
86 {                                                                                                                                               \\r
87 extern volatile void * volatile pxCurrentTCB;                                                   \\r
88 extern volatile uint32_t ulCriticalNesting;                                     \\r
89                                                                                                                                                 \\r
90         /* Set the LR to the task stack. */                                                                     \\r
91         __asm volatile (                                                                                                        \\r
92         "LDR            R0, =pxCurrentTCB                                                               \n\t"   \\r
93         "LDR            R0, [R0]                                                                                \n\t"   \\r
94         "LDR            LR, [R0]                                                                                \n\t"   \\r
95                                                                                                                                                 \\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
101                                                                                                                                                 \\r
102         /* Get the SPSR from the stack. */                                                                      \\r
103         "LDMFD  LR!, {R0}                                                                                       \n\t"   \\r
104         "MSR            SPSR, R0                                                                                \n\t"   \\r
105                                                                                                                                                 \\r
106         /* Restore all system mode registers for the task. */                           \\r
107         "LDMFD  LR, {R0-R14}^                                                                           \n\t"   \\r
108         "NOP                                                                                                            \n\t"   \\r
109                                                                                                                                                 \\r
110         /* Restore the return address. */                                                                       \\r
111         "LDR            LR, [LR, #+60]                                                                  \n\t"   \\r
112                                                                                                                                                 \\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
116         );                                                                                                                                      \\r
117         ( void ) ulCriticalNesting;                                                                                     \\r
118         ( void ) pxCurrentTCB;                                                                                          \\r
119 }\r
120 /*-----------------------------------------------------------*/\r
121 \r
122 #define portSAVE_CONTEXT()                                                                                              \\r
123 {                                                                                                                                               \\r
124 extern volatile void * volatile pxCurrentTCB;                                                   \\r
125 extern volatile uint32_t ulCriticalNesting;                                     \\r
126                                                                                                                                                 \\r
127         /* Push R0 as we are going to use the register. */                                      \\r
128         __asm volatile (                                                                                                        \\r
129         "STMDB  SP!, {R0}                                                                                       \n\t"   \\r
130                                                                                                                                                 \\r
131         /* Set R0 to point to the task stack pointer. */                                        \\r
132         "STMDB  SP,{SP}^                                                                                        \n\t"   \\r
133         "NOP                                                                                                            \n\t"   \\r
134         "SUB    SP, SP, #4                                                                                      \n\t"   \\r
135         "LDMIA  SP!,{R0}                                                                                        \n\t"   \\r
136                                                                                                                                                 \\r
137         /* Push the return address onto the stack. */                                           \\r
138         "STMDB  R0!, {LR}                                                                                       \n\t"   \\r
139                                                                                                                                                 \\r
140         /* Now we have saved LR we can use it instead of R0. */                         \\r
141         "MOV    LR, R0                                                                                          \n\t"   \\r
142                                                                                                                                                 \\r
143         /* Pop R0 so we can save it onto the system mode stack. */                      \\r
144         "LDMIA  SP!, {R0}                                                                                       \n\t"   \\r
145                                                                                                                                                 \\r
146         /* Push all the system mode registers onto the task stack. */           \\r
147         "STMDB  LR,{R0-LR}^                                                                                     \n\t"   \\r
148         "NOP                                                                                                            \n\t"   \\r
149         "SUB    LR, LR, #60                                                                                     \n\t"   \\r
150                                                                                                                                                 \\r
151         /* Push the SPSR onto the task stack. */                                                        \\r
152         "MRS    R0, SPSR                                                                                        \n\t"   \\r
153         "STMDB  LR!, {R0}                                                                                       \n\t"   \\r
154                                                                                                                                                 \\r
155         "LDR    R0, =ulCriticalNesting                                                          \n\t"   \\r
156         "LDR    R0, [R0]                                                                                        \n\t"   \\r
157         "STMDB  LR!, {R0}                                                                                       \n\t"   \\r
158                                                                                                                                                 \\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
163         );                                                                                                                                      \\r
164         ( void ) ulCriticalNesting;                                                                                     \\r
165         ( void ) pxCurrentTCB;                                                                                          \\r
166 }\r
167 \r
168 extern void vTaskSwitchContext( void );\r
169 #define portYIELD_FROM_ISR()            vTaskSwitchContext()\r
170 #define portYIELD()                                     __asm volatile ( "SWI 0" )\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 \r
174 /* Critical section management. */\r
175 \r
176 /*\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
181  */\r
182 \r
183 #ifdef THUMB_INTERWORK\r
184 \r
185         extern void vPortDisableInterruptsFromThumb( void ) __attribute__ ((naked));\r
186         extern void vPortEnableInterruptsFromThumb( void ) __attribute__ ((naked));\r
187 \r
188         #define portDISABLE_INTERRUPTS()        vPortDisableInterruptsFromThumb()\r
189         #define portENABLE_INTERRUPTS()         vPortEnableInterruptsFromThumb()\r
190 \r
191 #else\r
192 \r
193         #define portDISABLE_INTERRUPTS()                                                                                        \\r
194                 __asm volatile (                                                                                                                \\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
200 \r
201         #define portENABLE_INTERRUPTS()                                                                                         \\r
202                 __asm volatile (                                                                                                                \\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
208 \r
209 #endif /* THUMB_INTERWORK */\r
210 \r
211 extern void vPortEnterCritical( void );\r
212 extern void vPortExitCritical( void );\r
213 \r
214 #define portENTER_CRITICAL()            vPortEnterCritical();\r
215 #define portEXIT_CRITICAL()                     vPortExitCritical();\r
216 /*-----------------------------------------------------------*/\r
217 \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
221 \r
222 #ifdef __cplusplus\r
223 }\r
224 #endif\r
225 \r
226 #endif /* PORTMACRO_H */\r
227 \r