Basic example showing the Mail API

Dependencies:   mbed-rtos mbed

mbed 2 and mbed OS 5

This is an mbed 2 example. mbed OS 5 has integrated the mbed library with mbed-rtos. For an mbed-os example, please see:

Import programrtos_mail

mail example

Files at this revision

API Documentation at this revision

Comitter:
emilmont
Date:
Fri Nov 23 10:40:18 2012 +0000
Parent:
1:6fcbb6f050a4
Child:
3:a3428581e64c
Commit message:
libraries update

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Jul 13 11:33:33 2012 +0000
+++ b/main.cpp	Fri Nov 23 10:40:18 2012 +0000
@@ -1,40 +1,40 @@
-#include "mbed.h"
-#include "rtos.h"
-
-/* Mail */
-typedef struct {
-  float    voltage; /* AD result of measured voltage */
-  float    current; /* AD result of measured current */
-  uint32_t counter; /* A counter value               */
-} mail_t;
-
-Mail<mail_t, 16> mail_box;
-
-void send_thread (void const *argument) {
-    uint32_t i = 0;
-    while (true) {
-        i++; // fake data update
-        mail_t *mail = mail_box.alloc();
-        mail->voltage = (i * 0.1) * 33; 
-        mail->current = (i * 0.1) * 11;
-        mail->counter = i;
-        mail_box.put(mail);
-        Thread::wait(1000);
-    }
-}
-
-int main (void) {
-    Thread thread(send_thread);
-    
-    while (true) {
-        osEvent evt = mail_box.get();
-        if (evt.status == osEventMail) {
-            mail_t *mail = (mail_t*)evt.value.p;
-            printf("\nVoltage: %.2f V\n\r"   , mail->voltage);
-            printf("Current: %.2f A\n\r"     , mail->current);
-            printf("Number of cycles: %u\n\r", mail->counter);
-            
-            mail_box.free(mail);
-        }
-    }
-}
+#include "mbed.h"
+#include "rtos.h"
+
+/* Mail */
+typedef struct {
+  float    voltage; /* AD result of measured voltage */
+  float    current; /* AD result of measured current */
+  uint32_t counter; /* A counter value               */
+} mail_t;
+
+Mail<mail_t, 16> mail_box;
+
+void send_thread (void const *args) {
+    uint32_t i = 0;
+    while (true) {
+        i++; // fake data update
+        mail_t *mail = mail_box.alloc();
+        mail->voltage = (i * 0.1) * 33; 
+        mail->current = (i * 0.1) * 11;
+        mail->counter = i;
+        mail_box.put(mail);
+        Thread::wait(1000);
+    }
+}
+
+int main (void) {
+    Thread thread(send_thread);
+    
+    while (true) {
+        osEvent evt = mail_box.get();
+        if (evt.status == osEventMail) {
+            mail_t *mail = (mail_t*)evt.value.p;
+            printf("\nVoltage: %.2f V\n\r"   , mail->voltage);
+            printf("Current: %.2f A\n\r"     , mail->current);
+            printf("Number of cycles: %u\n\r", mail->counter);
+            
+            mail_box.free(mail);
+        }
+    }
+}
--- a/mbed-rtos.lib	Fri Jul 13 11:33:33 2012 +0000
+++ b/mbed-rtos.lib	Fri Nov 23 10:40:18 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#01158bb7600c
+http://mbed.org/users/mbed_official/code/mbed-rtos/#80173c64d05d
--- a/mbed.bld	Fri Jul 13 11:33:33 2012 +0000
+++ b/mbed.bld	Fri Nov 23 10:40:18 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/3d775a932e1d
\ No newline at end of file