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.
Fork of mbed-os-example-mbed5-blinky by
events.cpp
00001 #include "events.h" 00002 #include "mbed.h" 00003 #include "mbed_stats.h" 00004 00005 namespace duer { 00006 00007 #ifdef MBED_HEAP_STATS_ENABLED 00008 void memory_statistics(const char* tag) { 00009 if (tag == NULL) { 00010 tag = "main"; 00011 } 00012 00013 mbed_stats_heap_t current; 00014 mbed_stats_heap_get(¤t); 00015 printf("[%s] !!!MEMORY!!! current_size: %d, max_size: %d, total_size: %d, alloc_cnt: %d, " 00016 "alloc_fail_cnt: %d\n", tag, current.current_size, current.max_size, current.total_size, 00017 current.alloc_cnt, current.alloc_fail_cnt); 00018 } 00019 #endif 00020 00021 static rtos::Queue<int, 5> g_message_q; 00022 static event_handle_func g_events_handler[EVT_TOTAL]; 00023 00024 void event_set_handler(uint32_t evt_id, event_handle_func handler) { 00025 if (evt_id < EVT_TOTAL) { 00026 g_events_handler[evt_id] = handler; 00027 } 00028 } 00029 00030 void event_trigger(uint32_t evt_id) { 00031 g_message_q.put((int*)evt_id); 00032 } 00033 00034 static void event_loop_run() { 00035 osEvent evt; 00036 00037 do { 00038 evt = g_message_q.get(); 00039 00040 if (evt.status != osEventMessage) { 00041 continue; 00042 } 00043 00044 uint32_t evt_id = evt.value.v; 00045 00046 if (evt_id < EVT_TOTAL) { 00047 g_events_handler[evt_id](); 00048 } 00049 } while (true); 00050 } 00051 00052 void event_loop() { 00053 #ifdef __BAIDU_EVENT_SINGLE_TASK__ 00054 Thread th(osPriorityHigh); 00055 th.start(event_loop_run); 00056 Thread::wait(osWaitForever); 00057 #else 00058 event_loop_run(); 00059 #endif 00060 } 00061 00062 } // namespace duer
Generated on Tue Jul 12 2022 16:28:53 by
1.7.2
