]> begriffs open source - freertos/blob - portable/IAR/RL78/portmacro.h
[AUTO][RELEASE]: Bump file header version to "10.5.1"
[freertos] / portable / IAR / RL78 / portmacro.h
1 /*\r
2  * FreeRTOS Kernel V10.5.1\r
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * SPDX-License-Identifier: MIT\r
6  *\r
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
8  * this software and associated documentation files (the "Software"), to deal in\r
9  * the Software without restriction, including without limitation the rights to\r
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
11  * the Software, and to permit persons to whom the Software is furnished to do so,\r
12  * subject to the following conditions:\r
13  *\r
14  * The above copyright notice and this permission notice shall be included in all\r
15  * copies or substantial portions of the Software.\r
16  *\r
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
23  *\r
24  * https://www.FreeRTOS.org\r
25  * https://github.com/FreeRTOS\r
26  *\r
27  */\r
28 \r
29 #ifndef PORTMACRO_H\r
30 #define PORTMACRO_H\r
31 \r
32 #ifdef __IAR_SYSTEMS_ICC__\r
33 \r
34 #ifdef __cplusplus\r
35 extern "C" {\r
36 #endif\r
37 \r
38 /*-----------------------------------------------------------\r
39  * Port specific definitions.\r
40  *\r
41  * The settings in this file configure FreeRTOS correctly for the\r
42  * given hardware and compiler.\r
43  *\r
44  * These settings should not be altered.\r
45  *-----------------------------------------------------------\r
46  */\r
47 \r
48 #if __DATA_MODEL__ == __DATA_MODEL_FAR__ && __CODE_MODEL__ == __CODE_MODEL_NEAR__\r
49     #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.\r
50 #endif\r
51 \r
52 #if __DATA_MODEL__ == __DATA_MODEL_NEAR__ && __CODE_MODEL__ == __CODE_MODEL_FAR__\r
53     #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.\r
54 #endif\r
55 \r
56 /* Type definitions. */\r
57 \r
58 #define portCHAR        char\r
59 #define portFLOAT       float\r
60 #define portDOUBLE      double\r
61 #define portLONG        long\r
62 #define portSHORT       short\r
63 #define portSTACK_TYPE  uint16_t\r
64 #define portBASE_TYPE   short\r
65 \r
66 typedef portSTACK_TYPE StackType_t;\r
67 typedef short BaseType_t;\r
68 typedef unsigned short UBaseType_t;\r
69 \r
70 \r
71 #if __DATA_MODEL__ == __DATA_MODEL_FAR__\r
72     #define portPOINTER_SIZE_TYPE uint32_t\r
73 #else\r
74     #define portPOINTER_SIZE_TYPE uint16_t\r
75 #endif\r
76 \r
77 \r
78 #if ( configUSE_16_BIT_TICKS == 1 )\r
79     typedef unsigned int TickType_t;\r
80     #define portMAX_DELAY ( TickType_t ) 0xffff\r
81 #else\r
82     typedef uint32_t TickType_t;\r
83     #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\r
84 #endif\r
85 /*-----------------------------------------------------------*/\r
86 \r
87 /* Interrupt control macros. */\r
88 #define portDISABLE_INTERRUPTS()    __asm ( "DI" )\r
89 #define portENABLE_INTERRUPTS()     __asm ( "EI" )\r
90 /*-----------------------------------------------------------*/\r
91 \r
92 /* Critical section control macros. */\r
93 #define portNO_CRITICAL_SECTION_NESTING        ( ( uint16_t ) 0 )\r
94 \r
95 #define portENTER_CRITICAL()                                                   \\r
96 {                                                                              \\r
97 extern volatile uint16_t usCriticalNesting;                                    \\r
98                                                                                \\r
99     portDISABLE_INTERRUPTS();                                                  \\r
100                                                                                \\r
101     /* Now interrupts are disabled ulCriticalNesting can be accessed */        \\r
102     /* directly.  Increment ulCriticalNesting to keep a count of how many */   \\r
103     /* times portENTER_CRITICAL() has been called. */                          \\r
104     usCriticalNesting++;                                                       \\r
105 }\r
106 \r
107 #define portEXIT_CRITICAL()                                                    \\r
108 {                                                                              \\r
109 extern volatile uint16_t usCriticalNesting;                                    \\r
110                                                                                \\r
111     if( usCriticalNesting > portNO_CRITICAL_SECTION_NESTING )                  \\r
112     {                                                                          \\r
113         /* Decrement the nesting count when leaving a critical section. */     \\r
114         usCriticalNesting--;                                                   \\r
115                                                                                \\r
116         /* If the nesting level has reached zero then interrupts should be */  \\r
117         /* re-enabled. */                                                      \\r
118         if( usCriticalNesting == portNO_CRITICAL_SECTION_NESTING )             \\r
119         {                                                                      \\r
120             portENABLE_INTERRUPTS();                                           \\r
121         }                                                                      \\r
122     }                                                                          \\r
123 }\r
124 /*-----------------------------------------------------------*/\r
125 \r
126 /* Task utilities. */\r
127 #define portNOP()      __asm( "NOP" )\r
128 #define portYIELD()    __asm( "BRK" )\r
129 #define portYIELD_FROM_ISR( xHigherPriorityTaskWoken ) do { if( xHigherPriorityTaskWoken ) vTaskSwitchContext(); } while( 0 )\r
130 /*-----------------------------------------------------------*/\r
131 \r
132 /* Hardwware specifics. */\r
133 #define portBYTE_ALIGNMENT   2\r
134 #define portSTACK_GROWTH     ( -1 )\r
135 #define portTICK_PERIOD_MS   ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
136 /*-----------------------------------------------------------*/\r
137 \r
138 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
139 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
140 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
141 \r
142 #ifdef __cplusplus\r
143 }\r
144 #endif /* __cplusplus */\r
145 \r
146 #endif /* __IAR_SYSTEMS_ICC__ */\r
147 \r
148 ;//-----------------------------------------------------------------------------\r
149 ;// The macros below are processed for asm sources which include portmacro.h.\r
150 ;//-----------------------------------------------------------------------------\r
151 #ifdef __IAR_SYSTEMS_ASM__\r
152 \r
153 ;/* Functions and variables used by this file. */\r
154 ;//-----------------------------------------------------------------------------\r
155     EXTERN _pxCurrentTCB\r
156     EXTERN _usCriticalNesting\r
157 \r
158 ;/* Macro used to declutter calls, depends on the selected code model. */\r
159 ;//-----------------------------------------------------------------------------\r
160 #if __CODE_MODEL__ == __CODE_MODEL_FAR__\r
161     #define RCALL(X)    CALL    F:X\r
162 #else\r
163     #define RCALL(X)    CALL    X\r
164 #endif\r
165 \r
166 \r
167 ;/*-----------------------------------------------------------------------------\r
168 ; * portSAVE_CONTEXT MACRO\r
169 ; * Saves the context of the general purpose registers, CS and ES (only in __far\r
170 ; * memory mode) registers the _usCriticalNesting value and the Stack Pointer\r
171 ; * of the active Task onto the task stack.\r
172 ; *---------------------------------------------------------------------------*/\r
173 portSAVE_CONTEXT MACRO\r
174     PUSH      AX                       ; // Save AX Register to stack.\r
175     PUSH      HL\r
176 #if  __CODE_MODEL__  == __CODE_MODEL_FAR__\r
177     MOV       A, CS                    ; // Save CS register.\r
178     XCH       A, X\r
179     MOV       A, ES                    ; // Save ES register.\r
180     PUSH      AX\r
181 #else\r
182     MOV       A, CS                    ; // Save CS register.\r
183     PUSH      AX\r
184 #endif\r
185     PUSH      DE                       ; // Save the remaining general purpose registers.\r
186     PUSH      BC\r
187     MOVW      AX, _usCriticalNesting   ; // Save the _usCriticalNesting value.\r
188     PUSH      AX\r
189     MOVW      AX, _pxCurrentTCB        ; // Save the Task stack pointer.\r
190     MOVW      HL, AX\r
191     MOVW      AX, SP\r
192     MOVW      [HL], AX\r
193     ENDM\r
194 ;//-----------------------------------------------------------------------------\r
195 \r
196 \r
197 ;/*-----------------------------------------------------------------------------\r
198 ; * portRESTORE_CONTEXT MACRO\r
199 ; * Restores the task Stack Pointer then use this to restore _usCriticalNesting,\r
200 ; * general purpose registers and the CS and ES (only in __far memory mode)\r
201 ; * of the selected task from the task stack.\r
202 ; *---------------------------------------------------------------------------*/\r
203 portRESTORE_CONTEXT MACRO\r
204     MOVW    AX, _pxCurrentTCB          ; // Restore the Task stack pointer.\r
205     MOVW    HL, AX\r
206     MOVW    AX, [HL]\r
207     MOVW    SP, AX\r
208     POP     AX                         ; // Restore _usCriticalNesting value.\r
209     MOVW    _usCriticalNesting, AX\r
210     POP     BC                         ; // Restore the necessary general purpose registers.\r
211     POP     DE\r
212 #if __CODE_MODEL__  == __CODE_MODEL_FAR__\r
213     POP     AX                         ; // Restore the ES register.\r
214     MOV     ES, A\r
215     XCH     A, X                       ; // Restore the CS register.\r
216     MOV     CS, A\r
217 #else\r
218     POP     AX\r
219     MOV     CS, A                      ; // Restore CS register.\r
220 #endif\r
221     POP     HL                         ; // Restore general purpose register HL.\r
222     POP     AX                         ; // Restore AX.\r
223     ENDM\r
224 ;//-----------------------------------------------------------------------------\r
225 \r
226 #endif /* __IAR_SYSTEMS_ASM__ */\r
227 \r
228 #endif /* PORTMACRO_H */\r