]> begriffs open source - freertos/blob - portable/GCC/RISC-V/portmacro.h
[AUTO][RELEASE]: Bump file header version to "10.5.1"
[freertos] / portable / GCC / RISC-V / 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 \r
30 #ifndef PORTMACRO_H\r
31 #define PORTMACRO_H\r
32 \r
33 #ifdef __cplusplus\r
34 extern "C" {\r
35 #endif\r
36 \r
37 /*-----------------------------------------------------------\r
38  * Port specific definitions.\r
39  *\r
40  * The settings in this file configure FreeRTOS correctly for the\r
41  * given hardware and compiler.\r
42  *\r
43  * These settings should not be altered.\r
44  *-----------------------------------------------------------\r
45  */\r
46 \r
47 /* Type definitions. */\r
48 #if __riscv_xlen == 64\r
49     #define portSTACK_TYPE          uint64_t\r
50     #define portBASE_TYPE           int64_t\r
51     #define portUBASE_TYPE          uint64_t\r
52     #define portMAX_DELAY           ( TickType_t ) 0xffffffffffffffffUL\r
53     #define portPOINTER_SIZE_TYPE   uint64_t\r
54 #elif __riscv_xlen == 32\r
55     #define portSTACK_TYPE          uint32_t\r
56     #define portBASE_TYPE           int32_t\r
57     #define portUBASE_TYPE          uint32_t\r
58     #define portMAX_DELAY           ( TickType_t ) 0xffffffffUL\r
59 #else\r
60     #error Assembler did not define __riscv_xlen\r
61 #endif\r
62 \r
63 typedef portSTACK_TYPE StackType_t;\r
64 typedef portBASE_TYPE BaseType_t;\r
65 typedef portUBASE_TYPE UBaseType_t;\r
66 typedef portUBASE_TYPE TickType_t;\r
67 \r
68 /* Legacy type definitions. */\r
69 #define portCHAR            char\r
70 #define portFLOAT           float\r
71 #define portDOUBLE          double\r
72 #define portLONG            long\r
73 #define portSHORT           short\r
74 \r
75 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do\r
76  * not need to be guarded with a critical section. */\r
77 #define portTICK_TYPE_IS_ATOMIC 1\r
78 /*-----------------------------------------------------------*/\r
79 \r
80 /* Architecture specifics. */\r
81 #define portSTACK_GROWTH            ( -1 )\r
82 #define portTICK_PERIOD_MS          ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
83 #ifdef __riscv_32e\r
84     #define portBYTE_ALIGNMENT      8   /* RV32E uses RISC-V EABI with reduced stack alignment requirements */\r
85 #else\r
86     #define portBYTE_ALIGNMENT      16\r
87 #endif\r
88 /*-----------------------------------------------------------*/\r
89 \r
90 /* Scheduler utilities. */\r
91 extern void vTaskSwitchContext( void );\r
92 #define portYIELD() __asm volatile( "ecall" );\r
93 #define portEND_SWITCHING_ISR( xSwitchRequired ) do { if( xSwitchRequired ) vTaskSwitchContext(); } while( 0 )\r
94 #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )\r
95 /*-----------------------------------------------------------*/\r
96 \r
97 /* Critical section management. */\r
98 #define portCRITICAL_NESTING_IN_TCB                             0\r
99 \r
100 #define portSET_INTERRUPT_MASK_FROM_ISR()                       0\r
101 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue\r
102 \r
103 #define portDISABLE_INTERRUPTS()    __asm volatile( "csrc mstatus, 8" )\r
104 #define portENABLE_INTERRUPTS()     __asm volatile( "csrs mstatus, 8" )\r
105 \r
106 extern size_t xCriticalNesting;\r
107 #define portENTER_CRITICAL()            \\r
108 {                                       \\r
109     portDISABLE_INTERRUPTS();           \\r
110     xCriticalNesting++;                 \\r
111 }\r
112 \r
113 #define portEXIT_CRITICAL()             \\r
114 {                                       \\r
115     xCriticalNesting--;                 \\r
116     if( xCriticalNesting == 0 )         \\r
117     {                                   \\r
118         portENABLE_INTERRUPTS();        \\r
119     }                                   \\r
120 }\r
121 \r
122 /*-----------------------------------------------------------*/\r
123 \r
124 /* Architecture specific optimisations. */\r
125 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION\r
126     #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1\r
127 #endif\r
128 \r
129 #if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )\r
130 \r
131     /* Check the configuration. */\r
132     #if( configMAX_PRIORITIES > 32 )\r
133         #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.\r
134     #endif\r
135 \r
136     /* Store/clear the ready priorities in a bit map. */\r
137     #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
138     #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
139 \r
140     /*-----------------------------------------------------------*/\r
141 \r
142     #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - __builtin_clz( uxReadyPriorities ) )\r
143 \r
144 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
145 \r
146 \r
147 /*-----------------------------------------------------------*/\r
148 \r
149 /* Task function macros as described on the FreeRTOS.org WEB site. These are\r
150  * not necessary for to use this port.  They are defined so the common demo\r
151  * files (which build with all the ports) will build. */\r
152 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
153 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
154 \r
155 /*-----------------------------------------------------------*/\r
156 \r
157 #define portNOP()    __asm volatile( " nop " )\r
158 #define portINLINE   __inline\r
159 \r
160 #ifndef portFORCE_INLINE\r
161     #define portFORCE_INLINE inline __attribute__(( always_inline))\r
162 #endif\r
163 \r
164 #define portMEMORY_BARRIER() __asm volatile( "" ::: "memory" )\r
165 /*-----------------------------------------------------------*/\r
166 \r
167 /* configCLINT_BASE_ADDRESS is a legacy definition that was replaced by the\r
168  * configMTIME_BASE_ADDRESS and configMTIMECMP_BASE_ADDRESS definitions.  For\r
169  * backward compatibility derive the newer definitions from the old if the old\r
170  * definition is found. */\r
171 #if defined( configCLINT_BASE_ADDRESS ) && !defined( configMTIME_BASE_ADDRESS ) && ( configCLINT_BASE_ADDRESS == 0 )\r
172     /* Legacy case where configCLINT_BASE_ADDRESS was defined as 0 to indicate\r
173      * there was no CLINT.  Equivalent now is to set the MTIME and MTIMECMP\r
174      * addresses to 0. */\r
175     #define configMTIME_BASE_ADDRESS     ( 0 )\r
176     #define configMTIMECMP_BASE_ADDRESS ( 0 )\r
177 #elif defined( configCLINT_BASE_ADDRESS ) && !defined( configMTIME_BASE_ADDRESS )\r
178     /* Legacy case where configCLINT_BASE_ADDRESS was set to the base address of\r
179      * the CLINT.  Equivalent now is to derive the MTIME and MTIMECMP addresses\r
180      * from the CLINT address. */\r
181     #define configMTIME_BASE_ADDRESS     ( ( configCLINT_BASE_ADDRESS ) + 0xBFF8UL )\r
182     #define configMTIMECMP_BASE_ADDRESS ( ( configCLINT_BASE_ADDRESS ) + 0x4000UL )\r
183 #elif !defined( configMTIME_BASE_ADDRESS ) || !defined( configMTIMECMP_BASE_ADDRESS )\r
184     #error configMTIME_BASE_ADDRESS and configMTIMECMP_BASE_ADDRESS must be defined in FreeRTOSConfig.h.  Set them to zero if there is no MTIME (machine time) clock.  See https://www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html\r
185 #endif\r
186 \r
187 #ifdef __cplusplus\r
188 }\r
189 #endif\r
190 \r
191 #endif /* PORTMACRO_H */\r