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 0:03a01dc34973, committed 2018-11-16
- Comitter:
- iandil
- Date:
- Fri Nov 16 13:45:52 2018 +0000
- Child:
- 1:bc20d07886cc
- Commit message:
- put everything inside thread context;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed-os.lib | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Nov 16 13:45:52 2018 +0000
@@ -0,0 +1,46 @@
+#include "mbed.h"
+
+DigitalOut led3(LED3);
+InterruptIn button(USER_BUTTON);
+EventQueue queue(32 * EVENTS_EVENT_SIZE);
+Thread t;
+int counter = 0;
+volatile time_t seconds_now;
+
+void rise_handler_thread_context(void) {
+ counter++;
+ if((time(NULL) - seconds_now) < 2000) {
+ if(counter == 2) {
+ led3 = !led3;
+ wait(0.8);
+ led3 = !led3;
+ counter = 0;
+ seconds_now = time(NULL);
+ }
+ } else {
+ seconds_now = time(NULL);
+ counter = 0;
+ }
+}
+
+void rise_handler_iterrupt_context(void) {
+ // Execute the time critical part first
+ // 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_thread_context);
+}
+
+void fall_handler(void) {
+ printf("Output a String\n");
+}
+
+int main() {
+ // Start the event queue
+ t.start(callback(&queue, &EventQueue::dispatch_forever));
+ printf("Starting in context %p\r\n", Thread::gettid());
+ // The 'rise' handler will execute in IRQ context
+ seconds_now = time(NULL);
+ button.rise(rise_handler_iterrupt_context);
+ // The 'fall' handler will execute in the context of thread 't'
+ button.fall(queue.event(fall_handler));
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Fri Nov 16 13:45:52 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/armmbed/mbed-os/#bf6f2c3c6434a6de9eb9511feffa5948b3d1f20f