]> begriffs open source - freertos/blob - portable/GCC/ARM_CRx_No_GIC/portmacro.h
Add SMP in the License Header (#402)
[freertos] / portable / GCC / ARM_CRx_No_GIC / 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 /*-----------------------------------------------------------
36  * Port specific definitions.
37  *
38  * The settings in this file configure FreeRTOS correctly for the given hardware
39  * and compiler.
40  *
41  * These settings should not be altered.
42  *-----------------------------------------------------------
43  */
44
45 /* Type definitions. */
46 #define portCHAR                char
47 #define portFLOAT               float
48 #define portDOUBLE              double
49 #define portLONG                long
50 #define portSHORT               short
51 #define portSTACK_TYPE  uint32_t
52 #define portBASE_TYPE   long
53
54 typedef portSTACK_TYPE StackType_t;
55 typedef long BaseType_t;
56 typedef unsigned long UBaseType_t;
57
58 typedef uint32_t TickType_t;
59 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
60
61 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
62 not need to be guarded with a critical section. */
63 #define portTICK_TYPE_IS_ATOMIC 1
64
65 /*-----------------------------------------------------------*/
66
67 /* Hardware specifics. */
68 #define portSTACK_GROWTH                        ( -1 )
69 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
70 #define portBYTE_ALIGNMENT                      8
71
72 /*-----------------------------------------------------------*/
73
74 /* Task utilities. */
75
76 /* Called at the end of an ISR that can cause a context switch. */
77 #define portEND_SWITCHING_ISR( xSwitchRequired )\
78 {                                                                                               \
79 extern volatile uint32_t ulPortYieldRequired;   \
80                                                                                                 \
81         if( xSwitchRequired != pdFALSE )                        \
82         {                                                                                       \
83                 ulPortYieldRequired = pdTRUE;                   \
84         }                                                                                       \
85 }
86
87 #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
88 #define portYIELD() __asm volatile ( "SWI 0             \n"                             \
89                                                                          "ISB             " ::: "memory" );
90
91
92 /*-----------------------------------------------------------
93  * Critical section control
94  *----------------------------------------------------------*/
95
96 extern void vPortEnterCritical( void );
97 extern void vPortExitCritical( void );
98 extern uint32_t ulPortSetInterruptMask( void );
99 extern void vPortClearInterruptMask( uint32_t ulNewMaskValue );
100 extern void vPortInstallFreeRTOSVectorTable( void );
101
102 /* The I bit within the CPSR. */
103 #define portINTERRUPT_ENABLE_BIT        ( 1 << 7 )
104
105 /* In the absence of a priority mask register, these functions and macros
106 globally enable and disable interrupts. */
107 #define portENTER_CRITICAL()            vPortEnterCritical();
108 #define portEXIT_CRITICAL()                     vPortExitCritical();
109 #define portENABLE_INTERRUPTS()         __asm volatile ( "CPSIE i       \n"     ::: "memory" );
110 #define portDISABLE_INTERRUPTS()        __asm volatile ( "CPSID i       \n"             \
111                                                                                                          "DSB           \n"             \
112                                                                                                          "ISB             " ::: "memory" );
113
114 __attribute__( ( always_inline ) ) static __inline uint32_t portINLINE_SET_INTERRUPT_MASK_FROM_ISR( void )
115 {
116 volatile uint32_t ulCPSR;
117
118         __asm volatile ( "MRS %0, CPSR" : "=r" (ulCPSR) :: "memory" );
119         ulCPSR &= portINTERRUPT_ENABLE_BIT;
120         portDISABLE_INTERRUPTS();
121         return ulCPSR;
122 }
123
124 #define portSET_INTERRUPT_MASK_FROM_ISR() portINLINE_SET_INTERRUPT_MASK_FROM_ISR()
125 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x)    if( x == 0 ) portENABLE_INTERRUPTS()
126
127 /*-----------------------------------------------------------*/
128
129 /* Task function macros as described on the FreeRTOS.org WEB site.  These are
130 not required for this port but included in case common demo code that uses these
131 macros is used. */
132 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters )      void vFunction( void *pvParameters )
133 #define portTASK_FUNCTION( vFunction, pvParameters )    void vFunction( void *pvParameters )
134
135 /* Tickless idle/low power functionality. */
136 #ifndef portSUPPRESS_TICKS_AND_SLEEP
137         extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime );
138         #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime )
139 #endif
140
141 /* Prototype of the FreeRTOS tick handler.  This must be installed as the
142 handler for whichever peripheral is used to generate the RTOS tick. */
143 void FreeRTOS_Tick_Handler( void );
144
145 /* Any task that uses the floating point unit MUST call vPortTaskUsesFPU()
146 before any floating point instructions are executed. */
147 void vPortTaskUsesFPU( void );
148 #define portTASK_USES_FLOATING_POINT() vPortTaskUsesFPU()
149
150 #define portLOWEST_INTERRUPT_PRIORITY ( ( ( uint32_t ) configUNIQUE_INTERRUPT_PRIORITIES ) - 1UL )
151 #define portLOWEST_USABLE_INTERRUPT_PRIORITY ( portLOWEST_INTERRUPT_PRIORITY - 1UL )
152
153 /* Architecture specific optimisations. */
154 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
155         #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
156 #endif
157
158 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
159
160         /* Store/clear the ready priorities in a bit map. */
161         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
162         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
163
164         /*-----------------------------------------------------------*/
165
166         #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __builtin_clz( uxReadyPriorities ) )
167
168 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
169
170 #define portNOP() __asm volatile( "NOP" )
171 #define portINLINE __inline
172
173 #define portMEMORY_BARRIER() __asm volatile( "" ::: "memory" )
174
175 #ifdef __cplusplus
176         } /* extern C */
177 #endif
178
179
180 #endif /* PORTMACRO_H */
181