skeleton for lab1

Dependencies:   AvailableMemory mbed-rtos mbed

Fork of helloaabbc by 32314 mbed

Committer:
mbed36372
Date:
Fri Apr 04 21:31:22 2014 +0000
Revision:
1:55e99f6e2aa5
Parent:
0:1c8f2727e9f5
SP14_lab1

Who changed what in which revision?

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