]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/HCS12/portmacro.h
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Source / portable / GCC / HCS12 / portmacro.h
1 /*\r
2  * FreeRTOS Kernel V10.3.0\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  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 \r
29 #ifndef PORTMACRO_H\r
30 #define PORTMACRO_H\r
31 \r
32 #ifdef __cplusplus\r
33 extern "C" {\r
34 #endif\r
35 \r
36 /*-----------------------------------------------------------\r
37  * Port specific definitions.\r
38  *\r
39  * The settings in this file configure FreeRTOS correctly for the\r
40  * given hardware and compiler.\r
41  *\r
42  * These settings should not be altered.\r
43  *-----------------------------------------------------------\r
44  */\r
45 \r
46 /* Type definitions. */\r
47 #define portCHAR                char\r
48 #define portFLOAT               float\r
49 #define portDOUBLE              double\r
50 #define portLONG                long\r
51 #define portSHORT               short\r
52 #define portSTACK_TYPE  uint8_t\r
53 #define portBASE_TYPE   char\r
54 \r
55 typedef portSTACK_TYPE StackType_t;\r
56 typedef signed char BaseType_t;\r
57 typedef unsigned char UBaseType_t;\r
58 \r
59 \r
60 #if( configUSE_16_BIT_TICKS == 1 )\r
61         typedef uint16_t TickType_t;\r
62         #define portMAX_DELAY ( TickType_t ) 0xffff\r
63 #else\r
64         typedef uint32_t TickType_t;\r
65         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\r
66 #endif\r
67 /*-----------------------------------------------------------*/\r
68 \r
69 /* Hardware specifics. */\r
70 #define portBYTE_ALIGNMENT                      1\r
71 #define portSTACK_GROWTH                        ( -1 )\r
72 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
73 #define portYIELD()                                     __asm( "swi" );\r
74 /*-----------------------------------------------------------*/\r
75 \r
76 /* Critical section handling. */\r
77 #define portENABLE_INTERRUPTS()                         __asm( "cli" )\r
78 #define portDISABLE_INTERRUPTS()                        __asm( "sei" )\r
79 \r
80 /*\r
81  * Disable interrupts before incrementing the count of critical section nesting.\r
82  * The nesting count is maintained so we know when interrupts should be\r
83  * re-enabled.  Once interrupts are disabled the nesting count can be accessed\r
84  * directly.  Each task maintains its own nesting count.\r
85  */\r
86 #define portENTER_CRITICAL()                                                                    \\r
87 {                                                                                                                               \\r
88         extern volatile UBaseType_t uxCriticalNesting;  \\r
89                                                                                                                                 \\r
90         portDISABLE_INTERRUPTS();                                                                       \\r
91         uxCriticalNesting++;                                                                            \\r
92 }\r
93 \r
94 /*\r
95  * Interrupts are disabled so we can access the nesting count directly.  If the\r
96  * nesting is found to be 0 (no nesting) then we are leaving the critical\r
97  * section and interrupts can be re-enabled.\r
98  */\r
99 #define  portEXIT_CRITICAL()                                                                    \\r
100 {                                                                                                                               \\r
101         extern volatile UBaseType_t uxCriticalNesting;  \\r
102                                                                                                                                 \\r
103         uxCriticalNesting--;                                                                            \\r
104         if( uxCriticalNesting == 0 )                                                            \\r
105         {                                                                                                                       \\r
106                 portENABLE_INTERRUPTS();                                                                \\r
107         }                                                                                                                       \\r
108 }\r
109 /*-----------------------------------------------------------*/\r
110 \r
111 /* Task utilities. */\r
112 \r
113 /*\r
114  * These macros are very simple as the processor automatically saves and\r
115  * restores its registers as interrupts are entered and exited.  In\r
116  * addition to the (automatically stacked) registers we also stack the\r
117  * critical nesting count.  Each task maintains its own critical nesting\r
118  * count as it is legitimate for a task to yield from within a critical\r
119  * section.  If the banked memory model is being used then the PPAGE\r
120  * register is also stored as part of the tasks context.\r
121  */\r
122 \r
123 #ifdef BANKED_MODEL\r
124         /*\r
125          * Load the stack pointer for the task, then pull the critical nesting\r
126          * count and PPAGE register from the stack.  The remains of the\r
127          * context are restored by the RTI instruction.\r
128          */\r
129         #define portRESTORE_CONTEXT()                                                   \\r
130         {                                                                               \\r
131                 __asm( "                                                                \n\\r
132                 .globl pxCurrentTCB                     ; void *                        \n\\r
133                 .globl uxCriticalNesting                ; char                          \n\\r
134                                                                                         \n\\r
135                 ldx  pxCurrentTCB                                                       \n\\r
136                 lds  0,x                                ; Stack                         \n\\r
137                                                                                         \n\\r
138                 movb 1,sp+,uxCriticalNesting                                            \n\\r
139                 movb 1,sp+,0x30                         ; PPAGE                         \n\\r
140                 " );                                                                    \\r
141         }\r
142 \r
143         /*\r
144          * By the time this macro is called the processor has already stacked the\r
145          * registers.  Simply stack the nesting count and PPAGE value, then save\r
146          * the task stack pointer.\r
147          */\r
148         #define portSAVE_CONTEXT()                                                      \\r
149         {                                                                               \\r
150                 __asm( "                                                                \n\\r
151                 .globl pxCurrentTCB                     ; void *                        \n\\r
152                 .globl uxCriticalNesting                ; char                          \n\\r
153                                                                                         \n\\r
154                 movb 0x30, 1,-sp                        ; PPAGE                         \n\\r
155                 movb uxCriticalNesting, 1,-sp                                           \n\\r
156                                                                                         \n\\r
157                 ldx  pxCurrentTCB                                                       \n\\r
158                 sts  0,x                                ; Stack                         \n\\r
159                 " );                                                                    \\r
160         }\r
161 #else\r
162 \r
163         /*\r
164          * These macros are as per the BANKED versions above, but without saving\r
165          * and restoring the PPAGE register.\r
166          */\r
167 \r
168         #define portRESTORE_CONTEXT()                                                   \\r
169         {                                                                               \\r
170                 __asm( "                                                                \n\\r
171                 .globl pxCurrentTCB                     ; void *                        \n\\r
172                 .globl uxCriticalNesting                ; char                          \n\\r
173                                                                                         \n\\r
174                 ldx  pxCurrentTCB                                                       \n\\r
175                 lds  0,x                                ; Stack                         \n\\r
176                                                                                         \n\\r
177                 movb 1,sp+,uxCriticalNesting                                            \n\\r
178                 " );                                                                    \\r
179         }\r
180 \r
181         #define portSAVE_CONTEXT()                                                      \\r
182         {                                                                               \\r
183                 __asm( "                                                                \n\\r
184                 .globl pxCurrentTCB                     ; void *                        \n\\r
185                 .globl uxCriticalNesting                ; char                          \n\\r
186                                                                                         \n\\r
187                 movb uxCriticalNesting, 1,-sp                                           \n\\r
188                                                                                         \n\\r
189                 ldx  pxCurrentTCB                                                       \n\\r
190                 sts  0,x                                ; Stack                         \n\\r
191                 " );                                                                    \\r
192         }\r
193 #endif\r
194 \r
195 /*\r
196  * Utility macros to save/restore correct software registers for GCC. This is\r
197  * useful when GCC does not generate appropriate ISR head/tail code.\r
198  */\r
199 #define portISR_HEAD()                                                                  \\r
200 {                                                                                       \\r
201                 __asm("                                                                 \n\\r
202                 movw _.frame, 2,-sp                                                     \n\\r
203                 movw _.tmp, 2,-sp                                                       \n\\r
204                 movw _.z, 2,-sp                                                         \n\\r
205                 movw _.xy, 2,-sp                                                        \n\\r
206                 ;movw _.d2, 2,-sp                                                       \n\\r
207                 ;movw _.d1, 2,-sp                                                       \n\\r
208                 ");                                                                     \\r
209 }\r
210 \r
211 #define portISR_TAIL()                                                                  \\r
212 {                                                                                       \\r
213                 __asm("                                                                 \n\\r
214                 movw 2,sp+, _.xy                                                        \n\\r
215                 movw 2,sp+, _.z                                                         \n\\r
216                 movw 2,sp+, _.tmp                                                       \n\\r
217                 movw 2,sp+, _.frame                                                     \n\\r
218                 ;movw 2,sp+, _.d1                                                       \n\\r
219                 ;movw 2,sp+, _.d2                                                       \n\\r
220                 rti                                                                     \n\\r
221                 ");                                                                     \\r
222 }\r
223 \r
224 /*\r
225  * Utility macro to call macros above in correct order in order to perform a\r
226  * task switch from within a standard ISR.  This macro can only be used if\r
227  * the ISR does not use any local (stack) variables.  If the ISR uses stack\r
228  * variables portYIELD() should be used in it's place.\r
229  */\r
230 \r
231 #define portTASK_SWITCH_FROM_ISR()                                                              \\r
232         portSAVE_CONTEXT();                                                                                     \\r
233         vTaskSwitchContext();                                                                           \\r
234         portRESTORE_CONTEXT();\r
235 \r
236 \r
237 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
238 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
239 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
240 \r
241 #ifdef __cplusplus\r
242 }\r
243 #endif\r
244 \r
245 #endif /* PORTMACRO_H */\r
246 \r