desp koval / mbed-rtos

Dependents:   Mecatro_Filtre

Committer:
mecatro_prod
Date:
Mon Mar 15 14:18:11 2021 +0000
Revision:
0:4a2c9c1f5b9e
Pas de changement

Who changed what in which revision?

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