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.

Revision:
112:53ace74b190c
Parent:
49:77c8e4604045
Child:
118:6635230e06ba
--- a/rtx/TARGET_CORTEX_M/rt_System.c	Tue May 03 00:15:52 2016 +0100
+++ b/rtx/TARGET_CORTEX_M/rt_System.c	Thu May 05 20:45:13 2016 +0100
@@ -1,12 +1,12 @@
 /*----------------------------------------------------------------------------
- *      RL-ARM - RTX
+ *      CMSIS-RTOS  -  RTX
  *----------------------------------------------------------------------------
  *      Name:    RT_SYSTEM.C
  *      Purpose: System Task Manager
- *      Rev.:    V4.60
+ *      Rev.:    V4.80
  *----------------------------------------------------------------------------
  *
- * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
+ * Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
  * All rights reserved.
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -33,7 +33,7 @@
  *---------------------------------------------------------------------------*/
 
 #include "rt_TypeDef.h"
-#include "RTX_Conf.h"
+#include "RTX_Config.h"
 #include "rt_Task.h"
 #include "rt_System.h"
 #include "rt_Event.h"
@@ -41,6 +41,7 @@
 #include "rt_Mailbox.h"
 #include "rt_Semaphore.h"
 #include "rt_Time.h"
+#include "rt_Timer.h"
 #include "rt_Robin.h"
 #include "rt_HAL_CM.h"
 
@@ -48,7 +49,7 @@
  *      Global Variables
  *---------------------------------------------------------------------------*/
 
-int os_tick_irqn;
+S32 os_tick_irqn;
 
 /*----------------------------------------------------------------------------
  *      Local Variables
@@ -62,28 +63,39 @@
  *      Global Functions
  *---------------------------------------------------------------------------*/
 
+#define RL_RTX_VER      0x480
+
 #if defined (__CC_ARM)
 __asm void $$RTX$$version (void) {
    /* Export a version number symbol for a version control. */
 
                 EXPORT  __RL_RTX_VER
 
-__RL_RTX_VER    EQU     0x450
+__RL_RTX_VER    EQU     RL_RTX_VER
 }
 #endif
 
 
 /*--------------------------- rt_suspend ------------------------------------*/
