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    uint32_t
55 #define portBASE_TYPE     long
56 
57 typedef portSTACK_TYPE   StackType_t;
58 typedef long             BaseType_t;
59 typedef unsigned long    UBaseType_t;
60 
61 
62 #if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS )
63     typedef uint16_t     TickType_t;
64     #define portMAX_DELAY              ( TickType_t ) 0xffff
65 #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS )
66     typedef uint32_t     TickType_t;
67     #define portMAX_DELAY              ( TickType_t ) 0xffffffffUL
68 
69 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
70  * not need to be guarded with a critical section. */
71     #define portTICK_TYPE_IS_ATOMIC    1
72 #else
73     #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
74 #endif
75 /*-----------------------------------------------------------*/
76 
77 /* Hardware specifics. */
78 #define portSTACK_GROWTH      ( -1 )
79 #define portTICK_PERIOD_MS    ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
80 #define portBYTE_ALIGNMENT    8
81 
82 /*-----------------------------------------------------------*/
83 
84 /* Task utilities. */
85 
86 /* Called at the end of an ISR that can cause a context switch. */
87 #define portEND_SWITCHING_ISR( xSwitchRequired ) \
88     {                                            \
89         extern uint32_t ulPortYieldRequired;     \
90                                                  \
91         if( xSwitchRequired != pdFALSE )         \
92         {                                        \
93             ulPortYieldRequired = pdTRUE;        \
94         }                                        \
95     }
96 
97 #define portYIELD_FROM_ISR( x )    portEND_SWITCHING_ISR( x )
98 #define portYIELD()                __asm( "SWI 0" );
99 
100 
101 /*-----------------------------------------------------------
102 * Critical section control
103 *----------------------------------------------------------*/
104 
105 extern void vPortEnterCritical( void );
106 extern void vPortExitCritical( void );
107 extern uint32_t ulPortSetInterruptMask( void );
108 extern void vPortClearInterruptMask( uint32_t ulNewMaskValue );
109 
110 /* These macros do not globally disable/enable interrupts.  They do mask off
111  * interrupts that have a priority below configMAX_API_CALL_INTERRUPT_PRIORITY. */
112 #define portENTER_CRITICAL()                      vPortEnterCritical();
113 #define portEXIT_CRITICAL()                       vPortExitCritical();
114 #define portDISABLE_INTERRUPTS()                  ulPortSetInterruptMask()
115 #define portENABLE_INTERRUPTS()                   vPortClearInterruptMask( 0 )
116 #define portSET_INTERRUPT_MASK_FROM_ISR()         ulPortSetInterruptMask()
117 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x )    vPortClearInterruptMask( x )
118 
119 /*-----------------------------------------------------------*/
120 
121 /* Task function macros as described on the FreeRTOS.org WEB site.  These are
122  * not required for this port but included in case common demo code that uses these
123  * macros is used. */
124 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters )    void vFunction( void * pvParameters )
125 #define portTASK_FUNCTION( vFunction, pvParameters )          void vFunction( void * pvParameters )
126 
127 /* Prototype of the FreeRTOS tick handler.  This must be installed as the
128  * handler for whichever peripheral is used to generate the RTOS tick. */
129 void FreeRTOS_Tick_Handler( void );
130 
131 /* Any task that uses the floating point unit MUST call vPortTaskUsesFPU()
132  * before any floating point instructions are executed. */
133 void vPortTaskUsesFPU( void );
134 #define portTASK_USES_FLOATING_POINT()    vPortTaskUsesFPU()
135 
136 #define portLOWEST_INTERRUPT_PRIORITY           ( ( ( uint32_t ) configUNIQUE_INTERRUPT_PRIORITIES ) - 1UL )
137 #define portLOWEST_USABLE_INTERRUPT_PRIORITY    ( portLOWEST_INTERRUPT_PRIORITY - 1UL )
138 
139 /* Architecture specific optimisations. */
140 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
141     #define configUSE_PORT_OPTIMISED_TASK_SELECTION    1
142 #endif
143 
144 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
145 
146 /* Store/clear the ready priorities in a bit map. */
147     #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities )    ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
148     #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities )     ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
149 
150 /*-----------------------------------------------------------*/
151 
152     #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities )    uxTopPriority = ( 31 - __clz( uxReadyPriorities ) )
153 
154 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
155 
156 #ifdef configASSERT
157     void vPortValidateInterruptPriority( void );
158     #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID()    vPortValidateInterruptPriority()
159 #endif
160 
161 #define portNOP()                                         __nop()
162 
163 /* *INDENT-OFF* */
164 #ifdef __cplusplus
165     }
166 #endif
167 /* *INDENT-ON* */
168 
169 #endif /* PORTMACRO_H */
170