Test

Fork of events_ex_1 by mbed_example

Files at this revision

API Documentation at this revision

Comitter:
brandonboesch
Date:
Wed May 24 14:49:41 2017 +0000
Parent:
1:3ee1c217f3cb
Commit message:
Now has a safer background thread that does not call printf

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 3ee1c217f3cb -r 716e1b448b48 main.cpp
--- a/main.cpp	Tue May 23 10:20:54 2017 -0500
+++ b/main.cpp	Wed May 24 14:49:41 2017 +0000
@@ -6,9 +6,16 @@
 EventQueue queue(32 * EVENTS_EVENT_SIZE);
 Thread t;
 
+void rise_handler_user_context(void) {
+    printf("rise_handler_user_context in context %p\r\n", Thread::gettid());
+}
+
 void rise_handler(void) {
-    // Toggle LED
+    // Execute the time critical part first
     led1 = !led1;
+    // The rest can execute later in user context (and can contain code that's not interrupt safe).
+    // We use the 'queue.call' function to add an event (the call to 'rise_handler_user_context') to the queue.
+    queue.call(rise_handler_user_context);
 }
 
 void fall_handler(void) {
@@ -26,4 +33,3 @@
     // The 'fall' handler will execute in the context of thread 't'
     sw.fall(queue.event(fall_handler));
 }
-