+
+extern U32 sysUserTimerWakeupTime(void);
+
 U32 rt_suspend (void) {
   /* Suspend OS scheduler */
-  U32 delta = 0xFFFF;
+  U32 delta = 0xFFFFU;
+#ifdef __CMSIS_RTOS
+  U32 sleep;
+#endif
 
   rt_tsk_lock();
-
+  
   if (os_dly.p_dlnk) {
     delta = os_dly.delta_time;
   }
-#ifndef __CMSIS_RTOS
+#ifdef __CMSIS_RTOS
+  sleep = sysUserTimerWakeupTime();
+  if (sleep < delta) { delta = sleep; }
+#else
   if (os_tmr.next) {
     if (os_tmr.tcnt < delta) delta = os_tmr.tcnt;
   }
@@ -94,6 +106,9 @@
 
 
 /*--------------------------- rt_resume -------------------------------------*/
+
+extern void sysUserTimerUpdate (U32 sleep_time);
+
 void rt_resume (U32 sleep_time) {
   /* Resume OS scheduler after suspend */
   P_TCB next;
@@ -110,31 +125,33 @@
     if (delta >= os_dly.delta_time) {
       delta   -= os_dly.delta_time;
       os_time += os_dly.delta_time;
-      os_dly.delta_time = 1;
+      os_dly.delta_time = 1U;
       while (os_dly.p_dlnk) {
         rt_dec_dly();
-        if (delta == 0) break;
+        if (delta == 0U) { break; }
         delta--;
         os_time++;
       }
     } else {
-      os_time           += delta;
-      os_dly.delta_time -= delta;
+      os_time           +=      delta;
+      os_dly.delta_time -= (U16)delta;
     }
   } else {
     os_time += sleep_time;
   }
 
-#ifndef __CMSIS_RTOS
   /* Check the user timers. */
+#ifdef __CMSIS_RTOS
+  sysUserTimerUpdate(sleep_time);
+#else
   if (os_tmr.next) {
     delta = sleep_time;
     if (delta >= os_tmr.tcnt) {
       delta   -= os_tmr.tcnt;
-      os_tmr.tcnt = 1;
+      os_tmr.tcnt = 1U;
       while (os_tmr.next) {
         rt_tmr_tick();
-        if (delta == 0) break;
+        if (delta == 0U) { break; }
         delta--;
       }
     } else {
@@ -158,11 +175,11 @@
   if (os_tick_irqn < 0) {
     OS_LOCK();
     os_lock = __TRUE;
-    OS_UNPEND (&pend_flags);
+    OS_UNPEND(pend_flags);
   } else {
-    OS_X_LOCK(os_tick_irqn);
+    OS_X_LOCK((U32)os_tick_irqn);
     os_lock = __TRUE;
-    OS_X_UNPEND (&pend_flags);
+    OS_X_UNPEND(pend_flags);
   }
 }
 
@@ -174,12 +191,12 @@
   if (os_tick_irqn < 0) {
     OS_UNLOCK();
     os_lock = __FALSE;
-    OS_PEND (pend_flags, os_psh_flag);
+    OS_PEND(pend_flags, os_psh_flag);
     os_psh_flag = __FALSE;
   } else {
-    OS_X_UNLOCK(os_tick_irqn);
+    OS_X_UNLOCK((U32)os_tick_irqn);
     os_lock = __FALSE;
-    OS_X_PEND (pend_flags, os_psh_flag);
+    OS_X_PEND(pend_flags, os_psh_flag);
     os_psh_flag = __FALSE;
   }
 }
@@ -190,7 +207,7 @@
 void rt_psh_req (void) {
   /* Initiate a post service handling request if required. */
   if (os_lock == __FALSE) {
-    OS_PEND_IRQ ();
+    OS_PEND_IRQ();
   }
   else {
     os_psh_flag = __TRUE;
@@ -224,10 +241,10 @@
       /* Must be of SCB type */
       rt_sem_psh ((P_SCB)p_CB);
     }
-    if (++idx == os_psq->size) idx = 0;
+    if (++idx == os_psq->size) { idx = 0U; }
     rt_dec (&os_psq->count);
   }
-  os_psq->last = idx;
+  os_psq->last = (U8)idx;
 
   next = rt_get_first (&os_rdy);
   rt_switch_req (next);
@@ -236,12 +253,25 @@
 
 /*--------------------------- os_tick_init ----------------------------------*/
 
-__weak int os_tick_init (void) {
+__weak S32 os_tick_init (void) {
   /* Initialize SysTick timer as system tick timer. */
-  rt_systick_init ();
+  rt_systick_init();
   return (-1);  /* Return IRQ number of SysTick timer */
 }
 
+/*--------------------------- os_tick_val -----------------------------------*/
+
+__weak U32 os_tick_val (void) {
+  /* Get SysTick timer current value (0 .. OS_TRV). */
+  return rt_systick_val();
+}
+
+/*--------------------------- os_tick_ovf -----------------------------------*/
+
+__weak U32 os_tick_ovf (void) {
+  /* Get SysTick timer overflow flag */
+  return rt_systick_ovf();
+}
 
 /*--------------------------- os_tick_irqack --------------------------------*/
 
@@ -281,9 +311,11 @@
 }
 
 /*--------------------------- rt_stk_check ----------------------------------*/
+
 __weak void rt_stk_check (void) {
+#ifdef __MBED_CMSIS_RTOS_CM
     /* Check for stack overflow. */
-    if (os_tsk.run->task_id == 0x01) {
+    if (os_tsk.run->task_id == 0x02) {
         // TODO: For the main thread the check should be done against the main heap pointer
     } else {
         if ((os_tsk.run->tsk_stack < (U32)os_tsk.run->stack) ||
@@ -291,6 +323,12 @@
             os_error (OS_ERR_STK_OVF);
         }
     }
+#else
+    if ((os_tsk.run->tsk_stack < (U32)os_tsk.run->stack) ||
+        (os_tsk.run->stack[0] != MAGIC_WORD)) {
+        os_error (OS_ERR_STK_OVF);
+    }
+#endif
 }
 
 /*----------------------------------------------------------------------------