Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.

Dependents:   denki-yohou_b TestY201 Network-RTOS NTPClient_HelloWorld ... more

Deprecated

This is the mbed 2 rtos library. mbed OS 5 integrates the mbed library with mbed-rtos. With this, we have provided thread safety for all mbed APIs. If you'd like to learn about using mbed OS 5, please see the docs.

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Wed Jun 17 11:15:10 2015 +0100
Parent:
84:143955ffb790
Child:
86:58c3b7759abf
Commit message:
Synchronized with git revision c33e334a2273b85d12a0bf31aa2f0f86a205ee4b

Full URL: https://github.com/mbedmicro/mbed/commit/c33e334a2273b85d12a0bf31aa2f0f86a205ee4b/

RZ_A1H - Modify the OS track acquisition method

Changed in this revision

rtos/Thread.cpp Show annotated file Show diff for this revision Revisions of this file
rtx/TARGET_CORTEX_A/RTX_CM_lib.h Show annotated file Show diff for this revision Revisions of this file
rtx/TARGET_CORTEX_A/RTX_Conf_CA.c Show annotated file Show diff for this revision Revisions of this file
rtx/TARGET_CORTEX_A/cmsis_os.h Show annotated file Show diff for this revision Revisions of this file
rtx/TARGET_CORTEX_A/rt_CMSIS.c Show annotated file Show diff for this revision Revisions of this file
--- a/rtos/Thread.cpp	Wed Jun 17 10:00:10 2015 +0100
+++ b/rtos/Thread.cpp	Wed Jun 17 11:15:10 2015 +0100
@@ -31,7 +31,6 @@
     _thread_def.pthread = task;
     _thread_def.tpriority = priority;
     _thread_def.stacksize = stack_size;
-#ifndef __MBED_CMSIS_RTOS_CA9
     if (stack_pointer != NULL) {
         _thread_def.stack_pointer = (uint32_t*)stack_pointer;
         _dynamic_stack = false;
@@ -47,7 +46,6 @@
         _thread_def.stack_pointer[i] = 0xE25A2EA5;
     }
 #endif
-#endif
     _tid = osThreadCreate(&_thread_def, argument);
 }
 
@@ -136,11 +134,9 @@
 
 Thread::~Thread() {
     terminate();
-#ifndef __MBED_CMSIS_RTOS_CA9
     if (_dynamic_stack) {
         delete[] (_thread_def.stack_pointer);
     }
-#endif
 }
 
 }
--- a/rtx/TARGET_CORTEX_A/RTX_CM_lib.h	Wed Jun 17 10:00:10 2015 +0100
+++ b/rtx/TARGET_CORTEX_A/RTX_CM_lib.h	Wed Jun 17 11:15:10 2015 +0100
@@ -85,16 +85,24 @@
 
 #if (OS_TIMERS != 0)
 #define OS_TASK_CNT (OS_TASKCNT + 1)
+#ifndef __MBED_CMSIS_RTOS_CA9
 #define OS_PRIV_CNT (OS_PRIVCNT + 2)
 #define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE+OS_TIMERSTKSZ))
+#endif
 #else
 #define OS_TASK_CNT  OS_TASKCNT
+#ifndef __MBED_CMSIS_RTOS_CA9
 #define OS_PRIV_CNT (OS_PRIVCNT + 1)
 #define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE))
 #endif
+#endif
 
 uint16_t const os_maxtaskrun = OS_TASK_CNT;
+#ifdef __MBED_CMSIS_RTOS_CA9
+uint32_t const os_stackinfo  = (OS_STKCHECK<<24)| (OS_IDLESTKSIZE*4);
+#else
 uint32_t const os_stackinfo  = (OS_STKCHECK<<24)| (OS_PRIV_CNT<<16) | (OS_STKSIZE*4);
+#endif
 uint32_t const os_rrobin     = (OS_ROBIN << 16) | OS_ROBINTOUT;
 uint32_t const os_trv        = OS_TRV;
 uint8_t  const os_flags      = OS_RUNPRIV;
@@ -107,6 +115,11 @@
 _declare_box  (mp_tcb, OS_TCB_SIZE, OS_TASK_CNT);
 uint16_t const mp_tcb_size = sizeof(mp_tcb);
 
