Counter

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

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

Who changed what in which revision?

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