1 /*
2  * FreeRTOS Kernel V11.1.0
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 /*-----------------------------------------------------------
39  * Port specific definitions.
40  *
41  * The settings in this file configure FreeRTOS correctly for the given hardware
42  * and compiler.
43  *
44  * These settings should not be altered.
45  *-----------------------------------------------------------
46  */
47 
48 /* Type definitions. */
49 #define portCHAR          char
50 #define portFLOAT         float
51 #define portDOUBLE        double
52 #define portLONG          long
53 #define portSHORT         short
54 #define portSTACK_TYPE    size_t
55 #define portBASE_TYPE     long
56 
57 typedef portSTACK_TYPE   StackType_t;
58 typedef portBASE_TYPE    BaseType_t;
59 typedef uint64_t         UBaseType_t;
60 
61 typedef uint64_t         TickType_t;
62 #define portMAX_DELAY              ( ( TickType_t ) 0xffffffffffffffff )
63 
64 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
65  * not need to be guarded with a critical section. */
66 #define portTICK_TYPE_IS_ATOMIC    1
67 
68 /*-----------------------------------------------------------*/
69 
70 /* Hardware specifics. */
71 #define portSTACK_GROWTH         ( -1 )
72 #define portTICK_PERIOD_MS       ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
73 #define portBYTE_ALIGNMENT       16
74 #define portPOINTER_SIZE_TYPE    uint64_t
75 
76 /*-----------------------------------------------------------*/
77 
78 /* Task utilities. */
79 
80 /* Called at the end of an ISR that can cause a context switch. */
81 #define portEND_SWITCHING_ISR( xSwitchRequired ) \
82     {                                            \
83         extern uint64_t ullPortYieldRequired;    \
84                                                  \
85         if( xSwitchRequired != pdFALSE )         \
86         {                                        \
87             ullPortYieldRequired = pdTRUE;       \
88         }                                        \
89     }
90 
91 #define portYIELD_FROM_ISR( x )    portEND_SWITCHING_ISR( x )
92 #if defined( GUEST )
93     #define portYIELD()            __asm volatile ( "SVC 0" ::: "memory" )
94 #else
95     #define portYIELD()            __asm volatile ( "SMC 0" ::: "memory" )
96 #endif
97 
98 /*-----------------------------------------------------------
99 * Critical section control
100 *----------------------------------------------------------*/
101 
102 extern void vPortEnterCritical( void );
103 extern void vPortExitCritical( void );
104 extern UBaseType_t uxPortSetInterruptMask( void );
105 extern void vPortClearInterruptMask( UBaseType_t uxNewMaskValue );
106 extern void vPortInstallFreeRTOSVectorTable( void );
107 
108 #define portDISABLE_INTERRUPTS()                       \
109     __asm volatile ( "MSR DAIFSET, #2" ::: "memory" ); \
110     __asm volatile ( "DSB SY" );                       \
111     __asm volatile ( "ISB SY" );
112 
113 #define portENABLE_INTERRUPTS()                        \
114     __asm volatile ( "MSR DAIFCLR, #2" ::: "memory" ); \
115     __asm volatile ( "DSB SY" );                       \
116     __asm volatile ( "ISB SY" );
117 
118 
119 /* These macros do not globally disable/enable interrupts.  They do mask off
120  * interrupts that have a priority below configMAX_API_CALL_INTERRUPT_PRIORITY. */
121 #define portENTER_CRITICAL()                      vPortEnterCritical();
122 #define portEXIT_CRITICAL()                       vPortExitCritical();
123 #define portSET_INTERRUPT_MASK_FROM_ISR()         uxPortSetInterruptMask()
124 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x )    vPortClearInterruptMask( x )
125 
126 /*-----------------------------------------------------------*/
127 
128 /* Task function macros as described on the FreeRTOS.org WEB site.  These are
129  * not required for this port but included in case common demo code that uses these
130  * macros is used. */
131 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters )    void vFunction( void * pvParameters )
132 #define portTASK_FUNCTION( vFunction, pvParameters )          void vFunction( void * pvParameters )
133 
134 /* Prototype of the FreeRTOS tick handler.  This must be installed as the
135  * handler for whichever peripheral is used to generate the RTOS tick. */
136 void FreeRTOS_Tick_Handler( void );
137 
138 /* Any task that uses the floating point unit MUST call vPortTaskUsesFPU()
139  * before any floating point instructions are executed. */
140 void vPortTaskUsesFPU( void );
141 #define portTASK_USES_FLOATING_POINT()    vPortTaskUsesFPU()
142 
143 #define portLOWEST_INTERRUPT_PRIORITY           ( ( ( uint32_t ) configUNIQUE_INTERRUPT_PRIORITIES ) - 1UL )
144 #define portLOWEST_USABLE_INTERRUPT_PRIORITY    ( portLOWEST_INTERRUPT_PRIORITY - 1UL )
145 
146 /* Architecture specific optimisations. */
147 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
148     #define configUSE_PORT_OPTIMISED_TASK_SELECTION    1
149 #endif
150 
151 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
152 
153 /* Store/clear the ready priorities in a bit map. */
154     #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities )    ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
155     #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities )     ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
156 
157 /*-----------------------------------------------------------*/
158 
159     #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities )    uxTopPriority = ( 31 - __builtin_clz( uxReadyPriorities ) )
160 
161 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
162 
163 #ifdef configASSERT
164     void vPortValidateInterruptPriority( void );
165     #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID()    vPortValidateInterruptPriority()
166 #endif /* configASSERT */
167 
168 #define portNOP()                                         __asm volatile ( "NOP" )
169 #define portINLINE    __inline
170 
171 /* The number of bits to shift for an interrupt priority is dependent on the
172  * number of bits implemented by the interrupt controller. */
173 #if configUNIQUE_INTERRUPT_PRIORITIES == 16
174     #define portPRIORITY_SHIFT            4
175     #define portMAX_BINARY_POINT_VALUE    3
176 #elif configUNIQUE_INTERRUPT_PRIORITIES == 32
177     #define portPRIORITY_SHIFT            3
178     #define portMAX_BINARY_POINT_VALUE    2
179 #elif configUNIQUE_INTERRUPT_PRIORITIES == 64
180     #define portPRIORITY_SHIFT            2
181     #define portMAX_BINARY_POINT_VALUE    1
182 #elif configUNIQUE_INTERRUPT_PRIORITIES == 128
183     #define portPRIORITY_SHIFT            1
184     #define portMAX_BINARY_POINT_VALUE    0
185 #elif configUNIQUE_INTERRUPT_PRIORITIES == 256
186     #define portPRIORITY_SHIFT            0
187     #define portMAX_BINARY_POINT_VALUE    0
188 #else /* if configUNIQUE_INTERRUPT_PRIORITIES == 16 */
189     #error Invalid configUNIQUE_INTERRUPT_PRIORITIES setting.  configUNIQUE_INTERRUPT_PRIORITIES must be set to the number of unique priorities implemented by the target hardware
190 #endif /* if configUNIQUE_INTERRUPT_PRIORITIES == 16 */
191 
192 #define portMEMORY_BARRIER()    __asm volatile ( "" ::: "memory" )
193 
194 /* *INDENT-OFF* */
195 #ifdef __cplusplus
196     }
197 #endif
198 /* *INDENT-ON* */
199 
200 #endif /* PORTMACRO_H */
201