]> git.sur5r.net Git - freertos/blob - Source/portable/CodeWarrior/HCS12/portmacro.h
First version under SVN is V4.0.1
[freertos] / Source / portable / CodeWarrior / HCS12 / portmacro.h
1 /*\r
2         FreeRTOS V4.0.1 - Copyright (C) 2003-2006 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS distribution.\r
5 \r
6         FreeRTOS 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 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; 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, 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 #define portNOP()                                       __asm( "nop" );\r
71 /*-----------------------------------------------------------*/\r
72 \r
73 /* Critical section handling. */\r
74 #define portENABLE_INTERRUPTS()                         __asm( "cli" )  \r
75 #define portDISABLE_INTERRUPTS()                        __asm( "sei" )\r
76 \r
77 /*\r
78  * Disable interrupts before incrementing the count of critical section nesting.\r
79  * The nesting count is maintained so we know when interrupts should be\r
80  * re-enabled.  Once interrupts are disabled the nesting count can be accessed\r
81  * directly.  Each task maintains its own nesting count.\r
82  */\r
83 #define portENTER_CRITICAL()                                                                    \\r
84 {                                                                                                                               \\r
85         extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
86                                                                                                                                 \\r
87         portDISABLE_INTERRUPTS();                                                                       \\r
88         uxCriticalNesting++;                                                                            \\r
89 }\r
90 \r
91 /*\r
92  * Interrupts are disabled so we can access the nesting count directly.  If the\r
93  * nesting is found to be 0 (no nesting) then we are leaving the critical \r
94  * section and interrupts can be re-enabled.\r
95  */\r
96 #define  portEXIT_CRITICAL()                                                                    \\r
97 {                                                                                                                               \\r
98         extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
99                                                                                                                                 \\r
100         uxCriticalNesting--;                                                                            \\r
101         if( uxCriticalNesting == 0 )                                                            \\r
102         {                                                                                                                       \\r
103                 portENABLE_INTERRUPTS();                                                                \\r
104         }                                                                                                                       \\r
105 }\r
106 /*-----------------------------------------------------------*/\r
107 \r
108 /* Task utilities. */\r
109 \r
110 /* \r
111  * These macros are very simple as the processor automatically saves and \r
112  * restores its registers as interrupts are entered and exited.  In\r
113  * addition to the (automatically stacked) registers we also stack the \r
114  * critical nesting count.  Each task maintains its own critical nesting\r
115  * count as it is legitimate for a task to yield from within a critical\r
116  * section.  If the banked memory model is being used then the PPAGE\r
117  * register is also stored as part of the tasks context.\r
118  */\r
119 \r
120 #ifdef BANKED_MODEL\r
121         /* \r
122          * Load the stack pointer for the task, then pull the critical nesting\r
123          * count and PPAGE register from the stack.  The remains of the \r
124          * context are restored by the RTI instruction.\r
125          */\r
126         #define portRESTORE_CONTEXT()                                                                   \\r
127         {                                                                                                                               \\r
128                 extern volatile void * pxCurrentTCB;                                            \\r
129                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
130                                                                                                                                         \\r
131                 __asm( "ldx pxCurrentTCB" );                                                            \\r
132                 __asm( "lds 0, x" );                                                                            \\r
133                 __asm( "pula" );                                                                                        \\r
134                 __asm( "staa uxCriticalNesting" );                                                      \\r
135                 __asm( "pula" );                                                                                        \\r
136                 __asm( "staa 0x30" ); /* 0x30 = PPAGE */                                        \\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                 extern volatile void * pxCurrentTCB;                                            \\r
147                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
148                                                                                                                                         \\r
149                 __asm( "ldaa 0x30" );  /* 0x30 = PPAGE */                                       \\r
150                 __asm( "psha" );                                                                                        \\r
151                 __asm( "ldaa uxCriticalNesting" );                                                      \\r
152                 __asm( "psha" );                                                                                        \\r
153                 __asm( "ldx pxCurrentTCB" );                                                            \\r
154                 __asm( "sts 0, x" );                                                                            \\r
155         }\r
156 #else\r
157 \r
158         /* \r
159          * These macros are as per the BANKED versions above, but without saving\r
160          * and restoring the PPAGE register.\r
161          */\r
162 \r
163         #define portRESTORE_CONTEXT()                                                                   \\r
164         {                                                                                                                               \\r
165                 extern volatile void * pxCurrentTCB;                                            \\r
166                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
167                                                                                                                                         \\r
168                 __asm( "ldx pxCurrentTCB" );                                                            \\r
169                 __asm( "lds 0, x" );                                                                            \\r
170                 __asm( "pula" );                                                                                        \\r
171                 __asm( "staa uxCriticalNesting" );                                                      \\r
172         }\r
173 \r
174         #define portSAVE_CONTEXT()                                                                              \\r
175         {                                                                                                                               \\r
176                 extern volatile void * pxCurrentTCB;                                            \\r
177                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
178                                                                                                                                         \\r
179                 __asm( "ldaa uxCriticalNesting" );                                                      \\r
180                 __asm( "psha" );                                                                                        \\r
181                 __asm( "ldx pxCurrentTCB" );                                                            \\r
182                 __asm( "sts 0, x" );                                                                            \\r
183         }\r
184 #endif\r
185 \r
186 /*\r
187  * Utility macro to call macros above in correct order in order to perform a\r
188  * task switch from within a standard ISR.  This macro can only be used if\r
189  * the ISR does not use any local (stack) variables.  If the ISR uses stack\r
190  * variables portYIELD() should be used in it's place.\r
191  */\r
192 #define portTASK_SWITCH_FROM_ISR()                                                              \\r
193         portSAVE_CONTEXT();                                                                                     \\r
194         vTaskSwitchContext();                                                                           \\r
195         portRESTORE_CONTEXT();\r
196 \r
197 \r
198 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
199 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
200 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
201 \r
202 #define inline\r
203 \r
204 #endif /* PORTMACRO_H */\r
205 \r