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.
main.cpp
00001 #include "mbed.h" 00002 00003 DigitalOut led1(LED1); 00004 InterruptIn button(USER_BUTTON); 00005 EventQueue queue(32 * EVENTS_EVENT_SIZE); 00006 Thread t; 00007 00008 volatile time_t first_seconds = 0; 00009 00010 void fall_handler_thread_context(void) { 00011 printf("rise_handler_thread_context in context %p\r\n", Thread::gettid()); 00012 printf("firt_seconds: %d\n", first_seconds); 00013 time_t seconds = time(NULL); 00014 if (first_seconds != 0 && ((seconds - first_seconds) < 2)) { 00015 led1 = !led1; 00016 } 00017 printf("seconds: %d\n", seconds); 00018 first_seconds = seconds; 00019 } 00020 00021 void fall_handler_iterrupt_context(void) { 00022 // Execute the time critical part first 00023 00024 // The rest can execute later in user context (and can contain code that's not interrupt safe) 00025 // We use the 'queue.call' function to add an event (the call to 'rise_handler_user_context') to the queue 00026 queue.call(fall_handler_thread_context); 00027 } 00028 00029 00030 int main() { 00031 // Start the event queue 00032 t.start(callback(&queue, &EventQueue::dispatch_forever)); 00033 printf("Starting in context %p\r\n", Thread::gettid()); 00034 // The 'rise' handler will execute in IRQ context 00035 button.fall(fall_handler_iterrupt_context); 00036 // button.rise(queue.event(rise_handler)); 00037 // The 'fall' handler will execute in the context of thread 't' 00038 }
Generated on Tue Jul 19 2022 14:59:39 by
1.7.2