Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RTX_Conf_CA.c 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*----------------------------------------------------------------------------
  2. * RL-ARM - RTX
  3. *----------------------------------------------------------------------------
  4. * Name: RTX_Conf_CM.C
  5. * Purpose: Configuration of CMSIS RTX Kernel
  6. * Rev.: V4.60
  7. *----------------------------------------------------------------------------
  8. *
  9. * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
  10. * All rights reserved.
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. * - Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * - Neither the name of ARM nor the names of its contributors may be used
  19. * to endorse or promote products derived from this software without
  20. * specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *---------------------------------------------------------------------------*/
  34. #include "cmsis_os.h"
  35. /*----------------------------------------------------------------------------
  36. * RTX User configuration part BEGIN
  37. *---------------------------------------------------------------------------*/
  38. //-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
  39. //
  40. // <h>Thread Configuration
  41. // =======================
  42. //
  43. // <o>Number of concurrent running threads <0-250>
  44. // <i> Defines max. number of threads that will run at the same time.
  45. // <i> Default: 6
  46. #ifndef OS_TASKCNT
  47. #define OS_TASKCNT 25
  48. #endif
  49. // <o>Default Thread stack size [bytes] <64-4096:8><#/4>
  50. // <i> Defines default stack size for threads with osThreadDef stacksz = 0
  51. // <i> Default: 200
  52. #ifndef OS_STKSIZE
  53. #define OS_STKSIZE 200
  54. #endif
  55. // <o>Main Thread stack size [bytes] <64-4096:8><#/4>
  56. // <i> Defines stack size for main thread.
  57. // <i> Default: 200
  58. #ifndef OS_MAINSTKSIZE
  59. #define OS_MAINSTKSIZE 2048
  60. #endif
  61. // <o>Number of threads with user-provided stack size <0-250>
  62. // <i> Defines the number of threads with user-provided stack size.
  63. // <i> Default: 0
  64. #ifndef OS_PRIVCNT
  65. #define OS_PRIVCNT 10
  66. #endif
  67. // <o>Total stack size [bytes] for threads with user-provided stack size <0-4096:8><#/4>
  68. // <i> Defines the combined stack size for threads with user-provided stack size.
  69. // <i> Default: 0
  70. #ifndef OS_PRIVSTKSIZE
  71. #define OS_PRIVSTKSIZE 8192
  72. #endif
  73. // <q>Check for stack overflow
  74. // <i> Includes the stack checking code for stack overflow.
  75. // <i> Note that additional code reduces the Kernel performance.
  76. #ifndef OS_STKCHECK
  77. #define OS_STKCHECK 1
  78. #endif
  79. // <o>Processor mode for thread execution
  80. // <0=> Unprivileged mode
  81. // <1=> Privileged mode
  82. // <i> Default: Privileged mode
  83. #ifndef OS_RUNPRIV
  84. #define OS_RUNPRIV 1
  85. #endif
  86. // </h>
  87. // <h>RTX Kernel Timer Tick Configuration
  88. // ======================================
  89. // <q> Use Cortex-M SysTick timer as RTX Kernel Timer
  90. // <i> Use the Cortex-M SysTick timer as a time-base for RTX.
  91. #ifndef OS_SYSTICK
  92. #define OS_SYSTICK 0
  93. #endif
  94. //
  95. // <o>Timer clock value [Hz] <1-1000000000>
  96. // <i> Defines the timer clock value.
  97. // <i> Default: 12000000 (12MHz)
  98. #ifndef OS_CLOCK
  99. # if defined(TARGET_RZ_A1H)
  100. #define OS_CLOCK 12000000
  101. # else
  102. # error "no target defined"
  103. # endif
  104. #endif
  105. // <o>Timer tick value [us] <1-1000000>
  106. // <i> Defines the timer tick value.
  107. // <i> Default: 1000 (1ms)
  108. #ifndef OS_TICK
  109. #define OS_TICK 1000
  110. #endif
  111. // </h>
  112. // <h>System Configuration
  113. // =======================
  114. //
  115. // <e>Round-Robin Thread switching
  116. // ===============================
  117. //
  118. // <i> Enables Round-Robin Thread switching.
  119. #ifndef OS_ROBIN
  120. #define OS_ROBIN 1
  121. #endif
  122. // <o>Round-Robin Timeout [ticks] <1-1000>
  123. // <i> Defines how long a thread will execute before a thread switch.
  124. // <i> Default: 5
  125. #ifndef OS_ROBINTOUT
  126. #define OS_ROBINTOUT 5
  127. #endif
  128. // </e>
  129. // <e>User Timers
  130. // ==============
  131. // <i> Enables user Timers
  132. #ifndef OS_TIMERS
  133. #define OS_TIMERS 1
  134. #endif
  135. // <o>Timer Thread Priority
  136. // <1=> Low
  137. // <2=> Below Normal <3=> Normal <4=> Above Normal
  138. // <5=> High
  139. // <6=> Realtime (highest)
  140. // <i> Defines priority for Timer Thread
  141. // <i> Default: High
  142. #ifndef OS_TIMERPRIO
  143. #define OS_TIMERPRIO 5
  144. #endif
  145. // <o>Timer Thread stack size [bytes] <64-4096:8><#/4>
  146. // <i> Defines stack size for Timer thread.
  147. // <i> Default: 200
  148. #ifndef OS_TIMERSTKSZ
  149. #define OS_TIMERSTKSZ WORDS_STACK_SIZE
  150. #endif
  151. // <o>Timer Callback Queue size <1-32>
  152. // <i> Number of concurrent active timer callback functions.
  153. // <i> Default: 4
  154. #ifndef OS_TIMERCBQS
  155. #define OS_TIMERCBQS 4
  156. #endif
  157. // </e>
  158. // <o>ISR FIFO Queue size<4=> 4 entries <8=> 8 entries
  159. // <12=> 12 entries <16=> 16 entries
  160. // <24=> 24 entries <32=> 32 entries
  161. // <48=> 48 entries <64=> 64 entries
  162. // <96=> 96 entries
  163. // <i> ISR functions store requests to this buffer,
  164. // <i> when they are called from the interrupt handler.
  165. // <i> Default: 16 entries
  166. #ifndef OS_FIFOSZ
  167. #define OS_FIFOSZ 16
  168. #endif
  169. // </h>
  170. //------------- <<< end of configuration section >>> -----------------------
  171. // Standard library system mutexes
  172. // ===============================
  173. // Define max. number system mutexes that are used to protect
  174. // the arm standard runtime library. For microlib they are not used.
  175. #ifndef OS_MUTEXCNT
  176. #define OS_MUTEXCNT 12
  177. #endif
  178. /*----------------------------------------------------------------------------
  179. * RTX User configuration part END
  180. *---------------------------------------------------------------------------*/
  181. #define OS_TRV ((uint32_t)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
  182. /*----------------------------------------------------------------------------
  183. * Global Functions
  184. *---------------------------------------------------------------------------*/
  185. /*--------------------------- os_idle_demon ---------------------------------*/
  186. void os_idle_demon (void) {
  187. /* The idle demon is a system thread, running when no other thread is */
  188. /* ready to run. */
  189. for (;;) {
  190. /* HERE: include optional user code to be executed when no thread runs.*/
  191. }
  192. }
  193. #if (OS_SYSTICK == 0) // Functions for alternative timer as RTX kernel timer
  194. /*--------------------------- os_tick_init ----------------------------------*/
  195. #ifdef TARGET_RZ_A1H
  196. #define OSTM0 (0xFCFEC000uL) /* OSTM0 */
  197. #define OSTM1 (0xFCFEC400uL) /* OSTM1 */
  198. #define CPG (0xFCFE0410uL) /* CPG */
  199. #define CPGSTBCR5 (*((volatile unsigned char*)(CPG + 0x00000018uL)))
  200. #define OSTM0CMP (*((volatile unsigned long*)(OSTM0 + 0x00000000uL)))
  201. #define OSTM0CNT (*((volatile unsigned long*)(OSTM0 + 0x00000004uL)))
  202. #define OSTM0TE (*((volatile unsigned char*)(OSTM0 + 0x00000010uL)))
  203. #define OSTM0TS (*((volatile unsigned char*)(OSTM0 + 0x00000014uL)))
  204. #define OSTM0TT (*((volatile unsigned char*)(OSTM0 + 0x00000018uL)))
  205. #define OSTM0CTL (*((volatile unsigned char*)(OSTM0 + 0x00000020uL)))
  206. #define OSTM1CMP (*((volatile unsigned long*)(OSTM1 + 0x00000000uL)))
  207. #define OSTM1CNT (*((volatile unsigned long*)(OSTM1 + 0x00000004uL)))
  208. #define OSTM1TE (*((volatile unsigned char*)(OSTM1 + 0x00000010uL)))
  209. #define OSTM1TS (*((volatile unsigned char*)(OSTM1 + 0x00000014uL)))
  210. #define OSTM1TT (*((volatile unsigned char*)(OSTM1 + 0x00000018uL)))
  211. #define OSTM1CTL (*((volatile unsigned char*)(OSTM1 + 0x00000020uL)))
  212. #define CPG_STBCR5_BIT_MSTP51 (0x02u) /* OSTM0 */
  213. #define CM1_RENESAS_RZ_A1_P0_CLK ( 32000000u)
  214. #define CM0_RENESAS_RZ_A1_P0_CLK ( 33333333u)
  215. typedef enum
  216. {
  217. IRQ_SGI0 = 0,
  218. IRQ_OSTMI0TINT = 134
  219. } IRQn_Type;
  220. typedef void(*IRQHandler)();
  221. extern void PendSV_Handler(uint32_t);
  222. extern void OS_Tick_Handler(uint32_t);
  223. extern uint32_t InterruptHandlerRegister (IRQn_Type irq, IRQHandler handler);
  224. #endif
  225. // Initialize alternative hardware timer as RTX kernel timer
  226. // Return: IRQ number of the alternative hardware timer
  227. int os_tick_init (void) {
  228. #ifdef TARGET_RZ_A1H
  229. CPGSTBCR5 &= ~(CPG_STBCR5_BIT_MSTP51); /* enable OSTM0 clock */
  230. OSTM0TT = 0x1; /* Stop the counter and clears the OSTM0TE bit. */
  231. OSTM0CTL = 0x1; /* Interval timer mode. Interrupt enabled */
  232. OSTM0CMP = (uint32_t)(((double)CM0_RENESAS_RZ_A1_P0_CLK*(double)OS_TICK)/1E6);
  233. OSTM0TS = 0x1; /* Start the counter and sets the OSTM0TE bit. */
  234. InterruptHandlerRegister(IRQ_SGI0 , (IRQHandler)PendSV_Handler);
  235. InterruptHandlerRegister(IRQ_OSTMI0TINT, (IRQHandler)OS_Tick_Handler);
  236. return IRQ_OSTMI0TINT; /* Return IRQ number of timer (0..239) */
  237. /* RTX will set and configure the interrupt */
  238. #endif
  239. }
  240. /*--------------------------- os_tick_irqack --------------------------------*/
  241. // Acknowledge alternative hardware timer interrupt
  242. void os_tick_irqack (void) {
  243. /* ... */
  244. }
  245. #endif // (OS_SYSTICK == 0)
  246. /*--------------------------- os_error --------------------------------------*/
  247. extern void mbed_die(void);
  248. void os_error (uint32_t err_code) {
  249. /* This function is called when a runtime error is detected. Parameter */
  250. /* 'err_code' holds the runtime error code (defined in RTL.H). */
  251. mbed_die();
  252. /* HERE: include optional code to be executed on runtime error. */
  253. for (;;);
  254. }
  255. /*----------------------------------------------------------------------------
  256. * RTX Configuration Functions
  257. *---------------------------------------------------------------------------*/
  258. #include "RTX_CM_lib.h"
  259. /*----------------------------------------------------------------------------
  260. * end of file
  261. *---------------------------------------------------------------------------*/