ok

Dependencies:   mbed-rtos mbed

Fork of rtos_mail by mbed official

Committer:
emilmont
Date:
Fri Jul 13 11:33:33 2012 +0000
Revision:
1:6fcbb6f050a4
Parent:
0:aa38feded393
Child:
2:b84386915279
First implementation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:6fcbb6f050a4 1 #include "mbed.h"
emilmont 1:6fcbb6f050a4 2 #include "rtos.h"
emilmont 1:6fcbb6f050a4 3
emilmont 1:6fcbb6f050a4 4 /* Mail */
emilmont 1:6fcbb6f050a4 5 typedef struct {
emilmont 1:6fcbb6f050a4 6 float voltage; /* AD result of measured voltage */
emilmont 1:6fcbb6f050a4 7 float current; /* AD result of measured current */
emilmont 1:6fcbb6f050a4 8 uint32_t counter; /* A counter value */
emilmont 1:6fcbb6f050a4 9 } mail_t;
emilmont 1:6fcbb6f050a4 10
emilmont 1:6fcbb6f050a4 11 Mail<mail_t, 16> mail_box;
emilmont 1:6fcbb6f050a4 12
emilmont 1:6fcbb6f050a4 13 void send_thread (void const *argument) {
emilmont 1:6fcbb6f050a4 14 uint32_t i = 0;
emilmont 1:6fcbb6f050a4 15 while (true) {
emilmont 1:6fcbb6f050a4 16 i++; // fake data update
emilmont 1:6fcbb6f050a4 17 mail_t *mail = mail_box.alloc();
emilmont 1:6fcbb6f050a4 18 mail->voltage = (i * 0.1) * 33;
emilmont 1:6fcbb6f050a4 19 mail->current = (i * 0.1) * 11;
emilmont 1:6fcbb6f050a4 20 mail->counter = i;
emilmont 1:6fcbb6f050a4 21 mail_box.put(mail);
emilmont 1:6fcbb6f050a4 22 Thread::wait(1000);
emilmont 1:6fcbb6f050a4 23 }
emilmont 1:6fcbb6f050a4 24 }
emilmont 1:6fcbb6f050a4 25
emilmont 1:6fcbb6f050a4 26 int main (void) {
emilmont 1:6fcbb6f050a4 27 Thread thread(send_thread);
emilmont 1:6fcbb6f050a4 28
emilmont 1:6fcbb6f050a4 29 while (true) {
emilmont 1:6fcbb6f050a4 30 osEvent evt = mail_box.get();
emilmont 1:6fcbb6f050a4 31 if (evt.status == osEventMail) {
emilmont 1:6fcbb6f050a4 32 mail_t *mail = (mail_t*)evt.value.p;
emilmont 1:6fcbb6f050a4 33 printf("\nVoltage: %.2f V\n\r" , mail->voltage);
emilmont 1:6fcbb6f050a4 34 printf("Current: %.2f A\n\r" , mail->current);
emilmont 1:6fcbb6f050a4 35 printf("Number of cycles: %u\n\r", mail->counter);
emilmont 1:6fcbb6f050a4 36
emilmont 1:6fcbb6f050a4 37 mail_box.free(mail);
emilmont 1:6fcbb6f050a4 38 }
emilmont 1:6fcbb6f050a4 39 }
emilmont 1:6fcbb6f050a4 40 }