os_cpu_c.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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_c.c
  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.
  28. *********************************************************************************************************
  29. */
  30. #define OS_CPU_GLOBALS
  31. /*
  32. *********************************************************************************************************
  33. * INCLUDE FILES
  34. *********************************************************************************************************
  35. */
  36. #include <ucos_ii.h>
  37. /*
  38. *********************************************************************************************************
  39. * LOCAL VARIABLES
  40. *********************************************************************************************************
  41. */
  42. #if OS_TMR_EN > 0u
  43. static INT16U OSTmrCtr;
  44. #endif
  45. /*
  46. *********************************************************************************************************
  47. * OS INITIALIZATION HOOK
  48. * (BEGINNING)
  49. *
  50. * Description: This function is called by OSInit() at the beginning of OSInit().
  51. *
  52. * Arguments : none
  53. *
  54. * Note(s) : 1) Interrupts should be disabled during this call.
  55. *********************************************************************************************************
  56. */
  57. #if OS_CPU_HOOKS_EN > 0u
  58. void OSInitHookBegin(void)
  59. {
  60. #if OS_TMR_EN > 0u
  61. OSTmrCtr = 0u;
  62. #endif
  63. }
  64. #endif
  65. /*
  66. *********************************************************************************************************
  67. * OS INITIALIZATION HOOK
  68. * (END)
  69. *
  70. * Description: This function is called by OSInit() at the end of OSInit().
  71. *
  72. * Arguments : none
  73. *
  74. * Note(s) : 1) Interrupts should be disabled during this call.
  75. *********************************************************************************************************
  76. */
  77. #if OS_CPU_HOOKS_EN > 0u
  78. void OSInitHookEnd(void)
  79. {
  80. }
  81. #endif
  82. /*
  83. *********************************************************************************************************
  84. * TASK CREATION HOOK
  85. *
  86. * Description: This function is called when a task is created.
  87. *
  88. * Arguments : ptcb is a pointer to the task control block of the task being created.
  89. *
  90. * Note(s) : 1) Interrupts are disabled during this call.
  91. *********************************************************************************************************
  92. */
  93. #if OS_CPU_HOOKS_EN > 0u
  94. void OSTaskCreateHook(OS_TCB* p_tcb)
  95. {
  96. #if OS_APP_HOOKS_EN > 0u
  97. App_TaskCreateHook(p_tcb);
  98. #else
  99. (void)ptcb; /* Prevent compiler warning */
  100. #endif
  101. }
  102. #endif
  103. /*
  104. *********************************************************************************************************
  105. * TASK DELETION HOOK
  106. *
  107. * Description: This function is called when a task is deleted.
  108. *
  109. * Arguments : ptcb is a pointer to the task control block of the task being deleted.
  110. *
  111. * Note(s) : 1) Interrupts are disabled during this call.
  112. *********************************************************************************************************
  113. */
  114. #if OS_CPU_HOOKS_EN > 0u
  115. void OSTaskDelHook(OS_TCB* p_tcb)
  116. {
  117. #if OS_APP_HOOKS_EN > 0u
  118. App_TaskDelHook(p_tcb);
  119. #else
  120. (void)ptcb; /* Prevent compiler warning */
  121. #endif
  122. }
  123. #endif
  124. /*
  125. *********************************************************************************************************
  126. * IDLE TASK HOOK
  127. *
  128. * Description: This function is called by the idle task. This hook has been added to allow you to do
  129. * such things as STOP the CPU to conserve power.
  130. *
  131. * Arguments : none
  132. *
  133. * Note(s) : 1) Interrupts are enabled during this call.
  134. *********************************************************************************************************
  135. */
  136. #if OS_CPU_HOOKS_EN > 0u
  137. void OSTaskIdleHook(void)
  138. {
  139. #if OS_APP_HOOKS_EN > 0u
  140. App_TaskIdleHook();
  141. #endif
  142. }
  143. #endif
  144. /*
  145. *********************************************************************************************************
  146. * TASK RETURN HOOK
  147. *
  148. * Description: This function is called if a task accidentally returns. In other words, a task should
  149. * either be an infinite loop or delete itself when done.
  150. *
  151. * Arguments : ptcb is a pointer to the task control block of the task that is returning.
  152. *
  153. * Note(s) : none
  154. *********************************************************************************************************
  155. */
  156. #if OS_CPU_HOOKS_EN > 0u
  157. void OSTaskReturnHook(OS_TCB* p_tcb)
  158. {
  159. #if OS_APP_HOOKS_EN > 0u
  160. App_TaskReturnHook(p_tcb);
  161. #else
  162. (void)ptcb;
  163. #endif
  164. }
  165. #endif
  166. /*
  167. *********************************************************************************************************
  168. * STATISTIC TASK HOOK
  169. *
  170. * Description: This function is called every second by uC/OS-II's statistics task. This allows your
  171. * application to add functionality to the statistics task.
  172. *
  173. * Arguments : none
  174. *********************************************************************************************************
  175. */
  176. #if OS_CPU_HOOKS_EN > 0u
  177. void OSTaskStatHook(void)
  178. {
  179. #if OS_APP_HOOKS_EN > 0u
  180. App_TaskStatHook();
  181. #endif
  182. }
  183. #endif
  184. /*
  185. *********************************************************************************************************
  186. * INITIALIZE A TASK'S STACK
  187. * This OSTaskStkInit function is implemented in os_cpu_port.c portable source file
  188. *
  189. *********************************************************************************************************
  190. */
  191. /*
  192. *********************************************************************************************************
  193. * TASK SWITCH HOOK
  194. *
  195. * Description: This function is called when a task switch is performed. This allows you to perform other
  196. * operations during a context switch.
  197. *
  198. * Arguments : none
  199. *
  200. * Note(s) : 1) Interrupts are disabled during this call.
  201. * 2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
  202. * will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
  203. * task being switched out (i.e. the preempted task).
  204. *********************************************************************************************************
  205. */
  206. #if (OS_CPU_HOOKS_EN > 0u) && (OS_TASK_SW_HOOK_EN > 0u)
  207. void OSTaskSwHook(void)
  208. {
  209. #if OS_APP_HOOKS_EN > 0u
  210. App_TaskSwHook();
  211. #endif
  212. OS_TRACE_TASK_SWITCHED_IN(OSTCBHighRdy);
  213. }
  214. #endif
  215. /*
  216. *********************************************************************************************************
  217. * OS_TCBInit() HOOK
  218. *
  219. * Description: This function is called by OS_TCBInit() after setting up most of the TCB.
  220. *
  221. * Arguments : ptcb is a pointer to the TCB of the task being created.
  222. *
  223. * Note(s) : 1) Interrupts may or may not be ENABLED during this call.
  224. *********************************************************************************************************
  225. */
  226. #if OS_CPU_HOOKS_EN > 0u
  227. void OSTCBInitHook(OS_TCB* p_tcb)
  228. {
  229. #if OS_APP_HOOKS_EN > 0u
  230. App_TCBInitHook(p_tcb);
  231. #else
  232. (void)ptcb; /* Prevent compiler warning */
  233. #endif
  234. }
  235. #endif
  236. /*
  237. *********************************************************************************************************
  238. * TICK HOOK
  239. *
  240. * Description: This function is called every tick.
  241. *
  242. * Arguments : none
  243. *
  244. * Note(s) : 1) Interrupts may or may not be ENABLED during this call.
  245. *********************************************************************************************************
  246. */
  247. #if (OS_CPU_HOOKS_EN > 0u) && (OS_TIME_TICK_HOOK_EN > 0u)
  248. void OSTimeTickHook(void)
  249. {
  250. #if OS_APP_HOOKS_EN > 0u
  251. App_TimeTickHook();
  252. #endif
  253. #if OS_TMR_EN > 0u
  254. OSTmrCtr++;
  255. if (OSTmrCtr >= (OS_TICKS_PER_SEC / OS_TMR_CFG_TICKS_PER_SEC)) {
  256. OSTmrCtr = 0u;
  257. OSTmrSignal();
  258. }
  259. #endif
  260. }
  261. #endif
  262. /*
  263. *********************************************************************************************************
  264. * SYS TICK HANDLER
  265. * This Systick handler function is implemented in os_cpu_port.c portable source file
  266. * See xPortSysTickHandler in os_cpu_port.c
  267. *
  268. *********************************************************************************************************
  269. */