]> begriffs open source - freertos/blob - Source/portable/CodeWarrior/HCS12/portmacro.h
Update to V5.4.1
[freertos] / Source / portable / CodeWarrior / HCS12 / portmacro.h
1 /*\r
2         FreeRTOS V5.4.1 - Copyright (C) 2009 Real Time Engineers Ltd.\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 it     under \r
7         the terms of the GNU General Public License (version 2) as published by the \r
8         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 without being obliged to provide the \r
11         source code for proprietary components outside of the FreeRTOS kernel.  \r
12         Alternative commercial license and support terms are also available upon \r
13         request.  See the licensing section of http://www.FreeRTOS.org for full \r
14         license details.\r
15 \r
16         FreeRTOS is distributed in the hope that it will be useful,     but WITHOUT\r
17         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19         more details.\r
20 \r
21         You should have received a copy of the GNU General Public License along\r
22         with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26         ***************************************************************************\r
27         *                                                                         *\r
28         * Looking for a quick start?  Then check out the FreeRTOS eBook!          *\r
29         * See http://www.FreeRTOS.org/Documentation for details                   *\r
30         *                                                                         *\r
31         ***************************************************************************\r
32 \r
33         1 tab == 4 spaces!\r
34 \r
35         Please ensure to read the configuration and relevant port sections of the\r
36         online documentation.\r
37 \r
38         http://www.FreeRTOS.org - Documentation, latest information, license and\r
39         contact details.\r
40 \r
41         http://www.SafeRTOS.com - A version that is certified for use in safety\r
42         critical systems.\r
43 \r
44         http://www.OpenRTOS.com - Commercial support, development, porting,\r
45         licensing and training services.\r
46 */\r
47 \r
48 \r
49 #ifndef PORTMACRO_H\r
50 #define PORTMACRO_H\r
51 \r
52 /*-----------------------------------------------------------\r
53  * Port specific definitions.  \r
54  *\r
55  * The settings in this file configure FreeRTOS correctly for the\r
56  * given hardware and compiler.\r
57  *\r
58  * These settings should not be altered.\r
59  *-----------------------------------------------------------\r
60  */\r
61 \r
62 /* Type definitions. */\r
63 #define portCHAR                char\r
64 #define portFLOAT               float\r
65 #define portDOUBLE              double\r
66 #define portLONG                long\r
67 #define portSHORT               short\r
68 #define portSTACK_TYPE  unsigned portCHAR\r
69 #define portBASE_TYPE   char\r
70 \r
71 #if( configUSE_16_BIT_TICKS == 1 )\r
72         typedef unsigned portSHORT portTickType;\r
73         #define portMAX_DELAY ( portTickType ) 0xffff\r
74 #else\r
75         typedef unsigned portLONG portTickType;\r
76         #define portMAX_DELAY ( portTickType ) 0xffffffff\r
77 #endif\r
78 /*-----------------------------------------------------------*/\r
79 \r
80 /* Hardware specifics. */\r
81 #define portBYTE_ALIGNMENT                      1\r
82 #define portSTACK_GROWTH                        ( -1 )\r
83 #define portTICK_RATE_MS                        ( ( portTickType ) 1000 / configTICK_RATE_HZ )          \r
84 #define portYIELD()                                     __asm( "swi" );\r
85 #define portNOP()                                       __asm( "nop" );\r
86 /*-----------------------------------------------------------*/\r
87 \r
88 /* Critical section handling. */\r
89 #define portENABLE_INTERRUPTS()                         __asm( "cli" )  \r
90 #define portDISABLE_INTERRUPTS()                        __asm( "sei" )\r
91 \r
92 /*\r
93  * Disable interrupts before incrementing the count of critical section nesting.\r
94  * The nesting count is maintained so we know when interrupts should be\r
95  * re-enabled.  Once interrupts are disabled the nesting count can be accessed\r
96  * directly.  Each task maintains its own nesting count.\r
97  */\r
98 #define portENTER_CRITICAL()                                                                    \\r
99 {                                                                                                                               \\r
100         extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
101                                                                                                                                 \\r
102         portDISABLE_INTERRUPTS();                                                                       \\r
103         uxCriticalNesting++;                                                                            \\r
104 }\r
105 \r
106 /*\r
107  * Interrupts are disabled so we can access the nesting count directly.  If the\r
108  * nesting is found to be 0 (no nesting) then we are leaving the critical \r
109  * section and interrupts can be re-enabled.\r
110  */\r
111 #define  portEXIT_CRITICAL()                                                                    \\r
112 {                                                                                                                               \\r
113         extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
114                                                                                                                                 \\r
115         uxCriticalNesting--;                                                                            \\r
116         if( uxCriticalNesting == 0 )                                                            \\r
117         {                                                                                                                       \\r
118                 portENABLE_INTERRUPTS();                                                                \\r
119         }                                                                                                                       \\r
120 }\r
121 /*-----------------------------------------------------------*/\r
122 \r
123 /* Task utilities. */\r
124 \r
125 /* \r
126  * These macros are very simple as the processor automatically saves and \r
127  * restores its registers as interrupts are entered and exited.  In\r
128  * addition to the (automatically stacked) registers we also stack the \r
129  * critical nesting count.  Each task maintains its own critical nesting\r
130  * count as it is legitimate for a task to yield from within a critical\r
131  * section.  If the banked memory model is being used then the PPAGE\r
132  * register is also stored as part of the tasks context.\r
133  */\r
134 \r
135 #ifdef BANKED_MODEL\r
136         /* \r
137          * Load the stack pointer for the task, then pull the critical nesting\r
138          * count and PPAGE register from the stack.  The remains of the \r
139          * context are restored by the RTI instruction.\r
140          */\r
141         #define portRESTORE_CONTEXT()                                                                   \\r
142         {                                                                                                                               \\r
143                 extern volatile void * pxCurrentTCB;                                            \\r
144                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
145                                                                                                                                         \\r
146                 __asm( "ldx pxCurrentTCB" );                                                            \\r
147                 __asm( "lds 0, x" );                                                                            \\r
148                 __asm( "pula" );                                                                                        \\r
149                 __asm( "staa uxCriticalNesting" );                                                      \\r
150                 __asm( "pula" );                                                                                        \\r
151                 __asm( "staa 0x30" ); /* 0x30 = PPAGE */                                        \\r
152         }\r
153 \r
154         /* \r
155          * By the time this macro is called the processor has already stacked the\r
156          * registers.  Simply stack the nesting count and PPAGE value, then save \r
157          * the task stack pointer.\r
158          */\r
159         #define portSAVE_CONTEXT()                                                                              \\r
160         {                                                                                                                               \\r
161                 extern volatile void * pxCurrentTCB;                                            \\r
162                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
163                                                                                                                                         \\r
164                 __asm( "ldaa 0x30" );  /* 0x30 = PPAGE */                                       \\r
165                 __asm( "psha" );                                                                                        \\r
166                 __asm( "ldaa uxCriticalNesting" );                                                      \\r
167                 __asm( "psha" );                                                                                        \\r
168                 __asm( "ldx pxCurrentTCB" );                                                            \\r
169                 __asm( "sts 0, x" );                                                                            \\r
170         }\r
171 #else\r
172 \r
173         /* \r
174          * These macros are as per the BANKED versions above, but without saving\r
175          * and restoring the PPAGE register.\r
176          */\r
177 \r
178         #define portRESTORE_CONTEXT()                                                                   \\r
179         {                                                                                                                               \\r
180                 extern volatile void * pxCurrentTCB;                                            \\r
181                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
182                                                                                                                                         \\r
183                 __asm( "ldx pxCurrentTCB" );                                                            \\r
184                 __asm( "lds 0, x" );                                                                            \\r
185                 __asm( "pula" );                                                                                        \\r
186                 __asm( "staa uxCriticalNesting" );                                                      \\r
187         }\r
188 \r
189         #define portSAVE_CONTEXT()                                                                              \\r
190         {                                                                                                                               \\r
191                 extern volatile void * pxCurrentTCB;                                            \\r
192                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
193                                                                                                                                         \\r
194                 __asm( "ldaa uxCriticalNesting" );                                                      \\r
195                 __asm( "psha" );                                                                                        \\r
196                 __asm( "ldx pxCurrentTCB" );                                                            \\r
197                 __asm( "sts 0, x" );                                                                            \\r
198         }\r
199 #endif\r
200 \r
201 /*\r
202  * Utility macro to call macros above in correct order in order to perform a\r
203  * task switch from within a standard ISR.  This macro can only be used if\r
204  * the ISR does not use any local (stack) variables.  If the ISR uses stack\r
205  * variables portYIELD() should be used in it's place.\r
206  */\r
207 #define portTASK_SWITCH_FROM_ISR()                                                              \\r
208         portSAVE_CONTEXT();                                                                                     \\r
209         vTaskSwitchContext();                                                                           \\r
210         portRESTORE_CONTEXT();\r
211 \r
212 \r
213 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
214 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
215 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
216 \r
217 #endif /* PORTMACRO_H */\r
218 \r