RTX_Conf_CM.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*----------------------------------------------------------------------------
  2. * CMSIS-RTOS - RTX
  3. *----------------------------------------------------------------------------
  4. * Name: RTX_Conf_CM.C
  5. * Purpose: Configuration of CMSIS RTX Kernel for Cortex-M
  6. * Rev.: V4.70.1
  7. *----------------------------------------------------------------------------
  8. *
  9. * Copyright (c) 1999-2009 KEIL, 2009-2016 ARM Germany GmbH. All rights reserved.
  10. *
  11. * SPDX-License-Identifier: Apache-2.0
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the License); you may
  14. * not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  21. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *---------------------------------------------------------------------------*/
  25. #include "cmsis_os.h"
  26. /*----------------------------------------------------------------------------
  27. * RTX User configuration part BEGIN
  28. *---------------------------------------------------------------------------*/
  29. //-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
  30. //
  31. // <h>Thread Configuration
  32. // =======================
  33. //
  34. // <o>Number of concurrent running user threads <1-250>
  35. // <i> Defines max. number of user threads that will run at the same time.
  36. // <i> Default: 6
  37. #ifndef OS_TASKCNT
  38. #define OS_TASKCNT 6
  39. #endif
  40. // <o>Default Thread stack size [bytes] <64-4096:8><#/4>
  41. // <i> Defines default stack size for threads with osThreadDef stacksz = 0
  42. // <i> Default: 200
  43. #ifndef OS_STKSIZE
  44. #define OS_STKSIZE 50 // this stack size value is in words
  45. #endif
  46. // <o>Main Thread stack size [bytes] <64-32768:8><#/4>
  47. // <i> Defines stack size for main thread.
  48. // <i> Default: 200
  49. #ifndef OS_MAINSTKSIZE
  50. #define OS_MAINSTKSIZE 50 // this stack size value is in words
  51. #endif
  52. // <o>Number of threads with user-provided stack size <0-250>
  53. // <i> Defines the number of threads with user-provided stack size.
  54. // <i> Default: 0
  55. #ifndef OS_PRIVCNT
  56. #define OS_PRIVCNT 0
  57. #endif
  58. // <o>Total stack size [bytes] for threads with user-provided stack size <0-1048576:8><#/4>
  59. // <i> Defines the combined stack size for threads with user-provided stack size.
  60. // <i> Default: 0
  61. #ifndef OS_PRIVSTKSIZE
  62. #define OS_PRIVSTKSIZE 0 // this stack size value is in words
  63. #endif
  64. // <q>Stack overflow checking
  65. // <i> Enable stack overflow checks at thread switch.
  66. // <i> Enabling this option increases slightly the execution time of a thread switch.
  67. #ifndef OS_STKCHECK
  68. #define OS_STKCHECK 1
  69. #endif
  70. // <q>Stack usage watermark
  71. // <i> Initialize thread stack with watermark pattern for analyzing stack usage (current/maximum) in System and Thread Viewer.
  72. // <i> Enabling this option increases significantly the execution time of osThreadCreate.
  73. #ifndef OS_STKINIT
  74. #define OS_STKINIT 0
  75. #endif
  76. // <o>Processor mode for thread execution
  77. // <0=> Unprivileged mode
  78. // <1=> Privileged mode
  79. // <i> Default: Privileged mode
  80. #ifndef OS_RUNPRIV
  81. #define OS_RUNPRIV 1
  82. #endif
  83. // </h>
  84. // <h>RTX Kernel Timer Tick Configuration
  85. // ======================================
  86. // <q> Use Cortex-M SysTick timer as RTX Kernel Timer
  87. // <i> Cortex-M processors provide in most cases a SysTick timer that can be used as
  88. // <i> as time-base for RTX.
  89. #ifndef OS_SYSTICK
  90. #define OS_SYSTICK 1
  91. #endif
  92. //
  93. // <o>RTOS Kernel Timer input clock frequency [Hz] <1-1000000000>
  94. // <i> Defines the input frequency of the RTOS Kernel Timer.
  95. // <i> When the Cortex-M SysTick timer is used, the input clock
  96. // <i> is on most systems identical with the core clock.
  97. #ifndef OS_CLOCK
  98. #define OS_CLOCK 12000000
  99. #endif
  100. // <o>RTX Timer tick interval value [us] <1-1000000>
  101. // <i> The RTX Timer tick interval value is used to calculate timeout values.
  102. // <i> When the Cortex-M SysTick timer is enabled, the value also configures the SysTick timer.
  103. // <i> Default: 1000 (1ms)
  104. #ifndef OS_TICK
  105. #define OS_TICK 1000
  106. #endif
  107. // </h>
  108. // <h>System Configuration
  109. // =======================
  110. //
  111. // <e>Round-Robin Thread switching
  112. // ===============================
  113. //
  114. // <i> Enables Round-Robin Thread switching.
  115. #ifndef OS_ROBIN
  116. #define OS_ROBIN 1
  117. #endif
  118. // <o>Round-Robin Timeout [ticks] <1-1000>
  119. // <i> Defines how long a thread will execute before a thread switch.
  120. // <i> Default: 5
  121. #ifndef OS_ROBINTOUT
  122. #define OS_ROBINTOUT 5
  123. #endif
  124. // </e>
  125. // <e>User Timers
  126. // ==============
  127. // <i> Enables user Timers
  128. #ifndef OS_TIMERS
  129. #define OS_TIMERS 1
  130. #endif
  131. // <o>Timer Thread Priority
  132. // <1=> Low
  133. // <2=> Below Normal <3=> Normal <4=> Above Normal
  134. // <5=> High
  135. // <6=> Realtime (highest)
  136. // <i> Defines priority for Timer Thread
  137. // <i> Default: High
  138. #ifndef OS_TIMERPRIO
  139. #define OS_TIMERPRIO 5
  140. #endif
  141. // <o>Timer Thread stack size [bytes] <64-4096:8><#/4>
  142. // <i> Defines stack size for Timer thread.
  143. // <i> Default: 200
  144. #ifndef OS_TIMERSTKSZ
  145. #define OS_TIMERSTKSZ 50 // this stack size value is in words
  146. #endif
  147. // <o>Timer Callback Queue size <1-32>
  148. // <i> Number of concurrent active timer callback functions.
  149. // <i> Default: 4
  150. #ifndef OS_TIMERCBQS
  151. #define OS_TIMERCBQS 4
  152. #endif
  153. // </e>
  154. // <o>ISR FIFO Queue size<4=> 4 entries <8=> 8 entries
  155. // <12=> 12 entries <16=> 16 entries
  156. // <24=> 24 entries <32=> 32 entries
  157. // <48=> 48 entries <64=> 64 entries
  158. // <96=> 96 entries
  159. // <i> ISR functions store requests to this buffer,
  160. // <i> when they are called from the interrupt handler.
  161. // <i> Default: 16 entries
  162. #ifndef OS_FIFOSZ
  163. #define OS_FIFOSZ 16
  164. #endif
  165. // </h>
  166. //------------- <<< end of configuration section >>> -----------------------
  167. // Standard library system mutexes
  168. // ===============================
  169. // Define max. number system mutexes that are used to protect
  170. // the arm standard runtime library. For microlib they are not used.
  171. #ifndef OS_MUTEXCNT
  172. #define OS_MUTEXCNT 8
  173. #endif
  174. /*----------------------------------------------------------------------------
  175. * RTX User configuration part END
  176. *---------------------------------------------------------------------------*/
  177. #define OS_TRV ((uint32_t)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
  178. /*----------------------------------------------------------------------------
  179. * Global Functions
  180. *---------------------------------------------------------------------------*/
  181. /*--------------------------- os_idle_demon ---------------------------------*/
  182. /// \brief The idle demon is running when no other thread is ready to run
  183. void os_idle_demon (void) {
  184. for (;;) {
  185. /* HERE: include optional user code to be executed when no thread runs.*/
  186. }
  187. }
  188. #if (OS_SYSTICK == 0) // Functions for alternative timer as RTX kernel timer
  189. /*--------------------------- os_tick_init ----------------------------------*/
  190. /// \brief Initializes an alternative hardware timer as RTX kernel timer
  191. /// \return IRQ number of the alternative hardware timer
  192. int os_tick_init (void) {
  193. return (-1); /* Return IRQ number of timer (0..239) */
  194. }
  195. /*--------------------------- os_tick_val -----------------------------------*/
  196. /// \brief Get alternative hardware timer's current value (0 .. OS_TRV)
  197. /// \return Current value of the alternative hardware timer
  198. uint32_t os_tick_val (void) {
  199. return (0);
  200. }
  201. /*--------------------------- os_tick_ovf -----------------------------------*/
  202. /// \brief Get alternative hardware timer's overflow flag
  203. /// \return Overflow flag\n
  204. /// - 1 : overflow
  205. /// - 0 : no overflow
  206. uint32_t os_tick_ovf (void) {
  207. return (0);
  208. }
  209. /*--------------------------- os_tick_irqack --------------------------------*/
  210. /// \brief Acknowledge alternative hardware timer interrupt
  211. void os_tick_irqack (void) {
  212. /* ... */
  213. }
  214. #endif // (OS_SYSTICK == 0)
  215. /*--------------------------- os_error --------------------------------------*/
  216. /* OS Error Codes */
  217. #define OS_ERROR_STACK_OVF 1
  218. #define OS_ERROR_FIFO_OVF 2
  219. #define OS_ERROR_MBX_OVF 3
  220. #define OS_ERROR_TIMER_OVF 4
  221. extern osThreadId svcThreadGetId (void);
  222. /// \brief Called when a runtime error is detected
  223. /// \param[in] error_code actual error code that has been detected
  224. void os_error (uint32_t error_code) {
  225. /* HERE: include optional code to be executed on runtime error. */
  226. switch (error_code) {
  227. case OS_ERROR_STACK_OVF:
  228. /* Stack overflow detected for the currently running task. */
  229. /* Thread can be identified by calling svcThreadGetId(). */
  230. break;
  231. case OS_ERROR_FIFO_OVF:
  232. /* ISR FIFO Queue buffer overflow detected. */
  233. break;
  234. case OS_ERROR_MBX_OVF:
  235. /* Mailbox overflow detected. */
  236. break;
  237. case OS_ERROR_TIMER_OVF:
  238. /* User Timer Callback Queue overflow detected. */
  239. break;
  240. default:
  241. break;
  242. }
  243. for (;;);
  244. }
  245. /*----------------------------------------------------------------------------
  246. * RTX Configuration Functions
  247. *---------------------------------------------------------------------------*/
  248. #include "RTX_CM_lib.h"
  249. /*----------------------------------------------------------------------------
  250. * end of file
  251. *---------------------------------------------------------------------------*/