]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/mail/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / tests / rtos / cmsis / mail / main.cpp
1 #include "mbed.h"
2 #include "cmsis_os.h"
3
4 typedef struct {
5   float    voltage; /* AD result of measured voltage */
6   float    current; /* AD result of measured current */
7   uint32_t counter; /* A counter value               */
8 } mail_t;
9
10 osMailQDef(mail_box, 16, mail_t);
11 osMailQId  mail_box;
12
13 void send_thread (void const *argument) {
14     uint32_t i = 0;
15     while (true) {
16         i++; // fake data update
17         mail_t *mail = (mail_t*)osMailAlloc(mail_box, osWaitForever);
18         mail->voltage = (i * 0.1) * 33;
19         mail->current = (i * 0.1) * 11;
20         mail->counter = i;
21         osMailPut(mail_box, mail);
22         osDelay(1000);
23     }
24 }
25
26 osThreadDef(send_thread, osPriorityNormal, DEFAULT_STACK_SIZE);
27
28 int main (void) {
29     mail_box = osMailCreate(osMailQ(mail_box), NULL);
30     osThreadCreate(osThread(send_thread), NULL);
31
32     while (true) {
33         osEvent evt = osMailGet(mail_box, osWaitForever);
34         if (evt.status == osEventMail) {
35             mail_t *mail = (mail_t*)evt.value.p;
36             printf("\nVoltage: %.2f V\n\r"   , mail->voltage);
37             printf("Current: %.2f A\n\r"     , mail->current);
38             printf("Number of cycles: %u\n\r", mail->counter);
39
40             osMailFree(mail_box, mail);
41         }
42     }
43 }