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 #include <intrinsics.h>
33 
34 /* *INDENT-OFF* */
35 #ifdef __cplusplus
36     extern "C" {
37 #endif
38 /* *INDENT-ON* */
39 
40 /*-----------------------------------------------------------
41  * Port specific definitions.
42  *
43  * The settings in this file configure FreeRTOS correctly for the given hardware
44  * 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 typedef uint32_t         TickType_t;
64 #define portMAX_DELAY              ( TickType_t ) 0xffffffffUL
65 
66 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
67  * not need to be guarded with a critical section. */
68 #define portTICK_TYPE_IS_ATOMIC    1
69 
70 /*-----------------------------------------------------------*/
71 
72 /* Hardware specifics. */
73 #define portSTACK_GROWTH      ( -1 )
74 #define portTICK_PERIOD_MS    ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
75 #define portBYTE_ALIGNMENT    8
76 
77 /*-----------------------------------------------------------*/
78 
79 /* Task utilities. */
80 
81 /* Called at the end of an ISR that can cause a context switch. */
82 #define portEND_SWITCHING_ISR( xSwitchRequired )      \
83     {                                                 \
84         extern volatile uint32_t ulPortYieldRequired; \
85                                                       \
86         if( xSwitchRequired != pdFALSE )              \
87         {                                             \
88             ulPortYieldRequired = pdTRUE;             \
89         }                                             \
90     }
91 
92 #define portYIELD_FROM_ISR( x )    portEND_SWITCHING_ISR( x )
93 #define portYIELD()                 \
94     __asm volatile ( "SWI 0     \n" \
95                      "ISB         " );
96 
97 
98 /*-----------------------------------------------------------
99 * Critical section control
100 *----------------------------------------------------------*/
101 
102 extern void vPortEnterCritical( void );
103 extern void vPortExitCritical( void );
104 extern uint32_t ulPortSetInterruptMask( void );
105 extern void vPortClearInterruptMask( uint32_t ulNewMaskValue );
106 extern void vPortInstallFreeRTOSVectorTable( void );
107 
108 /* The I bit within the CPSR. */
109 #define portINTERRUPT_ENABLE_BIT    ( 1 << 7 )
110 
111 /* In the absence of a priority mask register, these functions and macros
112  * globally enable and disable interrupts. */
113 #define portENTER_CRITICAL()       vPortEnterCritical();
114 #define portEXIT_CRITICAL()        vPortExitCritical();
115 #define portENABLE_INTERRUPTS()    __asm volatile ( "CPSIE i   \n" );
116 #define portDISABLE_INTERRUPTS()    \
117     __asm volatile ( "CPSID i   \n" \
118                      "DSB       \n" \
119                      "ISB         " );
120 #pragma inline
portINLINE_SET_INTERRUPT_MASK_FROM_ISR(void)121 static inline uint32_t portINLINE_SET_INTERRUPT_MASK_FROM_ISR( void )
122 {
123     volatile uint32_t ulCPSR;
124 
125     __asm volatile ( "MRS %0, CPSR" : "=r" ( ulCPSR ) );
126 
127     ulCPSR &= portINTERRUPT_ENABLE_BIT;
128     portDISABLE_INTERRUPTS();
129     return ulCPSR;
130 }
131 
132 #define portSET_INTERRUPT_MASK_FROM_ISR()         portINLINE_SET_INTERRUPT_MASK_FROM_ISR()
133 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x )    do { if( x == 0 ) portENABLE_INTERRUPTS( ); } while( 0 )
134 
135 /*-----------------------------------------------------------*/
136 
137 /* Task function macros as described on the FreeRTOS.org WEB site.  These are
138  * not required for this port but included in case common demo code that uses these
139  * macros is used. */
140 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters )    void vFunction( void * pvParameters )
141 #define portTASK_FUNCTION( vFunction, pvParameters )          void vFunction( void * pvParameters )
142 
143 /* Prototype of the FreeRTOS tick handler.  This must be installed as the
144  * handler for whichever peripheral is used to generate the RTOS tick. */
145 void FreeRTOS_Tick_Handler( void );
146 
147 /* Any task that uses the floating point unit MUST call vPortTaskUsesFPU()
148  * before any floating point instructions are executed. */
149 void vPortTaskUsesFPU( void );
150 #define portTASK_USES_FLOATING_POINT()    vPortTaskUsesFPU()
151 
152 #define portLOWEST_INTERRUPT_PRIORITY           ( ( ( uint32_t ) configUNIQUE_INTERRUPT_PRIORITIES ) - 1UL )
153 #define portLOWEST_USABLE_INTERRUPT_PRIORITY    ( portLOWEST_INTERRUPT_PRIORITY - 1UL )
154 
155 /* Architecture specific optimisations. */
156 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
157     #define configUSE_PORT_OPTIMISED_TASK_SELECTION    1
158 #endif
159 
160 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
161 
162 /* Store/clear the ready priorities in a bit map. */
163     #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities )    ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
164     #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities )     ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
165 
166 /*-----------------------------------------------------------*/
167 
168     #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities )    uxTopPriority = ( 31UL - ( uint32_t ) __CLZ( uxReadyPriorities ) )
169 
170 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
171 
172 #define portNOP()    __asm volatile ( "NOP" )
173 #define portINLINE    inline
174 
175 /* Suppress warnings that are generated by the IAR tools, but cannot be fixed in
176  * the source code because to do so would cause other compilers to generate
177  * warnings. */
178 #pragma diag_suppress=Pe191
179 #pragma diag_suppress=Pa082
180 
181 /* *INDENT-OFF* */
182 #ifdef __cplusplus
183     }
184 #endif
185 /* *INDENT-ON* */
186 
187 #endif /* PORTMACRO_H */
188