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