os_cpu.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. *********************************************************************************************************
  3. * uC/OS-II
  4. * The Real-Time Kernel
  5. *
  6. * Copyright 1992-2020 Silicon Laboratories Inc. www.silabs.com
  7. *
  8. * SPDX-License-Identifier: APACHE-2.0
  9. *
  10. * This software is subject to an open source license and is distributed by
  11. * Silicon Laboratories Inc. pursuant to the terms of the Apache License,
  12. * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
  13. *
  14. *********************************************************************************************************
  15. */
  16. /*
  17. *********************************************************************************************************
  18. *
  19. * RISC-V Port
  20. *
  21. * Filename : os_cpu.h
  22. * Version : V2.93.00
  23. *********************************************************************************************************
  24. * For : Nuclei RISC-V RV32 and RV64
  25. * Toolchain : GNU C Compiler
  26. *********************************************************************************************************
  27. * Note(s) : Hardware FP is not supported, Modified by Nuclei to support Nuclei RISC-V Cores.
  28. *********************************************************************************************************
  29. */
  30. #ifndef OS_CPU_H
  31. #define OS_CPU_H
  32. #ifdef OS_CPU_GLOBALS
  33. #define OS_CPU_EXT
  34. #else
  35. #define OS_CPU_EXT extern
  36. #endif
  37. #include <stdint.h>
  38. #include "os_cpu_port.h"
  39. /*
  40. *********************************************************************************************************
  41. * EXTERNAL C LANGUAGE LINKAGE
  42. *
  43. * Note(s) : (1) C++ compilers MUST 'extern'ally declare ALL C function prototypes & variable/object
  44. * declarations for correct C language linkage.
  45. *********************************************************************************************************
  46. */
  47. #ifdef __cplusplus
  48. extern "C" { /* See Note #1. */
  49. #endif
  50. /*
  51. *********************************************************************************************************
  52. * DEFINES
  53. *********************************************************************************************************
  54. */
  55. /*
  56. *********************************************************************************************************
  57. * DATA TYPES
  58. * (Compiler Specific)
  59. *********************************************************************************************************
  60. */
  61. typedef unsigned char BOOLEAN; /* Unsigned 8 bit boolean or logical */
  62. typedef unsigned char INT8U; /* Unsigned 8 bit quantity */
  63. typedef signed char INT8S; /* Signed 8 bit quantity */
  64. typedef unsigned short INT16U; /* Unsigned 16 bit quantity */
  65. typedef signed short INT16S; /* Signed 16 bit quantity */
  66. typedef unsigned int INT32U; /* Unsigned 32 bit quantity */
  67. typedef signed int INT32S; /* Signed 32 bit quantity */
  68. typedef unsigned long long INT64U; /* 64-bit unsigned integer */
  69. typedef signed long long INT64S; /* 64-bit signed integer */
  70. typedef float FP32; /* Single precision floating point */
  71. typedef double FP64; /* Double precision floating point */
  72. #if __riscv_xlen == 64
  73. typedef uint64_t OS_STK; /* Each stack entry is 64-bit wide */
  74. typedef uint64_t OS_CPU_SR; /* Define size of Machine status register (64 bits) */
  75. #else
  76. typedef uint32_t OS_STK; /* Each stack entry is 32-bit wide */
  77. typedef uint32_t OS_CPU_SR; /* Define size of Machine status register (32 bits) */
  78. #endif
  79. /*
  80. *********************************************************************************************************
  81. * RISC-V
  82. * Critical Section Management
  83. *
  84. * Method #1: Disable/Enable interrupts using simple instructions. After critical section, interrupts
  85. * will be enabled even if they were disabled before entering the critical section.
  86. * NOT IMPLEMENTED
  87. *
  88. * Method #2: Disable/Enable interrupts by preserving the state of interrupts. In other words, if
  89. * interrupts were disabled before entering the critical section, they will be disabled when
  90. * leaving the critical section.
  91. * NOT IMPLEMENTED
  92. *
  93. * Method #3: Disable/Enable interrupts by preserving the state of interrupts. Generally speaking you
  94. * would store the state of the interrupt disable flag in the local variable 'cpu_sr' and then
  95. * disable interrupts. 'cpu_sr' is allocated in all of uC/OS-II's functions that need to
  96. * disable interrupts. You would restore the interrupt disable state by copying back 'cpu_sr'
  97. * into the CPU's status register.
  98. *********************************************************************************************************
  99. */
  100. #define OS_CRITICAL_METHOD 3u
  101. #if OS_CRITICAL_METHOD == 3u
  102. #define OS_ENTER_CRITICAL() do { cpu_sr = OS_CPU_SR_Save();} while (0)
  103. #define OS_EXIT_CRITICAL() do { OS_CPU_SR_Restore(cpu_sr);} while (0)
  104. #else
  105. #define OS_ENTER_CRITICAL() portENTER_CRITICAL()
  106. #define OS_EXIT_CRITICAL() portEXIT_CRITICAL()
  107. #endif
  108. /*
  109. *********************************************************************************************************
  110. * RISC-V Miscellaneous
  111. *********************************************************************************************************
  112. */
  113. #define OS_STK_GROWTH 1u /* Stack grows from HIGH to LOW memory */
  114. #define OS_TASK_SW() portYIELD()
  115. #define OSIntCtxSw() portYIELD()
  116. #ifndef OS_TICKS_PER_SEC
  117. #warning "Use default OS_TICKS_PER_SEC=100"
  118. #define OS_TICKS_PER_SEC 100
  119. #endif
  120. #ifndef configTICK_RATE_HZ
  121. #define configTICK_RATE_HZ OS_TICKS_PER_SEC
  122. #endif
  123. /*
  124. *********************************************************************************************************
  125. * FUNCTION PROTOTYPES
  126. *********************************************************************************************************
  127. */
  128. #if OS_CRITICAL_METHOD == 3u /* See os_cpu_a.S */
  129. portFORCE_INLINE OS_CPU_SR OS_CPU_SR_Save(void)
  130. {
  131. return __RV_CSR_READ_CLEAR(CSR_MSTATUS, MSTATUS_MIE);
  132. }
  133. portFORCE_INLINE void OS_CPU_SR_Restore(OS_CPU_SR cpu_sr)
  134. {
  135. __RV_CSR_WRITE(CSR_MSTATUS, cpu_sr);
  136. }
  137. #endif
  138. void OSCtxSw(void);
  139. void OSStartHighRdy(void);
  140. /*
  141. *********************************************************************************************************
  142. * EXTERNAL C LANGUAGE LINKAGE END
  143. *********************************************************************************************************
  144. */
  145. #ifdef __cplusplus
  146. } /* End of 'extern'al C lang linkage. */
  147. #endif
  148. /*
  149. *********************************************************************************************************
  150. * MODULE END
  151. *********************************************************************************************************
  152. */
  153. #endif