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