]> begriffs open source - freertos/blob - portable/GCC/CORTUS_APS3/portmacro.h
Add SMP in the License Header (#402)
[freertos] / portable / GCC / CORTUS_APS3 / 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 #ifndef PORTMACRO_H
29 #define PORTMACRO_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #include <machine/cpu.h>
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  uint32_t
54 #define portBASE_TYPE   long
55
56 typedef portSTACK_TYPE StackType_t;
57 typedef long BaseType_t;
58 typedef unsigned long UBaseType_t;
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 /* Architecture specifics. */
70 #define portSTACK_GROWTH                                                        ( -1 )
71 #define portTICK_PERIOD_MS                                                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
72 #define portBYTE_ALIGNMENT                                                      4
73 #define portNOP()                                                                       __asm__ volatile ( "mov r0, r0" )
74 #define portCRITICAL_NESTING_IN_TCB                                     1
75 #define portIRQ_TRAP_YIELD                                                      31
76 /*-----------------------------------------------------------*/
77
78 /* Task utilities. */
79
80 extern void vPortYield( void );
81
82 /*---------------------------------------------------------------------------*/
83
84 #define portYIELD()             asm __volatile__( " trap #%0 "::"i"(portIRQ_TRAP_YIELD):"memory")
85 /*---------------------------------------------------------------------------*/
86
87 extern void vTaskEnterCritical( void );
88 extern void vTaskExitCritical( void );
89 #define portENTER_CRITICAL()            vTaskEnterCritical()
90 #define portEXIT_CRITICAL()                     vTaskExitCritical()
91 /*---------------------------------------------------------------------------*/
92
93 /* Critical section management. */
94 #define portDISABLE_INTERRUPTS()        cpu_int_disable()
95 #define portENABLE_INTERRUPTS()         cpu_int_enable()
96
97 /*---------------------------------------------------------------------------*/
98
99 #define portYIELD_FROM_ISR( xHigherPriorityTaskWoken ) if( xHigherPriorityTaskWoken != pdFALSE ) vTaskSwitchContext()
100
101 /*---------------------------------------------------------------------------*/
102
103 #define portSAVE_CONTEXT()                              \
104         asm __volatile__                                                                                                                                                                                                \
105         (                                                                                                                                                                                                                               \
106                 "sub    r1, #68                                 \n" /* Make space on the stack for the context. */                                                      \
107                 "std    r2, [r1] +      0                       \n"                                                                                                                                                     \
108                 "stq    r4, [r1] +      8                       \n"                                                                                                                                                     \
109                 "stq    r8, [r1] +      24                      \n"                                                                                                                                                     \
110                 "stq    r12, [r1] +     40                      \n"                                                                                                                                                     \
111                 "mov    r6, rtt                                 \n"                                                                                                                                                     \
112                 "mov    r7, psr                                 \n"                                                                                                                                                     \
113                 "std    r6, [r1] +      56                      \n"                                                                                                                                                     \
114                 "movhi  r2, #16384                              \n"     /* Set the pointer to the IC. */                                                                                \
115                 "ldub   r3, [r2] + 2                    \n"     /* Load the current interrupt mask. */                                                                  \
116                 "st             r3, [r1]+ 64                    \n"     /* Store the interrupt mask on the stack. */                                                    \
117                 "ld             r2, [r0]+short(pxCurrentTCB)    \n"     /* Load the pointer to the TCB. */                                                              \
118                 "st             r1, [r2]                                \n"     /* Save the stack pointer into the TCB. */                                                              \
119                 "mov    r14, r1                                 \n"     /* Compiler expects r14 to be set to the function stack. */                             \
120         );
121 /*---------------------------------------------------------------------------*/
122
123 #define portRESTORE_CONTEXT()                                                                                                                                                                           \
124         asm __volatile__(                                                                                                                                                                                               \
125                 "ld             r2, [r0]+short(pxCurrentTCB)    \n"     /* Load the TCB to find the stack pointer and context. */               \
126                 "ld             r1, [r2]                                \n"                                                                                                                                                     \
127                 "movhi  r2, #16384                              \n"     /* Set the pointer to the IC. */                                                                                \
128                 "ld             r3, [r1] + 64                   \n"     /* Load the previous interrupt mask. */                                                                 \
129                 "stb    r3, [r2] + 2                    \n"     /* Set the current interrupt mask to be the previous. */                                \
130                 "ldd    r6, [r1] + 56                   \n"     /* Restore context. */                                                                                                  \
131                 "mov    rtt, r6                                 \n"                                                                                                                                                     \
132                 "mov    psr, r7                                 \n"                                                                                                                                                     \
133                 "ldd    r2, [r1] + 0                    \n"                                                                                                                                                     \
134                 "ldq    r4, [r1] +      8                       \n"                                                                                                                                                     \
135                 "ldq    r8, [r1] +      24                      \n"                                                                                                                                                     \
136                 "ldq    r12, [r1] +     40                      \n"                                                                                                                                                     \
137                 "add    r1, #68                                 \n"                                                                                                                                                     \
138                 "rti                                                    \n"                                                                                                                                                     \
139          );
140
141 /*---------------------------------------------------------------------------*/
142
143 /* Task function macros as described on the FreeRTOS.org WEB site. */
144 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
145 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
146 /*---------------------------------------------------------------------------*/
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 #endif /* PORTMACRO_H */