]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/CodeWarrior/HCS12/portmacro.h
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Source / portable / CodeWarrior / HCS12 / portmacro.h
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 \r
30 #ifndef PORTMACRO_H\r
31 #define PORTMACRO_H\r
32 \r
33 /*-----------------------------------------------------------\r
34  * Port specific definitions.\r
35  *\r
36  * The settings in this file configure FreeRTOS correctly for the\r
37  * given hardware and compiler.\r
38  *\r
39  * These settings should not be altered.\r
40  *-----------------------------------------------------------\r
41  */\r
42 \r
43 /* Type definitions. */\r
44 #define portCHAR                char\r
45 #define portFLOAT               float\r
46 #define portDOUBLE              double\r
47 #define portLONG                long\r
48 #define portSHORT               short\r
49 #define portSTACK_TYPE  uint8_t\r
50 #define portBASE_TYPE   char\r
51 \r
52 typedef portSTACK_TYPE StackType_t;\r
53 typedef signed char BaseType_t;\r
54 typedef unsigned char UBaseType_t;\r
55 \r
56 #if( configUSE_16_BIT_TICKS == 1 )\r
57         typedef uint16_t TickType_t;\r
58         #define portMAX_DELAY ( TickType_t ) 0xffff\r
59 #else\r
60         typedef uint32_t TickType_t;\r
61         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\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_PERIOD_MS                      ( ( TickType_t ) 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 UBaseType_t 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 UBaseType_t 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 UBaseType_t 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 UBaseType_t 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 UBaseType_t 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 UBaseType_t 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 #endif /* PORTMACRO_H */\r
203 \r