2 * FreeRTOS Kernel V11.0.1
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
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:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
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.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
32 #ifdef __IAR_SYSTEMS_ICC__
40 /*-----------------------------------------------------------
41 * Port specific definitions.
43 * The settings in this file configure FreeRTOS correctly for the
44 * given hardware and compiler.
46 * These settings should not be altered.
47 *-----------------------------------------------------------
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.
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.
58 /* Type definitions. */
61 #define portFLOAT float
62 #define portDOUBLE double
64 #define portSHORT short
65 #define portSTACK_TYPE uint16_t
66 #define portBASE_TYPE short
68 typedef portSTACK_TYPE StackType_t;
69 typedef short BaseType_t;
70 typedef unsigned short UBaseType_t;
73 #if __DATA_MODEL__ == __DATA_MODEL_FAR__
74 #define portPOINTER_SIZE_TYPE uint32_t
76 #define portPOINTER_SIZE_TYPE uint16_t
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 )
87 #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
89 /*-----------------------------------------------------------*/
91 /* Interrupt control macros. */
92 #define portDISABLE_INTERRUPTS() __asm( "DI" )
93 #define portENABLE_INTERRUPTS() __asm( "EI" )
94 /*-----------------------------------------------------------*/
96 /* Critical section control macros. */
97 #define portNO_CRITICAL_SECTION_NESTING ( ( uint16_t ) 0 )
99 #define portENTER_CRITICAL() \
101 extern volatile uint16_t usCriticalNesting; \
103 portDISABLE_INTERRUPTS(); \
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++; \
111 #define portEXIT_CRITICAL() \
113 extern volatile uint16_t usCriticalNesting; \
115 if( usCriticalNesting > portNO_CRITICAL_SECTION_NESTING ) \
117 /* Decrement the nesting count when leaving a critical section. */ \
118 usCriticalNesting--; \
120 /* If the nesting level has reached zero then interrupts should be */ \
122 if( usCriticalNesting == portNO_CRITICAL_SECTION_NESTING ) \
124 portENABLE_INTERRUPTS(); \
128 /*-----------------------------------------------------------*/
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 /*-----------------------------------------------------------*/
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 /*-----------------------------------------------------------*/
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 )
152 #endif /* __IAR_SYSTEMS_ICC__ */
154 ; /*----------------------------------------------------------------------------- */
155 /* The macros below are processed for asm sources which include portmacro.h. */
156 /*----------------------------------------------------------------------------- */
157 #ifdef __IAR_SYSTEMS_ASM__
159 ; /* Functions and variables used by this file. */
160 /*----------------------------------------------------------------------------- */
162 EXTERN _usCriticalNesting
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
169 #define RCALL( X ) CALL X
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. */
182 #if __CODE_MODEL__ == __CODE_MODEL_FAR__
183 MOV A, CS; /* Save CS register. */
185 MOV A, ES; /* Save ES register. */
188 MOV A, CS; /* Save CS register. */
191 PUSH DE; /* Save the remaining general purpose registers. */
193 MOVW AX, _usCriticalNesting; /* Save the _usCriticalNesting value. */
195 MOVW AX, _pxCurrentTCB; /* Save the Task stack pointer. */
200 ; /*----------------------------------------------------------------------------- */
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. */
214 POP AX; /* Restore _usCriticalNesting value. */
215 MOVW _usCriticalNesting, AX
216 POP BC; /* Restore the necessary general purpose registers. */
218 #if __CODE_MODEL__ == __CODE_MODEL_FAR__
219 POP AX; /* Restore the ES register. */
221 XCH A, X; /* Restore the CS register. */
225 MOV CS, A; /* Restore CS register. */
227 POP HL; /* Restore general purpose register HL. */
228 POP AX; /* Restore AX. */
230 ; /*----------------------------------------------------------------------------- */
232 #endif /* __IAR_SYSTEMS_ASM__ */
234 #endif /* PORTMACRO_H */