Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mkersh3 0:e7ca326e76ee 1 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 2 * RL-ARM - RTX
mkersh3 0:e7ca326e76ee 3 *----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 4 * Name: RTX_CM_LIB.H
mkersh3 0:e7ca326e76ee 5 * Purpose: RTX Kernel System Configuration
mkersh3 0:e7ca326e76ee 6 * Rev.: V4.50
mkersh3 0:e7ca326e76ee 7 *----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 8 *
mkersh3 0:e7ca326e76ee 9 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
mkersh3 0:e7ca326e76ee 10 * All rights reserved.
mkersh3 0:e7ca326e76ee 11 * Redistribution and use in source and binary forms, with or without
mkersh3 0:e7ca326e76ee 12 * modification, are permitted provided that the following conditions are met:
mkersh3 0:e7ca326e76ee 13 * - Redistributions of source code must retain the above copyright
mkersh3 0:e7ca326e76ee 14 * notice, this list of conditions and the following disclaimer.
mkersh3 0:e7ca326e76ee 15 * - Redistributions in binary form must reproduce the above copyright
mkersh3 0:e7ca326e76ee 16 * notice, this list of conditions and the following disclaimer in the
mkersh3 0:e7ca326e76ee 17 * documentation and/or other materials provided with the distribution.
mkersh3 0:e7ca326e76ee 18 * - Neither the name of ARM nor the names of its contributors may be used
mkersh3 0:e7ca326e76ee 19 * to endorse or promote products derived from this software without
mkersh3 0:e7ca326e76ee 20 * specific prior written permission.
mkersh3 0:e7ca326e76ee 21 *
mkersh3 0:e7ca326e76ee 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mkersh3 0:e7ca326e76ee 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mkersh3 0:e7ca326e76ee 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
mkersh3 0:e7ca326e76ee 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
mkersh3 0:e7ca326e76ee 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
mkersh3 0:e7ca326e76ee 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
mkersh3 0:e7ca326e76ee 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mkersh3 0:e7ca326e76ee 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mkersh3 0:e7ca326e76ee 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
mkersh3 0:e7ca326e76ee 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mkersh3 0:e7ca326e76ee 32 * POSSIBILITY OF SUCH DAMAGE.
mkersh3 0:e7ca326e76ee 33 *---------------------------------------------------------------------------*/
mkersh3 0:e7ca326e76ee 34
mkersh3 0:e7ca326e76ee 35 #if defined (__CC_ARM)
mkersh3 0:e7ca326e76ee 36 #pragma O3
mkersh3 0:e7ca326e76ee 37 #define __USED __attribute__((used))
mkersh3 0:e7ca326e76ee 38 #elif defined (__GNUC__)
mkersh3 0:e7ca326e76ee 39 #pragma GCC optimize ("O3")
mkersh3 0:e7ca326e76ee 40 #define __USED __attribute__((used))
mkersh3 0:e7ca326e76ee 41 #elif defined (__ICCARM__)
mkersh3 0:e7ca326e76ee 42 #define __USED __root
mkersh3 0:e7ca326e76ee 43 #endif
mkersh3 0:e7ca326e76ee 44
mkersh3 0:e7ca326e76ee 45
mkersh3 0:e7ca326e76ee 46 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 47 * Definitions
mkersh3 0:e7ca326e76ee 48 *---------------------------------------------------------------------------*/
mkersh3 0:e7ca326e76ee 49
mkersh3 0:e7ca326e76ee 50 #define _declare_box(pool,size,cnt) uint32_t pool[(((size)+3)/4)*(cnt) + 3]
mkersh3 0:e7ca326e76ee 51 #define _declare_box8(pool,size,cnt) uint64_t pool[(((size)+7)/8)*(cnt) + 2]
mkersh3 0:e7ca326e76ee 52
mkersh3 0:e7ca326e76ee 53 #define OS_TCB_SIZE 48
mkersh3 0:e7ca326e76ee 54 #define OS_TMR_SIZE 8
mkersh3 0:e7ca326e76ee 55
mkersh3 0:e7ca326e76ee 56 #if defined (__CC_ARM) && !defined (__MICROLIB)
mkersh3 0:e7ca326e76ee 57
mkersh3 0:e7ca326e76ee 58 typedef void *OS_ID;
mkersh3 0:e7ca326e76ee 59 typedef uint32_t OS_TID;
mkersh3 0:e7ca326e76ee 60 typedef uint32_t OS_MUT[3];
mkersh3 0:e7ca326e76ee 61 typedef uint32_t OS_RESULT;
mkersh3 0:e7ca326e76ee 62
mkersh3 0:e7ca326e76ee 63 #define runtask_id() rt_tsk_self()
mkersh3 0:e7ca326e76ee 64 #define mutex_init(m) rt_mut_init(m)
mkersh3 0:e7ca326e76ee 65 #define mutex_wait(m) os_mut_wait(m,0xFFFF)
mkersh3 0:e7ca326e76ee 66 #define mutex_rel(m) os_mut_release(m)
mkersh3 0:e7ca326e76ee 67
mkersh3 0:e7ca326e76ee 68 extern OS_TID rt_tsk_self (void);
mkersh3 0:e7ca326e76ee 69 extern void rt_mut_init (OS_ID mutex);
mkersh3 0:e7ca326e76ee 70 extern OS_RESULT rt_mut_release (OS_ID mutex);
mkersh3 0:e7ca326e76ee 71 extern OS_RESULT rt_mut_wait (OS_ID mutex, uint16_t timeout);
mkersh3 0:e7ca326e76ee 72
mkersh3 0:e7ca326e76ee 73 #define os_mut_wait(mutex,timeout) _os_mut_wait((uint32_t)rt_mut_wait,mutex,timeout)
mkersh3 0:e7ca326e76ee 74 #define os_mut_release(mutex) _os_mut_release((uint32_t)rt_mut_release,mutex)
mkersh3 0:e7ca326e76ee 75
mkersh3 0:e7ca326e76ee 76 OS_RESULT _os_mut_release (uint32_t p, OS_ID mutex) __svc_indirect(0);
mkersh3 0:e7ca326e76ee 77 OS_RESULT _os_mut_wait (uint32_t p, OS_ID mutex, uint16_t timeout) __svc_indirect(0);
mkersh3 0:e7ca326e76ee 78
mkersh3 0:e7ca326e76ee 79 #endif
mkersh3 0:e7ca326e76ee 80
mkersh3 0:e7ca326e76ee 81
mkersh3 0:e7ca326e76ee 82 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 83 * Global Variables
mkersh3 0:e7ca326e76ee 84 *---------------------------------------------------------------------------*/
mkersh3 0:e7ca326e76ee 85
mkersh3 0:e7ca326e76ee 86 #if (OS_TIMERS != 0)
mkersh3 0:e7ca326e76ee 87 #define OS_TASK_CNT (OS_TASKCNT + 1)
mkersh3 0:e7ca326e76ee 88 #else
mkersh3 0:e7ca326e76ee 89 #define OS_TASK_CNT OS_TASKCNT
mkersh3 0:e7ca326e76ee 90 #endif
mkersh3 0:e7ca326e76ee 91
mkersh3 0:e7ca326e76ee 92 uint16_t const os_maxtaskrun = OS_TASK_CNT;
mkersh3 0:e7ca326e76ee 93 uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT;
mkersh3 0:e7ca326e76ee 94 uint32_t const os_trv = OS_TRV;
mkersh3 0:e7ca326e76ee 95 uint8_t const os_flags = OS_RUNPRIV;
mkersh3 0:e7ca326e76ee 96
mkersh3 0:e7ca326e76ee 97 /* Export following defines to uVision debugger. */
mkersh3 0:e7ca326e76ee 98 __USED uint32_t const os_clockrate = OS_TICK;
mkersh3 0:e7ca326e76ee 99 __USED uint32_t const os_timernum = 0;
mkersh3 0:e7ca326e76ee 100
mkersh3 0:e7ca326e76ee 101 /* Stack for the os_idle_demon */
mkersh3 0:e7ca326e76ee 102 unsigned int idle_task_stack[OS_IDLESTKSIZE];
mkersh3 0:e7ca326e76ee 103 unsigned short const idle_task_stack_size = OS_IDLESTKSIZE;
mkersh3 0:e7ca326e76ee 104
mkersh3 0:e7ca326e76ee 105 #ifndef OS_FIFOSZ
mkersh3 0:e7ca326e76ee 106 #define OS_FIFOSZ 16
mkersh3 0:e7ca326e76ee 107 #endif
mkersh3 0:e7ca326e76ee 108
mkersh3 0:e7ca326e76ee 109 /* Fifo Queue buffer for ISR requests.*/
mkersh3 0:e7ca326e76ee 110 uint32_t os_fifo[OS_FIFOSZ*2+1];
mkersh3 0:e7ca326e76ee 111 uint8_t const os_fifo_size = OS_FIFOSZ;
mkersh3 0:e7ca326e76ee 112
mkersh3 0:e7ca326e76ee 113 /* An array of Active task pointers. */
mkersh3 0:e7ca326e76ee 114 void *os_active_TCB[OS_TASK_CNT];
mkersh3 0:e7ca326e76ee 115
mkersh3 0:e7ca326e76ee 116 /* User Timers Resources */
mkersh3 0:e7ca326e76ee 117 #if (OS_TIMERS != 0)
mkersh3 0:e7ca326e76ee 118 extern void osTimerThread (void const *argument);
mkersh3 0:e7ca326e76ee 119 osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ);
mkersh3 0:e7ca326e76ee 120 osThreadId osThreadId_osTimerThread;
mkersh3 0:e7ca326e76ee 121 osMessageQDef(osTimerMessageQ, OS_TIMERCBQS, void *);
mkersh3 0:e7ca326e76ee 122 osMessageQId osMessageQId_osTimerMessageQ;
mkersh3 0:e7ca326e76ee 123 #else
mkersh3 0:e7ca326e76ee 124 osThreadDef_t os_thread_def_osTimerThread = { NULL };
mkersh3 0:e7ca326e76ee 125 osThreadId osThreadId_osTimerThread;
mkersh3 0:e7ca326e76ee 126 osMessageQDef(osTimerMessageQ, 0, void *);
mkersh3 0:e7ca326e76ee 127 osMessageQId osMessageQId_osTimerMessageQ;
mkersh3 0:e7ca326e76ee 128 #endif
mkersh3 0:e7ca326e76ee 129
mkersh3 0:e7ca326e76ee 130
mkersh3 0:e7ca326e76ee 131 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 132 * RTX Optimizations (empty functions)
mkersh3 0:e7ca326e76ee 133 *---------------------------------------------------------------------------*/
mkersh3 0:e7ca326e76ee 134
mkersh3 0:e7ca326e76ee 135 #if OS_ROBIN == 0
mkersh3 0:e7ca326e76ee 136 void rt_init_robin (void) {;}
mkersh3 0:e7ca326e76ee 137 void rt_chk_robin (void) {;}
mkersh3 0:e7ca326e76ee 138 #endif
mkersh3 0:e7ca326e76ee 139
mkersh3 0:e7ca326e76ee 140 #if OS_STKCHECK == 0
mkersh3 0:e7ca326e76ee 141 void rt_stk_check (void) {;}
mkersh3 0:e7ca326e76ee 142 #endif
mkersh3 0:e7ca326e76ee 143
mkersh3 0:e7ca326e76ee 144
mkersh3 0:e7ca326e76ee 145 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 146 * Standard Library multithreading interface
mkersh3 0:e7ca326e76ee 147 *---------------------------------------------------------------------------*/
mkersh3 0:e7ca326e76ee 148
mkersh3 0:e7ca326e76ee 149 #if defined (__CC_ARM) && !defined (__MICROLIB)
mkersh3 0:e7ca326e76ee 150 static OS_MUT std_libmutex[OS_MUTEXCNT];
mkersh3 0:e7ca326e76ee 151 static uint32_t nr_mutex;
mkersh3 0:e7ca326e76ee 152
mkersh3 0:e7ca326e76ee 153 /*--------------------------- _mutex_initialize -----------------------------*/
mkersh3 0:e7ca326e76ee 154
mkersh3 0:e7ca326e76ee 155 int _mutex_initialize (OS_ID *mutex) {
mkersh3 0:e7ca326e76ee 156 /* Allocate and initialize a system mutex. */
mkersh3 0:e7ca326e76ee 157
mkersh3 0:e7ca326e76ee 158 if (nr_mutex >= OS_MUTEXCNT) {
mkersh3 0:e7ca326e76ee 159 /* If you are here, you need to increase the number OS_MUTEXCNT. */
mkersh3 0:e7ca326e76ee 160 for (;;);
mkersh3 0:e7ca326e76ee 161 }
mkersh3 0:e7ca326e76ee 162 *mutex = &std_libmutex[nr_mutex++];
mkersh3 0:e7ca326e76ee 163 mutex_init (*mutex);
mkersh3 0:e7ca326e76ee 164 return (1);
mkersh3 0:e7ca326e76ee 165 }
mkersh3 0:e7ca326e76ee 166
mkersh3 0:e7ca326e76ee 167
mkersh3 0:e7ca326e76ee 168 /*--------------------------- _mutex_acquire --------------------------------*/
mkersh3 0:e7ca326e76ee 169
mkersh3 0:e7ca326e76ee 170 __attribute__((used)) void _mutex_acquire (OS_ID *mutex) {
mkersh3 0:e7ca326e76ee 171 /* Acquire a system mutex, lock stdlib resources. */
mkersh3 0:e7ca326e76ee 172 if (runtask_id ()) {
mkersh3 0:e7ca326e76ee 173 /* RTX running, acquire a mutex. */
mkersh3 0:e7ca326e76ee 174 mutex_wait (*mutex);
mkersh3 0:e7ca326e76ee 175 }
mkersh3 0:e7ca326e76ee 176 }
mkersh3 0:e7ca326e76ee 177
mkersh3 0:e7ca326e76ee 178
mkersh3 0:e7ca326e76ee 179 /*--------------------------- _mutex_release --------------------------------*/
mkersh3 0:e7ca326e76ee 180
mkersh3 0:e7ca326e76ee 181 __attribute__((used)) void _mutex_release (OS_ID *mutex) {
mkersh3 0:e7ca326e76ee 182 /* Release a system mutex, unlock stdlib resources. */
mkersh3 0:e7ca326e76ee 183 if (runtask_id ()) {
mkersh3 0:e7ca326e76ee 184 /* RTX runnning, release a mutex. */
mkersh3 0:e7ca326e76ee 185 mutex_rel (*mutex);
mkersh3 0:e7ca326e76ee 186 }
mkersh3 0:e7ca326e76ee 187 }
mkersh3 0:e7ca326e76ee 188
mkersh3 0:e7ca326e76ee 189 #endif
mkersh3 0:e7ca326e76ee 190
mkersh3 0:e7ca326e76ee 191
mkersh3 0:e7ca326e76ee 192 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 193 * RTX Startup
mkersh3 0:e7ca326e76ee 194 *---------------------------------------------------------------------------*/
mkersh3 0:e7ca326e76ee 195
mkersh3 0:e7ca326e76ee 196 /* Main Thread definition */
mkersh3 0:e7ca326e76ee 197 extern int main (void);
mkersh3 0:e7ca326e76ee 198 osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 0, NULL};
mkersh3 0:e7ca326e76ee 199
mkersh3 0:e7ca326e76ee 200 #if defined (__CC_ARM)
mkersh3 0:e7ca326e76ee 201
mkersh3 0:e7ca326e76ee 202 // This define should be probably moved to the CMSIS layer
mkersh3 0:e7ca326e76ee 203 #ifdef TARGET_LPC1768
mkersh3 0:e7ca326e76ee 204 #define INITIAL_SP (0x10008000UL)
mkersh3 0:e7ca326e76ee 205
mkersh3 0:e7ca326e76ee 206 #elif TARGET_LPC11U24
mkersh3 0:e7ca326e76ee 207 #define INITIAL_SP (0x10001000UL)
mkersh3 0:e7ca326e76ee 208
mkersh3 0:e7ca326e76ee 209 #endif
mkersh3 0:e7ca326e76ee 210
mkersh3 0:e7ca326e76ee 211 extern unsigned char Image$$RW_IRAM1$$ZI$$Limit[];
mkersh3 0:e7ca326e76ee 212
mkersh3 0:e7ca326e76ee 213 void set_main_stack(void) {
mkersh3 0:e7ca326e76ee 214 // Leave OS_SCHEDULERSTKSIZE words for the scheduler and interrupts
mkersh3 0:e7ca326e76ee 215 os_thread_def_main.stack_pointer = Image$$RW_IRAM1$$ZI$$Limit;
mkersh3 0:e7ca326e76ee 216 os_thread_def_main.stacksize = (INITIAL_SP - (unsigned int)Image$$RW_IRAM1$$ZI$$Limit) - (OS_SCHEDULERSTKSIZE * 4);
mkersh3 0:e7ca326e76ee 217 }
mkersh3 0:e7ca326e76ee 218
mkersh3 0:e7ca326e76ee 219 #ifdef __MICROLIB
mkersh3 0:e7ca326e76ee 220 void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF")));
mkersh3 0:e7ca326e76ee 221 void _main_init (void) {
mkersh3 0:e7ca326e76ee 222 osKernelInitialize();
mkersh3 0:e7ca326e76ee 223 set_main_stack();
mkersh3 0:e7ca326e76ee 224 osThreadCreate(&os_thread_def_main, NULL);
mkersh3 0:e7ca326e76ee 225 osKernelStart();
mkersh3 0:e7ca326e76ee 226 for (;;);
mkersh3 0:e7ca326e76ee 227 }
mkersh3 0:e7ca326e76ee 228 #else
mkersh3 0:e7ca326e76ee 229
mkersh3 0:e7ca326e76ee 230 /* The single memory model is checking for stack collision at run time, verifing
mkersh3 0:e7ca326e76ee 231 that the heap pointer is underneath the stack pointer.
mkersh3 0:e7ca326e76ee 232
mkersh3 0:e7ca326e76ee 233 With the RTOS there is not only one stack above the heap, there are multiple
mkersh3 0:e7ca326e76ee 234 stacks and some of them are underneath the heap pointer.
mkersh3 0:e7ca326e76ee 235 */
mkersh3 0:e7ca326e76ee 236 #pragma import(__use_two_region_memory)
mkersh3 0:e7ca326e76ee 237
mkersh3 0:e7ca326e76ee 238 __asm void __rt_entry (void) {
mkersh3 0:e7ca326e76ee 239
mkersh3 0:e7ca326e76ee 240 IMPORT __user_setup_stackheap
mkersh3 0:e7ca326e76ee 241 IMPORT __rt_lib_init
mkersh3 0:e7ca326e76ee 242 IMPORT os_thread_def_main
mkersh3 0:e7ca326e76ee 243 IMPORT osKernelInitialize
mkersh3 0:e7ca326e76ee 244 IMPORT set_main_stack
mkersh3 0:e7ca326e76ee 245 IMPORT osKernelStart
mkersh3 0:e7ca326e76ee 246 IMPORT osThreadCreate
mkersh3 0:e7ca326e76ee 247 IMPORT exit
mkersh3 0:e7ca326e76ee 248
mkersh3 0:e7ca326e76ee 249 BL __user_setup_stackheap
mkersh3 0:e7ca326e76ee 250 MOV R1,R2
mkersh3 0:e7ca326e76ee 251 BL __rt_lib_init
mkersh3 0:e7ca326e76ee 252 BL osKernelInitialize
mkersh3 0:e7ca326e76ee 253 BL set_main_stack
mkersh3 0:e7ca326e76ee 254 LDR R0,=os_thread_def_main
mkersh3 0:e7ca326e76ee 255 MOVS R1,#0
mkersh3 0:e7ca326e76ee 256 BL osThreadCreate
mkersh3 0:e7ca326e76ee 257 BL osKernelStart
mkersh3 0:e7ca326e76ee 258 BL exit
mkersh3 0:e7ca326e76ee 259
mkersh3 0:e7ca326e76ee 260 ALIGN
mkersh3 0:e7ca326e76ee 261 }
mkersh3 0:e7ca326e76ee 262 #endif
mkersh3 0:e7ca326e76ee 263
mkersh3 0:e7ca326e76ee 264 #elif defined (__GNUC__)
mkersh3 0:e7ca326e76ee 265
mkersh3 0:e7ca326e76ee 266 #ifdef __CS3__
mkersh3 0:e7ca326e76ee 267
mkersh3 0:e7ca326e76ee 268 /* CS3 start_c routine.
mkersh3 0:e7ca326e76ee 269 *
mkersh3 0:e7ca326e76ee 270 * Copyright (c) 2006, 2007 CodeSourcery Inc
mkersh3 0:e7ca326e76ee 271 *
mkersh3 0:e7ca326e76ee 272 * The authors hereby grant permission to use, copy, modify, distribute,
mkersh3 0:e7ca326e76ee 273 * and license this software and its documentation for any purpose, provided
mkersh3 0:e7ca326e76ee 274 * that existing copyright notices are retained in all copies and that this
mkersh3 0:e7ca326e76ee 275 * notice is included verbatim in any distributions. No written agreement,
mkersh3 0:e7ca326e76ee 276 * license, or royalty fee is required for any of the authorized uses.
mkersh3 0:e7ca326e76ee 277 * Modifications to this software may be copyrighted by their authors
mkersh3 0:e7ca326e76ee 278 * and need not follow the licensing terms described here, provided that
mkersh3 0:e7ca326e76ee 279 * the new terms are clearly indicated on the first page of each file where
mkersh3 0:e7ca326e76ee 280 * they apply.
mkersh3 0:e7ca326e76ee 281 */
mkersh3 0:e7ca326e76ee 282
mkersh3 0:e7ca326e76ee 283 #include "cs3.h"
mkersh3 0:e7ca326e76ee 284
mkersh3 0:e7ca326e76ee 285 extern void __libc_init_array (void);
mkersh3 0:e7ca326e76ee 286
mkersh3 0:e7ca326e76ee 287 __attribute ((noreturn)) void __cs3_start_c (void){
mkersh3 0:e7ca326e76ee 288 unsigned regions = __cs3_region_num;
mkersh3 0:e7ca326e76ee 289 const struct __cs3_region *rptr = __cs3_regions;
mkersh3 0:e7ca326e76ee 290
mkersh3 0:e7ca326e76ee 291 /* Initialize memory */
mkersh3 0:e7ca326e76ee 292 for (regions = __cs3_region_num, rptr = __cs3_regions; regions--; rptr++) {
mkersh3 0:e7ca326e76ee 293 long long *src = (long long *)rptr->init;
mkersh3 0:e7ca326e76ee 294 long long *dst = (long long *)rptr->data;
mkersh3 0:e7ca326e76ee 295 unsigned limit = rptr->init_size;
mkersh3 0:e7ca326e76ee 296 unsigned count;
mkersh3 0:e7ca326e76ee 297
mkersh3 0:e7ca326e76ee 298 if (src != dst)
mkersh3 0:e7ca326e76ee 299 for (count = 0; count != limit; count += sizeof (long long))
mkersh3 0:e7ca326e76ee 300 *dst++ = *src++;
mkersh3 0:e7ca326e76ee 301 else
mkersh3 0:e7ca326e76ee 302 dst = (long long *)((char *)dst + limit);
mkersh3 0:e7ca326e76ee 303 limit = rptr->zero_size;
mkersh3 0:e7ca326e76ee 304 for (count = 0; count != limit; count += sizeof (long long))
mkersh3 0:e7ca326e76ee 305 *dst++ = 0;
mkersh3 0:e7ca326e76ee 306 }
mkersh3 0:e7ca326e76ee 307
mkersh3 0:e7ca326e76ee 308 /* Run initializers. */
mkersh3 0:e7ca326e76ee 309 __libc_init_array ();
mkersh3 0:e7ca326e76ee 310
mkersh3 0:e7ca326e76ee 311 osKernelInitialize();
mkersh3 0:e7ca326e76ee 312 osThreadCreate(&os_thread_def_main, NULL);
mkersh3 0:e7ca326e76ee 313 osKernelStart();
mkersh3 0:e7ca326e76ee 314 for (;;);
mkersh3 0:e7ca326e76ee 315 }
mkersh3 0:e7ca326e76ee 316
mkersh3 0:e7ca326e76ee 317 #else
mkersh3 0:e7ca326e76ee 318
mkersh3 0:e7ca326e76ee 319 __attribute__((naked)) void software_init_hook (void) {
mkersh3 0:e7ca326e76ee 320 __asm (
mkersh3 0:e7ca326e76ee 321 ".syntax unified\n"
mkersh3 0:e7ca326e76ee 322 ".thumb\n"
mkersh3 0:e7ca326e76ee 323 "movs r0,#0\n"
mkersh3 0:e7ca326e76ee 324 "movs r1,#0\n"
mkersh3 0:e7ca326e76ee 325 "mov r4,r0\n"
mkersh3 0:e7ca326e76ee 326 "mov r5,r1\n"
mkersh3 0:e7ca326e76ee 327 "ldr r0,= __libc_fini_array\n"
mkersh3 0:e7ca326e76ee 328 "bl atexit\n"
mkersh3 0:e7ca326e76ee 329 "bl __libc_init_array\n"
mkersh3 0:e7ca326e76ee 330 "mov r0,r4\n"
mkersh3 0:e7ca326e76ee 331 "mov r1,r5\n"
mkersh3 0:e7ca326e76ee 332 "bl osKernelInitialize\n"
mkersh3 0:e7ca326e76ee 333 "ldr r0,=os_thread_def_main\n"
mkersh3 0:e7ca326e76ee 334 "movs r1,#0\n"
mkersh3 0:e7ca326e76ee 335 "bl osThreadCreate\n"
mkersh3 0:e7ca326e76ee 336 "bl osKernelStart\n"
mkersh3 0:e7ca326e76ee 337 "bl exit\n"
mkersh3 0:e7ca326e76ee 338 );
mkersh3 0:e7ca326e76ee 339 }
mkersh3 0:e7ca326e76ee 340
mkersh3 0:e7ca326e76ee 341 #endif
mkersh3 0:e7ca326e76ee 342
mkersh3 0:e7ca326e76ee 343 #elif defined (__ICCARM__)
mkersh3 0:e7ca326e76ee 344
mkersh3 0:e7ca326e76ee 345 extern int __low_level_init(void);
mkersh3 0:e7ca326e76ee 346 extern void __iar_data_init3(void);
mkersh3 0:e7ca326e76ee 347 extern void exit(int arg);
mkersh3 0:e7ca326e76ee 348
mkersh3 0:e7ca326e76ee 349 __noreturn __stackless void __cmain(void) {
mkersh3 0:e7ca326e76ee 350 int a;
mkersh3 0:e7ca326e76ee 351
mkersh3 0:e7ca326e76ee 352 if (__low_level_init() != 0) {
mkersh3 0:e7ca326e76ee 353 __iar_data_init3();
mkersh3 0:e7ca326e76ee 354 }
mkersh3 0:e7ca326e76ee 355 osKernelInitialize();
mkersh3 0:e7ca326e76ee 356 osThreadCreate(&os_thread_def_main, NULL);
mkersh3 0:e7ca326e76ee 357 a = osKernelStart();
mkersh3 0:e7ca326e76ee 358 exit(a);
mkersh3 0:e7ca326e76ee 359 }
mkersh3 0:e7ca326e76ee 360
mkersh3 0:e7ca326e76ee 361 #endif
mkersh3 0:e7ca326e76ee 362
mkersh3 0:e7ca326e76ee 363
mkersh3 0:e7ca326e76ee 364 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 365 * end of file
mkersh3 0:e7ca326e76ee 366 *---------------------------------------------------------------------------*/
mkersh3 0:e7ca326e76ee 367