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
--- a/rtx/TARGET_CORTEX_M/rt_Mailbox.c	Tue May 03 00:15:52 2016 +0100
+++ b/rtx/TARGET_CORTEX_M/rt_Mailbox.c	Thu May 05 20:45:13 2016 +0100
@@ -1,12 +1,12 @@
 /*----------------------------------------------------------------------------
- *      RL-ARM - RTX
+ *      CMSIS-RTOS  -  RTX
  *----------------------------------------------------------------------------
  *      Name:    RT_MAILBOX.C
  *      Purpose: Implements waits and wake-ups for mailbox messages
- *      Rev.:    V4.60
+ *      Rev.:    V4.79
  *----------------------------------------------------------------------------
  *
- * 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_System.h"
 #include "rt_List.h"
 #include "rt_Mailbox.h"
@@ -54,14 +54,14 @@
   P_MCB p_MCB = mailbox;
 
   p_MCB->cb_type = MCB;
-  p_MCB->state   = 0;
-  p_MCB->isr_st  = 0;
+  p_MCB->state   = 0U;
+  p_MCB->isr_st  = 0U;
   p_MCB->p_lnk   = NULL;
-  p_MCB->first   = 0;
-  p_MCB->last    = 0;
-  p_MCB->count   = 0;
-  p_MCB->size    = (mbx_size + sizeof(void *) - sizeof(struct OS_MCB)) /
-                                                     (U32)sizeof (void *);
+  p_MCB->first   = 0U;
+  p_MCB->last    = 0U;
+  p_MCB->count   = 0U;
+  p_MCB->size    = (U16)((mbx_size - (sizeof(struct OS_MCB) - (sizeof(void *))))
+                         / sizeof(void *));
 }
 
 
@@ -72,11 +72,11 @@
   P_MCB p_MCB = mailbox;
   P_TCB p_TCB;
 
-  if ((p_MCB->p_lnk != NULL) && (p_MCB->state == 1)) {
+  if ((p_MCB->p_lnk != NULL) && (p_MCB->state == 1U)) {
     /* A task is waiting for message */
     p_TCB = rt_get_first ((P_XCB)p_MCB);
 #ifdef __CMSIS_RTOS
-    rt_ret_val2(p_TCB, 0x10/*osEventMessage*/, (U32)p_msg);
+    rt_ret_val2(p_TCB, 0x10U/*osEventMessage*/, (U32)p_msg);
 #else
     *p_TCB->msg = p_msg;
     rt_ret_val (p_TCB, OS_R_MBX);
@@ -90,7 +90,7 @@
       /* No free message entry, wait for one. If message queue is full, */
       /* then no task is waiting for message. The 'p_MCB->p_lnk' list   */
       /* pointer can now be reused for send message waits task list.    */
-      if (timeout == 0) {
+      if (timeout == 0U) {
         return (OS_R_TMO);
       }
       if (p_MCB->p_lnk != NULL) {
@@ -100,8 +100,8 @@
         p_MCB->p_lnk = os_tsk.run;
         os_tsk.run->p_lnk  = NULL;
         os_tsk.run->p_rlnk = (P_TCB)p_MCB;
-        /* Task is waiting to send a message */
-        p_MCB->state = 2;
+        /* Task is waiting to send a message */      
+        p_MCB->state = 2U;
       }
       os_tsk.run->msg = p_msg;
       rt_block (timeout, WAIT_MBX);
@@ -111,7 +111,7 @@
     p_MCB->msg[p_MCB->first] = p_msg;
     rt_inc (&p_MCB->count);
     if (++p_MCB->first == p_MCB->size) {
-      p_MCB->first = 0;
+      p_MCB->first = 0U;
     }
   }
   return (OS_R_OK);
