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