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