Control a robot over the internet using UDP and a Wifly module (WiFi).

Dependencies:   Motor TextLCD WiflyInterface mbed-rtos mbed

Committer:
apatel336
Date:
Thu Oct 17 13:27:56 2013 +0000
Revision:
0:c0dc3a76f3d4
Initial Release

Who changed what in which revision?

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