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