]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[qmk_firmware.git] / tmk_core / tool / mbed / mbed-sdk / libraries / rtos / rtx / TARGET_CORTEX_M / RTX_Conf_CM.c
1 /*----------------------------------------------------------------------------
2  *      RL-ARM - RTX
3  *----------------------------------------------------------------------------
4  *      Name:    RTX_Conf_CM.C
5  *      Purpose: Configuration of CMSIS RTX Kernel for Cortex-M
6  *      Rev.:    V4.60
7  *----------------------------------------------------------------------------
8  *
9  * Copyright (c) 1999-2009 KEIL, 2009-2012 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
35 #include "cmsis_os.h"
36
37
38 /*----------------------------------------------------------------------------
39  *      RTX User configuration part BEGIN
40  *---------------------------------------------------------------------------*/
41
42 //-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
43 //
44 // <h>Thread Configuration
45 // =======================
46 //
47 //   <o>Number of concurrent running threads <0-250>
48 //   <i> Defines max. number of threads that will run at the same time.
49 //       counting "main", but not counting "osTimerThread"
50 //   <i> Default: 6
51 #ifndef OS_TASKCNT
52 #  if   defined(TARGET_LPC1768) || defined(TARGET_LPC2368)   || defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) || defined(TARGET_LPC4330) || defined(TARGET_LPC4337) || defined(TARGET_LPC1347) || defined(TARGET_K64F) || defined(TARGET_STM32F401RE)\
53    || defined(TARGET_KL46Z) || defined(TARGET_KL43Z)  || defined(TARGET_STM32F407) || defined(TARGET_F407VG)  || defined(TARGET_STM32F303VC) || defined(TARGET_LPC1549) || defined(TARGET_LPC11U68) \
54    || defined(TARGET_STM32F411RE) || defined(TARGET_STM32F405RG) || defined(TARGET_K22F) || defined(TARGET_STM32F429ZI) || defined(TARGET_STM32F401VC) || defined(TARGET_MAX32610) || defined(TARGET_MAX32600) || defined(TARGET_TEENSY3_1)
55 #    define OS_TASKCNT         14
56 #  elif defined(TARGET_LPC11U24) || defined(TARGET_STM32F303RE) || defined(TARGET_LPC11U35_401)  || defined(TARGET_LPC11U35_501) || defined(TARGET_LPCCAPPUCCINO) || defined(TARGET_LPC1114) \
57    || defined(TARGET_LPC812)   || defined(TARGET_KL25Z)         || defined(TARGET_KL05Z)        || defined(TARGET_STM32F100RB)  || defined(TARGET_STM32F051R8) \
58    || defined(TARGET_STM32F103RB) || defined(TARGET_LPC824) || defined(TARGET_STM32F302R8) || defined(TARGET_STM32F334R8) || defined(TARGET_STM32F334C8) \
59    || defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8) || defined(TARGET_STM32F072RB) || defined(TARGET_STM32F091RC)
60 #    define OS_TASKCNT         6
61 #  else
62 #    error "no target defined"
63 #  endif
64 #endif
65
66 //   <o>Scheduler (+ interrupts) stack size [bytes] <64-4096:8><#/4>
67 #ifndef OS_SCHEDULERSTKSIZE
68 #  if   defined(TARGET_LPC1768) || defined(TARGET_LPC2368)   || defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) || defined(TARGET_LPC4330) || defined(TARGET_LPC4337) || defined(TARGET_LPC1347)  || defined(TARGET_K64F) || defined(TARGET_STM32F401RE)\
69    || defined(TARGET_KL46Z) || defined(TARGET_KL43Z) || defined(TARGET_STM32F407) || defined(TARGET_F407VG)  || defined(TARGET_STM32F303VC) || defined(TARGET_LPC1549) || defined(TARGET_LPC11U68) \
70    || defined(TARGET_STM32F411RE) || defined(TARGET_STM32F405RG) || defined(TARGET_K22F) || defined(TARGET_STM32F429ZI) || defined(TARGET_STM32F401VC) || defined(TARGET_MAX32610) || defined(TARGET_MAX32600) || defined(TARGET_TEENSY3_1)
71 #      define OS_SCHEDULERSTKSIZE    256
72 #  elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401)  || defined(TARGET_LPC11U35_501) || defined(TARGET_LPCCAPPUCCINO)  || defined(TARGET_LPC1114) \
73    || defined(TARGET_LPC812)   || defined(TARGET_KL25Z)         || defined(TARGET_KL05Z)        || defined(TARGET_STM32F100RB)  || defined(TARGET_STM32F051R8) \
74    || defined(TARGET_STM32F103RB) || defined(TARGET_LPC824) || defined(TARGET_STM32F302R8) || defined(TARGET_STM32F072RB) || defined(TARGET_STM32F091RC)
75 #      define OS_SCHEDULERSTKSIZE    128
76 #  elif defined(TARGET_STM32F334R8) || defined(TARGET_STM32F303RE) ||  defined(TARGET_STM32F334C8) || defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
77 #      define OS_SCHEDULERSTKSIZE    112
78 #  else
79 #    error "no target defined"
80 #  endif
81 #endif
82
83 //   <o>Idle stack size [bytes] <64-4096:8><#/4>
84 //   <i> Defines default stack size for the Idle thread.
85 #ifndef OS_IDLESTKSIZE
86  #define OS_IDLESTKSIZE         128
87 #endif
88
89 //   <o>Timer Thread stack size [bytes] <64-4096:8><#/4>
90 //   <i> Defines stack size for Timer thread.
91 //   <i> Default: 200
92 #ifndef OS_TIMERSTKSZ
93  #define OS_TIMERSTKSZ  WORDS_STACK_SIZE
94 #endif
95
96 // <q>Check for stack overflow
97 // <i> Includes the stack checking code for stack overflow.
98 // <i> Note that additional code reduces the Kernel performance.
99 #ifndef OS_STKCHECK
100  #define OS_STKCHECK    1
101 #endif
102
103 // <o>Processor mode for thread execution
104 //   <0=> Unprivileged mode
105 //   <1=> Privileged mode
106 // <i> Default: Privileged mode
107 #ifndef OS_RUNPRIV
108  #define OS_RUNPRIV     1
109 #endif
110
111 // </h>
112 // <h>SysTick Timer Configuration
113 // ==============================
114 //
115 //   <o>Timer clock value [Hz] <1-1000000000>
116 //   <i> Defines the timer clock value.
117 //   <i> Default: 6000000  (6MHz)
118 #ifndef OS_CLOCK
119 #  if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
120 #    define OS_CLOCK       96000000
121
122 #  elif defined(TARGET_LPC1347) || defined(TARGET_STM32F303VC) || defined(TARGET_LPC1549) || defined(TARGET_STM32F334R8) || defined(TARGET_STM32F334C8) || defined(TARGET_STM32F303RE) || defined(TARGET_TEENSY3_1)
123 #    define OS_CLOCK       72000000
124
125 #  elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401)  || defined(TARGET_LPC11U35_501) || defined(TARGET_LPCCAPPUCCINO)  || defined(TARGET_LPC1114) || defined(TARGET_KL25Z) \
126      || defined(TARGET_KL05Z) || defined(TARGET_KL46Z) || defined(TARGET_KL43Z) || defined(TARGET_STM32F051R8) || defined(TARGET_LPC11U68) || defined(TARGET_STM32F072RB) || defined(TARGET_STM32F091RC)
127 #    define OS_CLOCK       48000000
128
129 #  elif defined(TARGET_LPC812)
130 #    define OS_CLOCK       36000000
131
132 #  elif defined(TARGET_LPC824)
133 #    define OS_CLOCK       30000000
134
135 #  elif  defined(TARGET_STM32F100RB)
136 #    define OS_CLOCK       24000000
137
138 #  elif defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) || defined(TARGET_K64F) || defined(TARGET_K22F)
139 #    define OS_CLOCK       120000000
140
141 #  elif defined(TARGET_LPC4330)
142 #    define OS_CLOCK       204000000
143
144 #  elif defined(TARGET_LPC4337)
145 #    define OS_CLOCK       204000000
146
147 #  elif defined(TARGET_STM32F407) || defined(TARGET_F407VG)
148 #    define OS_CLOCK       168000000
149
150 #  elif defined(TARGET_STM32F401RE)
151 #    define OS_CLOCK       84000000
152
153 #  elif defined(TARGET_STM32F411RE)
154 #     define OS_CLOCK      100000000
155
156 #elif defined(TARGET_STM32F103RB) 
157 #    define OS_CLOCK       72000000
158
159 #elif defined(TARGET_STM32F429ZI)
160 #    define OS_CLOCK       168000000
161
162 #elif defined(TARGET_STM32F302R8)
163 #    define OS_CLOCK       64000000
164
165 #elif defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
166 #    define OS_CLOCK       32000000
167
168 #elif defined(TARGET_STM32F401VC)
169 #    define OS_CLOCK       84000000
170
171 #elif defined(TARGET_MAX32610) || defined(TARGET_MAX32600)
172 #    define OS_CLOCK       24000000
173
174 #  else
175 #    error "no target defined"
176 #  endif
177 #endif
178
179 //   <o>Timer tick value [us] <1-1000000>
180 //   <i> Defines the timer tick value.
181 //   <i> Default: 1000  (1ms)
182 #ifndef OS_TICK
183  #define OS_TICK        1000
184 #endif
185
186 // </h>
187
188 // <h>System Configuration
189 // =======================
190 //
191 // <e>Round-Robin Thread switching
192 // ===============================
193 //
194 // <i> Enables Round-Robin Thread switching.
195 #ifndef OS_ROBIN
196  #define OS_ROBIN       1
197 #endif
198
199 //   <o>Round-Robin Timeout [ticks] <1-1000>
200 //   <i> Defines how long a thread will execute before a thread switch.
201 //   <i> Default: 5
202 #ifndef OS_ROBINTOUT
203  #define OS_ROBINTOUT   5
204 #endif
205
206 // </e>
207
208 // <e>User Timers
209 // ==============
210 //   <i> Enables user Timers
211 #ifndef OS_TIMERS
212  #define OS_TIMERS      1
213 #endif
214
215 //   <o>Timer Thread Priority
216 //                        <1=> Low
217 //                        <2=> Below Normal
218 //                        <3=> Normal
219 //                        <4=> Above Normal
220 //                        <5=> High
221 //                        <6=> Realtime (highest)
222 //   <i> Defines priority for Timer Thread
223 //   <i> Default: High
224 #ifndef OS_TIMERPRIO
225  #define OS_TIMERPRIO   5
226 #endif
227
228 //   <o>Timer Callback Queue size <1-32>
229 //   <i> Number of concurrent active timer callback functions.
230 //   <i> Default: 4
231 #ifndef OS_TIMERCBQSZ
232  #define OS_TIMERCBQS   4
233 #endif
234
235 // </e>
236
237 //   <o>ISR FIFO Queue size<4=>   4 entries  <8=>   8 entries
238 //                         <12=> 12 entries  <16=> 16 entries
239 //                         <24=> 24 entries  <32=> 32 entries
240 //                         <48=> 48 entries  <64=> 64 entries
241 //                         <96=> 96 entries
242 //   <i> ISR functions store requests to this buffer,
243 //   <i> when they are called from the interrupt handler.
244 //   <i> Default: 16 entries
245 #ifndef OS_FIFOSZ
246  #define OS_FIFOSZ      16
247 #endif
248
249 // </h>
250
251 //------------- <<< end of configuration section >>> -----------------------
252
253 // Standard library system mutexes
254 // ===============================
255 //  Define max. number system mutexes that are used to protect
256 //  the arm standard runtime library. For microlib they are not used.
257 #ifndef OS_MUTEXCNT
258  #define OS_MUTEXCNT    12
259 #endif
260
261 /*----------------------------------------------------------------------------
262  *      RTX User configuration part END
263  *---------------------------------------------------------------------------*/
264
265 #define OS_TRV          ((uint32_t)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
266
267
268 /*----------------------------------------------------------------------------
269  *      OS Idle daemon
270  *---------------------------------------------------------------------------*/
271 void os_idle_demon (void) {
272   /* The idle demon is a system thread, running when no other thread is      */
273   /* ready to run.                                                           */
274
275   /* Sleep: ideally, we should put the chip to sleep.
276      Unfortunately, this usually requires disconnecting the interface chip (debugger).
277      This can be done, but it would break the local file system.
278   */
279   for (;;) {
280       // sleep();
281   }
282 }
283
284 /*----------------------------------------------------------------------------
285  *      RTX Errors
286  *---------------------------------------------------------------------------*/
287 extern void mbed_die(void);
288
289 void os_error (uint32_t err_code) {
290     /* This function is called when a runtime error is detected. Parameter     */
291     /* 'err_code' holds the runtime error code (defined in RTX_Conf.h).      */
292     mbed_die();
293 }
294
295 void sysThreadError(osStatus status) {
296     if (status != osOK) {
297         mbed_die();
298     }
299 }
300
301 /*----------------------------------------------------------------------------
302  *      RTX Configuration Functions
303  *---------------------------------------------------------------------------*/
304
305 #include "RTX_CM_lib.h"
306
307 /*----------------------------------------------------------------------------
308  * end of file
309  *---------------------------------------------------------------------------*/
310