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