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