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 #ifdef __IAR_SYSTEMS_ICC__ 33 34 /* *INDENT-OFF* */ 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 /* *INDENT-ON* */ 39 40 /*----------------------------------------------------------- 41 * Port specific definitions. 42 * 43 * The settings in this file configure FreeRTOS correctly for the 44 * given hardware and compiler. 45 * 46 * These settings should not be altered. 47 *----------------------------------------------------------- 48 */ 49 50 #if __DATA_MODEL__ == __DATA_MODEL_FAR__ && __CODE_MODEL__ == __CODE_MODEL_NEAR__ 51 #warning This port has not been tested with your selected memory model combination. If a far data model is required it is recommended to also use a far code model. 52 #endif 53 54 #if __DATA_MODEL__ == __DATA_MODEL_NEAR__ && __CODE_MODEL__ == __CODE_MODEL_FAR__ 55 #warning This port has not been tested with your selected memory model combination. If a far code model is required it is recommended to also use a far data model. 56 #endif 57 58 /* Type definitions. */ 59 60 #define portCHAR char 61 #define portFLOAT float 62 #define portDOUBLE double 63 #define portLONG long 64 #define portSHORT short 65 #define portSTACK_TYPE uint16_t 66 #define portBASE_TYPE short 67 68 typedef portSTACK_TYPE StackType_t; 69 typedef short BaseType_t; 70 typedef unsigned short UBaseType_t; 71 72 73 #if __DATA_MODEL__ == __DATA_MODEL_FAR__ 74 #define portPOINTER_SIZE_TYPE uint32_t 75 #else 76 #define portPOINTER_SIZE_TYPE uint16_t 77 #endif 78 79 80 #if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS ) 81 typedef unsigned int TickType_t; 82 #define portMAX_DELAY ( TickType_t ) 0xffff 83 #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS ) 84 typedef uint32_t TickType_t; 85 #define portMAX_DELAY ( TickType_t ) ( 0xFFFFFFFFUL ) 86 #else 87 #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width. 88 #endif 89 /*-----------------------------------------------------------*/ 90 91 /* Interrupt control macros. */ 92 #define portDISABLE_INTERRUPTS() __asm( "DI" ) 93 #define portENABLE_INTERRUPTS() __asm( "EI" ) 94 /*-----------------------------------------------------------*/ 95 96 /* Critical section control macros. */ 97 #define portNO_CRITICAL_SECTION_NESTING ( ( uint16_t ) 0 ) 98 99 #define portENTER_CRITICAL() \ 100 { \ 101 extern volatile uint16_t usCriticalNesting; \ 102 \ 103 portDISABLE_INTERRUPTS(); \ 104 \ 105 /* Now that interrupts are disabled, ulCriticalNesting can be accessed */ \ 106 /* directly. Increment ulCriticalNesting to keep a count of how many */ \ 107 /* times portENTER_CRITICAL() has been called. */ \ 108 usCriticalNesting++; \ 109 } 110 111 #define portEXIT_CRITICAL() \ 112 { \ 113 extern volatile uint16_t usCriticalNesting; \ 114 \ 115 if( usCriticalNesting > portNO_CRITICAL_SECTION_NESTING ) \ 116 { \ 117 /* Decrement the nesting count when leaving a critical section. */ \ 118 usCriticalNesting--; \ 119 \ 120 /* If the nesting level has reached zero then interrupts should be */ \ 121 /* re-enabled. */ \ 122 if( usCriticalNesting == portNO_CRITICAL_SECTION_NESTING ) \ 123 { \ 124 portENABLE_INTERRUPTS(); \ 125 } \ 126 } \ 127 } 128 /*-----------------------------------------------------------*/ 129 130 /* Task utilities. */ 131 #define portNOP() __asm( "NOP" ) 132 #define portYIELD() __asm( "BRK" ) 133 #define portYIELD_FROM_ISR( xHigherPriorityTaskWoken ) do { if( xHigherPriorityTaskWoken ) vTaskSwitchContext( ); } while( 0 ) 134 /*-----------------------------------------------------------*/ 135 136 /* Hardware specifics. */ 137 #define portBYTE_ALIGNMENT 2 138 #define portSTACK_GROWTH ( -1 ) 139 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) 140 /*-----------------------------------------------------------*/ 141 142 /* Task function macros as described on the FreeRTOS.org WEB site. */ 143 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) 144 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) 145 146 /* *INDENT-OFF* */ 147 #ifdef __cplusplus 148 } 149 #endif 150 /* *INDENT-ON* */ 151 152 #endif /* __IAR_SYSTEMS_ICC__ */ 153 154 ; /*----------------------------------------------------------------------------- */ 155 /* The macros below are processed for asm sources which include portmacro.h. */ 156 /*----------------------------------------------------------------------------- */ 157 #ifdef __IAR_SYSTEMS_ASM__ 158 159 ; /* Functions and variables used by this file. */ 160 /*----------------------------------------------------------------------------- */ 161 EXTERN _pxCurrentTCB 162 EXTERN _usCriticalNesting 163 164 ; /* Macro used to declutter calls, depends on the selected code model. */ 165 /*----------------------------------------------------------------------------- */ 166 #if __CODE_MODEL__ == __CODE_MODEL_FAR__ 167 #define RCALL( X ) CALL F: X 168 #else 169 #define RCALL( X ) CALL X 170 #endif 171 172 173 ; /*----------------------------------------------------------------------------- 174 * ; * portSAVE_CONTEXT MACRO 175 * ; * Saves the context of the general purpose registers, CS and ES (only in __far 176 * ; * memory mode) registers the _usCriticalNesting value and the Stack Pointer 177 * ; * of the active Task onto the task stack. 178 * ; *---------------------------------------------------------------------------*/ 179 portSAVE_CONTEXT MACRO 180 PUSH AX; /* Save AX Register to stack. */ 181 PUSH HL 182 #if __CODE_MODEL__ == __CODE_MODEL_FAR__ 183 MOV A, CS; /* Save CS register. */ 184 XCH A, X 185 MOV A, ES; /* Save ES register. */ 186 PUSH AX 187 #else 188 MOV A, CS; /* Save CS register. */ 189 PUSH AX 190 #endif 191 PUSH DE; /* Save the remaining general purpose registers. */ 192 PUSH BC 193 MOVW AX, _usCriticalNesting; /* Save the _usCriticalNesting value. */ 194 PUSH AX 195 MOVW AX, _pxCurrentTCB; /* Save the Task stack pointer. */ 196 MOVW HL, AX 197 MOVW AX, SP 198 MOVW[ HL ], AX 199 ENDM 200 ; /*----------------------------------------------------------------------------- */ 201 202 203 /*----------------------------------------------------------------------------- 204 * ; * portRESTORE_CONTEXT MACRO 205 * ; * Restores the task Stack Pointer then use this to restore _usCriticalNesting, 206 * ; * general purpose registers and the CS and ES (only in __far memory mode) 207 * ; * of the selected task from the task stack. 208 * ; *---------------------------------------------------------------------------*/ 209 portRESTORE_CONTEXT MACRO 210 MOVW AX, _pxCurrentTCB; /* Restore the Task stack pointer. */ 211 MOVW HL, AX 212 MOVW AX, [ HL ] 213 MOVW SP, AX 214 POP AX; /* Restore _usCriticalNesting value. */ 215 MOVW _usCriticalNesting, AX 216 POP BC; /* Restore the necessary general purpose registers. */ 217 POP DE 218 #if __CODE_MODEL__ == __CODE_MODEL_FAR__ 219 POP AX; /* Restore the ES register. */ 220 MOV ES, A 221 XCH A, X; /* Restore the CS register. */ 222 MOV CS, A 223 #else 224 POP AX 225 MOV CS, A; /* Restore CS register. */ 226 #endif 227 POP HL; /* Restore general purpose register HL. */ 228 POP AX; /* Restore AX. */ 229 ENDM 230 ; /*----------------------------------------------------------------------------- */ 231 232 #endif /* __IAR_SYSTEMS_ASM__ */ 233 234 #endif /* PORTMACRO_H */ 235