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.
Revision 13:510fb9ae8592, committed 2020-05-03
- Comitter:
- wssingle
- Date:
- Sun May 03 19:15:05 2020 +0000
- Parent:
- 12:4e3f46e615d9
- Commit message:
- Lab 8 part 4
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Mar 30 18:54:14 2020 +0000
+++ b/main.cpp Sun May 03 19:15:05 2020 +0000
@@ -0,0 +1,42 @@
+#include "mbed.h"
+#include "rtos.h"
+
+typedef struct {
+ float voltage; /* AD result of measured voltage */
+ float current; /* AD result of measured current */
+ uint32_t counter; /* A counter value */
+} message_t;
+
+MemoryPool<message_t, 16> mpool;
+Queue<message_t, 16> queue;
+
+/* Send Thread */
+void send_thread (void) {
+ uint32_t i = 0;
+ while (true) {
+ i++; // fake data update
+ message_t *message = mpool.alloc();
+ message->voltage = (i * 0.1) * 33;
+ message->current = (i * 0.1) * 11;
+ message->counter = i;
+ queue.put(message);
+ Thread::wait(1000);
+ }
+}
+
+int main (void) {
+ Thread thread;
+ thread.start(callback(send_thread));
+
+ while (true) {
+ osEvent evt = queue.get();
+ if (evt.status == osEventMessage) {
+ message_t *message = (message_t*)evt.value.p;
+ printf("\nVoltage: %.2f V\n\r" , message->voltage);
+ printf("Current: %.2f A\n\r" , message->current);
+ printf("Number of cycles: %u\n\r", message->counter);
+
+ mpool.free(message);
+ }
+ }
+}
\ No newline at end of file