Counter

Dependencies:   EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem

Committer:
Tuxitheone
Date:
Mon Feb 29 18:59:15 2016 +0000
Revision:
0:ecaf3e593122
TankCounter

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Tuxitheone 0:ecaf3e593122 1 /*----------------------------------------------------------------------------
Tuxitheone 0:ecaf3e593122 2 * RL-ARM - RTX
Tuxitheone 0:ecaf3e593122 3 *----------------------------------------------------------------------------
Tuxitheone 0:ecaf3e593122 4 * Name: RTX_Conf_CM.C
Tuxitheone 0:ecaf3e593122 5 * Purpose: Configuration of CMSIS RTX Kernel for Cortex-M
Tuxitheone 0:ecaf3e593122 6 * Rev.: V4.60
Tuxitheone 0:ecaf3e593122 7 *----------------------------------------------------------------------------
Tuxitheone 0:ecaf3e593122 8 *
Tuxitheone 0:ecaf3e593122 9 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
Tuxitheone 0:ecaf3e593122 10 * All rights reserved.
Tuxitheone 0:ecaf3e593122 11 * Redistribution and use in source and binary forms, with or without
Tuxitheone 0:ecaf3e593122 12 * modification, are permitted provided that the following conditions are met:
Tuxitheone 0:ecaf3e593122 13 * - Redistributions of source code must retain the above copyright
Tuxitheone 0:ecaf3e593122 14 * notice, this list of conditions and the following disclaimer.
Tuxitheone 0:ecaf3e593122 15 * - Redistributions in binary form must reproduce the above copyright
Tuxitheone 0:ecaf3e593122 16 * notice, this list of conditions and the following disclaimer in the
Tuxitheone 0:ecaf3e593122 17 * documentation and/or other materials provided with the distribution.
Tuxitheone 0:ecaf3e593122 18 * - Neither the name of ARM nor the names of its contributors may be used
Tuxitheone 0:ecaf3e593122 19 * to endorse or promote products derived from this software without
Tuxitheone 0:ecaf3e593122 20 * specific prior written permission.
Tuxitheone 0:ecaf3e593122 21 *
Tuxitheone 0:ecaf3e593122 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Tuxitheone 0:ecaf3e593122 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Tuxitheone 0:ecaf3e593122 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Tuxitheone 0:ecaf3e593122 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
Tuxitheone 0:ecaf3e593122 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Tuxitheone 0:ecaf3e593122 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Tuxitheone 0:ecaf3e593122 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Tuxitheone 0:ecaf3e593122 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Tuxitheone 0:ecaf3e593122 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Tuxitheone 0:ecaf3e593122 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Tuxitheone 0:ecaf3e593122 32 * POSSIBILITY OF SUCH DAMAGE.
Tuxitheone 0:ecaf3e593122 33 *---------------------------------------------------------------------------*/
Tuxitheone 0:ecaf3e593122 34
Tuxitheone 0:ecaf3e593122 35 #include "cmsis_os.h"
Tuxitheone 0:ecaf3e593122 36
Tuxitheone 0:ecaf3e593122 37
Tuxitheone 0:ecaf3e593122 38 /*----------------------------------------------------------------------------
Tuxitheone 0:ecaf3e593122 39 * RTX User configuration part BEGIN
Tuxitheone 0:ecaf3e593122 40 *---------------------------------------------------------------------------*/
Tuxitheone 0:ecaf3e593122 41
Tuxitheone 0:ecaf3e593122 42 //-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
Tuxitheone 0:ecaf3e593122 43 //
Tuxitheone 0:ecaf3e593122 44 // <h>Thread Configuration
Tuxitheone 0:ecaf3e593122 45 // =======================
Tuxitheone 0:ecaf3e593122 46 //
Tuxitheone 0:ecaf3e593122 47 // <o>Number of concurrent running threads <0-250>
Tuxitheone 0:ecaf3e593122 48 // <i> Defines max. number of threads that will run at the same time.
Tuxitheone 0:ecaf3e593122 49 // counting "main", but not counting "osTimerThread"
Tuxitheone 0:ecaf3e593122 50 // <i> Default: 6
Tuxitheone 0:ecaf3e593122 51 #ifndef OS_TASKCNT
Tuxitheone 0:ecaf3e593122 52 # if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088) || defined(TARGET_LPC1347)
Tuxitheone 0:ecaf3e593122 53 # define OS_TASKCNT 14
Tuxitheone 0:ecaf3e593122 54 # elif defined(TARGET_LPC11U24) || (TARGET_LPC1114) || (TARGET_LPC812) || defined(TARGET_KL25Z)
Tuxitheone 0:ecaf3e593122 55 # define OS_TASKCNT 6
Tuxitheone 0:ecaf3e593122 56 # endif
Tuxitheone 0:ecaf3e593122 57 #endif
Tuxitheone 0:ecaf3e593122 58
Tuxitheone 0:ecaf3e593122 59 // <o>Scheduler (+ interrupts) stack size [bytes] <64-4096:8><#/4>
Tuxitheone 0:ecaf3e593122 60 #ifndef OS_SCHEDULERSTKSIZE
Tuxitheone 0:ecaf3e593122 61 # if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088) || defined(TARGET_LPC1347)
Tuxitheone 0:ecaf3e593122 62 # define OS_SCHEDULERSTKSIZE 256
Tuxitheone 0:ecaf3e593122 63 # elif defined(TARGET_LPC11U24) || (TARGET_LPC1114) || (TARGET_LPC812) || defined(TARGET_KL25Z)
Tuxitheone 0:ecaf3e593122 64 # define OS_SCHEDULERSTKSIZE 128
Tuxitheone 0:ecaf3e593122 65 # endif
Tuxitheone 0:ecaf3e593122 66 #endif
Tuxitheone 0:ecaf3e593122 67
Tuxitheone 0:ecaf3e593122 68 // <o>Idle stack size [bytes] <64-4096:8><#/4>
Tuxitheone 0:ecaf3e593122 69 // <i> Defines default stack size for the Idle thread.
Tuxitheone 0:ecaf3e593122 70 #ifndef OS_IDLESTKSIZE
Tuxitheone 0:ecaf3e593122 71 #define OS_IDLESTKSIZE 128
Tuxitheone 0:ecaf3e593122 72 #endif
Tuxitheone 0:ecaf3e593122 73
Tuxitheone 0:ecaf3e593122 74 // <o>Timer Thread stack size [bytes] <64-4096:8><#/4>
Tuxitheone 0:ecaf3e593122 75 // <i> Defines stack size for Timer thread.
Tuxitheone 0:ecaf3e593122 76 // <i> Default: 200
Tuxitheone 0:ecaf3e593122 77 #ifndef OS_TIMERSTKSZ
Tuxitheone 0:ecaf3e593122 78 #define OS_TIMERSTKSZ WORDS_STACK_SIZE
Tuxitheone 0:ecaf3e593122 79 #endif
Tuxitheone 0:ecaf3e593122 80
Tuxitheone 0:ecaf3e593122 81 // <q>Check for stack overflow
Tuxitheone 0:ecaf3e593122 82 // <i> Includes the stack checking code for stack overflow.
Tuxitheone 0:ecaf3e593122 83 // <i> Note that additional code reduces the Kernel performance.
Tuxitheone 0:ecaf3e593122 84 #ifndef OS_STKCHECK
Tuxitheone 0:ecaf3e593122 85 #define OS_STKCHECK 1
Tuxitheone 0:ecaf3e593122 86 #endif
Tuxitheone 0:ecaf3e593122 87
Tuxitheone 0:ecaf3e593122 88 // <o>Processor mode for thread execution
Tuxitheone 0:ecaf3e593122 89 // <0=> Unprivileged mode
Tuxitheone 0:ecaf3e593122 90 // <1=> Privileged mode
Tuxitheone 0:ecaf3e593122 91 // <i> Default: Privileged mode
Tuxitheone 0:ecaf3e593122 92 #ifndef OS_RUNPRIV
Tuxitheone 0:ecaf3e593122 93 #define OS_RUNPRIV 1
Tuxitheone 0:ecaf3e593122 94 #endif
Tuxitheone 0:ecaf3e593122 95
Tuxitheone 0:ecaf3e593122 96 // </h>
Tuxitheone 0:ecaf3e593122 97 // <h>SysTick Timer Configuration
Tuxitheone 0:ecaf3e593122 98 // ==============================
Tuxitheone 0:ecaf3e593122 99 //
Tuxitheone 0:ecaf3e593122 100 // <o>Timer clock value [Hz] <1-1000000000>
Tuxitheone 0:ecaf3e593122 101 // <i> Defines the timer clock value.
Tuxitheone 0:ecaf3e593122 102 // <i> Default: 6000000 (6MHz)
Tuxitheone 0:ecaf3e593122 103 #ifndef OS_CLOCK
Tuxitheone 0:ecaf3e593122 104 # if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
Tuxitheone 0:ecaf3e593122 105 # define OS_CLOCK 96000000
Tuxitheone 0:ecaf3e593122 106
Tuxitheone 0:ecaf3e593122 107 # elif defined(TARGET_LPC1347)
Tuxitheone 0:ecaf3e593122 108 # define OS_CLOCK 72000000
Tuxitheone 0:ecaf3e593122 109
Tuxitheone 0:ecaf3e593122 110 # elif defined(TARGET_LPC11U24) || (TARGET_LPC1114) || defined(TARGET_KL25Z)
Tuxitheone 0:ecaf3e593122 111 # define OS_CLOCK 48000000
Tuxitheone 0:ecaf3e593122 112 #
Tuxitheone 0:ecaf3e593122 113 # elif defined(TARGET_LPC812)
Tuxitheone 0:ecaf3e593122 114 # define OS_CLOCK 36000000
Tuxitheone 0:ecaf3e593122 115 #
Tuxitheone 0:ecaf3e593122 116 # elif defined(TARGET_LPC4088)
Tuxitheone 0:ecaf3e593122 117 # define OS_CLOCK 120000000
Tuxitheone 0:ecaf3e593122 118 # endif
Tuxitheone 0:ecaf3e593122 119 #endif
Tuxitheone 0:ecaf3e593122 120
Tuxitheone 0:ecaf3e593122 121 // <o>Timer tick value [us] <1-1000000>
Tuxitheone 0:ecaf3e593122 122 // <i> Defines the timer tick value.
Tuxitheone 0:ecaf3e593122 123 // <i> Default: 1000 (1ms)
Tuxitheone 0:ecaf3e593122 124 #ifndef OS_TICK
Tuxitheone 0:ecaf3e593122 125 #define OS_TICK 1000
Tuxitheone 0:ecaf3e593122 126 #endif
Tuxitheone 0:ecaf3e593122 127
Tuxitheone 0:ecaf3e593122 128 // </h>
Tuxitheone 0:ecaf3e593122 129
Tuxitheone 0:ecaf3e593122 130 // <h>System Configuration
Tuxitheone 0:ecaf3e593122 131 // =======================
Tuxitheone 0:ecaf3e593122 132 //
Tuxitheone 0:ecaf3e593122 133 // <e>Round-Robin Thread switching
Tuxitheone 0:ecaf3e593122 134 // ===============================
Tuxitheone 0:ecaf3e593122 135 //
Tuxitheone 0:ecaf3e593122 136 // <i> Enables Round-Robin Thread switching.
Tuxitheone 0:ecaf3e593122 137 #ifndef OS_ROBIN
Tuxitheone 0:ecaf3e593122 138 #define OS_ROBIN 1
Tuxitheone 0:ecaf3e593122 139 #endif
Tuxitheone 0:ecaf3e593122 140
Tuxitheone 0:ecaf3e593122 141 // <o>Round-Robin Timeout [ticks] <1-1000>
Tuxitheone 0:ecaf3e593122 142 // <i> Defines how long a thread will execute before a thread switch.
Tuxitheone 0:ecaf3e593122 143 // <i> Default: 5
Tuxitheone 0:ecaf3e593122 144 #ifndef OS_ROBINTOUT
Tuxitheone 0:ecaf3e593122 145 #define OS_ROBINTOUT 5
Tuxitheone 0:ecaf3e593122 146 #endif
Tuxitheone 0:ecaf3e593122 147
Tuxitheone 0:ecaf3e593122 148 // </e>
Tuxitheone 0:ecaf3e593122 149
Tuxitheone 0:ecaf3e593122 150 // <e>User Timers
Tuxitheone 0:ecaf3e593122 151 // ==============
Tuxitheone 0:ecaf3e593122 152 // <i> Enables user Timers
Tuxitheone 0:ecaf3e593122 153 #ifndef OS_TIMERS
Tuxitheone 0:ecaf3e593122 154 #define OS_TIMERS 1
Tuxitheone 0:ecaf3e593122 155 #endif
Tuxitheone 0:ecaf3e593122 156
Tuxitheone 0:ecaf3e593122 157 // <o>Timer Thread Priority
Tuxitheone 0:ecaf3e593122 158 // <1=> Low
Tuxitheone 0:ecaf3e593122 159 // <2=> Below Normal
Tuxitheone 0:ecaf3e593122 160 // <3=> Normal
Tuxitheone 0:ecaf3e593122 161 // <4=> Above Normal
Tuxitheone 0:ecaf3e593122 162 // <5=> High
Tuxitheone 0:ecaf3e593122 163 // <6=> Realtime (highest)
Tuxitheone 0:ecaf3e593122 164 // <i> Defines priority for Timer Thread
Tuxitheone 0:ecaf3e593122 165 // <i> Default: High
Tuxitheone 0:ecaf3e593122 166 #ifndef OS_TIMERPRIO
Tuxitheone 0:ecaf3e593122 167 #define OS_TIMERPRIO 5
Tuxitheone 0:ecaf3e593122 168 #endif
Tuxitheone 0:ecaf3e593122 169
Tuxitheone 0:ecaf3e593122 170 // <o>Timer Callback Queue size <1-32>
Tuxitheone 0:ecaf3e593122 171 // <i> Number of concurrent active timer callback functions.
Tuxitheone 0:ecaf3e593122 172 // <i> Default: 4
Tuxitheone 0:ecaf3e593122 173 #ifndef OS_TIMERCBQSZ
Tuxitheone 0:ecaf3e593122 174 #define OS_TIMERCBQS 4
Tuxitheone 0:ecaf3e593122 175 #endif
Tuxitheone 0:ecaf3e593122 176
Tuxitheone 0:ecaf3e593122 177 // </e>
Tuxitheone 0:ecaf3e593122 178
Tuxitheone 0:ecaf3e593122 179 // <o>ISR FIFO Queue size<4=> 4 entries <8=> 8 entries
Tuxitheone 0:ecaf3e593122 180 // <12=> 12 entries <16=> 16 entries
Tuxitheone 0:ecaf3e593122 181 // <24=> 24 entries <32=> 32 entries
Tuxitheone 0:ecaf3e593122 182 // <48=> 48 entries <64=> 64 entries
Tuxitheone 0:ecaf3e593122 183 // <96=> 96 entries
Tuxitheone 0:ecaf3e593122 184 // <i> ISR functions store requests to this buffer,
Tuxitheone 0:ecaf3e593122 185 // <i> when they are called from the interrupt handler.
Tuxitheone 0:ecaf3e593122 186 // <i> Default: 16 entries
Tuxitheone 0:ecaf3e593122 187 #ifndef OS_FIFOSZ
Tuxitheone 0:ecaf3e593122 188 #define OS_FIFOSZ 16
Tuxitheone 0:ecaf3e593122 189 #endif
Tuxitheone 0:ecaf3e593122 190
Tuxitheone 0:ecaf3e593122 191 // </h>
Tuxitheone 0:ecaf3e593122 192
Tuxitheone 0:ecaf3e593122 193 //------------- <<< end of configuration section >>> -----------------------
Tuxitheone 0:ecaf3e593122 194
Tuxitheone 0:ecaf3e593122 195 // Standard library system mutexes
Tuxitheone 0:ecaf3e593122 196 // ===============================
Tuxitheone 0:ecaf3e593122 197 // Define max. number system mutexes that are used to protect
Tuxitheone 0:ecaf3e593122 198 // the arm standard runtime library. For microlib they are not used.
Tuxitheone 0:ecaf3e593122 199 #ifndef OS_MUTEXCNT
Tuxitheone 0:ecaf3e593122 200 #define OS_MUTEXCNT 12
Tuxitheone 0:ecaf3e593122 201 #endif
Tuxitheone 0:ecaf3e593122 202
Tuxitheone 0:ecaf3e593122 203 /*----------------------------------------------------------------------------
Tuxitheone 0:ecaf3e593122 204 * RTX User configuration part END
Tuxitheone 0:ecaf3e593122 205 *---------------------------------------------------------------------------*/
Tuxitheone 0:ecaf3e593122 206
Tuxitheone 0:ecaf3e593122 207 #define OS_TRV ((uint32_t)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
Tuxitheone 0:ecaf3e593122 208
Tuxitheone 0:ecaf3e593122 209
Tuxitheone 0:ecaf3e593122 210 /*----------------------------------------------------------------------------
Tuxitheone 0:ecaf3e593122 211 * OS Idle daemon
Tuxitheone 0:ecaf3e593122 212 *---------------------------------------------------------------------------*/
Tuxitheone 0:ecaf3e593122 213 void os_idle_demon (void) {
Tuxitheone 0:ecaf3e593122 214 /* The idle demon is a system thread, running when no other thread is */
Tuxitheone 0:ecaf3e593122 215 /* ready to run. */
Tuxitheone 0:ecaf3e593122 216
Tuxitheone 0:ecaf3e593122 217 /* Sleep: ideally, we should put the chip to sleep.
Tuxitheone 0:ecaf3e593122 218 Unfortunately, this usually requires disconnecting the interface chip (debugger).
Tuxitheone 0:ecaf3e593122 219 This can be done, but it would break the local file system.
Tuxitheone 0:ecaf3e593122 220 */
Tuxitheone 0:ecaf3e593122 221 for (;;) {
Tuxitheone 0:ecaf3e593122 222 // sleep();
Tuxitheone 0:ecaf3e593122 223 }
Tuxitheone 0:ecaf3e593122 224 }
Tuxitheone 0:ecaf3e593122 225
Tuxitheone 0:ecaf3e593122 226 /*----------------------------------------------------------------------------
Tuxitheone 0:ecaf3e593122 227 * RTX Errors
Tuxitheone 0:ecaf3e593122 228 *---------------------------------------------------------------------------*/
Tuxitheone 0:ecaf3e593122 229 extern void mbed_die(void);
Tuxitheone 0:ecaf3e593122 230
Tuxitheone 0:ecaf3e593122 231 void os_error (uint32_t err_code) {
Tuxitheone 0:ecaf3e593122 232 /* This function is called when a runtime error is detected. Parameter */
Tuxitheone 0:ecaf3e593122 233 /* 'err_code' holds the runtime error code (defined in RTX_Conf.h). */
Tuxitheone 0:ecaf3e593122 234 mbed_die();
Tuxitheone 0:ecaf3e593122 235 }
Tuxitheone 0:ecaf3e593122 236
Tuxitheone 0:ecaf3e593122 237 void sysThreadError(osStatus status) {
Tuxitheone 0:ecaf3e593122 238 if (status != osOK) {
Tuxitheone 0:ecaf3e593122 239 mbed_die();
Tuxitheone 0:ecaf3e593122 240 }
Tuxitheone 0:ecaf3e593122 241 }
Tuxitheone 0:ecaf3e593122 242
Tuxitheone 0:ecaf3e593122 243 /*----------------------------------------------------------------------------
Tuxitheone 0:ecaf3e593122 244 * RTX Configuration Functions
Tuxitheone 0:ecaf3e593122 245 *---------------------------------------------------------------------------*/
Tuxitheone 0:ecaf3e593122 246
Tuxitheone 0:ecaf3e593122 247 #include "RTX_CM_lib.h"
Tuxitheone 0:ecaf3e593122 248
Tuxitheone 0:ecaf3e593122 249 /*----------------------------------------------------------------------------
Tuxitheone 0:ecaf3e593122 250 * end of file
Tuxitheone 0:ecaf3e593122 251 *---------------------------------------------------------------------------*/