KEIS

Dependencies:   C12832_lcd mbed-rtos mbed

Fork of rtos_mail by mbed official

Committer:
emilmont
Date:
Fri Nov 23 10:40:18 2012 +0000
Revision:
2:b84386915279
Parent:
1:6fcbb6f050a4
Child:
4:4273c11c7ac1
libraries update

Who changed what in which revision?

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