Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RTX_CM_lib.h Source File

RTX_CM_lib.h

00001 /*----------------------------------------------------------------------------
00002  *      RL-ARM - RTX
00003  *----------------------------------------------------------------------------
00004  *      Name:    RTX_CM_LIB.H
00005  *      Purpose: RTX Kernel System Configuration
00006  *      Rev.:    V4.50
00007  *----------------------------------------------------------------------------
00008  *
00009  * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
00010  * All rights reserved.
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are met:
00013  *  - Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  *  - Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  *  - Neither the name of ARM  nor the names of its contributors may be used 
00019  *    to endorse or promote products derived from this software without 
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
00026  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00027  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00028  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  * POSSIBILITY OF SUCH DAMAGE.
00033  *---------------------------------------------------------------------------*/
00034 
00035 #if   defined (__CC_ARM)
00036 #pragma O3
00037 #define __USED __attribute__((used))
00038 #elif defined (__GNUC__)
00039 #pragma GCC optimize ("O3")
00040 #define __USED __attribute__((used))
00041 #elif defined (__ICCARM__)
00042 #define __USED __root
00043 #endif
00044 
00045 
00046 /*----------------------------------------------------------------------------
00047  *      Definitions
00048  *---------------------------------------------------------------------------*/
00049 
00050 #define _declare_box(pool,size,cnt)  uint32_t pool[(((size)+3)/4)*(cnt) + 3]
00051 #define _declare_box8(pool,size,cnt) uint64_t pool[(((size)+7)/8)*(cnt) + 2]
00052 
00053 #define OS_TCB_SIZE     48
00054 #define OS_TMR_SIZE     8
00055 
00056 #if defined (__CC_ARM) && !defined (__MICROLIB)
00057 
00058 typedef void    *OS_ID;
00059 typedef uint32_t OS_TID;
00060 typedef uint32_t OS_MUT[3];
00061 typedef uint32_t OS_RESULT;
00062 
00063 #define runtask_id()    rt_tsk_self()
00064 #define mutex_init(m)   rt_mut_init(m)
00065 #define mutex_wait(m)   os_mut_wait(m,0xFFFF)
00066 #define mutex_rel(m)    os_mut_release(m)
00067 
00068 extern OS_TID    rt_tsk_self    (void);
00069 extern void      rt_mut_init    (OS_ID mutex);
00070 extern OS_RESULT rt_mut_release (OS_ID mutex);
00071 extern OS_RESULT rt_mut_wait    (OS_ID mutex, uint16_t timeout);
00072 
00073 #define os_mut_wait(mutex,timeout) _os_mut_wait((uint32_t)rt_mut_wait,mutex,timeout)
00074 #define os_mut_release(mutex)      _os_mut_release((uint32_t)rt_mut_release,mutex)
00075 
00076 OS_RESULT _os_mut_release (uint32_t p, OS_ID mutex)                   __svc_indirect(0);
00077 OS_RESULT _os_mut_wait    (uint32_t p, OS_ID mutex, uint16_t timeout) __svc_indirect(0);
00078 
00079 #endif
00080 
00081 
00082 /*----------------------------------------------------------------------------
00083  *      Global Variables
00084  *---------------------------------------------------------------------------*/
00085 
00086 #if (OS_TIMERS != 0)
00087 #define OS_TASK_CNT (OS_TASKCNT + 1)
00088 #else
00089 #define OS_TASK_CNT  OS_TASKCNT
00090 #endif
00091 
00092 uint16_t const os_maxtaskrun = OS_TASK_CNT;
00093 uint32_t const os_rrobin     = (OS_ROBIN << 16) | OS_ROBINTOUT;
00094 uint32_t const os_trv        = OS_TRV;
00095 uint8_t  const os_flags      = OS_RUNPRIV;
00096 
00097 /* Export following defines to uVision debugger. */
00098 __USED uint32_t const os_clockrate = OS_TICK;
00099 __USED uint32_t const os_timernum  = 0;
00100 
00101 /* Stack for the os_idle_demon */
00102 unsigned int idle_task_stack[OS_IDLESTKSIZE];
00103 unsigned short const idle_task_stack_size = OS_IDLESTKSIZE;
00104 
00105 #ifndef OS_FIFOSZ
00106  #define OS_FIFOSZ      16
00107 #endif
00108 
00109 /* Fifo Queue buffer for ISR requests.*/
00110 uint32_t       os_fifo[OS_FIFOSZ*2+1];
00111 uint8_t  const os_fifo_size = OS_FIFOSZ;
00112 
00113 /* An array of Active task pointers. */
00114 void *os_active_TCB[OS_TASK_CNT];
00115 
00116 /* User Timers Resources */
00117 #if (OS_TIMERS != 0)
00118 extern void osTimerThread (void const *argument);
00119 osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ);
00120 osThreadId osThreadId_osTimerThread;
00121 osMessageQDef(osTimerMessageQ, OS_TIMERCBQS, void *);
00122 osMessageQId osMessageQId_osTimerMessageQ;
00123 #else
00124 osThreadDef_t os_thread_def_osTimerThread = { NULL };
00125 osThreadId osThreadId_osTimerThread;
00126 osMessageQDef(osTimerMessageQ, 0, void *);
00127 osMessageQId osMessageQId_osTimerMessageQ;
00128 #endif
00129 
00130 
00131 /*----------------------------------------------------------------------------
00132  *      RTX Optimizations (empty functions)
00133  *---------------------------------------------------------------------------*/
00134 
00135 #if OS_ROBIN == 0
00136  void rt_init_robin (void) {;}
00137  void rt_chk_robin  (void) {;}
00138 #endif
00139 
00140 #if OS_STKCHECK == 0
00141  void rt_stk_check  (void) {;}
00142 #endif
00143 
00144 
00145 /*----------------------------------------------------------------------------
00146  *      Standard Library multithreading interface
00147  *---------------------------------------------------------------------------*/
00148 
00149 #if defined (__CC_ARM) && !defined (__MICROLIB)
00150  static OS_MUT   std_libmutex[OS_MUTEXCNT];
00151  static uint32_t nr_mutex;
00152 
00153  /*--------------------------- _mutex_initialize -----------------------------*/
00154  
00155 int _mutex_initialize (OS_ID *mutex) {
00156   /* Allocate and initialize a system mutex. */
00157 
00158   if (nr_mutex >= OS_MUTEXCNT) {
00159     /* If you are here, you need to increase the number OS_MUTEXCNT. */
00160     for (;;);
00161   }
00162   *mutex = &std_libmutex[nr_mutex++];
00163   mutex_init (*mutex);
00164   return (1);
00165 }
00166 
00167 
00168 /*--------------------------- _mutex_acquire --------------------------------*/
00169 
00170 __attribute__((used)) void _mutex_acquire (OS_ID *mutex) {
00171   /* Acquire a system mutex, lock stdlib resources. */
00172   if (runtask_id ()) {
00173     /* RTX running, acquire a mutex. */
00174     mutex_wait (*mutex);
00175   }
00176 }
00177 
00178 
00179 /*--------------------------- _mutex_release --------------------------------*/
00180 
00181 __attribute__((used)) void _mutex_release (OS_ID *mutex) {
00182   /* Release a system mutex, unlock stdlib resources. */
00183   if (runtask_id ()) {
00184     /* RTX runnning, release a mutex. */
00185     mutex_rel (*mutex);
00186   }
00187 }
00188 
00189 #endif
00190 
00191 
00192 /*----------------------------------------------------------------------------
00193  *      RTX Startup
00194  *---------------------------------------------------------------------------*/
00195 
00196 /* Main Thread definition */
00197 extern int main (void);
00198 osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 0, NULL};
00199 
00200 #if defined (__CC_ARM)
00201 
00202 // This define should be probably moved to the CMSIS layer
00203 #ifdef TARGET_LPC1768
00204 #define INITIAL_SP            (0x10008000UL)
00205 
00206 #elif TARGET_LPC11U24
00207 #define INITIAL_SP            (0x10001000UL)
00208 
00209 #endif
00210 
00211 extern unsigned char Image$$RW_IRAM1$$ZI$$Limit[];
00212 
00213 void set_main_stack(void) {
00214     // Leave OS_SCHEDULERSTKSIZE words for the scheduler and interrupts
00215     os_thread_def_main.stack_pointer = Image$$RW_IRAM1$$ZI$$Limit;
00216     os_thread_def_main.stacksize = (INITIAL_SP - (unsigned int)Image$$RW_IRAM1$$ZI$$Limit) - (OS_SCHEDULERSTKSIZE * 4);
00217 }
00218 
00219 #ifdef __MICROLIB
00220 void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF")));
00221 void _main_init (void) {
00222   osKernelInitialize();
00223   set_main_stack();
00224   osThreadCreate(&os_thread_def_main, NULL);
00225   osKernelStart();
00226   for (;;);
00227 }
00228 #else
00229 
00230 /* The single memory model is checking for stack collision at run time, verifing
00231    that the heap pointer is underneath the stack pointer.
00232    
00233    With the RTOS there is not only one stack above the heap, there are multiple
00234    stacks and some of them are underneath the heap pointer.
00235 */
00236 #pragma import(__use_two_region_memory)
00237 
00238 __asm void __rt_entry (void) {
00239 
00240   IMPORT  __user_setup_stackheap
00241   IMPORT  __rt_lib_init
00242   IMPORT  os_thread_def_main
00243   IMPORT  osKernelInitialize
00244   IMPORT  set_main_stack
00245   IMPORT  osKernelStart
00246   IMPORT  osThreadCreate
00247   IMPORT  exit
00248 
00249   BL      __user_setup_stackheap
00250   MOV     R1,R2
00251   BL      __rt_lib_init
00252   BL      osKernelInitialize
00253   BL      set_main_stack
00254   LDR     R0,=os_thread_def_main
00255   MOVS    R1,#0
00256   BL      osThreadCreate
00257   BL      osKernelStart
00258   BL      exit
00259 
00260   ALIGN
00261 }
00262 #endif
00263 
00264 #elif defined (__GNUC__)
00265 
00266 #ifdef __CS3__
00267 
00268 /* CS3 start_c routine.
00269  *
00270  * Copyright (c) 2006, 2007 CodeSourcery Inc
00271  *
00272  * The authors hereby grant permission to use, copy, modify, distribute,
00273  * and license this software and its documentation for any purpose, provided
00274  * that existing copyright notices are retained in all copies and that this
00275  * notice is included verbatim in any distributions. No written agreement,
00276  * license, or royalty fee is required for any of the authorized uses.
00277  * Modifications to this software may be copyrighted by their authors
00278  * and need not follow the licensing terms described here, provided that
00279  * the new terms are clearly indicated on the first page of each file where
00280  * they apply.
00281  */
00282 
00283 #include "cs3.h"
00284 
00285 extern void __libc_init_array (void);
00286 
00287 __attribute ((noreturn)) void __cs3_start_c (void){
00288   unsigned regions = __cs3_region_num;
00289   const struct __cs3_region *rptr = __cs3_regions;
00290 
00291   /* Initialize memory */
00292   for (regions = __cs3_region_num, rptr = __cs3_regions; regions--; rptr++) {
00293     long long *src = (long long *)rptr->init;
00294     long long *dst = (long long *)rptr->data;
00295     unsigned limit = rptr->init_size;
00296     unsigned count;
00297 
00298     if (src != dst)
00299       for (count = 0; count != limit; count += sizeof (long long))
00300         *dst++ = *src++;
00301     else 
00302       dst = (long long *)((char *)dst + limit);
00303     limit = rptr->zero_size;
00304     for (count = 0; count != limit; count += sizeof (long long))
00305       *dst++ = 0;
00306   }
00307 
00308   /* Run initializers.  */
00309   __libc_init_array ();
00310 
00311   osKernelInitialize();
00312   osThreadCreate(&os_thread_def_main, NULL);
00313   osKernelStart();
00314   for (;;);
00315 }
00316 
00317 #else
00318 
00319 __attribute__((naked)) void software_init_hook (void) {
00320   __asm (
00321     ".syntax unified\n"
00322     ".thumb\n"
00323     "movs r0,#0\n"
00324     "movs r1,#0\n"
00325     "mov  r4,r0\n"
00326     "mov  r5,r1\n"
00327     "ldr  r0,= __libc_fini_array\n"
00328     "bl   atexit\n"
00329     "bl   __libc_init_array\n"
00330     "mov  r0,r4\n"
00331     "mov  r1,r5\n"
00332     "bl   osKernelInitialize\n"
00333     "ldr  r0,=os_thread_def_main\n"
00334     "movs r1,#0\n"
00335     "bl   osThreadCreate\n"
00336     "bl   osKernelStart\n"
00337     "bl   exit\n"
00338   );
00339 }
00340 
00341 #endif
00342 
00343 #elif defined (__ICCARM__)
00344 
00345 extern int  __low_level_init(void);
00346 extern void __iar_data_init3(void);
00347 extern void exit(int arg);
00348 
00349 __noreturn __stackless void __cmain(void) {
00350   int a;
00351   
00352   if (__low_level_init() != 0) {
00353     __iar_data_init3();
00354   }
00355   osKernelInitialize();
00356   osThreadCreate(&os_thread_def_main, NULL);
00357   a = osKernelStart();
00358   exit(a);
00359 }
00360 
00361 #endif
00362 
00363 
00364 /*----------------------------------------------------------------------------
00365  * end of file
00366  *---------------------------------------------------------------------------*/
00367