]> git.sur5r.net Git - freertos/blob - Source/portable/GCC/HCS12/portmacro.h
Changes between V4.5.0 and V4.6.0 released October 28 2007
[freertos] / Source / portable / GCC / HCS12 / portmacro.h
1 /*\r
2         FreeRTOS.org V4.6.0 - Copyright (C) 2003-2007 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org 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.org 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.org; 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.org, 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         Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along\r
32         with commercial development and support options.\r
33         ***************************************************************************\r
34 */\r
35 \r
36 \r
37 #ifndef PORTMACRO_H\r
38 #define PORTMACRO_H\r
39 \r
40 /*-----------------------------------------------------------\r
41  * Port specific definitions.  \r
42  *\r
43  * The settings in this file configure FreeRTOS correctly for the\r
44  * given hardware and compiler.\r
45  *\r
46  * These settings should not be altered.\r
47  *-----------------------------------------------------------\r
48  */\r
49 \r
50 /* Type definitions. */\r
51 #define portCHAR                char\r
52 #define portFLOAT               float\r
53 #define portDOUBLE              double\r
54 #define portLONG                long\r
55 #define portSHORT               short\r
56 #define portSTACK_TYPE  unsigned portCHAR\r
57 #define portBASE_TYPE   char\r
58 \r
59 #if( configUSE_16_BIT_TICKS == 1 )\r
60         typedef unsigned portSHORT portTickType;\r
61         #define portMAX_DELAY ( portTickType ) 0xffff\r
62 #else\r
63         typedef unsigned portLONG portTickType;\r
64         #define portMAX_DELAY ( portTickType ) 0xffffffff\r
65 #endif\r
66 /*-----------------------------------------------------------*/\r
67 \r
68 /* Hardware specifics. */\r
69 #define portBYTE_ALIGNMENT                      1\r
70 #define portSTACK_GROWTH                        ( -1 )\r
71 #define portTICK_RATE_MS                        ( ( portTickType ) 1000 / configTICK_RATE_HZ )\r
72 #define portYIELD()                                     __asm( "swi" );\r
73 /*-----------------------------------------------------------*/\r
74 \r
75 /* Critical section handling. */\r
76 #define portENABLE_INTERRUPTS()                         __asm( "cli" )  \r
77 #define portDISABLE_INTERRUPTS()                        __asm( "sei" )\r
78 \r
79 /*\r
80  * Disable interrupts before incrementing the count of critical section nesting.\r
81  * The nesting count is maintained so we know when interrupts should be\r
82  * re-enabled.  Once interrupts are disabled the nesting count can be accessed\r
83  * directly.  Each task maintains its own nesting count.\r
84  */\r
85 #define portENTER_CRITICAL()                                                                    \\r
86 {                                                                                                                               \\r
87         extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
88                                                                                                                                 \\r
89         portDISABLE_INTERRUPTS();                                                                       \\r
90         uxCriticalNesting++;                                                                            \\r
91 }\r
92 \r
93 /*\r
94  * Interrupts are disabled so we can access the nesting count directly.  If the\r
95  * nesting is found to be 0 (no nesting) then we are leaving the critical \r
96  * section and interrupts can be re-enabled.\r
97  */\r
98 #define  portEXIT_CRITICAL()                                                                    \\r
99 {                                                                                                                               \\r
100         extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
101                                                                                                                                 \\r
102         uxCriticalNesting--;                                                                            \\r
103         if( uxCriticalNesting == 0 )                                                            \\r
104         {                                                                                                                       \\r
105                 portENABLE_INTERRUPTS();                                                                \\r
106         }                                                                                                                       \\r
107 }\r
108 /*-----------------------------------------------------------*/\r
109 \r
110 /* Task utilities. */\r
111 \r
112 /* \r
113  * These macros are very simple as the processor automatically saves and \r
114  * restores its registers as interrupts are entered and exited.  In\r
115  * addition to the (automatically stacked) registers we also stack the \r
116  * critical nesting count.  Each task maintains its own critical nesting\r
117  * count as it is legitimate for a task to yield from within a critical\r
118  * section.  If the banked memory model is being used then the PPAGE\r
119  * register is also stored as part of the tasks context.\r
120  */\r
121 \r
122 #ifdef BANKED_MODEL\r
123         /* \r
124          * Load the stack pointer for the task, then pull the critical nesting\r
125          * count and PPAGE register from the stack.  The remains of the \r
126          * context are restored by the RTI instruction.\r
127          */\r
128         #define portRESTORE_CONTEXT()                                                   \\r
129         {                                                                               \\r
130                 __asm( "                                                                \n\\r
131                 .globl pxCurrentTCB                     ; void *                        \n\\r
132                 .globl uxCriticalNesting                ; char                          \n\\r
133                                                                                         \n\\r
134                 ldx  pxCurrentTCB                                                       \n\\r
135                 lds  0,x                                ; Stack                         \n\\r
136                                                                                         \n\\r
137                 movb 1,sp+,uxCriticalNesting                                            \n\\r
138                 movb 1,sp+,0x30                         ; PPAGE                         \n\\r
139                 " );                                                                    \\r
140         }\r
141 \r
142         /* \r
143          * By the time this macro is called the processor has already stacked the\r
144          * registers.  Simply stack the nesting count and PPAGE value, then save \r
145          * the task stack pointer.\r
146          */\r
147         #define portSAVE_CONTEXT()                                                      \\r
148         {                                                                               \\r
149                 __asm( "                                                                \n\\r
150                 .globl pxCurrentTCB                     ; void *                        \n\\r
151                 .globl uxCriticalNesting                ; char                          \n\\r
152                                                                                         \n\\r
153                 movb 0x30, 1,-sp                        ; PPAGE                         \n\\r
154                 movb uxCriticalNesting, 1,-sp                                           \n\\r
155                                                                                         \n\\r
156                 ldx  pxCurrentTCB                                                       \n\\r
157                 sts  0,x                                ; Stack                         \n\\r
158                 " );                                                                    \\r
159         }\r
160 #else\r
161 \r
162         /* \r
163          * These macros are as per the BANKED versions above, but without saving\r
164          * and restoring the PPAGE register.\r
165          */\r
166 \r
167         #define portRESTORE_CONTEXT()                                                   \\r
168         {                                                                               \\r
169                 __asm( "                                                                \n\\r
170                 .globl pxCurrentTCB                     ; void *                        \n\\r
171                 .globl uxCriticalNesting                ; char                          \n\\r
172                                                                                         \n\\r
173                 ldx  pxCurrentTCB                                                       \n\\r
174                 lds  0,x                                ; Stack                         \n\\r
175                                                                                         \n\\r
176                 movb 1,sp+,uxCriticalNesting                                            \n\\r
177                 " );                                                                    \\r
178         }\r
179 \r
180         #define portSAVE_CONTEXT()                                                      \\r
181         {                                                                               \\r
182                 __asm( "                                                                \n\\r
183                 .globl pxCurrentTCB                     ; void *                        \n\\r
184                 .globl uxCriticalNesting                ; char                          \n\\r
185                                                                                         \n\\r
186                 movb uxCriticalNesting, 1,-sp                                           \n\\r
187                                                                                         \n\\r
188                 ldx  pxCurrentTCB                                                       \n\\r
189                 sts  0,x                                ; Stack                         \n\\r
190                 " );                                                                    \\r
191         }\r
192 #endif\r
193 \r
194 /*\r
195  * Utility macros to save/restore correct software registers for GCC. This is\r
196  * useful when GCC does not generate appropriate ISR head/tail code.\r
197  */\r
198 #define portISR_HEAD()                                                                  \\r
199 {                                                                                       \\r
200                 __asm("                                                                 \n\\r
201                 movw _.frame, 2,-sp                                                     \n\\r
202                 movw _.tmp, 2,-sp                                                       \n\\r
203                 movw _.z, 2,-sp                                                         \n\\r
204                 movw _.xy, 2,-sp                                                        \n\\r
205                 ;movw _.d2, 2,-sp                                                       \n\\r
206                 ;movw _.d1, 2,-sp                                                       \n\\r
207                 ");                                                                     \\r
208 }\r
209 \r
210 #define portISR_TAIL()                                                                  \\r
211 {                                                                                       \\r
212                 __asm("                                                                 \n\\r
213                 movw 2,sp+, _.xy                                                        \n\\r
214                 movw 2,sp+, _.z                                                         \n\\r
215                 movw 2,sp+, _.tmp                                                       \n\\r
216                 movw 2,sp+, _.frame                                                     \n\\r
217                 ;movw 2,sp+, _.d1                                                       \n\\r
218                 ;movw 2,sp+, _.d2                                                       \n\\r
219                 rti                                                                     \n\\r
220                 ");                                                                     \\r
221 }\r
222 \r
223 /*\r
224  * Utility macro to call macros above in correct order in order to perform a\r
225  * task switch from within a standard ISR.  This macro can only be used if\r
226  * the ISR does not use any local (stack) variables.  If the ISR uses stack\r
227  * variables portYIELD() should be used in it's place.\r
228  */\r
229 \r
230 #define portTASK_SWITCH_FROM_ISR()                                                              \\r
231         portSAVE_CONTEXT();                                                                                     \\r
232         vTaskSwitchContext();                                                                           \\r
233         portRESTORE_CONTEXT();\r
234 \r
235 \r
236 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
237 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
238 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
239 \r
240 \r
241 #endif /* PORTMACRO_H */\r
242 \r