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