mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 2 * RL-ARM - RTX
mbedAustin 11:cada08fc8a70 3 *----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 4 * Name: RTX_CM_LIB.H
mbedAustin 11:cada08fc8a70 5 * Purpose: RTX Kernel System Configuration
mbedAustin 11:cada08fc8a70 6 * Rev.: V4.60
mbedAustin 11:cada08fc8a70 7 *----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
mbedAustin 11:cada08fc8a70 10 * All rights reserved.
mbedAustin 11:cada08fc8a70 11 * Redistribution and use in source and binary forms, with or without
mbedAustin 11:cada08fc8a70 12 * modification, are permitted provided that the following conditions are met:
mbedAustin 11:cada08fc8a70 13 * - Redistributions of source code must retain the above copyright
mbedAustin 11:cada08fc8a70 14 * notice, this list of conditions and the following disclaimer.
mbedAustin 11:cada08fc8a70 15 * - Redistributions in binary form must reproduce the above copyright
mbedAustin 11:cada08fc8a70 16 * notice, this list of conditions and the following disclaimer in the
mbedAustin 11:cada08fc8a70 17 * documentation and/or other materials provided with the distribution.
mbedAustin 11:cada08fc8a70 18 * - Neither the name of ARM nor the names of its contributors may be used
mbedAustin 11:cada08fc8a70 19 * to endorse or promote products derived from this software without
mbedAustin 11:cada08fc8a70 20 * specific prior written permission.
mbedAustin 11:cada08fc8a70 21 *
mbedAustin 11:cada08fc8a70 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbedAustin 11:cada08fc8a70 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbedAustin 11:cada08fc8a70 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
mbedAustin 11:cada08fc8a70 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
mbedAustin 11:cada08fc8a70 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
mbedAustin 11:cada08fc8a70 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
mbedAustin 11:cada08fc8a70 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbedAustin 11:cada08fc8a70 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbedAustin 11:cada08fc8a70 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
mbedAustin 11:cada08fc8a70 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbedAustin 11:cada08fc8a70 32 * POSSIBILITY OF SUCH DAMAGE.
mbedAustin 11:cada08fc8a70 33 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 34 #include "mbed_error.h"
mbedAustin 11:cada08fc8a70 35
mbedAustin 11:cada08fc8a70 36 #if defined (__CC_ARM)
mbedAustin 11:cada08fc8a70 37 #pragma O3
mbedAustin 11:cada08fc8a70 38 #define __USED __attribute__((used))
mbedAustin 11:cada08fc8a70 39 #elif defined (__GNUC__)
mbedAustin 11:cada08fc8a70 40 #pragma GCC optimize ("O3")
mbedAustin 11:cada08fc8a70 41 #define __USED __attribute__((used))
mbedAustin 11:cada08fc8a70 42 #elif defined (__ICCARM__)
mbedAustin 11:cada08fc8a70 43 #define __USED __root
mbedAustin 11:cada08fc8a70 44 #endif
mbedAustin 11:cada08fc8a70 45
mbedAustin 11:cada08fc8a70 46
mbedAustin 11:cada08fc8a70 47 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 48 * Definitions
mbedAustin 11:cada08fc8a70 49 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 50
mbedAustin 11:cada08fc8a70 51 #define _declare_box(pool,size,cnt) uint32_t pool[(((size)+3)/4)*(cnt) + 3]
mbedAustin 11:cada08fc8a70 52 #define _declare_box8(pool,size,cnt) uint64_t pool[(((size)+7)/8)*(cnt) + 2]
mbedAustin 11:cada08fc8a70 53
mbedAustin 11:cada08fc8a70 54 #define OS_TCB_SIZE 48
mbedAustin 11:cada08fc8a70 55 #define OS_TMR_SIZE 8
mbedAustin 11:cada08fc8a70 56
mbedAustin 11:cada08fc8a70 57 #if defined (__CC_ARM) && !defined (__MICROLIB)
mbedAustin 11:cada08fc8a70 58
mbedAustin 11:cada08fc8a70 59 typedef void *OS_ID;
mbedAustin 11:cada08fc8a70 60 typedef uint32_t OS_TID;
mbedAustin 11:cada08fc8a70 61 typedef uint32_t OS_MUT[3];
mbedAustin 11:cada08fc8a70 62 typedef uint32_t OS_RESULT;
mbedAustin 11:cada08fc8a70 63
mbedAustin 11:cada08fc8a70 64 #define runtask_id() rt_tsk_self()
mbedAustin 11:cada08fc8a70 65 #define mutex_init(m) rt_mut_init(m)
mbedAustin 11:cada08fc8a70 66 #define mutex_wait(m) os_mut_wait(m,0xFFFF)
mbedAustin 11:cada08fc8a70 67 #define mutex_rel(m) os_mut_release(m)
mbedAustin 11:cada08fc8a70 68
mbedAustin 11:cada08fc8a70 69 extern OS_TID rt_tsk_self (void);
mbedAustin 11:cada08fc8a70 70 extern void rt_mut_init (OS_ID mutex);
mbedAustin 11:cada08fc8a70 71 extern OS_RESULT rt_mut_release (OS_ID mutex);
mbedAustin 11:cada08fc8a70 72 extern OS_RESULT rt_mut_wait (OS_ID mutex, uint16_t timeout);
mbedAustin 11:cada08fc8a70 73
mbedAustin 11:cada08fc8a70 74 #define os_mut_wait(mutex,timeout) _os_mut_wait((uint32_t)rt_mut_wait,mutex,timeout)
mbedAustin 11:cada08fc8a70 75 #define os_mut_release(mutex) _os_mut_release((uint32_t)rt_mut_release,mutex)
mbedAustin 11:cada08fc8a70 76
mbedAustin 11:cada08fc8a70 77 OS_RESULT _os_mut_release (uint32_t p, OS_ID mutex) __svc_indirect(0);
mbedAustin 11:cada08fc8a70 78 OS_RESULT _os_mut_wait (uint32_t p, OS_ID mutex, uint16_t timeout) __svc_indirect(0);
mbedAustin 11:cada08fc8a70 79
mbedAustin 11:cada08fc8a70 80 #endif
mbedAustin 11:cada08fc8a70 81
mbedAustin 11:cada08fc8a70 82
mbedAustin 11:cada08fc8a70 83 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 84 * Global Variables
mbedAustin 11:cada08fc8a70 85 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 86
mbedAustin 11:cada08fc8a70 87 #if (OS_TIMERS != 0)
mbedAustin 11:cada08fc8a70 88 #define OS_TASK_CNT (OS_TASKCNT + 1)
mbedAustin 11:cada08fc8a70 89 #else
mbedAustin 11:cada08fc8a70 90 #define OS_TASK_CNT OS_TASKCNT
mbedAustin 11:cada08fc8a70 91 #endif
mbedAustin 11:cada08fc8a70 92
mbedAustin 11:cada08fc8a70 93 uint16_t const os_maxtaskrun = OS_TASK_CNT;
mbedAustin 11:cada08fc8a70 94 uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT;
mbedAustin 11:cada08fc8a70 95 uint32_t const os_trv = OS_TRV;
mbedAustin 11:cada08fc8a70 96 uint8_t const os_flags = OS_RUNPRIV;
mbedAustin 11:cada08fc8a70 97
mbedAustin 11:cada08fc8a70 98 /* Export following defines to uVision debugger. */
mbedAustin 11:cada08fc8a70 99 __USED uint32_t const os_clockrate = OS_TICK;
mbedAustin 11:cada08fc8a70 100 __USED uint32_t const os_timernum = 0;
mbedAustin 11:cada08fc8a70 101
mbedAustin 11:cada08fc8a70 102 /* Stack for the os_idle_demon */
mbedAustin 11:cada08fc8a70 103 unsigned int idle_task_stack[OS_IDLESTKSIZE];
mbedAustin 11:cada08fc8a70 104 unsigned short const idle_task_stack_size = OS_IDLESTKSIZE;
mbedAustin 11:cada08fc8a70 105
mbedAustin 11:cada08fc8a70 106 #ifndef OS_FIFOSZ
mbedAustin 11:cada08fc8a70 107 #define OS_FIFOSZ 16
mbedAustin 11:cada08fc8a70 108 #endif
mbedAustin 11:cada08fc8a70 109
mbedAustin 11:cada08fc8a70 110 /* Fifo Queue buffer for ISR requests.*/
mbedAustin 11:cada08fc8a70 111 uint32_t os_fifo[OS_FIFOSZ*2+1];
mbedAustin 11:cada08fc8a70 112 uint8_t const os_fifo_size = OS_FIFOSZ;
mbedAustin 11:cada08fc8a70 113
mbedAustin 11:cada08fc8a70 114 /* An array of Active task pointers. */
mbedAustin 11:cada08fc8a70 115 void *os_active_TCB[OS_TASK_CNT];
mbedAustin 11:cada08fc8a70 116
mbedAustin 11:cada08fc8a70 117 /* User Timers Resources */
mbedAustin 11:cada08fc8a70 118 #if (OS_TIMERS != 0)
mbedAustin 11:cada08fc8a70 119 extern void osTimerThread (void const *argument);
mbedAustin 11:cada08fc8a70 120 osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ);
mbedAustin 11:cada08fc8a70 121 osThreadId osThreadId_osTimerThread;
mbedAustin 11:cada08fc8a70 122 osMessageQDef(osTimerMessageQ, OS_TIMERCBQS, void *);
mbedAustin 11:cada08fc8a70 123 osMessageQId osMessageQId_osTimerMessageQ;
mbedAustin 11:cada08fc8a70 124 #else
mbedAustin 11:cada08fc8a70 125 osThreadDef_t os_thread_def_osTimerThread = { NULL };
mbedAustin 11:cada08fc8a70 126 osThreadId osThreadId_osTimerThread;
mbedAustin 11:cada08fc8a70 127 osMessageQDef(osTimerMessageQ, 0, void *);
mbedAustin 11:cada08fc8a70 128 osMessageQId osMessageQId_osTimerMessageQ;
mbedAustin 11:cada08fc8a70 129 #endif
mbedAustin 11:cada08fc8a70 130
mbedAustin 11:cada08fc8a70 131
mbedAustin 11:cada08fc8a70 132 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 133 * RTX Optimizations (empty functions)
mbedAustin 11:cada08fc8a70 134 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 135
mbedAustin 11:cada08fc8a70 136 #if OS_ROBIN == 0
mbedAustin 11:cada08fc8a70 137 void rt_init_robin (void) {;}
mbedAustin 11:cada08fc8a70 138 void rt_chk_robin (void) {;}
mbedAustin 11:cada08fc8a70 139 #endif
mbedAustin 11:cada08fc8a70 140
mbedAustin 11:cada08fc8a70 141 #if OS_STKCHECK == 0
mbedAustin 11:cada08fc8a70 142 void rt_stk_check (void) {;}
mbedAustin 11:cada08fc8a70 143 #endif
mbedAustin 11:cada08fc8a70 144
mbedAustin 11:cada08fc8a70 145
mbedAustin 11:cada08fc8a70 146 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 147 * Standard Library multithreading interface
mbedAustin 11:cada08fc8a70 148 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 149
mbedAustin 11:cada08fc8a70 150 #if defined (__CC_ARM) && !defined (__MICROLIB)
mbedAustin 11:cada08fc8a70 151 static OS_MUT std_libmutex[OS_MUTEXCNT];
mbedAustin 11:cada08fc8a70 152 static uint32_t nr_mutex;
mbedAustin 11:cada08fc8a70 153
mbedAustin 11:cada08fc8a70 154 /*--------------------------- _mutex_initialize -----------------------------*/
mbedAustin 11:cada08fc8a70 155
mbedAustin 11:cada08fc8a70 156 int _mutex_initialize (OS_ID *mutex) {
mbedAustin 11:cada08fc8a70 157 /* Allocate and initialize a system mutex. */
mbedAustin 11:cada08fc8a70 158
mbedAustin 11:cada08fc8a70 159 if (nr_mutex >= OS_MUTEXCNT) {
mbedAustin 11:cada08fc8a70 160 /* If you are here, you need to increase the number OS_MUTEXCNT. */
mbedAustin 11:cada08fc8a70 161 error("Not enough stdlib mutexes\n");
mbedAustin 11:cada08fc8a70 162 }
mbedAustin 11:cada08fc8a70 163 *mutex = &std_libmutex[nr_mutex++];
mbedAustin 11:cada08fc8a70 164 mutex_init (*mutex);
mbedAustin 11:cada08fc8a70 165 return (1);
mbedAustin 11:cada08fc8a70 166 }
mbedAustin 11:cada08fc8a70 167
mbedAustin 11:cada08fc8a70 168
mbedAustin 11:cada08fc8a70 169 /*--------------------------- _mutex_acquire --------------------------------*/
mbedAustin 11:cada08fc8a70 170
mbedAustin 11:cada08fc8a70 171 __attribute__((used)) void _mutex_acquire (OS_ID *mutex) {
mbedAustin 11:cada08fc8a70 172 /* Acquire a system mutex, lock stdlib resources. */
mbedAustin 11:cada08fc8a70 173 if (runtask_id ()) {
mbedAustin 11:cada08fc8a70 174 /* RTX running, acquire a mutex. */
mbedAustin 11:cada08fc8a70 175 mutex_wait (*mutex);
mbedAustin 11:cada08fc8a70 176 }
mbedAustin 11:cada08fc8a70 177 }
mbedAustin 11:cada08fc8a70 178
mbedAustin 11:cada08fc8a70 179
mbedAustin 11:cada08fc8a70 180 /*--------------------------- _mutex_release --------------------------------*/
mbedAustin 11:cada08fc8a70 181
mbedAustin 11:cada08fc8a70 182 __attribute__((used)) void _mutex_release (OS_ID *mutex) {
mbedAustin 11:cada08fc8a70 183 /* Release a system mutex, unlock stdlib resources. */
mbedAustin 11:cada08fc8a70 184 if (runtask_id ()) {
mbedAustin 11:cada08fc8a70 185 /* RTX running, release a mutex. */
mbedAustin 11:cada08fc8a70 186 mutex_rel (*mutex);
mbedAustin 11:cada08fc8a70 187 }
mbedAustin 11:cada08fc8a70 188 }
mbedAustin 11:cada08fc8a70 189
mbedAustin 11:cada08fc8a70 190 #endif
mbedAustin 11:cada08fc8a70 191
mbedAustin 11:cada08fc8a70 192
mbedAustin 11:cada08fc8a70 193 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 194 * RTX Startup
mbedAustin 11:cada08fc8a70 195 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 196
mbedAustin 11:cada08fc8a70 197 /* Main Thread definition */
mbedAustin 11:cada08fc8a70 198 extern int main (void);
mbedAustin 11:cada08fc8a70 199 osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 0, NULL};
mbedAustin 11:cada08fc8a70 200
mbedAustin 11:cada08fc8a70 201 // This define should be probably moved to the CMSIS layer
mbedAustin 11:cada08fc8a70 202 #if defined(TARGET_LPC1768)
mbedAustin 11:cada08fc8a70 203 #define INITIAL_SP (0x10008000UL)
mbedAustin 11:cada08fc8a70 204
mbedAustin 11:cada08fc8a70 205 #elif defined(TARGET_LPC11U24)
mbedAustin 11:cada08fc8a70 206 #define INITIAL_SP (0x10002000UL)
mbedAustin 11:cada08fc8a70 207
mbedAustin 11:cada08fc8a70 208 #elif defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501) || defined(TARGET_LPCCAPPUCCINO)
mbedAustin 11:cada08fc8a70 209 #define INITIAL_SP (0x10002000UL)
mbedAustin 11:cada08fc8a70 210
mbedAustin 11:cada08fc8a70 211 #elif defined(TARGET_LPC1114)
mbedAustin 11:cada08fc8a70 212 #define INITIAL_SP (0x10001000UL)
mbedAustin 11:cada08fc8a70 213
mbedAustin 11:cada08fc8a70 214 #elif defined(TARGET_LPC812)
mbedAustin 11:cada08fc8a70 215 #define INITIAL_SP (0x10001000UL)
mbedAustin 11:cada08fc8a70 216
mbedAustin 11:cada08fc8a70 217 #elif defined(TARGET_LPC824) || defined(TARGET_SSCI824)
mbedAustin 11:cada08fc8a70 218 #define INITIAL_SP (0x10002000UL)
mbedAustin 11:cada08fc8a70 219
mbedAustin 11:cada08fc8a70 220 #elif defined(TARGET_KL25Z)
mbedAustin 11:cada08fc8a70 221 #define INITIAL_SP (0x20003000UL)
mbedAustin 11:cada08fc8a70 222
mbedAustin 11:cada08fc8a70 223 #elif defined(TARGET_KL26Z)
mbedAustin 11:cada08fc8a70 224 #define INITIAL_SP (0x20003000UL)
mbedAustin 11:cada08fc8a70 225
mbedAustin 11:cada08fc8a70 226 #elif defined(TARGET_K64F)
mbedAustin 11:cada08fc8a70 227 #define INITIAL_SP (0x20030000UL)
mbedAustin 11:cada08fc8a70 228
mbedAustin 11:cada08fc8a70 229 #elif defined(TARGET_K22F)
mbedAustin 11:cada08fc8a70 230 #define INITIAL_SP (0x20010000UL)
mbedAustin 11:cada08fc8a70 231
mbedAustin 11:cada08fc8a70 232 #elif defined(TARGET_KL46Z)
mbedAustin 11:cada08fc8a70 233 #define INITIAL_SP (0x20006000UL)
mbedAustin 11:cada08fc8a70 234
mbedAustin 11:cada08fc8a70 235 #elif defined(TARGET_KL43Z)
mbedAustin 11:cada08fc8a70 236 #define INITIAL_SP (0x20006000UL)
mbedAustin 11:cada08fc8a70 237
mbedAustin 11:cada08fc8a70 238 #elif defined(TARGET_KL05Z)
mbedAustin 11:cada08fc8a70 239 #define INITIAL_SP (0x20000C00UL)
mbedAustin 11:cada08fc8a70 240
mbedAustin 11:cada08fc8a70 241 #elif defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM)
mbedAustin 11:cada08fc8a70 242 #define INITIAL_SP (0x10010000UL)
mbedAustin 11:cada08fc8a70 243
mbedAustin 11:cada08fc8a70 244 #elif defined(TARGET_LPC4330)
mbedAustin 11:cada08fc8a70 245 #define INITIAL_SP (0x10008000UL)
mbedAustin 11:cada08fc8a70 246
mbedAustin 11:cada08fc8a70 247 #elif defined(TARGET_LPC4337)
mbedAustin 11:cada08fc8a70 248 #define INITIAL_SP (0x10008000UL)
mbedAustin 11:cada08fc8a70 249
mbedAustin 11:cada08fc8a70 250 #elif defined(TARGET_LPC1347)
mbedAustin 11:cada08fc8a70 251 #define INITIAL_SP (0x10002000UL)
mbedAustin 11:cada08fc8a70 252
mbedAustin 11:cada08fc8a70 253 #elif defined(TARGET_STM32F100RB) || defined(TARGET_STM32F051R8)
mbedAustin 11:cada08fc8a70 254 #define INITIAL_SP (0x20002000UL)
mbedAustin 11:cada08fc8a70 255
mbedAustin 11:cada08fc8a70 256 #elif defined(TARGET_DISCO_F303VC)
mbedAustin 11:cada08fc8a70 257 #define INITIAL_SP (0x2000A000UL)
mbedAustin 11:cada08fc8a70 258
mbedAustin 11:cada08fc8a70 259 #elif defined(TARGET_STM32F407) || defined(TARGET_F407VG)
mbedAustin 11:cada08fc8a70 260 #define INITIAL_SP (0x20020000UL)
mbedAustin 11:cada08fc8a70 261
mbedAustin 11:cada08fc8a70 262 #elif defined(TARGET_STM32F401RE)
mbedAustin 11:cada08fc8a70 263 #define INITIAL_SP (0x20018000UL)
mbedAustin 11:cada08fc8a70 264
mbedAustin 11:cada08fc8a70 265 #elif defined(TARGET_LPC1549)
mbedAustin 11:cada08fc8a70 266 #define INITIAL_SP (0x02009000UL)
mbedAustin 11:cada08fc8a70 267
mbedAustin 11:cada08fc8a70 268 #elif defined(TARGET_LPC11U68)
mbedAustin 11:cada08fc8a70 269 #define INITIAL_SP (0x10008000UL)
mbedAustin 11:cada08fc8a70 270
mbedAustin 11:cada08fc8a70 271 #elif defined(TARGET_STM32F411RE)
mbedAustin 11:cada08fc8a70 272 #define INITIAL_SP (0x20020000UL)
mbedAustin 11:cada08fc8a70 273
mbedAustin 11:cada08fc8a70 274 #elif defined(TARGET_STM32F410RB)
mbedAustin 11:cada08fc8a70 275 #define INITIAL_SP (0x20008000UL)
mbedAustin 11:cada08fc8a70 276
mbedAustin 11:cada08fc8a70 277 #elif defined(TARGET_STM32F103RB)
mbedAustin 11:cada08fc8a70 278 #define INITIAL_SP (0x20005000UL)
mbedAustin 11:cada08fc8a70 279
mbedAustin 11:cada08fc8a70 280 #elif defined(TARGET_STM32F302R8)
mbedAustin 11:cada08fc8a70 281 #define INITIAL_SP (0x20004000UL)
mbedAustin 11:cada08fc8a70 282
mbedAustin 11:cada08fc8a70 283 #elif defined(TARGET_STM32F334R8)
mbedAustin 11:cada08fc8a70 284 #define INITIAL_SP (0x20003000UL)
mbedAustin 11:cada08fc8a70 285
mbedAustin 11:cada08fc8a70 286 #elif defined(TARGET_STM32F334C8)
mbedAustin 11:cada08fc8a70 287 #define INITIAL_SP (0x20003000UL)
mbedAustin 11:cada08fc8a70 288
mbedAustin 11:cada08fc8a70 289 #elif defined(TARGET_STM32F405RG)
mbedAustin 11:cada08fc8a70 290 #define INITIAL_SP (0x20020000UL)
mbedAustin 11:cada08fc8a70 291
mbedAustin 11:cada08fc8a70 292 #elif defined(TARGET_STM32F429ZI)
mbedAustin 11:cada08fc8a70 293 #define INITIAL_SP (0x20030000UL)
mbedAustin 11:cada08fc8a70 294
mbedAustin 11:cada08fc8a70 295 #elif defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
mbedAustin 11:cada08fc8a70 296 #define INITIAL_SP (0x20002000UL)
mbedAustin 11:cada08fc8a70 297
mbedAustin 11:cada08fc8a70 298 #elif defined(TARGET_STM32F072RB)
mbedAustin 11:cada08fc8a70 299 #define INITIAL_SP (0x20004000UL)
mbedAustin 11:cada08fc8a70 300
mbedAustin 11:cada08fc8a70 301 #elif defined(TARGET_STM32F091RC)
mbedAustin 11:cada08fc8a70 302 #define INITIAL_SP (0x20008000UL)
mbedAustin 11:cada08fc8a70 303
mbedAustin 11:cada08fc8a70 304 #elif defined(TARGET_STM32F401VC)
mbedAustin 11:cada08fc8a70 305 #define INITIAL_SP (0x20010000UL)
mbedAustin 11:cada08fc8a70 306
mbedAustin 11:cada08fc8a70 307 #elif defined(TARGET_STM32F303RE)
mbedAustin 11:cada08fc8a70 308 #define INITIAL_SP (0x20010000UL)
mbedAustin 11:cada08fc8a70 309
mbedAustin 11:cada08fc8a70 310 #elif defined(TARGET_STM32F303K8)
mbedAustin 11:cada08fc8a70 311 #define INITIAL_SP (0x20003000UL)
mbedAustin 11:cada08fc8a70 312
mbedAustin 11:cada08fc8a70 313 #elif defined(TARGET_STM32F746NG)
mbedAustin 11:cada08fc8a70 314 #define INITIAL_SP (0x20050000UL)
mbedAustin 11:cada08fc8a70 315
mbedAustin 11:cada08fc8a70 316 #elif defined(TARGET_MAX32610) || defined(TARGET_MAX32600)
mbedAustin 11:cada08fc8a70 317 #define INITIAL_SP (0x20008000UL)
mbedAustin 11:cada08fc8a70 318
mbedAustin 11:cada08fc8a70 319 #elif defined(TARGET_TEENSY3_1)
mbedAustin 11:cada08fc8a70 320 #define INITIAL_SP (0x20008000UL)
mbedAustin 11:cada08fc8a70 321
mbedAustin 11:cada08fc8a70 322 #elif defined(TARGET_STM32L152RE)
mbedAustin 11:cada08fc8a70 323 #define INITIAL_SP (0x20014000UL)
mbedAustin 11:cada08fc8a70 324
mbedAustin 11:cada08fc8a70 325 #elif defined(TARGET_NZ32_SC151)
mbedAustin 11:cada08fc8a70 326 #define INITIAL_SP (0x20008000UL)
mbedAustin 11:cada08fc8a70 327
mbedAustin 11:cada08fc8a70 328 #elif (defined(TARGET_STM32F446RE) || defined(TARGET_STM32F446VE))
mbedAustin 11:cada08fc8a70 329 #define INITIAL_SP (0x20020000UL)
mbedAustin 11:cada08fc8a70 330
mbedAustin 11:cada08fc8a70 331 #elif defined(TARGET_STM32F070RB) || defined(TARGET_STM32F030R8)
mbedAustin 11:cada08fc8a70 332 #define INITIAL_SP (0x20002000UL)
mbedAustin 11:cada08fc8a70 333
mbedAustin 11:cada08fc8a70 334 #elif defined(TARGET_STM32L476VG)
mbedAustin 11:cada08fc8a70 335 #define INITIAL_SP (0x20018000UL)
mbedAustin 11:cada08fc8a70 336
mbedAustin 11:cada08fc8a70 337 #elif defined(TARGET_STM32L476RG)
mbedAustin 11:cada08fc8a70 338 #define INITIAL_SP (0x20018000UL)
mbedAustin 11:cada08fc8a70 339
mbedAustin 11:cada08fc8a70 340 #elif defined(TARGET_STM32F469NI)
mbedAustin 11:cada08fc8a70 341 #define INITIAL_SP (0x20050000UL)
mbedAustin 11:cada08fc8a70 342
mbedAustin 11:cada08fc8a70 343 #elif defined(TARGET_STM32L152RC)
mbedAustin 11:cada08fc8a70 344 #define INITIAL_SP (0x20008000UL)
mbedAustin 11:cada08fc8a70 345
mbedAustin 11:cada08fc8a70 346
mbedAustin 11:cada08fc8a70 347 #else
mbedAustin 11:cada08fc8a70 348 #error "no target defined"
mbedAustin 11:cada08fc8a70 349
mbedAustin 11:cada08fc8a70 350 #endif
mbedAustin 11:cada08fc8a70 351
mbedAustin 11:cada08fc8a70 352 #ifdef __CC_ARM
mbedAustin 11:cada08fc8a70 353 extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[];
mbedAustin 11:cada08fc8a70 354 #define HEAP_START (Image$$RW_IRAM1$$ZI$$Limit)
mbedAustin 11:cada08fc8a70 355 #elif defined(__GNUC__)
mbedAustin 11:cada08fc8a70 356 extern uint32_t __end__[];
mbedAustin 11:cada08fc8a70 357 #define HEAP_START (__end__)
mbedAustin 11:cada08fc8a70 358 #elif defined(__ICCARM__)
mbedAustin 11:cada08fc8a70 359 #pragma section="HEAP"
mbedAustin 11:cada08fc8a70 360 #define HEAP_START (void *)__section_begin("HEAP")
mbedAustin 11:cada08fc8a70 361 #endif
mbedAustin 11:cada08fc8a70 362
mbedAustin 11:cada08fc8a70 363 void set_main_stack(void) {
mbedAustin 11:cada08fc8a70 364 // That is the bottom of the main stack block: no collision detection
mbedAustin 11:cada08fc8a70 365 os_thread_def_main.stack_pointer = HEAP_START;
mbedAustin 11:cada08fc8a70 366
mbedAustin 11:cada08fc8a70 367 // Leave OS_SCHEDULERSTKSIZE words for the scheduler and interrupts
mbedAustin 11:cada08fc8a70 368 os_thread_def_main.stacksize = (INITIAL_SP - (unsigned int)HEAP_START) - (OS_SCHEDULERSTKSIZE * 4);
mbedAustin 11:cada08fc8a70 369 }
mbedAustin 11:cada08fc8a70 370
mbedAustin 11:cada08fc8a70 371 #if defined (__CC_ARM)
mbedAustin 11:cada08fc8a70 372 #ifdef __MICROLIB
mbedAustin 11:cada08fc8a70 373 void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF")));
mbedAustin 11:cada08fc8a70 374 void _main_init (void) {
mbedAustin 11:cada08fc8a70 375 osKernelInitialize();
mbedAustin 11:cada08fc8a70 376 set_main_stack();
mbedAustin 11:cada08fc8a70 377 osThreadCreate(&os_thread_def_main, NULL);
mbedAustin 11:cada08fc8a70 378 osKernelStart();
mbedAustin 11:cada08fc8a70 379 for (;;);
mbedAustin 11:cada08fc8a70 380 }
mbedAustin 11:cada08fc8a70 381 #else
mbedAustin 11:cada08fc8a70 382
mbedAustin 11:cada08fc8a70 383 /* The single memory model is checking for stack collision at run time, verifing
mbedAustin 11:cada08fc8a70 384 that the heap pointer is underneath the stack pointer.
mbedAustin 11:cada08fc8a70 385
mbedAustin 11:cada08fc8a70 386 With the RTOS there is not only one stack above the heap, there are multiple
mbedAustin 11:cada08fc8a70 387 stacks and some of them are underneath the heap pointer.
mbedAustin 11:cada08fc8a70 388 */
mbedAustin 11:cada08fc8a70 389 #pragma import(__use_two_region_memory)
mbedAustin 11:cada08fc8a70 390
mbedAustin 11:cada08fc8a70 391 __asm void __rt_entry (void) {
mbedAustin 11:cada08fc8a70 392
mbedAustin 11:cada08fc8a70 393 IMPORT __user_setup_stackheap
mbedAustin 11:cada08fc8a70 394 IMPORT __rt_lib_init
mbedAustin 11:cada08fc8a70 395 IMPORT os_thread_def_main
mbedAustin 11:cada08fc8a70 396 IMPORT osKernelInitialize
mbedAustin 11:cada08fc8a70 397 IMPORT set_main_stack
mbedAustin 11:cada08fc8a70 398 IMPORT osKernelStart
mbedAustin 11:cada08fc8a70 399 IMPORT osThreadCreate
mbedAustin 11:cada08fc8a70 400 IMPORT exit
mbedAustin 11:cada08fc8a70 401
mbedAustin 11:cada08fc8a70 402 BL __user_setup_stackheap
mbedAustin 11:cada08fc8a70 403 MOV R1,R2
mbedAustin 11:cada08fc8a70 404 BL __rt_lib_init
mbedAustin 11:cada08fc8a70 405 BL osKernelInitialize
mbedAustin 11:cada08fc8a70 406 BL set_main_stack
mbedAustin 11:cada08fc8a70 407 LDR R0,=os_thread_def_main
mbedAustin 11:cada08fc8a70 408 MOVS R1,#0
mbedAustin 11:cada08fc8a70 409 BL osThreadCreate
mbedAustin 11:cada08fc8a70 410 BL osKernelStart
mbedAustin 11:cada08fc8a70 411 BL exit
mbedAustin 11:cada08fc8a70 412
mbedAustin 11:cada08fc8a70 413 ALIGN
mbedAustin 11:cada08fc8a70 414 }
mbedAustin 11:cada08fc8a70 415 #endif
mbedAustin 11:cada08fc8a70 416
mbedAustin 11:cada08fc8a70 417 #elif defined (__GNUC__)
mbedAustin 11:cada08fc8a70 418
mbedAustin 11:cada08fc8a70 419 #ifdef __CS3__
mbedAustin 11:cada08fc8a70 420
mbedAustin 11:cada08fc8a70 421 /* CS3 start_c routine.
mbedAustin 11:cada08fc8a70 422 *
mbedAustin 11:cada08fc8a70 423 * Copyright (c) 2006, 2007 CodeSourcery Inc
mbedAustin 11:cada08fc8a70 424 *
mbedAustin 11:cada08fc8a70 425 * The authors hereby grant permission to use, copy, modify, distribute,
mbedAustin 11:cada08fc8a70 426 * and license this software and its documentation for any purpose, provided
mbedAustin 11:cada08fc8a70 427 * that existing copyright notices are retained in all copies and that this
mbedAustin 11:cada08fc8a70 428 * notice is included verbatim in any distributions. No written agreement,
mbedAustin 11:cada08fc8a70 429 * license, or royalty fee is required for any of the authorized uses.
mbedAustin 11:cada08fc8a70 430 * Modifications to this software may be copyrighted by their authors
mbedAustin 11:cada08fc8a70 431 * and need not follow the licensing terms described here, provided that
mbedAustin 11:cada08fc8a70 432 * the new terms are clearly indicated on the first page of each file where
mbedAustin 11:cada08fc8a70 433 * they apply.
mbedAustin 11:cada08fc8a70 434 */
mbedAustin 11:cada08fc8a70 435
mbedAustin 11:cada08fc8a70 436 #include "cs3.h"
mbedAustin 11:cada08fc8a70 437
mbedAustin 11:cada08fc8a70 438 extern void __libc_init_array (void);
mbedAustin 11:cada08fc8a70 439
mbedAustin 11:cada08fc8a70 440 __attribute ((noreturn)) void __cs3_start_c (void){
mbedAustin 11:cada08fc8a70 441 unsigned regions = __cs3_region_num;
mbedAustin 11:cada08fc8a70 442 const struct __cs3_region *rptr = __cs3_regions;
mbedAustin 11:cada08fc8a70 443
mbedAustin 11:cada08fc8a70 444 /* Initialize memory */
mbedAustin 11:cada08fc8a70 445 for (regions = __cs3_region_num, rptr = __cs3_regions; regions--; rptr++) {
mbedAustin 11:cada08fc8a70 446 long long *src = (long long *)rptr->init;
mbedAustin 11:cada08fc8a70 447 long long *dst = (long long *)rptr->data;
mbedAustin 11:cada08fc8a70 448 unsigned limit = rptr->init_size;
mbedAustin 11:cada08fc8a70 449 unsigned count;
mbedAustin 11:cada08fc8a70 450
mbedAustin 11:cada08fc8a70 451 if (src != dst)
mbedAustin 11:cada08fc8a70 452 for (count = 0; count != limit; count += sizeof (long long))
mbedAustin 11:cada08fc8a70 453 *dst++ = *src++;
mbedAustin 11:cada08fc8a70 454 else
mbedAustin 11:cada08fc8a70 455 dst = (long long *)((char *)dst + limit);
mbedAustin 11:cada08fc8a70 456 limit = rptr->zero_size;
mbedAustin 11:cada08fc8a70 457 for (count = 0; count != limit; count += sizeof (long long))
mbedAustin 11:cada08fc8a70 458 *dst++ = 0;
mbedAustin 11:cada08fc8a70 459 }
mbedAustin 11:cada08fc8a70 460
mbedAustin 11:cada08fc8a70 461 /* Run initializers. */
mbedAustin 11:cada08fc8a70 462 __libc_init_array ();
mbedAustin 11:cada08fc8a70 463
mbedAustin 11:cada08fc8a70 464 osKernelInitialize();
mbedAustin 11:cada08fc8a70 465 set_main_stack();
mbedAustin 11:cada08fc8a70 466 osThreadCreate(&os_thread_def_main, NULL);
mbedAustin 11:cada08fc8a70 467 osKernelStart();
mbedAustin 11:cada08fc8a70 468 for (;;);
mbedAustin 11:cada08fc8a70 469 }
mbedAustin 11:cada08fc8a70 470
mbedAustin 11:cada08fc8a70 471 #else
mbedAustin 11:cada08fc8a70 472
mbedAustin 11:cada08fc8a70 473 __attribute__((naked)) void software_init_hook (void) {
mbedAustin 11:cada08fc8a70 474 __asm (
mbedAustin 11:cada08fc8a70 475 ".syntax unified\n"
mbedAustin 11:cada08fc8a70 476 ".thumb\n"
mbedAustin 11:cada08fc8a70 477 "movs r0,#0\n"
mbedAustin 11:cada08fc8a70 478 "movs r1,#0\n"
mbedAustin 11:cada08fc8a70 479 "mov r4,r0\n"
mbedAustin 11:cada08fc8a70 480 "mov r5,r1\n"
mbedAustin 11:cada08fc8a70 481 "ldr r0,= __libc_fini_array\n"
mbedAustin 11:cada08fc8a70 482 "bl atexit\n"
mbedAustin 11:cada08fc8a70 483 "bl __libc_init_array\n"
mbedAustin 11:cada08fc8a70 484 "mov r0,r4\n"
mbedAustin 11:cada08fc8a70 485 "mov r1,r5\n"
mbedAustin 11:cada08fc8a70 486 "bl osKernelInitialize\n"
mbedAustin 11:cada08fc8a70 487 "bl set_main_stack\n"
mbedAustin 11:cada08fc8a70 488 "ldr r0,=os_thread_def_main\n"
mbedAustin 11:cada08fc8a70 489 "movs r1,#0\n"
mbedAustin 11:cada08fc8a70 490 "bl osThreadCreate\n"
mbedAustin 11:cada08fc8a70 491 "bl osKernelStart\n"
mbedAustin 11:cada08fc8a70 492 "bl exit\n"
mbedAustin 11:cada08fc8a70 493 );
mbedAustin 11:cada08fc8a70 494 }
mbedAustin 11:cada08fc8a70 495
mbedAustin 11:cada08fc8a70 496 #endif
mbedAustin 11:cada08fc8a70 497
mbedAustin 11:cada08fc8a70 498 #elif defined (__ICCARM__)
mbedAustin 11:cada08fc8a70 499
mbedAustin 11:cada08fc8a70 500 extern void* __vector_table;
mbedAustin 11:cada08fc8a70 501 extern int __low_level_init(void);
mbedAustin 11:cada08fc8a70 502 extern void __iar_data_init3(void);
mbedAustin 11:cada08fc8a70 503 extern __weak void __iar_init_core( void );
mbedAustin 11:cada08fc8a70 504 extern __weak void __iar_init_vfp( void );
mbedAustin 11:cada08fc8a70 505 extern void __iar_dynamic_initialization(void);
mbedAustin 11:cada08fc8a70 506 extern void mbed_sdk_init(void);
mbedAustin 11:cada08fc8a70 507 extern void exit(int arg);
mbedAustin 11:cada08fc8a70 508
mbedAustin 11:cada08fc8a70 509 #pragma required=__vector_table
mbedAustin 11:cada08fc8a70 510 void __iar_program_start( void )
mbedAustin 11:cada08fc8a70 511 {
mbedAustin 11:cada08fc8a70 512 __iar_init_core();
mbedAustin 11:cada08fc8a70 513 __iar_init_vfp();
mbedAustin 11:cada08fc8a70 514
mbedAustin 11:cada08fc8a70 515 int a;
mbedAustin 11:cada08fc8a70 516
mbedAustin 11:cada08fc8a70 517 if (__low_level_init() != 0) {
mbedAustin 11:cada08fc8a70 518 __iar_data_init3();
mbedAustin 11:cada08fc8a70 519 mbed_sdk_init();
mbedAustin 11:cada08fc8a70 520 __iar_dynamic_initialization();
mbedAustin 11:cada08fc8a70 521 }
mbedAustin 11:cada08fc8a70 522 osKernelInitialize();
mbedAustin 11:cada08fc8a70 523 set_main_stack();
mbedAustin 11:cada08fc8a70 524 osThreadCreate(&os_thread_def_main, NULL);
mbedAustin 11:cada08fc8a70 525 a = osKernelStart();
mbedAustin 11:cada08fc8a70 526 exit(a);
mbedAustin 11:cada08fc8a70 527
mbedAustin 11:cada08fc8a70 528 }
mbedAustin 11:cada08fc8a70 529
mbedAustin 11:cada08fc8a70 530 #endif
mbedAustin 11:cada08fc8a70 531
mbedAustin 11:cada08fc8a70 532
mbedAustin 11:cada08fc8a70 533 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 534 * end of file
mbedAustin 11:cada08fc8a70 535 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 536
mbedAustin 11:cada08fc8a70 537