ProjetoBB

Dependencies:   F7_Ethernet WebSocketClient mbed mcp3008

Fork of Nucleo_F746ZG_Ethernet by Dieter Graef

Committer:
DieterGraef
Date:
Sat Jun 18 10:49:12 2016 +0000
Revision:
0:f9b6112278fe
Ethernet for the NUCLEO STM32F746 Board Testprogram uses DHCP and NTP to set the clock

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 0:f9b6112278fe 1 /*----------------------------------------------------------------------------
DieterGraef 0:f9b6112278fe 2 * RL-ARM - RTX
DieterGraef 0:f9b6112278fe 3 *----------------------------------------------------------------------------
DieterGraef 0:f9b6112278fe 4 * Name: RTX_CM_LIB.H
DieterGraef 0:f9b6112278fe 5 * Purpose: RTX Kernel System Configuration
DieterGraef 0:f9b6112278fe 6 * Rev.: V4.73
DieterGraef 0:f9b6112278fe 7 *----------------------------------------------------------------------------
DieterGraef 0:f9b6112278fe 8 *
DieterGraef 0:f9b6112278fe 9 * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
DieterGraef 0:f9b6112278fe 10 * All rights reserved.
DieterGraef 0:f9b6112278fe 11 * Redistribution and use in source and binary forms, with or without
DieterGraef 0:f9b6112278fe 12 * modification, are permitted provided that the following conditions are met:
DieterGraef 0:f9b6112278fe 13 * - Redistributions of source code must retain the above copyright
DieterGraef 0:f9b6112278fe 14 * notice, this list of conditions and the following disclaimer.
DieterGraef 0:f9b6112278fe 15 * - Redistributions in binary form must reproduce the above copyright
DieterGraef 0:f9b6112278fe 16 * notice, this list of conditions and the following disclaimer in the
DieterGraef 0:f9b6112278fe 17 * documentation and/or other materials provided with the distribution.
DieterGraef 0:f9b6112278fe 18 * - Neither the name of ARM nor the names of its contributors may be used
DieterGraef 0:f9b6112278fe 19 * to endorse or promote products derived from this software without
DieterGraef 0:f9b6112278fe 20 * specific prior written permission.
DieterGraef 0:f9b6112278fe 21 *
DieterGraef 0:f9b6112278fe 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
DieterGraef 0:f9b6112278fe 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
DieterGraef 0:f9b6112278fe 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
DieterGraef 0:f9b6112278fe 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
DieterGraef 0:f9b6112278fe 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
DieterGraef 0:f9b6112278fe 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
DieterGraef 0:f9b6112278fe 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
DieterGraef 0:f9b6112278fe 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
DieterGraef 0:f9b6112278fe 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
DieterGraef 0:f9b6112278fe 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
DieterGraef 0:f9b6112278fe 32 * POSSIBILITY OF SUCH DAMAGE.
DieterGraef 0:f9b6112278fe 33 *---------------------------------------------------------------------------*/
DieterGraef 0:f9b6112278fe 34
DieterGraef 0:f9b6112278fe 35 #if defined (__CC_ARM)
DieterGraef 0:f9b6112278fe 36 #pragma O3
DieterGraef 0:f9b6112278fe 37 #define __USED __attribute__((used))
DieterGraef 0:f9b6112278fe 38 #elif defined (__GNUC__)
DieterGraef 0:f9b6112278fe 39 #pragma GCC optimize ("O3")
DieterGraef 0:f9b6112278fe 40 #define __USED __attribute__((used))
DieterGraef 0:f9b6112278fe 41 #elif defined (__ICCARM__)
DieterGraef 0:f9b6112278fe 42 #define __USED __root
DieterGraef 0:f9b6112278fe 43 #endif
DieterGraef 0:f9b6112278fe 44
DieterGraef 0:f9b6112278fe 45
DieterGraef 0:f9b6112278fe 46 /*----------------------------------------------------------------------------
DieterGraef 0:f9b6112278fe 47 * Definitions
DieterGraef 0:f9b6112278fe 48 *---------------------------------------------------------------------------*/
DieterGraef 0:f9b6112278fe 49
DieterGraef 0:f9b6112278fe 50 #define _declare_box(pool,size,cnt) uint32_t pool[(((size)+3)/4)*(cnt) + 3]
DieterGraef 0:f9b6112278fe 51 #define _declare_box8(pool,size,cnt) uint64_t pool[(((size)+7)/8)*(cnt) + 2]
DieterGraef 0:f9b6112278fe 52
DieterGraef 0:f9b6112278fe 53 #define OS_TCB_SIZE 52
DieterGraef 0:f9b6112278fe 54 #define OS_TMR_SIZE 8
DieterGraef 0:f9b6112278fe 55
DieterGraef 0:f9b6112278fe 56 #if defined (__CC_ARM) && !defined (__MICROLIB)
DieterGraef 0:f9b6112278fe 57
DieterGraef 0:f9b6112278fe 58 typedef void *OS_ID;
DieterGraef 0:f9b6112278fe 59 typedef uint32_t OS_TID;
DieterGraef 0:f9b6112278fe 60 typedef uint32_t OS_MUT[4];
DieterGraef 0:f9b6112278fe 61 typedef uint32_t OS_RESULT;
DieterGraef 0:f9b6112278fe 62
DieterGraef 0:f9b6112278fe 63 #define runtask_id() rt_tsk_self()
DieterGraef 0:f9b6112278fe 64 #define mutex_init(m) rt_mut_init(m)
DieterGraef 0:f9b6112278fe 65 #define mutex_wait(m) os_mut_wait(m,0xFFFF)
DieterGraef 0:f9b6112278fe 66 #define mutex_rel(m) os_mut_release(m)
DieterGraef 0:f9b6112278fe 67
DieterGraef 0:f9b6112278fe 68 extern OS_TID rt_tsk_self (void);
DieterGraef 0:f9b6112278fe 69 extern void rt_mut_init (OS_ID mutex);
DieterGraef 0:f9b6112278fe 70 extern OS_RESULT rt_mut_release (OS_ID mutex);
DieterGraef 0:f9b6112278fe 71 extern OS_RESULT rt_mut_wait (OS_ID mutex, uint16_t timeout);
DieterGraef 0:f9b6112278fe 72
DieterGraef 0:f9b6112278fe 73 #define os_mut_wait(mutex,timeout) _os_mut_wait((uint32_t)rt_mut_wait,mutex,timeout)
DieterGraef 0:f9b6112278fe 74 #define os_mut_release(mutex) _os_mut_release((uint32_t)rt_mut_release,mutex)
DieterGraef 0:f9b6112278fe 75
DieterGraef 0:f9b6112278fe 76 OS_RESULT _os_mut_release (uint32_t p, OS_ID mutex) __svc_indirect(0);
DieterGraef 0:f9b6112278fe 77 OS_RESULT _os_mut_wait (uint32_t p, OS_ID mutex, uint16_t timeout) __svc_indirect(0);
DieterGraef 0:f9b6112278fe 78
DieterGraef 0:f9b6112278fe 79 #elif defined (__ICCARM__)
DieterGraef 0:f9b6112278fe 80
DieterGraef 0:f9b6112278fe 81 typedef void *OS_ID;
DieterGraef 0:f9b6112278fe 82 typedef uint32_t OS_TID;
DieterGraef 0:f9b6112278fe 83 typedef uint32_t OS_MUT[4];
DieterGraef 0:f9b6112278fe 84 typedef uint32_t OS_RESULT;
DieterGraef 0:f9b6112278fe 85
DieterGraef 0:f9b6112278fe 86 #define runtask_id() rt_tsk_self()
DieterGraef 0:f9b6112278fe 87 #define mutex_init(m) rt_mut_init(m)
DieterGraef 0:f9b6112278fe 88 #define mutex_del(m) os_mut_delete(m)
DieterGraef 0:f9b6112278fe 89 #define mutex_wait(m) os_mut_wait(m,0xFFFF)
DieterGraef 0:f9b6112278fe 90 #define mutex_rel(m) os_mut_release(m)
DieterGraef 0:f9b6112278fe 91
DieterGraef 0:f9b6112278fe 92 extern OS_TID rt_tsk_self (void);
DieterGraef 0:f9b6112278fe 93 extern void rt_mut_init (OS_ID mutex);
DieterGraef 0:f9b6112278fe 94 extern OS_RESULT rt_mut_delete (OS_ID mutex);
DieterGraef 0:f9b6112278fe 95 extern OS_RESULT rt_mut_release (OS_ID mutex);
DieterGraef 0:f9b6112278fe 96 extern OS_RESULT rt_mut_wait (OS_ID mutex, uint16_t timeout);
DieterGraef 0:f9b6112278fe 97
DieterGraef 0:f9b6112278fe 98 #pragma swi_number=0
DieterGraef 0:f9b6112278fe 99 __swi OS_RESULT _os_mut_delete (OS_ID mutex);
DieterGraef 0:f9b6112278fe 100
DieterGraef 0:f9b6112278fe 101 static inline OS_RESULT os_mut_delete(OS_ID mutex)
DieterGraef 0:f9b6112278fe 102 {
DieterGraef 0:f9b6112278fe 103 __asm("mov r12,%0\n" :: "r"(&rt_mut_delete) : "r12" );
DieterGraef 0:f9b6112278fe 104 return _os_mut_delete(mutex);
DieterGraef 0:f9b6112278fe 105 }
DieterGraef 0:f9b6112278fe 106
DieterGraef 0:f9b6112278fe 107 #pragma swi_number=0
DieterGraef 0:f9b6112278fe 108 __swi OS_RESULT _os_mut_release (OS_ID mutex);
DieterGraef 0:f9b6112278fe 109
DieterGraef 0:f9b6112278fe 110 static inline OS_RESULT os_mut_release(OS_ID mutex)
DieterGraef 0:f9b6112278fe 111 {
DieterGraef 0:f9b6112278fe 112 __asm("mov r12,%0\n" :: "r"(&rt_mut_release) : "r12" );
DieterGraef 0:f9b6112278fe 113 return _os_mut_release(mutex);
DieterGraef 0:f9b6112278fe 114 }
DieterGraef 0:f9b6112278fe 115
DieterGraef 0:f9b6112278fe 116 #pragma swi_number=0
DieterGraef 0:f9b6112278fe 117 __swi OS_RESULT _os_mut_wait (OS_ID mutex, uint16_t timeout);
DieterGraef 0:f9b6112278fe 118
DieterGraef 0:f9b6112278fe 119 static inline OS_RESULT os_mut_wait(OS_ID mutex, uint16_t timeout)
DieterGraef 0:f9b6112278fe 120 {
DieterGraef 0:f9b6112278fe 121 __asm("mov r12,%0\n" :: "r"(&rt_mut_wait) : "r12" );
DieterGraef 0:f9b6112278fe 122 return _os_mut_wait(mutex, timeout);
DieterGraef 0:f9b6112278fe 123 }
DieterGraef 0:f9b6112278fe 124
DieterGraef 0:f9b6112278fe 125 #include <yvals.h> /* for include DLib_Thread.h */
DieterGraef 0:f9b6112278fe 126
DieterGraef 0:f9b6112278fe 127 void __iar_system_Mtxinit(__iar_Rmtx *);
DieterGraef 0:f9b6112278fe 128 void __iar_system_Mtxdst(__iar_Rmtx *);
DieterGraef 0:f9b6112278fe 129 void __iar_system_Mtxlock(__iar_Rmtx *);
DieterGraef 0:f9b6112278fe 130 void __iar_system_Mtxunlock(__iar_Rmtx *);
DieterGraef 0:f9b6112278fe 131
DieterGraef 0:f9b6112278fe 132
DieterGraef 0:f9b6112278fe 133
DieterGraef 0:f9b6112278fe 134
DieterGraef 0:f9b6112278fe 135 #endif
DieterGraef 0:f9b6112278fe 136
DieterGraef 0:f9b6112278fe 137
DieterGraef 0:f9b6112278fe 138 /*----------------------------------------------------------------------------
DieterGraef 0:f9b6112278fe 139 * Global Variables
DieterGraef 0:f9b6112278fe 140 *---------------------------------------------------------------------------*/
DieterGraef 0:f9b6112278fe 141
DieterGraef 0:f9b6112278fe 142 #if (OS_TIMERS != 0)
DieterGraef 0:f9b6112278fe 143 #define OS_TASK_CNT (OS_TASKCNT + 1)
DieterGraef 0:f9b6112278fe 144 #ifndef __MBED_CMSIS_RTOS_CA9
DieterGraef 0:f9b6112278fe 145 #define OS_PRIV_CNT (OS_PRIVCNT + 2)
DieterGraef 0:f9b6112278fe 146 #define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE+OS_TIMERSTKSZ))
DieterGraef 0:f9b6112278fe 147 #endif
DieterGraef 0:f9b6112278fe 148 #else
DieterGraef 0:f9b6112278fe 149 #define OS_TASK_CNT OS_TASKCNT
DieterGraef 0:f9b6112278fe 150 #ifndef __MBED_CMSIS_RTOS_CA9
DieterGraef 0:f9b6112278fe 151 #define OS_PRIV_CNT (OS_PRIVCNT + 1)
DieterGraef 0:f9b6112278fe 152 #define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE))
DieterGraef 0:f9b6112278fe 153 #endif
DieterGraef 0:f9b6112278fe 154 #endif
DieterGraef 0:f9b6112278fe 155
DieterGraef 0:f9b6112278fe 156 uint16_t const os_maxtaskrun = OS_TASK_CNT;
DieterGraef 0:f9b6112278fe 157 #ifdef __MBED_CMSIS_RTOS_CA9
DieterGraef 0:f9b6112278fe 158 uint32_t const os_stackinfo = (OS_STKCHECK<<24)| (OS_IDLESTKSIZE*4);
DieterGraef 0:f9b6112278fe 159 #else
DieterGraef 0:f9b6112278fe 160 uint32_t const os_stackinfo = (OS_STKCHECK<<24)| (OS_PRIV_CNT<<16) | (OS_STKSIZE*4);
DieterGraef 0:f9b6112278fe 161 #endif
DieterGraef 0:f9b6112278fe 162 uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT;
DieterGraef 0:f9b6112278fe 163 uint32_t const os_tickfreq = OS_CLOCK;
DieterGraef 0:f9b6112278fe 164 uint16_t const os_tickus_i = OS_CLOCK/1000000;
DieterGraef 0:f9b6112278fe 165 uint16_t const os_tickus_f = (((uint64_t)(OS_CLOCK-1000000*(OS_CLOCK/1000000)))<<16)/1000000;
DieterGraef 0:f9b6112278fe 166 uint32_t const os_trv = OS_TRV;
DieterGraef 0:f9b6112278fe 167 uint8_t const os_flags = OS_RUNPRIV;
DieterGraef 0:f9b6112278fe 168
DieterGraef 0:f9b6112278fe 169 /* Export following defines to uVision debugger. */
DieterGraef 0:f9b6112278fe 170 __USED uint32_t const CMSIS_RTOS_API_Version = osCMSIS;
DieterGraef 0:f9b6112278fe 171 __USED uint32_t const CMSIS_RTOS_RTX_Version = osCMSIS_RTX;
DieterGraef 0:f9b6112278fe 172 __USED uint32_t const os_clockrate = OS_TICK;
DieterGraef 0:f9b6112278fe 173 __USED uint32_t const os_timernum = 0;
DieterGraef 0:f9b6112278fe 174
DieterGraef 0:f9b6112278fe 175 /* Memory pool for TCB allocation */
DieterGraef 0:f9b6112278fe 176 _declare_box (mp_tcb, OS_TCB_SIZE, OS_TASK_CNT);
DieterGraef 0:f9b6112278fe 177 uint16_t const mp_tcb_size = sizeof(mp_tcb);
DieterGraef 0:f9b6112278fe 178
DieterGraef 0:f9b6112278fe 179 #ifdef __MBED_CMSIS_RTOS_CA9
DieterGraef 0:f9b6112278fe 180 /* Memory pool for os_idle_demon stack allocation. */
DieterGraef 0:f9b6112278fe 181 _declare_box8 (mp_stk, OS_IDLESTKSIZE*4, 1);
DieterGraef 0:f9b6112278fe 182 uint32_t const mp_stk_size = sizeof(mp_stk);
DieterGraef 0:f9b6112278fe 183 #else
DieterGraef 0:f9b6112278fe 184 /* Memory pool for System stack allocation (+os_idle_demon). */
DieterGraef 0:f9b6112278fe 185 _declare_box8 (mp_stk, OS_STKSIZE*4, OS_TASK_CNT-OS_PRIV_CNT+1);
DieterGraef 0:f9b6112278fe 186 uint32_t const mp_stk_size = sizeof(mp_stk);
DieterGraef 0:f9b6112278fe 187
DieterGraef 0:f9b6112278fe 188 /* Memory pool for user specified stack allocation (+main, +timer) */
DieterGraef 0:f9b6112278fe 189 uint64_t os_stack_mem[2+OS_PRIV_CNT+(OS_STACK_SZ/8)];
DieterGraef 0:f9b6112278fe 190 uint32_t const os_stack_sz = sizeof(os_stack_mem);
DieterGraef 0:f9b6112278fe 191 #endif
DieterGraef 0:f9b6112278fe 192
DieterGraef 0:f9b6112278fe 193 #ifndef OS_FIFOSZ
DieterGraef 0:f9b6112278fe 194 #define OS_FIFOSZ 16
DieterGraef 0:f9b6112278fe 195 #endif
DieterGraef 0:f9b6112278fe 196
DieterGraef 0:f9b6112278fe 197 /* Fifo Queue buffer for ISR requests.*/
DieterGraef 0:f9b6112278fe 198 uint32_t os_fifo[OS_FIFOSZ*2+1];
DieterGraef 0:f9b6112278fe 199 uint8_t const os_fifo_size = OS_FIFOSZ;
DieterGraef 0:f9b6112278fe 200
DieterGraef 0:f9b6112278fe 201 /* An array of Active task pointers. */
DieterGraef 0:f9b6112278fe 202 void *os_active_TCB[OS_TASK_CNT];
DieterGraef 0:f9b6112278fe 203
DieterGraef 0:f9b6112278fe 204 /* User Timers Resources */
DieterGraef 0:f9b6112278fe 205 #if (OS_TIMERS != 0)
DieterGraef 0:f9b6112278fe 206 extern void osTimerThread (void const *argument);
DieterGraef 0:f9b6112278fe 207 #ifdef __MBED_CMSIS_RTOS_CA9
DieterGraef 0:f9b6112278fe 208 osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ);
DieterGraef 0:f9b6112278fe 209 #else
DieterGraef 0:f9b6112278fe 210 osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 1, 4*OS_TIMERSTKSZ);
DieterGraef 0:f9b6112278fe 211 #endif
DieterGraef 0:f9b6112278fe 212 osThreadId osThreadId_osTimerThread;
DieterGraef 0:f9b6112278fe 213 osMessageQDef(osTimerMessageQ, OS_TIMERCBQS, void *);
DieterGraef 0:f9b6112278fe 214 osMessageQId osMessageQId_osTimerMessageQ;
DieterGraef 0:f9b6112278fe 215 #else
DieterGraef 0:f9b6112278fe 216 osThreadDef_t os_thread_def_osTimerThread = { NULL };
DieterGraef 0:f9b6112278fe 217 osThreadId osThreadId_osTimerThread;
DieterGraef 0:f9b6112278fe 218 osMessageQDef(osTimerMessageQ, 0, void *);
DieterGraef 0:f9b6112278fe 219 osMessageQId osMessageQId_osTimerMessageQ;
DieterGraef 0:f9b6112278fe 220 #endif
DieterGraef 0:f9b6112278fe 221
DieterGraef 0:f9b6112278fe 222 /* Legacy RTX User Timers not used */
DieterGraef 0:f9b6112278fe 223 uint32_t os_tmr = 0;
DieterGraef 0:f9b6112278fe 224 uint32_t const *m_tmr = NULL;
DieterGraef 0:f9b6112278fe 225 uint16_t const mp_tmr_size = 0;
DieterGraef 0:f9b6112278fe 226
DieterGraef 0:f9b6112278fe 227 #if defined (__CC_ARM) && !defined (__MICROLIB)
DieterGraef 0:f9b6112278fe 228 /* A memory space for arm standard library. */
DieterGraef 0:f9b6112278fe 229 static uint32_t std_libspace[OS_TASK_CNT][96/4];
DieterGraef 0:f9b6112278fe 230 static OS_MUT std_libmutex[OS_MUTEXCNT];
DieterGraef 0:f9b6112278fe 231 static uint32_t nr_mutex;
DieterGraef 0:f9b6112278fe 232 extern void *__libspace_start;
DieterGraef 0:f9b6112278fe 233 #elif defined (__ICCARM__)
DieterGraef 0:f9b6112278fe 234 typedef struct os_mut_array {
DieterGraef 0:f9b6112278fe 235 OS_MUT mutex;
DieterGraef 0:f9b6112278fe 236 uint32_t used;
DieterGraef 0:f9b6112278fe 237 } os_mut_array_t;
DieterGraef 0:f9b6112278fe 238
DieterGraef 0:f9b6112278fe 239 static os_mut_array_t std_libmutex[OS_MUTEXCNT];/* must be Zero clear */
DieterGraef 0:f9b6112278fe 240 static uint32_t nr_mutex = 0;
DieterGraef 0:f9b6112278fe 241 #endif
DieterGraef 0:f9b6112278fe 242
DieterGraef 0:f9b6112278fe 243
DieterGraef 0:f9b6112278fe 244 /*----------------------------------------------------------------------------
DieterGraef 0:f9b6112278fe 245 * RTX Optimizations (empty functions)
DieterGraef 0:f9b6112278fe 246 *---------------------------------------------------------------------------*/
DieterGraef 0:f9b6112278fe 247
DieterGraef 0:f9b6112278fe 248 #if OS_ROBIN == 0
DieterGraef 0:f9b6112278fe 249 void rt_init_robin (void) {;}
DieterGraef 0:f9b6112278fe 250 void rt_chk_robin (void) {;}
DieterGraef 0:f9b6112278fe 251 #endif
DieterGraef 0:f9b6112278fe 252
DieterGraef 0:f9b6112278fe 253 #if OS_STKCHECK == 0
DieterGraef 0:f9b6112278fe 254 void rt_stk_check (void) {;}
DieterGraef 0:f9b6112278fe 255 #endif
DieterGraef 0:f9b6112278fe 256
DieterGraef 0:f9b6112278fe 257
DieterGraef 0:f9b6112278fe 258 /*----------------------------------------------------------------------------
DieterGraef 0:f9b6112278fe 259 * Standard Library multithreading interface
DieterGraef 0:f9b6112278fe 260 *---------------------------------------------------------------------------*/
DieterGraef 0:f9b6112278fe 261
DieterGraef 0:f9b6112278fe 262 #if defined (__CC_ARM) && !defined (__MICROLIB)
DieterGraef 0:f9b6112278fe 263
DieterGraef 0:f9b6112278fe 264 /*--------------------------- __user_perthread_libspace ---------------------*/
DieterGraef 0:f9b6112278fe 265
DieterGraef 0:f9b6112278fe 266 void *__user_perthread_libspace (void) {
DieterGraef 0:f9b6112278fe 267 /* Provide a separate libspace for each task. */
DieterGraef 0:f9b6112278fe 268 uint32_t idx;
DieterGraef 0:f9b6112278fe 269
DieterGraef 0:f9b6112278fe 270 idx = runtask_id ();
DieterGraef 0:f9b6112278fe 271 if (idx == 0) {
DieterGraef 0:f9b6112278fe 272 /* RTX not running yet. */
DieterGraef 0:f9b6112278fe 273 return (&__libspace_start);
DieterGraef 0:f9b6112278fe 274 }
DieterGraef 0:f9b6112278fe 275 return ((void *)&std_libspace[idx-1]);
DieterGraef 0:f9b6112278fe 276 }
DieterGraef 0:f9b6112278fe 277
DieterGraef 0:f9b6112278fe 278 /*--------------------------- _mutex_initialize -----------------------------*/
DieterGraef 0:f9b6112278fe 279
DieterGraef 0:f9b6112278fe 280 int _mutex_initialize (OS_ID *mutex) {
DieterGraef 0:f9b6112278fe 281 /* Allocate and initialize a system mutex. */
DieterGraef 0:f9b6112278fe 282
DieterGraef 0:f9b6112278fe 283 if (nr_mutex >= OS_MUTEXCNT) {
DieterGraef 0:f9b6112278fe 284 /* If you are here, you need to increase the number OS_MUTEXCNT. */
DieterGraef 0:f9b6112278fe 285 for (;;);
DieterGraef 0:f9b6112278fe 286 }
DieterGraef 0:f9b6112278fe 287 *mutex = &std_libmutex[nr_mutex++];
DieterGraef 0:f9b6112278fe 288 mutex_init (*mutex);
DieterGraef 0:f9b6112278fe 289 return (1);
DieterGraef 0:f9b6112278fe 290 }
DieterGraef 0:f9b6112278fe 291
DieterGraef 0:f9b6112278fe 292
DieterGraef 0:f9b6112278fe 293 /*--------------------------- _mutex_acquire --------------------------------*/
DieterGraef 0:f9b6112278fe 294
DieterGraef 0:f9b6112278fe 295 __attribute__((used)) void _mutex_acquire (OS_ID *mutex) {
DieterGraef 0:f9b6112278fe 296 /* Acquire a system mutex, lock stdlib resources. */
DieterGraef 0:f9b6112278fe 297 if (runtask_id ()) {
DieterGraef 0:f9b6112278fe 298 /* RTX running, acquire a mutex. */
DieterGraef 0:f9b6112278fe 299 mutex_wait (*mutex);
DieterGraef 0:f9b6112278fe 300 }
DieterGraef 0:f9b6112278fe 301 }
DieterGraef 0:f9b6112278fe 302
DieterGraef 0:f9b6112278fe 303
DieterGraef 0:f9b6112278fe 304 /*--------------------------- _mutex_release --------------------------------*/
DieterGraef 0:f9b6112278fe 305
DieterGraef 0:f9b6112278fe 306 __attribute__((used)) void _mutex_release (OS_ID *mutex) {
DieterGraef 0:f9b6112278fe 307 /* Release a system mutex, unlock stdlib resources. */
DieterGraef 0:f9b6112278fe 308 if (runtask_id ()) {
DieterGraef 0:f9b6112278fe 309 /* RTX running, release a mutex. */
DieterGraef 0:f9b6112278fe 310 mutex_rel (*mutex);
DieterGraef 0:f9b6112278fe 311 }
DieterGraef 0:f9b6112278fe 312 }
DieterGraef 0:f9b6112278fe 313
DieterGraef 0:f9b6112278fe 314 #elif defined (__ICCARM__)
DieterGraef 0:f9b6112278fe 315
DieterGraef 0:f9b6112278fe 316 /*--------------------------- __iar_system_Mtxinit --------------------------*/
DieterGraef 0:f9b6112278fe 317
DieterGraef 0:f9b6112278fe 318 void __iar_system_Mtxinit(__iar_Rmtx *mutex)
DieterGraef 0:f9b6112278fe 319 {
DieterGraef 0:f9b6112278fe 320 /* Allocate and initialize a system mutex. */
DieterGraef 0:f9b6112278fe 321 int32_t idx;
DieterGraef 0:f9b6112278fe 322
DieterGraef 0:f9b6112278fe 323 for (idx = 0; idx < OS_MUTEXCNT; idx++)
DieterGraef 0:f9b6112278fe 324 {
DieterGraef 0:f9b6112278fe 325 if (std_libmutex[idx].used == 0)
DieterGraef 0:f9b6112278fe 326 {
DieterGraef 0:f9b6112278fe 327 std_libmutex[idx].used = 1;
DieterGraef 0:f9b6112278fe 328 *mutex = &std_libmutex[idx].mutex;
DieterGraef 0:f9b6112278fe 329 nr_mutex++;
DieterGraef 0:f9b6112278fe 330 break;
DieterGraef 0:f9b6112278fe 331 }
DieterGraef 0:f9b6112278fe 332 }
DieterGraef 0:f9b6112278fe 333 if (nr_mutex >= OS_MUTEXCNT)
DieterGraef 0:f9b6112278fe 334 {
DieterGraef 0:f9b6112278fe 335 /* If you are here, you need to increase the number OS_MUTEXCNT. */
DieterGraef 0:f9b6112278fe 336 for (;;);
DieterGraef 0:f9b6112278fe 337 }
DieterGraef 0:f9b6112278fe 338
DieterGraef 0:f9b6112278fe 339 mutex_init (*mutex);
DieterGraef 0:f9b6112278fe 340 }
DieterGraef 0:f9b6112278fe 341
DieterGraef 0:f9b6112278fe 342 /*--------------------------- __iar_system_Mtxdst ---------------------------*/
DieterGraef 0:f9b6112278fe 343
DieterGraef 0:f9b6112278fe 344 void __iar_system_Mtxdst(__iar_Rmtx *mutex)
DieterGraef 0:f9b6112278fe 345 {
DieterGraef 0:f9b6112278fe 346 /* Free a system mutex. */
DieterGraef 0:f9b6112278fe 347 int32_t idx;
DieterGraef 0:f9b6112278fe 348
DieterGraef 0:f9b6112278fe 349 if (nr_mutex == 0)
DieterGraef 0:f9b6112278fe 350 {
DieterGraef 0:f9b6112278fe 351 for (;;);
DieterGraef 0:f9b6112278fe 352 }
DieterGraef 0:f9b6112278fe 353
DieterGraef 0:f9b6112278fe 354 idx = ((((uint32_t)mutex) - ((uint32_t)&std_libmutex[0].mutex))
DieterGraef 0:f9b6112278fe 355 / sizeof(os_mut_array_t));
DieterGraef 0:f9b6112278fe 356
DieterGraef 0:f9b6112278fe 357 if (idx >= OS_MUTEXCNT)
DieterGraef 0:f9b6112278fe 358 {
DieterGraef 0:f9b6112278fe 359 for (;;);
DieterGraef 0:f9b6112278fe 360 }
DieterGraef 0:f9b6112278fe 361
DieterGraef 0:f9b6112278fe 362 mutex_del (*mutex);
DieterGraef 0:f9b6112278fe 363 std_libmutex[idx].used = 0;
DieterGraef 0:f9b6112278fe 364 }
DieterGraef 0:f9b6112278fe 365
DieterGraef 0:f9b6112278fe 366 /*--------------------------- __iar_system_Mtxlock --------------------------*/
DieterGraef 0:f9b6112278fe 367
DieterGraef 0:f9b6112278fe 368 void __iar_system_Mtxlock(__iar_Rmtx *mutex)
DieterGraef 0:f9b6112278fe 369 {
DieterGraef 0:f9b6112278fe 370 /* Acquire a system mutex, lock stdlib resources. */
DieterGraef 0:f9b6112278fe 371 if (runtask_id ())
DieterGraef 0:f9b6112278fe 372 {
DieterGraef 0:f9b6112278fe 373 /* RTX running, acquire a mutex. */
DieterGraef 0:f9b6112278fe 374 mutex_wait (*mutex);
DieterGraef 0:f9b6112278fe 375 }
DieterGraef 0:f9b6112278fe 376 }
DieterGraef 0:f9b6112278fe 377
DieterGraef 0:f9b6112278fe 378 /*--------------------------- __iar_system_Mtxunlock ------------------------*/
DieterGraef 0:f9b6112278fe 379
DieterGraef 0:f9b6112278fe 380 void __iar_system_Mtxunlock(__iar_Rmtx *mutex)
DieterGraef 0:f9b6112278fe 381 {
DieterGraef 0:f9b6112278fe 382 /* Release a system mutex, unlock stdlib resources. */
DieterGraef 0:f9b6112278fe 383 if (runtask_id ())
DieterGraef 0:f9b6112278fe 384 {
DieterGraef 0:f9b6112278fe 385 /* RTX running, release a mutex. */
DieterGraef 0:f9b6112278fe 386 mutex_rel (*mutex);
DieterGraef 0:f9b6112278fe 387 }
DieterGraef 0:f9b6112278fe 388 }
DieterGraef 0:f9b6112278fe 389
DieterGraef 0:f9b6112278fe 390 #endif
DieterGraef 0:f9b6112278fe 391
DieterGraef 0:f9b6112278fe 392
DieterGraef 0:f9b6112278fe 393 /*----------------------------------------------------------------------------
DieterGraef 0:f9b6112278fe 394 * RTX Startup
DieterGraef 0:f9b6112278fe 395 *---------------------------------------------------------------------------*/
DieterGraef 0:f9b6112278fe 396
DieterGraef 0:f9b6112278fe 397 /* Main Thread definition */
DieterGraef 0:f9b6112278fe 398 extern int main (void);
DieterGraef 0:f9b6112278fe 399 #ifdef __MBED_CMSIS_RTOS_CA9
DieterGraef 0:f9b6112278fe 400 uint32_t os_thread_def_stack_main [(4 * OS_MAINSTKSIZE) / sizeof(uint32_t)];
DieterGraef 0:f9b6112278fe 401 osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1, 4*OS_MAINSTKSIZE, os_thread_def_stack_main };
DieterGraef 0:f9b6112278fe 402 #else
DieterGraef 0:f9b6112278fe 403 osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1, 4*OS_MAINSTKSIZE };
DieterGraef 0:f9b6112278fe 404 #endif
DieterGraef 0:f9b6112278fe 405
DieterGraef 0:f9b6112278fe 406 #if defined (__CC_ARM)
DieterGraef 0:f9b6112278fe 407
DieterGraef 0:f9b6112278fe 408 #ifdef __MICROLIB
DieterGraef 0:f9b6112278fe 409 void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF")));
DieterGraef 0:f9b6112278fe 410 #if __TARGET_ARCH_ARM
DieterGraef 0:f9b6112278fe 411 #pragma push
DieterGraef 0:f9b6112278fe 412 #pragma arm
DieterGraef 0:f9b6112278fe 413 #endif
DieterGraef 0:f9b6112278fe 414 void _main_init (void) {
DieterGraef 0:f9b6112278fe 415 osKernelInitialize();
DieterGraef 0:f9b6112278fe 416 osThreadCreate(&os_thread_def_main, NULL);
DieterGraef 0:f9b6112278fe 417 osKernelStart();
DieterGraef 0:f9b6112278fe 418 for (;;);
DieterGraef 0:f9b6112278fe 419 }
DieterGraef 0:f9b6112278fe 420 #if __TARGET_ARCH_ARM
DieterGraef 0:f9b6112278fe 421 #pragma pop
DieterGraef 0:f9b6112278fe 422 #endif
DieterGraef 0:f9b6112278fe 423 #else
DieterGraef 0:f9b6112278fe 424 __asm void __rt_entry (void) {
DieterGraef 0:f9b6112278fe 425
DieterGraef 0:f9b6112278fe 426 IMPORT __user_setup_stackheap
DieterGraef 0:f9b6112278fe 427 IMPORT __rt_lib_init
DieterGraef 0:f9b6112278fe 428 IMPORT os_thread_def_main
DieterGraef 0:f9b6112278fe 429 IMPORT osKernelInitialize
DieterGraef 0:f9b6112278fe 430 IMPORT osKernelStart
DieterGraef 0:f9b6112278fe 431 IMPORT osThreadCreate
DieterGraef 0:f9b6112278fe 432 IMPORT exit
DieterGraef 0:f9b6112278fe 433
DieterGraef 0:f9b6112278fe 434 BL __user_setup_stackheap
DieterGraef 0:f9b6112278fe 435 MOV R1,R2
DieterGraef 0:f9b6112278fe 436 BL __rt_lib_init
DieterGraef 0:f9b6112278fe 437 BL osKernelInitialize
DieterGraef 0:f9b6112278fe 438 LDR R0,=os_thread_def_main
DieterGraef 0:f9b6112278fe 439 MOVS R1,#0
DieterGraef 0:f9b6112278fe 440 BL osThreadCreate
DieterGraef 0:f9b6112278fe 441 BL osKernelStart
DieterGraef 0:f9b6112278fe 442 BL exit
DieterGraef 0:f9b6112278fe 443
DieterGraef 0:f9b6112278fe 444 ALIGN
DieterGraef 0:f9b6112278fe 445 }
DieterGraef 0:f9b6112278fe 446 #endif
DieterGraef 0:f9b6112278fe 447
DieterGraef 0:f9b6112278fe 448 #elif defined (__GNUC__)
DieterGraef 0:f9b6112278fe 449
DieterGraef 0:f9b6112278fe 450 __attribute__((naked)) void software_init_hook (void) {
DieterGraef 0:f9b6112278fe 451 __asm (
DieterGraef 0:f9b6112278fe 452 ".syntax unified\n"
DieterGraef 0:f9b6112278fe 453 ".arm\n"
DieterGraef 0:f9b6112278fe 454 "movs r0,#0\n"
DieterGraef 0:f9b6112278fe 455 "movs r1,#0\n"
DieterGraef 0:f9b6112278fe 456 "mov r4,r0\n"
DieterGraef 0:f9b6112278fe 457 "mov r5,r1\n"
DieterGraef 0:f9b6112278fe 458 "ldr r0,= __libc_fini_array\n"
DieterGraef 0:f9b6112278fe 459 "bl atexit\n"
DieterGraef 0:f9b6112278fe 460 "bl __libc_init_array\n"
DieterGraef 0:f9b6112278fe 461 "mov r0,r4\n"
DieterGraef 0:f9b6112278fe 462 "mov r1,r5\n"
DieterGraef 0:f9b6112278fe 463 "bl osKernelInitialize\n"
DieterGraef 0:f9b6112278fe 464 "ldr r0,=os_thread_def_main\n"
DieterGraef 0:f9b6112278fe 465 "movs r1,#0\n"
DieterGraef 0:f9b6112278fe 466 "bl osThreadCreate\n"
DieterGraef 0:f9b6112278fe 467 "bl osKernelStart\n"
DieterGraef 0:f9b6112278fe 468 "bl exit\n"
DieterGraef 0:f9b6112278fe 469 );
DieterGraef 0:f9b6112278fe 470 }
DieterGraef 0:f9b6112278fe 471
DieterGraef 0:f9b6112278fe 472 #elif defined (__ICCARM__)
DieterGraef 0:f9b6112278fe 473
DieterGraef 0:f9b6112278fe 474 extern void exit(int arg);
DieterGraef 0:f9b6112278fe 475
DieterGraef 0:f9b6112278fe 476 void mbed_main(void) {
DieterGraef 0:f9b6112278fe 477 int a;
DieterGraef 0:f9b6112278fe 478
DieterGraef 0:f9b6112278fe 479 osKernelInitialize();
DieterGraef 0:f9b6112278fe 480 osThreadCreate(&os_thread_def_main, NULL);
DieterGraef 0:f9b6112278fe 481 a = osKernelStart();
DieterGraef 0:f9b6112278fe 482 exit(a);
DieterGraef 0:f9b6112278fe 483 }
DieterGraef 0:f9b6112278fe 484
DieterGraef 0:f9b6112278fe 485 #endif
DieterGraef 0:f9b6112278fe 486
DieterGraef 0:f9b6112278fe 487
DieterGraef 0:f9b6112278fe 488 /*----------------------------------------------------------------------------
DieterGraef 0:f9b6112278fe 489 * end of file
DieterGraef 0:f9b6112278fe 490 *---------------------------------------------------------------------------*/
DieterGraef 0:f9b6112278fe 491