2 * FreeRTOS Kernel V10.5.1
\r
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * SPDX-License-Identifier: MIT
\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
14 * The above copyright notice and this permission notice shall be included in all
\r
15 * copies or substantial portions of the Software.
\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
24 * https://www.FreeRTOS.org
\r
25 * https://github.com/FreeRTOS
\r
37 /*-----------------------------------------------------------
\r
38 * Port specific definitions.
\r
40 * The settings in this file configure FreeRTOS correctly for the
\r
41 * given hardware and compiler.
\r
43 * These settings should not be altered.
\r
44 *-----------------------------------------------------------
\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
60 #error Assembler did not define __riscv_xlen
\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
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
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
80 /* Architecture specifics. */
\r
81 #define portSTACK_GROWTH ( -1 )
\r
82 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
\r
84 #define portBYTE_ALIGNMENT 8 /* RV32E uses RISC-V EABI with reduced stack alignment requirements */
\r
86 #define portBYTE_ALIGNMENT 16
\r
88 /*-----------------------------------------------------------*/
\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
97 /* Critical section management. */
\r
98 #define portCRITICAL_NESTING_IN_TCB 0
\r
100 #define portSET_INTERRUPT_MASK_FROM_ISR() 0
\r
101 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue
\r
103 #define portDISABLE_INTERRUPTS() __asm volatile( "csrc mstatus, 8" )
\r
104 #define portENABLE_INTERRUPTS() __asm volatile( "csrs mstatus, 8" )
\r
106 extern size_t xCriticalNesting;
\r
107 #define portENTER_CRITICAL() \
\r
109 portDISABLE_INTERRUPTS(); \
\r
110 xCriticalNesting++; \
\r
113 #define portEXIT_CRITICAL() \
\r
115 xCriticalNesting--; \
\r
116 if( xCriticalNesting == 0 ) \
\r
118 portENABLE_INTERRUPTS(); \
\r
122 /*-----------------------------------------------------------*/
\r
124 /* Architecture specific optimisations. */
\r
125 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
\r
126 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
\r
129 #if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )
\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
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
140 /*-----------------------------------------------------------*/
\r
142 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - __builtin_clz( uxReadyPriorities ) )
\r
144 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
\r
147 /*-----------------------------------------------------------*/
\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
155 /*-----------------------------------------------------------*/
\r
157 #define portNOP() __asm volatile( " nop " )
\r
158 #define portINLINE __inline
\r
160 #ifndef portFORCE_INLINE
\r
161 #define portFORCE_INLINE inline __attribute__(( always_inline))
\r
164 #define portMEMORY_BARRIER() __asm volatile( "" ::: "memory" )
\r
165 /*-----------------------------------------------------------*/
\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
191 #endif /* PORTMACRO_H */
\r