]> begriffs open source - freertos/blob - portable/CodeWarrior/HCS12/portmacro.h
Style: uncrusitfy
[freertos] / portable / CodeWarrior / HCS12 / portmacro.h
1 /*\r
2  * FreeRTOS Kernel V10.3.1\r
3  * Copyright (C) 2020 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.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  */\r
26 \r
27 \r
28 #ifndef PORTMACRO_H\r
29 #define PORTMACRO_H\r
30 \r
31 /*-----------------------------------------------------------\r
32  * Port specific definitions.\r
33  *\r
34  * The settings in this file configure FreeRTOS correctly for the\r
35  * given hardware and compiler.\r
36  *\r
37  * These settings should not be altered.\r
38  *-----------------------------------------------------------\r
39  */\r
40 \r
41 /* Type definitions. */\r
42 #define portCHAR          char\r
43 #define portFLOAT         float\r
44 #define portDOUBLE        double\r
45 #define portLONG          long\r
46 #define portSHORT         short\r
47 #define portSTACK_TYPE    uint8_t\r
48 #define portBASE_TYPE     char\r
49 \r
50 typedef portSTACK_TYPE   StackType_t;\r
51 typedef signed char      BaseType_t;\r
52 typedef unsigned char    UBaseType_t;\r
53 \r
54 #if ( configUSE_16_BIT_TICKS == 1 )\r
55     typedef uint16_t     TickType_t;\r
56     #define portMAX_DELAY    ( TickType_t ) 0xffff\r
57 #else\r
58     typedef uint32_t     TickType_t;\r
59     #define portMAX_DELAY    ( TickType_t ) 0xffffffffUL\r
60 #endif\r
61 /*-----------------------------------------------------------*/\r
62 \r
63 /* Hardware specifics. */\r
64 #define portBYTE_ALIGNMENT    1\r
65 #define portSTACK_GROWTH      ( -1 )\r
66 #define portTICK_PERIOD_MS    ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
67 #define portYIELD()    __asm( "swi" );\r
68 #define portNOP()      __asm( "nop" );\r
69 /*-----------------------------------------------------------*/\r
70 \r
71 /* Critical section handling. */\r
72 #define portENABLE_INTERRUPTS()     __asm( "cli" )\r
73 #define portDISABLE_INTERRUPTS()    __asm( "sei" )\r
74 \r
75 /*\r
76  * Disable interrupts before incrementing the count of critical section nesting.\r
77  * The nesting count is maintained so we know when interrupts should be\r
78  * re-enabled.  Once interrupts are disabled the nesting count can be accessed\r
79  * directly.  Each task maintains its own nesting count.\r
80  */\r
81 #define portENTER_CRITICAL()                           \\r
82     {                                                  \\r
83         extern volatile UBaseType_t uxCriticalNesting; \\r
84                                                        \\r
85         portDISABLE_INTERRUPTS();                      \\r
86         uxCriticalNesting++;                           \\r
87     }\r
88 \r
89 /*\r
90  * Interrupts are disabled so we can access the nesting count directly.  If the\r
91  * nesting is found to be 0 (no nesting) then we are leaving the critical\r
92  * section and interrupts can be re-enabled.\r
93  */\r
94 #define  portEXIT_CRITICAL()                           \\r
95     {                                                  \\r
96         extern volatile UBaseType_t uxCriticalNesting; \\r
97                                                        \\r
98         uxCriticalNesting--;                           \\r
99         if( uxCriticalNesting == 0 )                   \\r
100         {                                              \\r
101             portENABLE_INTERRUPTS();                   \\r
102         }                                              \\r
103     }\r
104 /*-----------------------------------------------------------*/\r
105 \r
106 /* Task utilities. */\r
107 \r
108 /*\r
109  * These macros are very simple as the processor automatically saves and\r
110  * restores its registers as interrupts are entered and exited.  In\r
111  * addition to the (automatically stacked) registers we also stack the\r
112  * critical nesting count.  Each task maintains its own critical nesting\r
113  * count as it is legitimate for a task to yield from within a critical\r
114  * section.  If the banked memory model is being used then the PPAGE\r
115  * register is also stored as part of the tasks context.\r
116  */\r
117 \r
118 #ifdef BANKED_MODEL\r
119 \r
120 /*\r
121  * Load the stack pointer for the task, then pull the critical nesting\r
122  * count and PPAGE register from the stack.  The remains of the\r
123  * context are restored by the RTI instruction.\r
124  */\r
125     #define portRESTORE_CONTEXT()                      \\r
126     {                                                  \\r
127         extern volatile void *      pxCurrentTCB;      \\r
128         extern volatile UBaseType_t uxCriticalNesting; \\r
129                                                        \\r
130         __asm( "ldx pxCurrentTCB" );                   \\r
131         __asm( "lds 0, x" );                           \\r
132         __asm( "pula" );                               \\r
133         __asm( "staa uxCriticalNesting" );             \\r
134         __asm( "pula" );                               \\r
135         __asm( "staa 0x30" ); /* 0x30 = PPAGE */       \\r
136     }\r
137 \r
138 /*\r
139  * By the time this macro is called the processor has already stacked the\r
140  * registers.  Simply stack the nesting count and PPAGE value, then save\r
141  * the task stack pointer.\r
142  */\r
143     #define portSAVE_CONTEXT()                         \\r
144     {                                                  \\r
145         extern volatile void *      pxCurrentTCB;      \\r
146         extern volatile UBaseType_t uxCriticalNesting; \\r
147                                                        \\r
148         __asm( "ldaa 0x30" ); /* 0x30 = PPAGE */       \\r
149         __asm( "psha" );                               \\r
150         __asm( "ldaa uxCriticalNesting" );             \\r
151         __asm( "psha" );                               \\r
152         __asm( "ldx pxCurrentTCB" );                   \\r
153         __asm( "sts 0, x" );                           \\r
154     }\r
155 #else /* ifdef BANKED_MODEL */\r
156 \r
157 /*\r
158  * These macros are as per the BANKED versions above, but without saving\r
159  * and restoring the PPAGE register.\r
160  */\r
161 \r
162     #define portRESTORE_CONTEXT()                      \\r
163     {                                                  \\r
164         extern volatile void *      pxCurrentTCB;      \\r
165         extern volatile UBaseType_t uxCriticalNesting; \\r
166                                                        \\r
167         __asm( "ldx pxCurrentTCB" );                   \\r
168         __asm( "lds 0, x" );                           \\r
169         __asm( "pula" );                               \\r
170         __asm( "staa uxCriticalNesting" );             \\r
171     }\r
172 \r
173     #define portSAVE_CONTEXT()                         \\r
174     {                                                  \\r
175         extern volatile void *      pxCurrentTCB;      \\r
176         extern volatile UBaseType_t uxCriticalNesting; \\r
177                                                        \\r
178         __asm( "ldaa uxCriticalNesting" );             \\r
179         __asm( "psha" );                               \\r
180         __asm( "ldx pxCurrentTCB" );                   \\r
181         __asm( "sts 0, x" );                           \\r
182     }\r
183 #endif /* ifdef BANKED_MODEL */\r
184 \r
185 /*\r
186  * Utility macro to call macros above in correct order in order to perform a\r
187  * task switch from within a standard ISR.  This macro can only be used if\r
188  * the ISR does not use any local (stack) variables.  If the ISR uses stack\r
189  * variables portYIELD() should be used in it's place.\r
190  */\r
191 #define portTASK_SWITCH_FROM_ISR() \\r
192     portSAVE_CONTEXT();            \\r
193     vTaskSwitchContext();          \\r
194     portRESTORE_CONTEXT();\r
195 \r
196 \r
197 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
198 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters )    void vFunction( void * pvParameters )\r
199 #define portTASK_FUNCTION( vFunction, pvParameters )          void vFunction( void * pvParameters )\r
200 \r
201 #endif /* PORTMACRO_H */\r