]> begriffs open source - freertos/blob - portable/GCC/HCS12/portmacro.h
Update SMP branch readme for port migration (#999)
[freertos] / portable / GCC / HCS12 / portmacro.h
1 /*
2  * FreeRTOS SMP Kernel V202110.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  * 1 tab == 4 spaces!
26  */
27
28
29 #ifndef PORTMACRO_H
30 #define PORTMACRO_H
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /*-----------------------------------------------------------
37  * Port specific definitions.
38  *
39  * The settings in this file configure FreeRTOS correctly for the
40  * given hardware and compiler.
41  *
42  * These settings should not be altered.
43  *-----------------------------------------------------------
44  */
45
46 /* Type definitions. */
47 #define portCHAR                char
48 #define portFLOAT               float
49 #define portDOUBLE              double
50 #define portLONG                long
51 #define portSHORT               short
52 #define portSTACK_TYPE  uint8_t
53 #define portBASE_TYPE   char
54
55 typedef portSTACK_TYPE StackType_t;
56 typedef signed char BaseType_t;
57 typedef unsigned char UBaseType_t;
58
59
60 #if( configUSE_16_BIT_TICKS == 1 )
61         typedef uint16_t TickType_t;
62         #define portMAX_DELAY ( TickType_t ) 0xffff
63 #else
64         typedef uint32_t TickType_t;
65         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
66 #endif
67 /*-----------------------------------------------------------*/
68
69 /* Hardware specifics. */
70 #define portBYTE_ALIGNMENT                      1
71 #define portSTACK_GROWTH                        ( -1 )
72 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
73 #define portYIELD()                                     __asm( "swi" );
74 /*-----------------------------------------------------------*/
75
76 /* Critical section handling. */
77 #define portENABLE_INTERRUPTS()                         __asm( "cli" )
78 #define portDISABLE_INTERRUPTS()                        __asm( "sei" )
79
80 /*
81  * Disable interrupts before incrementing the count of critical section nesting.
82  * The nesting count is maintained so we know when interrupts should be
83  * re-enabled.  Once interrupts are disabled the nesting count can be accessed
84  * directly.  Each task maintains its own nesting count.
85  */
86 #define portENTER_CRITICAL()                                                                    \
87 {                                                                                                                               \
88         extern volatile UBaseType_t uxCriticalNesting;  \
89                                                                                                                                 \
90         portDISABLE_INTERRUPTS();                                                                       \
91         uxCriticalNesting++;                                                                            \
92 }
93
94 /*
95  * Interrupts are disabled so we can access the nesting count directly.  If the
96  * nesting is found to be 0 (no nesting) then we are leaving the critical
97  * section and interrupts can be re-enabled.
98  */
99 #define  portEXIT_CRITICAL()                                                                    \
100 {                                                                                                                               \
101         extern volatile UBaseType_t uxCriticalNesting;  \
102                                                                                                                                 \
103         uxCriticalNesting--;                                                                            \
104         if( uxCriticalNesting == 0 )                                                            \
105         {                                                                                                                       \
106                 portENABLE_INTERRUPTS();                                                                \
107         }                                                                                                                       \
108 }
109 /*-----------------------------------------------------------*/
110
111 /* Task utilities. */
112
113 /*
114  * These macros are very simple as the processor automatically saves and
115  * restores its registers as interrupts are entered and exited.  In
116  * addition to the (automatically stacked) registers we also stack the
117  * critical nesting count.  Each task maintains its own critical nesting
118  * count as it is legitimate for a task to yield from within a critical
119  * section.  If the banked memory model is being used then the PPAGE
120  * register is also stored as part of the tasks context.
121  */
122
123 #ifdef BANKED_MODEL
124         /*
125          * Load the stack pointer for the task, then pull the critical nesting
126          * count and PPAGE register from the stack.  The remains of the
127          * context are restored by the RTI instruction.
128          */
129         #define portRESTORE_CONTEXT()                                                   \
130         {                                                                               \
131                 __asm( "                                                                \n\
132                 .globl pxCurrentTCB                     ; void *                        \n\
133                 .globl uxCriticalNesting                ; char                          \n\
134                                                                                         \n\
135                 ldx  pxCurrentTCB                                                       \n\
136                 lds  0,x                                ; Stack                         \n\
137                                                                                         \n\
138                 movb 1,sp+,uxCriticalNesting                                            \n\
139                 movb 1,sp+,0x30                         ; PPAGE                         \n\
140                 " );                                                                    \
141         }
142
143         /*
144          * By the time this macro is called the processor has already stacked the
145          * registers.  Simply stack the nesting count and PPAGE value, then save
146          * the task stack pointer.
147          */
148         #define portSAVE_CONTEXT()                                                      \
149         {                                                                               \
150                 __asm( "                                                                \n\
151                 .globl pxCurrentTCB                     ; void *                        \n\
152                 .globl uxCriticalNesting                ; char                          \n\
153                                                                                         \n\
154                 movb 0x30, 1,-sp                        ; PPAGE                         \n\
155                 movb uxCriticalNesting, 1,-sp                                           \n\
156                                                                                         \n\
157                 ldx  pxCurrentTCB                                                       \n\
158                 sts  0,x                                ; Stack                         \n\
159                 " );                                                                    \
160         }
161 #else
162
163         /*
164          * These macros are as per the BANKED versions above, but without saving
165          * and restoring the PPAGE register.
166          */
167
168         #define portRESTORE_CONTEXT()                                                   \
169         {                                                                               \
170                 __asm( "                                                                \n\
171                 .globl pxCurrentTCB                     ; void *                        \n\
172                 .globl uxCriticalNesting                ; char                          \n\
173                                                                                         \n\
174                 ldx  pxCurrentTCB                                                       \n\
175                 lds  0,x                                ; Stack                         \n\
176                                                                                         \n\
177                 movb 1,sp+,uxCriticalNesting                                            \n\
178                 " );                                                                    \
179         }
180
181         #define portSAVE_CONTEXT()                                                      \
182         {                                                                               \
183                 __asm( "                                                                \n\
184                 .globl pxCurrentTCB                     ; void *                        \n\
185                 .globl uxCriticalNesting                ; char                          \n\
186                                                                                         \n\
187                 movb uxCriticalNesting, 1,-sp                                           \n\
188                                                                                         \n\
189                 ldx  pxCurrentTCB                                                       \n\
190                 sts  0,x                                ; Stack                         \n\
191                 " );                                                                    \
192         }
193 #endif
194
195 /*
196  * Utility macros to save/restore correct software registers for GCC. This is
197  * useful when GCC does not generate appropriate ISR head/tail code.
198  */
199 #define portISR_HEAD()                                                                  \
200 {                                                                                       \
201                 __asm("                                                                 \n\
202                 movw _.frame, 2,-sp                                                     \n\
203                 movw _.tmp, 2,-sp                                                       \n\
204                 movw _.z, 2,-sp                                                         \n\
205                 movw _.xy, 2,-sp                                                        \n\
206                 ;movw _.d2, 2,-sp                                                       \n\
207                 ;movw _.d1, 2,-sp                                                       \n\
208                 ");                                                                     \
209 }
210
211 #define portISR_TAIL()                                                                  \
212 {                                                                                       \
213                 __asm("                                                                 \n\
214                 movw 2,sp+, _.xy                                                        \n\
215                 movw 2,sp+, _.z                                                         \n\
216                 movw 2,sp+, _.tmp                                                       \n\
217                 movw 2,sp+, _.frame                                                     \n\
218                 ;movw 2,sp+, _.d1                                                       \n\
219                 ;movw 2,sp+, _.d2                                                       \n\
220                 rti                                                                     \n\
221                 ");                                                                     \
222 }
223
224 /*
225  * Utility macro to call macros above in correct order in order to perform a
226  * task switch from within a standard ISR.  This macro can only be used if
227  * the ISR does not use any local (stack) variables.  If the ISR uses stack
228  * variables portYIELD() should be used in it's place.
229  */
230
231 #define portTASK_SWITCH_FROM_ISR()                                                              \
232         portSAVE_CONTEXT();                                                                                     \
233         vTaskSwitchContext();                                                                           \
234         portRESTORE_CONTEXT();
235
236
237 /* Task function macros as described on the FreeRTOS.org WEB site. */
238 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
239 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
240
241 #ifdef __cplusplus
242 }
243 #endif
244
245 #endif /* PORTMACRO_H */
246