portmacro.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  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. #include "intrinsics.h"
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /*-----------------------------------------------------------
  35. * Port specific definitions.
  36. *
  37. * The settings in this file configure FreeRTOS correctly for the
  38. * given hardware and compiler.
  39. *
  40. * These settings should not be altered.
  41. *-----------------------------------------------------------
  42. */
  43. /* Type definitions. */
  44. #if __riscv_xlen == 64
  45. #define portSTACK_TYPE uint64_t
  46. #define portBASE_TYPE int64_t
  47. #define portUBASE_TYPE uint64_t
  48. #define portMAX_DELAY ( TickType_t ) 0xffffffffffffffffUL
  49. #define portPOINTER_SIZE_TYPE uint64_t
  50. #elif __riscv_xlen == 32
  51. #define portSTACK_TYPE uint32_t
  52. #define portBASE_TYPE int32_t
  53. #define portUBASE_TYPE uint32_t
  54. #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
  55. #else
  56. #error Assembler did not define __riscv_xlen
  57. #endif
  58. typedef portSTACK_TYPE StackType_t;
  59. typedef portBASE_TYPE BaseType_t;
  60. typedef portUBASE_TYPE UBaseType_t;
  61. typedef portUBASE_TYPE TickType_t;
  62. /* Legacy type definitions. */
  63. #define portCHAR char
  64. #define portFLOAT float
  65. #define portDOUBLE double
  66. #define portLONG long
  67. #define portSHORT short
  68. /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
  69. not need to be guarded with a critical section. */
  70. #define portTICK_TYPE_IS_ATOMIC 1
  71. /*-----------------------------------------------------------*/
  72. /* Architecture specifics. */
  73. #define portSTACK_GROWTH ( -1 )
  74. #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
  75. #ifdef __riscv64
  76. #error This is the RV32 port that has not yet been adapted for 64.
  77. #define portBYTE_ALIGNMENT 16
  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 ) do { if( xSwitchRequired ) vTaskSwitchContext(); } while( 0 )
  86. #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
  87. /*-----------------------------------------------------------*/
  88. /* Critical section management. */
  89. #define portCRITICAL_NESTING_IN_TCB 1
  90. extern void vTaskEnterCritical( void );
  91. extern void vTaskExitCritical( void );
  92. #define portSET_INTERRUPT_MASK_FROM_ISR() 0
  93. #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue
  94. #define portDISABLE_INTERRUPTS() __disable_interrupt()
  95. #define portENABLE_INTERRUPTS() __enable_interrupt()
  96. #define portENTER_CRITICAL() vTaskEnterCritical()
  97. #define portEXIT_CRITICAL() vTaskExitCritical()
  98. /*-----------------------------------------------------------*/
  99. /* Architecture specific optimisations. */
  100. #if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )
  101. #error configUSE_PORT_OPTIMISED_TASK_SELECTION cannot yet be used in the IAR RISC-V port, the CLZ instruction needs to be emulated.
  102. #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
  103. /*-----------------------------------------------------------*/
  104. /* Task function macros as described on the FreeRTOS.org WEB site. These are
  105. not necessary for to use this port. They are defined so the common demo files
  106. (which build with all the ports) will build. */
  107. #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
  108. #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
  109. /*-----------------------------------------------------------*/
  110. #define portNOP() __asm volatile ( " nop " )
  111. #define portINLINE __inline
  112. #ifndef portFORCE_INLINE
  113. #define portFORCE_INLINE inline __attribute__(( always_inline))
  114. #endif
  115. #define portMEMORY_BARRIER() __asm volatile( "" ::: "memory" )
  116. /* Suppress warnings that are generated by the IAR tools, but cannot be fixed in
  117. the source code because to do so would cause other compilers to generate
  118. warnings. */
  119. #pragma diag_suppress=Pa082
  120. /* configCLINT_BASE_ADDRESS is a legacy definition that was replaced by the
  121. configMTIME_BASE_ADDRESS and configMTIMECMP_BASE_ADDRESS definitions. For
  122. backward compatibility derive the newer definitions from the old if the old
  123. definition is found. */
  124. #if defined( configCLINT_BASE_ADDRESS ) && !defined( configMTIME_BASE_ADDRESS ) && ( configCLINT_BASE_ADDRESS == 0 )
  125. /* Legacy case where configCLINT_BASE_ADDRESS was defined as 0 to indicate
  126. there was no CLINT. Equivalent now is to set the MTIME and MTIMECMP
  127. addresses to 0. */
  128. #define configMTIME_BASE_ADDRESS ( 0 )
  129. #define configMTIMECMP_BASE_ADDRESS ( 0 )
  130. #elif defined( configCLINT_BASE_ADDRESS ) && !defined( configMTIME_BASE_ADDRESS )
  131. /* Legacy case where configCLINT_BASE_ADDRESS was set to the base address of
  132. the CLINT. Equivalent now is to derive the MTIME and MTIMECMP addresses
  133. from the CLINT address. */
  134. #define configMTIME_BASE_ADDRESS ( ( configCLINT_BASE_ADDRESS ) + 0xBFF8UL )
  135. #define configMTIMECMP_BASE_ADDRESS ( ( configCLINT_BASE_ADDRESS ) + 0x4000UL )
  136. #elif !defined( configMTIME_BASE_ADDRESS ) || !defined( configMTIMECMP_BASE_ADDRESS )
  137. #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
  138. #endif
  139. #ifdef __cplusplus
  140. }
  141. #endif
  142. #endif /* PORTMACRO_H */