1 /* 2 * FreeRTOS Kernel <DEVELOPMENT BRANCH> 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 { 35 #endif 36 37 /*----------------------------------------------------------- 38 * Port specific definitions. 39 * 40 * The settings in this file configure FreeRTOS correctly for the 41 * given hardware and compiler. 42 * 43 * These settings should not be altered. 44 *----------------------------------------------------------- 45 */ 46 47 /* Type definitions - These are a bit legacy and not really used now, other 48 * than portSTACK_TYPE and portBASE_TYPE. */ 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 /* Defines the maximum time when using a wait command in a task */ 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 78 /* Architecture specifics */ 79 80 #define portSTSR( reg ) __stsr( ( reg ) ) 81 #define portLDSR( reg, val ) __ldsr( ( reg ), ( val ) ) 82 #define portSTSR_CCRH( reg, sel ) __stsr_rh( ( reg ), ( sel ) ) 83 #define portSYNCM() __syncm() 84 85 /* Determine the descending of the stack from high address to address */ 86 #define portSTACK_GROWTH ( -1 ) 87 88 /* Determine the time (in milliseconds) corresponding to each tick */ 89 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) 90 91 /* It is a multiple of 4 (the two lower-order bits of the address = 0), 92 * otherwise it will cause MAE (Misaligned Exception) according to the manual */ 93 #define portBYTE_ALIGNMENT ( 4 ) 94 95 /* Interrupt control macros. */ 96 97 #define portENABLE_INTERRUPTS() __EI() /* Macro to enable all maskable interrupts. */ 98 #define portDISABLE_INTERRUPTS() __DI() /* Macro to disable all maskable interrupts. */ 99 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS() 100 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS() 101 102 /* SMP build which means configNUM_CORES is relevant */ 103 #define portSUPPORT_SMP 1 104 105 #define portMAX_CORE_COUNT 2 106 #ifndef configNUMBER_OF_CORES 107 #define configNUMBER_OF_CORES 1 108 #endif 109 110 /*-----------------------------------------------------------*/ 111 /* Scheduler utilities */ 112 113 /* Called at the end of an ISR that can cause a context switch */ 114 extern void vPortSetSwitch( BaseType_t xSwitchRequired ); 115 116 #define portEND_SWITCHING_ISR( x ) vPortSetSwitch( x ) 117 118 #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) 119 120 /* Use to transfer control from one task to perform other tasks of 121 * higher priority */ 122 extern void vPortYield( void ); 123 124 #define portYIELD() vPortYield() 125 #if ( configNUMBER_OF_CORES > 1 ) 126 127 /* Return the core ID on which the code is running. */ 128 extern BaseType_t xPortGET_CORE_ID(); 129 130 #define portGET_CORE_ID() xPortGET_CORE_ID() 131 #define coreid xPortGET_CORE_ID() 132 133 /* Request the core ID x to yield. */ 134 extern void vPortYieldCore( uint32_t coreID ); 135 136 #define portYIELD_CORE( x ) vPortYieldCore( x ) 137 138 #define portENTER_CRITICAL_FROM_ISR() vTaskEnterCriticalFromISR() 139 #define portEXIT_CRITICAL_FROM_ISR( x ) vTaskExitCriticalFromISR( x ) 140 141 #endif /* if ( configNUMBER_OF_CORES > 1 ) */ 142 143 #if ( configNUMBER_OF_CORES == 1 ) 144 #define portGET_ISR_LOCK( xCoreID ) 145 #define portRELEASE_ISR_LOCK( xCoreID ) 146 #define portGET_TASK_LOCK( xCoreID ) 147 #define portRELEASE_TASK_LOCK( xCoreID ) 148 #else 149 extern void vPortRecursiveLockAcquire( BaseType_t xCoreID, BaseType_t xFromIsr ); 150 extern void vPortRecursiveLockRelease( BaseType_t xCoreID, BaseType_t xFromIsr ); 151 152 #define portGET_ISR_LOCK( xCoreID ) vPortRecursiveLockAcquire( ( xCoreID ), pdTRUE ) 153 #define portRELEASE_ISR_LOCK( xCoreID ) vPortRecursiveLockRelease( ( xCoreID ), pdTRUE ) 154 #define portGET_TASK_LOCK( xCoreID ) vPortRecursiveLockAcquire( ( xCoreID ), pdFALSE ) 155 #define portRELEASE_TASK_LOCK( xCoreID ) vPortRecursiveLockRelease( ( xCoreID ), pdFALSE ) 156 #endif /* if ( configNUMBER_OF_CORES == 1 ) */ 157 158 /*-----------------------------------------------------------*/ 159 /* Critical section management. */ 160 161 /* The critical nesting functions defined within tasks.c */ 162 163 extern void vTaskEnterCritical( void ); 164 extern void vTaskExitCritical( void ); 165 166 /* Macro to mark the start of a critical code region */ 167 #define portENTER_CRITICAL() vTaskEnterCritical() 168 169 /* Macro to mark the end of a critical code region */ 170 #define portEXIT_CRITICAL() vTaskExitCritical() 171 172 /*-----------------------------------------------------------*/ 173 /* Macros to set and clear the interrupt mask. */ 174 portLONG xPortSetInterruptMask(); 175 void vPortClearInterruptMask( portLONG ); 176 177 #define portSET_INTERRUPT_MASK() xPortSetInterruptMask() 178 #define portCLEAR_INTERRUPT_MASK( x ) vPortClearInterruptMask( ( x ) ) 179 #define portSET_INTERRUPT_MASK_FROM_ISR() xPortSetInterruptMask() 180 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vPortClearInterruptMask( ( x ) ) 181 182 /*-----------------------------------------------------------*/ 183 /* Task function macros as described on the FreeRTOS.org WEB site. */ 184 185 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) 186 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) 187 188 /*-----------------------------------------------------------*/ 189 190 #ifdef __cplusplus 191 } 192 #endif 193 #endif /* PORTMACRO_H */ 194