portmacro.h 8.7 KB

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