]> begriffs open source - cmsis-freertos/blob - Source/portable/GCC/CORTUS_APS3/portmacro.h
Update FreeRTOS-Kernel to v10.6.2
[cmsis-freertos] / Source / portable / GCC / CORTUS_APS3 / portmacro.h
1 /*
2  * FreeRTOS Kernel V10.6.2
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 #ifndef PORTMACRO_H
30 #define PORTMACRO_H
31
32 /* *INDENT-OFF* */
33 #ifdef __cplusplus
34     extern "C" {
35 #endif
36 /* *INDENT-ON* */
37
38 #include <machine/cpu.h>
39
40 /*-----------------------------------------------------------
41  * Port specific definitions.
42  *
43  * The settings in this file configure FreeRTOS correctly for the
44  * given hardware and compiler.
45  *
46  * These settings should not be altered.
47  *-----------------------------------------------------------
48  */
49
50 /* Type definitions. */
51 #define portCHAR        char
52 #define portFLOAT       float
53 #define portDOUBLE      double
54 #define portLONG        long
55 #define portSHORT       short
56 #define portSTACK_TYPE  uint32_t
57 #define portBASE_TYPE   long
58
59 typedef portSTACK_TYPE StackType_t;
60 typedef long BaseType_t;
61 typedef unsigned long UBaseType_t;
62
63 #if( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS )
64     typedef uint16_t TickType_t;
65     #define portMAX_DELAY ( TickType_t ) 0xffff
66 #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS )
67     typedef uint32_t TickType_t;
68     #define portMAX_DELAY ( TickType_t )    ( 0xFFFFFFFFUL )
69 #else
70     #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
71 #endif
72 /*-----------------------------------------------------------*/
73
74 /* Architecture specifics. */
75 #define portSTACK_GROWTH                            ( -1 )
76 #define portTICK_PERIOD_MS                          ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
77 #define portBYTE_ALIGNMENT                          4
78 #define portNOP()                                   __asm__ volatile ( "mov r0, r0" )
79 #define portCRITICAL_NESTING_IN_TCB                 1
80 #define portIRQ_TRAP_YIELD                          31
81 /*-----------------------------------------------------------*/
82
83 /* Task utilities. */
84
85 extern void vPortYield( void );
86
87 /*---------------------------------------------------------------------------*/
88
89 #define portYIELD()     asm __volatile__( " trap #%0 "::"i"(portIRQ_TRAP_YIELD):"memory")
90 /*---------------------------------------------------------------------------*/
91
92 extern void vTaskEnterCritical( void );
93 extern void vTaskExitCritical( void );
94 #define portENTER_CRITICAL()        vTaskEnterCritical()
95 #define portEXIT_CRITICAL()         vTaskExitCritical()
96 /*---------------------------------------------------------------------------*/
97
98 /* Critical section management. */
99 #define portDISABLE_INTERRUPTS()    cpu_int_disable()
100 #define portENABLE_INTERRUPTS()     cpu_int_enable()
101
102 /*---------------------------------------------------------------------------*/
103
104 #define portYIELD_FROM_ISR( xHigherPriorityTaskWoken ) do { if( xHigherPriorityTaskWoken != pdFALSE ) vTaskSwitchContext(); } while( 0 )
105
106 /*---------------------------------------------------------------------------*/
107
108 #define portSAVE_CONTEXT()              \
109     asm __volatile__                                                                                                \
110     (                                                                                                               \
111         "sub    r1, #68                 \n" /* Make space on the stack for the context. */                          \
112         "std    r2, [r1] +  0           \n"                                                                         \
113         "stq    r4, [r1] +  8           \n"                                                                         \
114         "stq    r8, [r1] +  24          \n"                                                                         \
115         "stq    r12, [r1] + 40          \n"                                                                         \
116         "mov    r6, rtt                 \n"                                                                         \
117         "mov    r7, psr                 \n"                                                                         \
118         "std    r6, [r1] +  56          \n"                                                                         \
119         "movhi  r2, #16384              \n" /* Set the pointer to the IC. */                                        \
120         "ldub   r3, [r2] + 2            \n" /* Load the current interrupt mask. */                                  \
121         "st     r3, [r1]+ 64            \n" /* Store the interrupt mask on the stack. */                            \
122         "ld     r2, [r0]+short(pxCurrentTCB)    \n" /* Load the pointer to the TCB. */                              \
123         "st     r1, [r2]                \n" /* Save the stack pointer into the TCB. */                              \
124         "mov    r14, r1                 \n" /* Compiler expects r14 to be set to the function stack. */             \
125     );
126 /*---------------------------------------------------------------------------*/
127
128 #define portRESTORE_CONTEXT()                                                                                       \
129     asm __volatile__(                                                                                               \
130         "ld     r2, [r0]+short(pxCurrentTCB)    \n" /* Load the TCB to find the stack pointer and context. */       \
131         "ld     r1, [r2]                \n"                                                                         \
132         "movhi  r2, #16384              \n" /* Set the pointer to the IC. */                                        \
133         "ld     r3, [r1] + 64           \n" /* Load the previous interrupt mask. */                                 \
134         "stb    r3, [r2] + 2            \n" /* Set the current interrupt mask to be the previous. */                \
135         "ldd    r6, [r1] + 56           \n" /* Restore context. */                                                  \
136         "mov    rtt, r6                 \n"                                                                         \
137         "mov    psr, r7                 \n"                                                                         \
138         "ldd    r2, [r1] + 0            \n"                                                                         \
139         "ldq    r4, [r1] +  8           \n"                                                                         \
140         "ldq    r8, [r1] +  24          \n"                                                                         \
141         "ldq    r12, [r1] + 40          \n"                                                                         \
142         "add    r1, #68                 \n"                                                                         \
143         "rti                            \n"                                                                         \
144      );
145
146 /*---------------------------------------------------------------------------*/
147
148 /* Task function macros as described on the FreeRTOS.org WEB site. */
149 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
150 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
151 /*---------------------------------------------------------------------------*/
152
153 /* *INDENT-OFF* */
154 #ifdef __cplusplus
155     }
156 #endif
157 /* *INDENT-ON* */
158
159 #endif /* PORTMACRO_H */