@@ -130,19 +130,19 @@
   if (p_MCB->count) {
     *message = p_MCB->msg[p_MCB->last];
     if (++p_MCB->last == p_MCB->size) {
-      p_MCB->last = 0;
+      p_MCB->last = 0U;
     }
-    if ((p_MCB->p_lnk != NULL) && (p_MCB->state == 2)) {
+    if ((p_MCB->p_lnk != NULL) && (p_MCB->state == 2U)) {
       /* A task is waiting to send message */
       p_TCB = rt_get_first ((P_XCB)p_MCB);
 #ifdef __CMSIS_RTOS
-      rt_ret_val(p_TCB, 0/*osOK*/);
+      rt_ret_val(p_TCB, 0U/*osOK*/);
 #else
       rt_ret_val(p_TCB, OS_R_OK);
 #endif
       p_MCB->msg[p_MCB->first] = p_TCB->msg;
       if (++p_MCB->first == p_MCB->size) {
-        p_MCB->first = 0;
+        p_MCB->first = 0U;
       }
       rt_rmv_dly (p_TCB);
       rt_dispatch (p_TCB);
@@ -153,7 +153,7 @@
     return (OS_R_OK);
   }
   /* No message available: wait for one */
-  if (timeout == 0) {
+  if (timeout == 0U) {
     return (OS_R_TMO);
   }
   if (p_MCB->p_lnk != NULL) {
@@ -163,8 +163,8 @@
     p_MCB->p_lnk = os_tsk.run;
     os_tsk.run->p_lnk = NULL;
     os_tsk.run->p_rlnk = (P_TCB)p_MCB;
-    /* Task is waiting to receive a message */
-    p_MCB->state = 1;
+    /* Task is waiting to receive a message */      
+    p_MCB->state = 1U;
   }
   rt_block(timeout, WAIT_MBX);
 #ifndef __CMSIS_RTOS
@@ -181,7 +181,7 @@
   /* that can be stored to a mailbox. It returns 0 when mailbox is full.   */
   P_MCB p_MCB = mailbox;
 
-  return (p_MCB->size - p_MCB->count);
+  return ((U32)(p_MCB->size - p_MCB->count));
 }
 
 
@@ -206,14 +206,14 @@
   if (p_MCB->count) {
     /* A message is available in the fifo buffer. */
     *message = p_MCB->msg[p_MCB->last];
-    if (p_MCB->state == 2) {
+    if (p_MCB->state == 2U) {
       /* A task is locked waiting to send message */
-      rt_psq_enq (p_MCB, 0);
+      rt_psq_enq (p_MCB, 0U);
       rt_psh_req ();
     }
     rt_dec (&p_MCB->count);
     if (++p_MCB->last == p_MCB->size) {
-      p_MCB->last = 0;
+      p_MCB->last = 0U;
     }
     return (OS_R_MBX);
   }
@@ -233,7 +233,7 @@
     case 3:
       /* Task is waiting to allocate memory, remove it from the waiting list */
       mem = rt_alloc_box(p_msg);
-      if (mem == NULL) break;
+      if (mem == NULL) { break; }
       p_TCB = rt_get_first ((P_XCB)p_CB);
       rt_ret_val(p_TCB, (U32)mem);
       p_TCB->state = READY;
@@ -245,14 +245,14 @@
       /* Task is waiting to send a message, remove it from the waiting list */
       p_TCB = rt_get_first ((P_XCB)p_CB);
 #ifdef __CMSIS_RTOS
-      rt_ret_val(p_TCB, 0/*osOK*/);
+      rt_ret_val(p_TCB, 0U/*osOK*/);
 #else
       rt_ret_val(p_TCB, OS_R_OK);
 #endif
       p_CB->msg[p_CB->first] = p_TCB->msg;
       rt_inc (&p_CB->count);
       if (++p_CB->first == p_CB->size) {
-        p_CB->first = 0;
+        p_CB->first = 0U;
       }
       p_TCB->state = READY;
       rt_rmv_dly (p_TCB);
@@ -262,7 +262,7 @@
       /* Task is waiting for a message, pass the message to the task directly */
       p_TCB = rt_get_first ((P_XCB)p_CB);
 #ifdef __CMSIS_RTOS
-      rt_ret_val2(p_TCB, 0x10/*osEventMessage*/, (U32)p_msg);
+      rt_ret_val2(p_TCB, 0x10U/*osEventMessage*/, (U32)p_msg);
 #else
       *p_TCB->msg = p_msg;
       rt_ret_val (p_TCB, OS_R_MBX);
@@ -271,22 +271,23 @@
       rt_rmv_dly (p_TCB);
       rt_put_prio (&os_rdy, p_TCB);
       break;
+    default:
+      break;
   } else {
-      /* No task is waiting for a message, store it to the mailbox queue */
-      if (p_CB->count < p_CB->size) {
-        p_CB->msg[p_CB->first] = p_msg;
-        rt_inc (&p_CB->count);
-        if (++p_CB->first == p_CB->size) {
-          p_CB->first = 0;
-        }
+    /* No task is waiting for a message, store it to the mailbox queue */
+    if (p_CB->count < p_CB->size) {
+      p_CB->msg[p_CB->first] = p_msg;
+      rt_inc (&p_CB->count);
+      if (++p_CB->first == p_CB->size) {
+        p_CB->first = 0U;
       }
-      else {
-        os_error (OS_ERR_MBX_OVF);
-      }
+    }
+    else {
+      os_error (OS_ERR_MBX_OVF);
+    }
   }
 }
 
 /*----------------------------------------------------------------------------
  * end of file
  *---------------------------------------------------------------------------*/
-