1 /* 2 * FreeRTOS Kernel V10.6.2 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 30 #ifndef PORTMACRO_H 31 #define PORTMACRO_H 32 33 /* *INDENT-OFF* */ 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 /* *INDENT-ON* */ 38 39 /*----------------------------------------------------------- 40 * Port specific definitions. 41 * 42 * The settings in this file configure FreeRTOS correctly for the 43 * given hardware and compiler. 44 * 45 * These settings should not be altered. 46 *----------------------------------------------------------- 47 */ 48 49 /* IAR includes. */ 50 #include <intrinsics.h> 51 52 /* Type definitions. */ 53 #define portCHAR char 54 #define portFLOAT float 55 #define portDOUBLE double 56 #define portLONG long 57 #define portSHORT short 58 #define portSTACK_TYPE uint32_t 59 #define portBASE_TYPE long 60 61 typedef portSTACK_TYPE StackType_t; 62 typedef long BaseType_t; 63 typedef unsigned long UBaseType_t; 64 65 #if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS ) 66 typedef uint16_t TickType_t; 67 #define portMAX_DELAY ( TickType_t ) 0xffff 68 #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS ) 69 typedef uint32_t TickType_t; 70 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL 71 72 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do 73 * not need to be guarded with a critical section. */ 74 #define portTICK_TYPE_IS_ATOMIC 1 75 #else 76 #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width. 77 #endif 78 /*-----------------------------------------------------------*/ 79 80 /* Architecture specifics. */ 81 #define portSTACK_GROWTH ( -1 ) 82 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) 83 #define portBYTE_ALIGNMENT 8 84 /*-----------------------------------------------------------*/ 85 86 /* Compiler directives. */ 87 #define portWEAK_SYMBOL __attribute__( ( weak ) ) 88 89 /*-----------------------------------------------------------*/ 90 91 92 /* Scheduler utilities. */ 93 #define portYIELD() \ 94 { \ 95 /* Set a PendSV to request a context switch. */ \ 96 portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; \ 97 __DSB(); \ 98 __ISB(); \ 99 } 100 101 #define portNVIC_INT_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000ed04 ) ) 102 #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) 103 #define portEND_SWITCHING_ISR( xSwitchRequired ) do { if( xSwitchRequired != pdFALSE ) portYIELD(); } while( 0 ) 104 #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) 105 106 /*-----------------------------------------------------------*/ 107 108 /* Architecture specific optimisations. */ 109 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION 110 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 111 #endif 112 113 #if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 ) 114 115 /* Check the configuration. */ 116 #if ( configMAX_PRIORITIES > 32 ) 117 #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice. 118 #endif 119 120 /* Store/clear the ready priorities in a bit map. */ 121 #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) 122 #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) 123 124 /*-----------------------------------------------------------*/ 125 126 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( ( uint32_t ) __CLZ( ( uxReadyPriorities ) ) ) ) 127 128 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ 129 /*-----------------------------------------------------------*/ 130 131 /* Critical section management. */ 132 extern void vPortEnterCritical( void ); 133 extern void vPortExitCritical( void ); 134 135 #define portDISABLE_INTERRUPTS() \ 136 { \ 137 __set_BASEPRI( configMAX_SYSCALL_INTERRUPT_PRIORITY ); \ 138 __DSB(); \ 139 __ISB(); \ 140 } 141 142 #define portENABLE_INTERRUPTS() __set_BASEPRI( 0 ) 143 #define portENTER_CRITICAL() vPortEnterCritical() 144 #define portEXIT_CRITICAL() vPortExitCritical() 145 #define portSET_INTERRUPT_MASK_FROM_ISR() __get_BASEPRI(); portDISABLE_INTERRUPTS() 146 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) __set_BASEPRI( x ) 147 /*-----------------------------------------------------------*/ 148 149 /* Tickless idle/low power functionality. */ 150 #ifndef portSUPPRESS_TICKS_AND_SLEEP 151 extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ); 152 #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime ) 153 #endif 154 155 /*-----------------------------------------------------------*/ 156 157 /* Task function macros as described on the FreeRTOS.org WEB site. These are 158 * not necessary for to use this port. They are defined so the common demo files 159 * (which build with all the ports) will build. */ 160 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) 161 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) 162 /*-----------------------------------------------------------*/ 163 164 #ifdef configASSERT 165 void vPortValidateInterruptPriority( void ); 166 #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority() 167 #endif 168 169 /* portNOP() is not required by this port. */ 170 #define portNOP() 171 172 #define portINLINE __inline 173 174 #ifndef portFORCE_INLINE 175 #define portFORCE_INLINE inline __attribute__( ( always_inline ) ) 176 #endif 177 178 /*-----------------------------------------------------------*/ 179 xPortIsInsideInterrupt(void)180 portFORCE_INLINE static BaseType_t xPortIsInsideInterrupt( void ) 181 { 182 uint32_t ulCurrentInterrupt; 183 BaseType_t xReturn; 184 185 /* Obtain the number of the currently executing interrupt. */ 186 __asm volatile ( "mrs %0, ipsr" : "=r" ( ulCurrentInterrupt )::"memory" ); 187 188 if( ulCurrentInterrupt == 0 ) 189 { 190 xReturn = pdFALSE; 191 } 192 else 193 { 194 xReturn = pdTRUE; 195 } 196 197 return xReturn; 198 } 199 200 /*-----------------------------------------------------------*/ 201 202 /* Suppress warnings that are generated by the IAR tools, but cannot be fixed in 203 * the source code because to do so would cause other compilers to generate 204 * warnings. */ 205 #pragma diag_suppress=Pe191 206 #pragma diag_suppress=Pa082 207 208 /* *INDENT-OFF* */ 209 #ifdef __cplusplus 210 } 211 #endif 212 /* *INDENT-ON* */ 213 214 #endif /* PORTMACRO_H */ 215