]> git.sur5r.net Git - freertos/blob - Source/portable/GCC/HCS12/portmacro.h
0393ea7ee0e07379c79efb70761b521aba3a03f9
[freertos] / Source / portable / GCC / HCS12 / portmacro.h
1 /*\r
2         FreeRTOS.org V4.8.0 - Copyright (C) 2003-2008 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     ***************************************************************************\r
28     *                                                                         *\r
29     * SAVE TIME AND MONEY!  We can port FreeRTOS.org to your own hardware,    *\r
30     * and even write all or part of your application on your behalf.          *\r
31     * See http://www.OpenRTOS.com for details of the services we provide to   *\r
32     * expedite your project.                                                  *\r
33     *                                                                         *\r
34     ***************************************************************************\r
35     ***************************************************************************\r
36 \r
37         Please ensure to read the configuration and relevant port sections of the\r
38         online documentation.\r
39 \r
40         http://www.FreeRTOS.org - Documentation, latest information, license and \r
41         contact details.\r
42 \r
43         http://www.SafeRTOS.com - A version that is certified for use in safety \r
44         critical systems.\r
45 \r
46         http://www.OpenRTOS.com - Commercial support, development, porting, \r
47         licensing and training services.\r
48 */\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  unsigned portCHAR\r
75 #define portBASE_TYPE   char\r
76 \r
77 #if( configUSE_16_BIT_TICKS == 1 )\r
78         typedef unsigned portSHORT portTickType;\r
79         #define portMAX_DELAY ( portTickType ) 0xffff\r
80 #else\r
81         typedef unsigned portLONG portTickType;\r
82         #define portMAX_DELAY ( portTickType ) 0xffffffff\r
83 #endif\r
84 /*-----------------------------------------------------------*/\r
85 \r
86 /* Hardware specifics. */\r
87 #define portBYTE_ALIGNMENT                      1\r
88 #define portSTACK_GROWTH                        ( -1 )\r
89 #define portTICK_RATE_MS                        ( ( portTickType ) 1000 / configTICK_RATE_HZ )\r
90 #define portYIELD()                                     __asm( "swi" );\r
91 /*-----------------------------------------------------------*/\r
92 \r
93 /* Critical section handling. */\r
94 #define portENABLE_INTERRUPTS()                         __asm( "cli" )  \r
95 #define portDISABLE_INTERRUPTS()                        __asm( "sei" )\r
96 \r
97 /*\r
98  * Disable interrupts before incrementing the count of critical section nesting.\r
99  * The nesting count is maintained so we know when interrupts should be\r
100  * re-enabled.  Once interrupts are disabled the nesting count can be accessed\r
101  * directly.  Each task maintains its own nesting count.\r
102  */\r
103 #define portENTER_CRITICAL()                                                                    \\r
104 {                                                                                                                               \\r
105         extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
106                                                                                                                                 \\r
107         portDISABLE_INTERRUPTS();                                                                       \\r
108         uxCriticalNesting++;                                                                            \\r
109 }\r
110 \r
111 /*\r
112  * Interrupts are disabled so we can access the nesting count directly.  If the\r
113  * nesting is found to be 0 (no nesting) then we are leaving the critical \r
114  * section and interrupts can be re-enabled.\r
115  */\r
116 #define  portEXIT_CRITICAL()                                                                    \\r
117 {                                                                                                                               \\r
118         extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
119                                                                                                                                 \\r
120         uxCriticalNesting--;                                                                            \\r
121         if( uxCriticalNesting == 0 )                                                            \\r
122         {                                                                                                                       \\r
123                 portENABLE_INTERRUPTS();                                                                \\r
124         }                                                                                                                       \\r
125 }\r
126 /*-----------------------------------------------------------*/\r
127 \r
128 /* Task utilities. */\r
129 \r
130 /* \r
131  * These macros are very simple as the processor automatically saves and \r
132  * restores its registers as interrupts are entered and exited.  In\r
133  * addition to the (automatically stacked) registers we also stack the \r
134  * critical nesting count.  Each task maintains its own critical nesting\r
135  * count as it is legitimate for a task to yield from within a critical\r
136  * section.  If the banked memory model is being used then the PPAGE\r
137  * register is also stored as part of the tasks context.\r
138  */\r
139 \r
140 #ifdef BANKED_MODEL\r
141         /* \r
142          * Load the stack pointer for the task, then pull the critical nesting\r
143          * count and PPAGE register from the stack.  The remains of the \r
144          * context are restored by the RTI instruction.\r
145          */\r
146         #define portRESTORE_CONTEXT()                                                   \\r
147         {                                                                               \\r
148                 __asm( "                                                                \n\\r
149                 .globl pxCurrentTCB                     ; void *                        \n\\r
150                 .globl uxCriticalNesting                ; char                          \n\\r
151                                                                                         \n\\r
152                 ldx  pxCurrentTCB                                                       \n\\r
153                 lds  0,x                                ; Stack                         \n\\r
154                                                                                         \n\\r
155                 movb 1,sp+,uxCriticalNesting                                            \n\\r
156                 movb 1,sp+,0x30                         ; PPAGE                         \n\\r
157                 " );                                                                    \\r
158         }\r
159 \r
160         /* \r
161          * By the time this macro is called the processor has already stacked the\r
162          * registers.  Simply stack the nesting count and PPAGE value, then save \r
163          * the task stack pointer.\r
164          */\r
165         #define portSAVE_CONTEXT()                                                      \\r
166         {                                                                               \\r
167                 __asm( "                                                                \n\\r
168                 .globl pxCurrentTCB                     ; void *                        \n\\r
169                 .globl uxCriticalNesting                ; char                          \n\\r
170                                                                                         \n\\r
171                 movb 0x30, 1,-sp                        ; PPAGE                         \n\\r
172                 movb uxCriticalNesting, 1,-sp                                           \n\\r
173                                                                                         \n\\r
174                 ldx  pxCurrentTCB                                                       \n\\r
175                 sts  0,x                                ; Stack                         \n\\r
176                 " );                                                                    \\r
177         }\r
178 #else\r
179 \r
180         /* \r
181          * These macros are as per the BANKED versions above, but without saving\r
182          * and restoring the PPAGE register.\r
183          */\r
184 \r
185         #define portRESTORE_CONTEXT()                                                   \\r
186         {                                                                               \\r
187                 __asm( "                                                                \n\\r
188                 .globl pxCurrentTCB                     ; void *                        \n\\r
189                 .globl uxCriticalNesting                ; char                          \n\\r
190                                                                                         \n\\r
191                 ldx  pxCurrentTCB                                                       \n\\r
192                 lds  0,x                                ; Stack                         \n\\r
193                                                                                         \n\\r
194                 movb 1,sp+,uxCriticalNesting                                            \n\\r
195                 " );                                                                    \\r
196         }\r
197 \r
198         #define portSAVE_CONTEXT()                                                      \\r
199         {                                                                               \\r
200                 __asm( "                                                                \n\\r
201                 .globl pxCurrentTCB                     ; void *                        \n\\r
202                 .globl uxCriticalNesting                ; char                          \n\\r
203                                                                                         \n\\r
204                 movb uxCriticalNesting, 1,-sp                                           \n\\r
205                                                                                         \n\\r
206                 ldx  pxCurrentTCB                                                       \n\\r
207                 sts  0,x                                ; Stack                         \n\\r
208                 " );                                                                    \\r
209         }\r
210 #endif\r
211 \r
212 /*\r
213  * Utility macros to save/restore correct software registers for GCC. This is\r
214  * useful when GCC does not generate appropriate ISR head/tail code.\r
215  */\r
216 #define portISR_HEAD()                                                                  \\r
217 {                                                                                       \\r
218                 __asm("                                                                 \n\\r
219                 movw _.frame, 2,-sp                                                     \n\\r
220                 movw _.tmp, 2,-sp                                                       \n\\r
221                 movw _.z, 2,-sp                                                         \n\\r
222                 movw _.xy, 2,-sp                                                        \n\\r
223                 ;movw _.d2, 2,-sp                                                       \n\\r
224                 ;movw _.d1, 2,-sp                                                       \n\\r
225                 ");                                                                     \\r
226 }\r
227 \r
228 #define portISR_TAIL()                                                                  \\r
229 {                                                                                       \\r
230                 __asm("                                                                 \n\\r
231                 movw 2,sp+, _.xy                                                        \n\\r
232                 movw 2,sp+, _.z                                                         \n\\r
233                 movw 2,sp+, _.tmp                                                       \n\\r
234                 movw 2,sp+, _.frame                                                     \n\\r
235                 ;movw 2,sp+, _.d1                                                       \n\\r
236                 ;movw 2,sp+, _.d2                                                       \n\\r
237                 rti                                                                     \n\\r
238                 ");                                                                     \\r
239 }\r
240 \r
241 /*\r
242  * Utility macro to call macros above in correct order in order to perform a\r
243  * task switch from within a standard ISR.  This macro can only be used if\r
244  * the ISR does not use any local (stack) variables.  If the ISR uses stack\r
245  * variables portYIELD() should be used in it's place.\r
246  */\r
247 \r
248 #define portTASK_SWITCH_FROM_ISR()                                                              \\r
249         portSAVE_CONTEXT();                                                                                     \\r
250         vTaskSwitchContext();                                                                           \\r
251         portRESTORE_CONTEXT();\r
252 \r
253 \r
254 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
255 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
256 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
257 \r
258 #ifdef __cplusplus\r
259 }\r
260 #endif\r
261 \r
262 #endif /* PORTMACRO_H */\r
263 \r