Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of rtos_mail by
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 00004 /* Mail */ 00005 typedef struct { 00006 float voltage; /* AD result of measured voltage */ 00007 float current; /* AD result of measured current */ 00008 uint32_t counter; /* A counter value */ 00009 } mail_t; 00010 00011 Mail<mail_t, 16> mail_box; 00012 00013 void send_thread (void const *args) { 00014 uint32_t i = 0; 00015 while (true) { 00016 i++; // fake data update 00017 mail_t *mail = mail_box.alloc(); 00018 mail->voltage = (i * 0.1) * 33; 00019 mail->current = (i * 0.1) * 11; 00020 mail->counter = i; 00021 mail_box.put(mail); 00022 Thread::wait(1000); 00023 } 00024 } 00025 00026 int main (void) { 00027 Thread thread(send_thread); 00028 00029 while (true) { 00030 osEvent evt = mail_box.get(); 00031 if (evt.status == osEventMail) { 00032 mail_t *mail = (mail_t*)evt.value.p; 00033 printf("\nVoltage: %.2f V\n\r" , mail->voltage); 00034 printf("Current: %.2f A\n\r" , mail->current); 00035 printf("Number of cycles: %u\n\r", mail->counter); 00036 00037 mail_box.free(mail); 00038 } 00039 } 00040 }
Generated on Thu Jul 14 2022 01:10:20 by
1.7.2
