Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

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