+#ifdef __MBED_CMSIS_RTOS_CA9
+/* Memory pool for os_idle_demon stack allocation. */
+_declare_box8 (mp_stk, OS_IDLESTKSIZE*4, 1);
+uint32_t const mp_stk_size = sizeof(mp_stk);
+#else
 /* Memory pool for System stack allocation (+os_idle_demon). */
 _declare_box8 (mp_stk, OS_STKSIZE*4, OS_TASK_CNT-OS_PRIV_CNT+1);
 uint32_t const mp_stk_size = sizeof(mp_stk);
@@ -114,6 +127,7 @@
 /* Memory pool for user specified stack allocation (+main, +timer) */
 uint64_t       os_stack_mem[2+OS_PRIV_CNT+(OS_STACK_SZ/8)];
 uint32_t const os_stack_sz = sizeof(os_stack_mem);
+#endif
 
 #ifndef OS_FIFOSZ
  #define OS_FIFOSZ      16
@@ -129,7 +143,7 @@
 /* User Timers Resources */
 #if (OS_TIMERS != 0)
 extern void osTimerThread (void const *argument);
-#if defined (__MBED_CMSIS_RTOS_CA9)
+#ifdef __MBED_CMSIS_RTOS_CA9
 osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ);
 #else
 osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 1, 4*OS_TIMERSTKSZ);
@@ -237,7 +251,12 @@
 
 /* Main Thread definition */
 extern int main (void);
+#ifdef __MBED_CMSIS_RTOS_CA9
+uint32_t os_thread_def_stack_main [(4 * OS_MAINSTKSIZE) / sizeof(uint32_t)];
+osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1, 4*OS_MAINSTKSIZE, os_thread_def_stack_main };
+#else
 osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1, 4*OS_MAINSTKSIZE };
+#endif
 
 
 #if defined (__CC_ARM)
--- a/rtx/TARGET_CORTEX_A/RTX_Conf_CA.c	Wed Jun 17 10:00:10 2015 +0100
+++ b/rtx/TARGET_CORTEX_A/RTX_Conf_CA.c	Wed Jun 17 11:15:10 2015 +0100
@@ -50,12 +50,20 @@
  #define OS_TASKCNT     25
 #endif
 
+#ifdef __MBED_CMSIS_RTOS_CA9
+//   <o>Idle stack size [bytes] <64-4096:8><#/4>
+//   <i> Defines default stack size for the Idle thread.
+#ifndef OS_IDLESTKSIZE
+ #define OS_IDLESTKSIZE 128
+#endif
+#else // __MBED_CMSIS_RTOS_CA9
 //   <o>Default Thread stack size [bytes] <64-4096:8><#/4>
 //   <i> Defines default stack size for threads with osThreadDef stacksz = 0
 //   <i> Default: 200
 #ifndef OS_STKSIZE
  #define OS_STKSIZE     200
 #endif
+#endif // __MBED_CMSIS_RTOS_CA9
 
 //   <o>Main Thread stack size [bytes] <64-4096:8><#/4>
 //   <i> Defines stack size for main thread.
@@ -64,19 +72,21 @@
  #define OS_MAINSTKSIZE 2048
 #endif
 
+#ifndef __MBED_CMSIS_RTOS_CA9
 //   <o>Number of threads with user-provided stack size <0-250>
 //   <i> Defines the number of threads with user-provided stack size.
 //   <i> Default: 0
 #ifndef OS_PRIVCNT
- #define OS_PRIVCNT     10
+ #define OS_PRIVCNT     0
 #endif
 
 //   <o>Total stack size [bytes] for threads with user-provided stack size <0-4096:8><#/4>
 //   <i> Defines the combined stack size for threads with user-provided stack size.
 //   <i> Default: 0
 #ifndef OS_PRIVSTKSIZE
- #define OS_PRIVSTKSIZE 8192
+ #define OS_PRIVSTKSIZE 0
 #endif
+#endif // __MBED_CMSIS_RTOS_CA9
 
 // <q>Check for stack overflow
 // <i> Includes the stack checking code for stack overflow.
--- a/rtx/TARGET_CORTEX_A/cmsis_os.h	Wed Jun 17 10:00:10 2015 +0100
+++ b/rtx/TARGET_CORTEX_A/cmsis_os.h	Wed Jun 17 11:15:10 2015 +0100
@@ -264,6 +264,9 @@
   osPriority             tpriority;    ///< initial thread priority
   uint32_t               instances;    ///< maximum number of instances of that thread function
   uint32_t               stacksize;    ///< stack size requirements in bytes; 0 is default stack size
