]> begriffs open source - freertos/blob - Source/portable/CodeWarrior/HCS12/portmacro.h
Update headers for Version 7.0.0 release.
[freertos] / Source / portable / CodeWarrior / HCS12 / portmacro.h
1 /*\r
2     FreeRTOS V7.0.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 \r
55 #ifndef PORTMACRO_H\r
56 #define PORTMACRO_H\r
57 \r
58 /*-----------------------------------------------------------\r
59  * Port specific definitions.  \r
60  *\r
61  * The settings in this file configure FreeRTOS correctly for the\r
62  * given hardware and compiler.\r
63  *\r
64  * These settings should not be altered.\r
65  *-----------------------------------------------------------\r
66  */\r
67 \r
68 /* Type definitions. */\r
69 #define portCHAR                char\r
70 #define portFLOAT               float\r
71 #define portDOUBLE              double\r
72 #define portLONG                long\r
73 #define portSHORT               short\r
74 #define portSTACK_TYPE  unsigned portCHAR\r
75 #define portBASE_TYPE   char\r
76 \r
77 #if( configUSE_16_BIT_TICKS == 1 )\r
78         typedef unsigned portSHORT portTickType;\r
79         #define portMAX_DELAY ( portTickType ) 0xffff\r
80 #else\r
81         typedef unsigned portLONG portTickType;\r
82         #define portMAX_DELAY ( portTickType ) 0xffffffff\r
83 #endif\r
84 /*-----------------------------------------------------------*/\r
85 \r
86 /* Hardware specifics. */\r
87 #define portBYTE_ALIGNMENT                      1\r
88 #define portSTACK_GROWTH                        ( -1 )\r
89 #define portTICK_RATE_MS                        ( ( portTickType ) 1000 / configTICK_RATE_HZ )          \r
90 #define portYIELD()                                     __asm( "swi" );\r
91 #define portNOP()                                       __asm( "nop" );\r
92 /*-----------------------------------------------------------*/\r
93 \r
94 /* Critical section handling. */\r
95 #define portENABLE_INTERRUPTS()                         __asm( "cli" )  \r
96 #define portDISABLE_INTERRUPTS()                        __asm( "sei" )\r
97 \r
98 /*\r
99  * Disable interrupts before incrementing the count of critical section nesting.\r
100  * The nesting count is maintained so we know when interrupts should be\r
101  * re-enabled.  Once interrupts are disabled the nesting count can be accessed\r
102  * directly.  Each task maintains its own nesting count.\r
103  */\r
104 #define portENTER_CRITICAL()                                                                    \\r
105 {                                                                                                                               \\r
106         extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
107                                                                                                                                 \\r
108         portDISABLE_INTERRUPTS();                                                                       \\r
109         uxCriticalNesting++;                                                                            \\r
110 }\r
111 \r
112 /*\r
113  * Interrupts are disabled so we can access the nesting count directly.  If the\r
114  * nesting is found to be 0 (no nesting) then we are leaving the critical \r
115  * section and interrupts can be re-enabled.\r
116  */\r
117 #define  portEXIT_CRITICAL()                                                                    \\r
118 {                                                                                                                               \\r
119         extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
120                                                                                                                                 \\r
121         uxCriticalNesting--;                                                                            \\r
122         if( uxCriticalNesting == 0 )                                                            \\r
123         {                                                                                                                       \\r
124                 portENABLE_INTERRUPTS();                                                                \\r
125         }                                                                                                                       \\r
126 }\r
127 /*-----------------------------------------------------------*/\r
128 \r
129 /* Task utilities. */\r
130 \r
131 /* \r
132  * These macros are very simple as the processor automatically saves and \r
133  * restores its registers as interrupts are entered and exited.  In\r
134  * addition to the (automatically stacked) registers we also stack the \r
135  * critical nesting count.  Each task maintains its own critical nesting\r
136  * count as it is legitimate for a task to yield from within a critical\r
137  * section.  If the banked memory model is being used then the PPAGE\r
138  * register is also stored as part of the tasks context.\r
139  */\r
140 \r
141 #ifdef BANKED_MODEL\r
142         /* \r
143          * Load the stack pointer for the task, then pull the critical nesting\r
144          * count and PPAGE register from the stack.  The remains of the \r
145          * context are restored by the RTI instruction.\r
146          */\r
147         #define portRESTORE_CONTEXT()                                                                   \\r
148         {                                                                                                                               \\r
149                 extern volatile void * pxCurrentTCB;                                            \\r
150                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
151                                                                                                                                         \\r
152                 __asm( "ldx pxCurrentTCB" );                                                            \\r
153                 __asm( "lds 0, x" );                                                                            \\r
154                 __asm( "pula" );                                                                                        \\r
155                 __asm( "staa uxCriticalNesting" );                                                      \\r
156                 __asm( "pula" );                                                                                        \\r
157                 __asm( "staa 0x30" ); /* 0x30 = PPAGE */                                        \\r
158         }\r
159 \r
160         /* \r
161          * By the time this macro is called the processor has already stacked the\r
162          * registers.  Simply stack the nesting count and PPAGE value, then save \r
163          * the task stack pointer.\r
164          */\r
165         #define portSAVE_CONTEXT()                                                                              \\r
166         {                                                                                                                               \\r
167                 extern volatile void * pxCurrentTCB;                                            \\r
168                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
169                                                                                                                                         \\r
170                 __asm( "ldaa 0x30" );  /* 0x30 = PPAGE */                                       \\r
171                 __asm( "psha" );                                                                                        \\r
172                 __asm( "ldaa uxCriticalNesting" );                                                      \\r
173                 __asm( "psha" );                                                                                        \\r
174                 __asm( "ldx pxCurrentTCB" );                                                            \\r
175                 __asm( "sts 0, x" );                                                                            \\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                 extern volatile void * pxCurrentTCB;                                            \\r
187                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
188                                                                                                                                         \\r
189                 __asm( "ldx pxCurrentTCB" );                                                            \\r
190                 __asm( "lds 0, x" );                                                                            \\r
191                 __asm( "pula" );                                                                                        \\r
192                 __asm( "staa uxCriticalNesting" );                                                      \\r
193         }\r
194 \r
195         #define portSAVE_CONTEXT()                                                                              \\r
196         {                                                                                                                               \\r
197                 extern volatile void * pxCurrentTCB;                                            \\r
198                 extern volatile unsigned portBASE_TYPE uxCriticalNesting;       \\r
199                                                                                                                                         \\r
200                 __asm( "ldaa uxCriticalNesting" );                                                      \\r
201                 __asm( "psha" );                                                                                        \\r
202                 __asm( "ldx pxCurrentTCB" );                                                            \\r
203                 __asm( "sts 0, x" );                                                                            \\r
204         }\r
205 #endif\r
206 \r
207 /*\r
208  * Utility macro to call macros above in correct order in order to perform a\r
209  * task switch from within a standard ISR.  This macro can only be used if\r
210  * the ISR does not use any local (stack) variables.  If the ISR uses stack\r
211  * variables portYIELD() should be used in it's place.\r
212  */\r
213 #define portTASK_SWITCH_FROM_ISR()                                                              \\r
214         portSAVE_CONTEXT();                                                                                     \\r
215         vTaskSwitchContext();                                                                           \\r
216         portRESTORE_CONTEXT();\r
217 \r
218 \r
219 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
220 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
221 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
222 \r
223 #endif /* PORTMACRO_H */\r
224 \r