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