+#ifdef __MBED_CMSIS_RTOS_CA9
+  uint32_t               *stack_pointer;  ///< pointer to the stack memory block
+#endif
 } osThreadDef_t;
 
 /// Timer Definition structure contains timer parameters.
@@ -356,10 +359,11 @@
 #define osThreadDef(name, priority, instances, stacksz)  \
 extern const osThreadDef_t os_thread_def_##name
 #else                            // define the object
-#if defined (__MBED_CMSIS_RTOS_CA9)
+#ifdef __MBED_CMSIS_RTOS_CA9
 #define osThreadDef(name, priority, stacksz)  \
+uint32_t os_thread_def_stack_##name [stacksz / sizeof(uint32_t)]; \
 const osThreadDef_t os_thread_def_##name = \
-{ (name), (priority), 1, (stacksz)  }
+{ (name), (priority), 1, (stacksz), (os_thread_def_stack_##name) }
 #else
 #define osThreadDef(name, priority, instances, stacksz)  \
 const osThreadDef_t os_thread_def_##name = \
--- a/rtx/TARGET_CORTEX_A/rt_CMSIS.c	Wed Jun 17 10:00:10 2015 +0100
+++ b/rtx/TARGET_CORTEX_A/rt_CMSIS.c	Wed Jun 17 11:15:10 2015 +0100
@@ -442,9 +442,11 @@
 extern const uint32_t  os_section_id$$Limit;
 #endif
 
+#ifndef __MBED_CMSIS_RTOS_CA9
 // OS Stack Memory for Threads definitions
 extern       uint64_t  os_stack_mem[];
 extern const uint32_t  os_stack_sz;
+#endif
 
 // OS Timers external resources
 extern const osThreadDef_t   os_thread_def_osTimerThread;
@@ -546,6 +548,11 @@
 
 /// Initialize the RTOS Kernel for creating objects
 osStatus svcKernelInitialize (void) {
+#ifdef __MBED_CMSIS_RTOS_CA9
+  if (!os_initialized) {
+    rt_sys_init();                              // RTX System Initialization
+  }
+#else
   int ret;
 
   if (!os_initialized) {
@@ -557,6 +564,7 @@
 
     rt_sys_init();                              // RTX System Initialization
   }
+#endif
 
   os_tsk.run->prio = 255;                       // Highest priority
 
@@ -668,6 +676,13 @@
     return NULL;
   }
 
+#ifdef __MBED_CMSIS_RTOS_CA9
+  if (thread_def->stacksize != 0) {             // Custom stack size
+    stk = (void *)thread_def->stack_pointer;
+  } else {                                      // Default stack size
+    stk = NULL;
+  }
+#else
   if (thread_def->stacksize != 0) {             // Custom stack size
     stk = rt_alloc_mem(                         // Allocate stack
       os_stack_mem,
@@ -680,6 +695,7 @@
   } else {                                      // Default stack size
     stk = NULL;
   }
+#endif
 
   tsk = rt_tsk_create(                          // Create task
     (FUNCP)thread_def->pthread,                 // Task function pointer
@@ -690,9 +706,11 @@
   );
 
   if (tsk == 0) {                               // Invalid task ID
+#ifndef __MBED_CMSIS_RTOS_CA9
     if (stk != NULL) {
       rt_free_mem(os_stack_mem, stk);           // Free allocated stack
     }
+#endif
     sysThreadError(osErrorNoMemory);            // Create task failed (Out of memory)
     return NULL;
   }
@@ -717,20 +735,26 @@
 osStatus svcThreadTerminate (osThreadId thread_id) {
   OS_RESULT res;
   P_TCB     ptcb;
+#ifndef __MBED_CMSIS_RTOS_CA9
   void     *stk;
+#endif
 
   ptcb = rt_tid2ptcb(thread_id);                // Get TCB pointer
   if (ptcb == NULL) return osErrorParameter;
 
+#ifndef __MBED_CMSIS_RTOS_CA9
   stk = ptcb->priv_stack ? ptcb->stack : NULL;  // Private stack
+#endif
 
   res = rt_tsk_delete(ptcb->task_id);           // Delete task
 
   if (res == OS_R_NOK) return osErrorResource;  // Delete task failed
 
+#ifndef __MBED_CMSIS_RTOS_CA9
   if (stk != NULL) {
     rt_free_mem(os_stack_mem, stk);             // Free private stack
   }
+#endif
 
   return osOK;
 }