Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard. Support for nucleo F401RE

Dependents:   rtos_basic_stm32_F401

Fork of mbed-rtos by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RTX_Conf_CM.c Source File

RTX_Conf_CM.c

00001 /*----------------------------------------------------------------------------
00002  *      RL-ARM - RTX
00003  *----------------------------------------------------------------------------
00004  *      Name:    RTX_Conf_CM.C
00005  *      Purpose: Configuration of CMSIS RTX Kernel for Cortex-M
00006  *      Rev.:    V4.60
00007  *----------------------------------------------------------------------------
00008  *
00009  * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
00010  * All rights reserved.
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are met:
00013  *  - Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  *  - Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  *  - Neither the name of ARM  nor the names of its contributors may be used 
00019  *    to endorse or promote products derived from this software without 
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
00026  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00027  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00028  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  * POSSIBILITY OF SUCH DAMAGE.
00033  *---------------------------------------------------------------------------*/
00034 
00035 #include "cmsis_os.h"
00036 
00037 
00038 /*----------------------------------------------------------------------------
00039  *      RTX User configuration part BEGIN
00040  *---------------------------------------------------------------------------*/
00041 
00042 //-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
00043 //
00044 // <h>Thread Configuration
00045 // =======================
00046 //
00047 //   <o>Number of concurrent running threads <0-250>
00048 //   <i> Defines max. number of threads that will run at the same time.
00049 //       counting "main", but not counting "osTimerThread"
00050 //   <i> Default: 6
00051 #ifndef OS_TASKCNT
00052 #  if   defined(TARGET_LPC1768) || defined(TARGET_LPC2368)   || defined(TARGET_LPC4088) || defined(TARGET_LPC1347) || defined(TARGET_K64F) \
00053      || defined(TARGET_KL46Z)   || defined(TARGET_STM32F407) || defined(TARGET_F407VG)  || defined(TARGET_STM32F303VC) || defined(TARGET_STM32F401RE)
00054 #    define OS_TASKCNT         14
00055 #  elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401)  || defined(TARGET_LPC11U35_501) || defined(TARGET_LPC1114) \
00056      || defined(TARGET_LPC812)   || defined(TARGET_KL25Z)         || defined(TARGET_STM32F100RB)  || defined(TARGET_STM32F051R8)
00057 #    define OS_TASKCNT         6
00058 #  else
00059 #    error "no target defined"
00060 #  endif
00061 #endif
00062 
00063 //   <o>Scheduler (+ interrupts) stack size [bytes] <64-4096:8><#/4>
00064 #ifndef OS_SCHEDULERSTKSIZE
00065 #  if   defined(TARGET_LPC1768) || defined(TARGET_LPC2368)   || defined(TARGET_LPC4088) || defined(TARGET_LPC1347)  || defined(TARGET_K64F) \
00066      || defined(TARGET_KL46Z)   || defined(TARGET_STM32F407) || defined(TARGET_F407VG)  || defined(TARGET_STM32F303VC) || defined(TARGET_STM32F401RE)
00067 #      define OS_SCHEDULERSTKSIZE    256
00068 #  elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401)  || defined(TARGET_LPC11U35_501) || defined(TARGET_LPC1114) \
00069      || defined(TARGET_LPC812)   || defined(TARGET_KL25Z)         || defined(TARGET_STM32F100RB)  || defined(TARGET_STM32F051R8)
00070 #      define OS_SCHEDULERSTKSIZE    128
00071 #  else
00072 #    error "no target defined"
00073 #  endif
00074 #endif
00075 
00076 //   <o>Idle stack size [bytes] <64-4096:8><#/4>
00077 //   <i> Defines default stack size for the Idle thread.
00078 #ifndef OS_IDLESTKSIZE
00079  #define OS_IDLESTKSIZE         128
00080 #endif
00081 
00082 //   <o>Timer Thread stack size [bytes] <64-4096:8><#/4>
00083 //   <i> Defines stack size for Timer thread.
00084 //   <i> Default: 200
00085 #ifndef OS_TIMERSTKSZ
00086  #define OS_TIMERSTKSZ  WORDS_STACK_SIZE
00087 #endif
00088 
00089 // <q>Check for stack overflow
00090 // <i> Includes the stack checking code for stack overflow.
00091 // <i> Note that additional code reduces the Kernel performance.
00092 #ifndef OS_STKCHECK
00093  #define OS_STKCHECK    1
00094 #endif
00095 
00096 // <o>Processor mode for thread execution 
00097 //   <0=> Unprivileged mode 
00098 //   <1=> Privileged mode
00099 // <i> Default: Privileged mode
00100 #ifndef OS_RUNPRIV
00101  #define OS_RUNPRIV     1
00102 #endif
00103 
00104 // </h>
00105 // <h>SysTick Timer Configuration
00106 // ==============================
00107 //
00108 //   <o>Timer clock value [Hz] <1-1000000000>
00109 //   <i> Defines the timer clock value.
00110 //   <i> Default: 6000000  (6MHz)
00111 #ifndef OS_CLOCK
00112 #  if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
00113 #    define OS_CLOCK       96000000
00114 
00115 #  elif defined(TARGET_LPC1347) || defined(TARGET_STM32F303VC)
00116 #    define OS_CLOCK       72000000
00117 
00118 #  elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401)  || defined(TARGET_LPC11U35_501) || defined(TARGET_LPC1114) || defined(TARGET_KL25Z) || defined(TARGET_KL46Z) || defined(TARGET_STM32F051R8)
00119 #    define OS_CLOCK       48000000
00120 
00121 #  elif defined(TARGET_LPC812)
00122 #    define OS_CLOCK       36000000
00123 
00124 #  elif  defined(TARGET_STM32F100RB)
00125 #    define OS_CLOCK       24000000
00126 
00127 #  elif defined(TARGET_LPC4088) || defined(TARGET_K64F)
00128 #    define OS_CLOCK       120000000
00129 
00130 #  elif defined(TARGET_STM32F407) || defined(TARGET_F407VG)
00131 #    define OS_CLOCK       168000000
00132 
00133 #  elif defined(TARGET_STM32F401RE)
00134 #    define OS_CLOCK       84000000
00135 
00136 
00137 #  else
00138 #    error "no target defined"
00139 #  endif
00140 #endif
00141 
00142 //   <o>Timer tick value [us] <1-1000000>
00143 //   <i> Defines the timer tick value.
00144 //   <i> Default: 1000  (1ms)
00145 #ifndef OS_TICK
00146  #define OS_TICK        1000
00147 #endif
00148 
00149 // </h>
00150 
00151 // <h>System Configuration
00152 // =======================
00153 //
00154 // <e>Round-Robin Thread switching
00155 // ===============================
00156 //
00157 // <i> Enables Round-Robin Thread switching.
00158 #ifndef OS_ROBIN
00159  #define OS_ROBIN       1
00160 #endif
00161 
00162 //   <o>Round-Robin Timeout [ticks] <1-1000>
00163 //   <i> Defines how long a thread will execute before a thread switch.
00164 //   <i> Default: 5
00165 #ifndef OS_ROBINTOUT
00166  #define OS_ROBINTOUT   5
00167 #endif
00168 
00169 // </e>
00170 
00171 // <e>User Timers
00172 // ==============
00173 //   <i> Enables user Timers
00174 #ifndef OS_TIMERS
00175  #define OS_TIMERS      1
00176 #endif
00177 
00178 //   <o>Timer Thread Priority
00179 //                        <1=> Low
00180 //                        <2=> Below Normal
00181 //                        <3=> Normal
00182 //                        <4=> Above Normal
00183 //                        <5=> High
00184 //                        <6=> Realtime (highest)
00185 //   <i> Defines priority for Timer Thread
00186 //   <i> Default: High
00187 #ifndef OS_TIMERPRIO
00188  #define OS_TIMERPRIO   5
00189 #endif
00190 
00191 //   <o>Timer Callback Queue size <1-32>
00192 //   <i> Number of concurrent active timer callback functions.
00193 //   <i> Default: 4
00194 #ifndef OS_TIMERCBQSZ
00195  #define OS_TIMERCBQS   4
00196 #endif
00197 
00198 // </e>
00199 
00200 //   <o>ISR FIFO Queue size<4=>   4 entries  <8=>   8 entries
00201 //                         <12=> 12 entries  <16=> 16 entries
00202 //                         <24=> 24 entries  <32=> 32 entries
00203 //                         <48=> 48 entries  <64=> 64 entries
00204 //                         <96=> 96 entries
00205 //   <i> ISR functions store requests to this buffer,
00206 //   <i> when they are called from the interrupt handler.
00207 //   <i> Default: 16 entries
00208 #ifndef OS_FIFOSZ
00209  #define OS_FIFOSZ      16
00210 #endif
00211 
00212 // </h>
00213 
00214 //------------- <<< end of configuration section >>> -----------------------
00215 
00216 // Standard library system mutexes
00217 // ===============================
00218 //  Define max. number system mutexes that are used to protect 
00219 //  the arm standard runtime library. For microlib they are not used.
00220 #ifndef OS_MUTEXCNT
00221  #define OS_MUTEXCNT    12
00222 #endif
00223 
00224 /*----------------------------------------------------------------------------
00225  *      RTX User configuration part END
00226  *---------------------------------------------------------------------------*/
00227 
00228 #define OS_TRV          ((uint32_t)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
00229 
00230 
00231 /*----------------------------------------------------------------------------
00232  *      OS Idle daemon
00233  *---------------------------------------------------------------------------*/
00234 void os_idle_demon (void) {
00235   /* The idle demon is a system thread, running when no other thread is      */
00236   /* ready to run.                                                           */
00237   
00238   /* Sleep: ideally, we should put the chip to sleep.
00239      Unfortunately, this usually requires disconnecting the interface chip (debugger).
00240      This can be done, but it would break the local file system.
00241   */
00242   for (;;) {
00243       // sleep();
00244   }
00245 }
00246 
00247 /*----------------------------------------------------------------------------
00248  *      RTX Errors
00249  *---------------------------------------------------------------------------*/
00250 extern void mbed_die(void);
00251 
00252 void os_error (uint32_t err_code) {
00253     /* This function is called when a runtime error is detected. Parameter     */
00254     /* 'err_code' holds the runtime error code (defined in RTX_Conf.h).      */
00255     mbed_die();
00256 }
00257 
00258 void sysThreadError(osStatus status) {
00259     if (status != osOK) {
00260         mbed_die();
00261     }
00262 }
00263 
00264 /*----------------------------------------------------------------------------
00265  *      RTX Configuration Functions
00266  *---------------------------------------------------------------------------*/
00267 
00268 #include "RTX_CM_lib.h"
00269 
00270 /*----------------------------------------------------------------------------
00271  * end of file
00272  *---------------------------------------------------------------------------*/