Lab Checkoff

Dependencies:   SDFileSystem TextLCD mbed-rtos mbed wave_player FATFileSystem

Committer:
doubster
Date:
Wed Nov 13 20:00:28 2013 +0000
Revision:
0:67dbd54e60d4
Lab Checkoff

Who changed what in which revision?

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