ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
tmboy
Date:
Tue Jul 18 09:08:52 2017 +0000
Revision:
50:9ecaa144d1f3
Parent:
47:9e361da97763
add .json

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 47:9e361da97763 1 #include "events.h"
TMBOY 47:9e361da97763 2 #include "mbed.h"
TMBOY 47:9e361da97763 3 #include "mbed_stats.h"
TMBOY 47:9e361da97763 4
TMBOY 47:9e361da97763 5 namespace duer {
TMBOY 47:9e361da97763 6
TMBOY 47:9e361da97763 7 #ifdef MBED_HEAP_STATS_ENABLED
TMBOY 47:9e361da97763 8 void memory_statistics(const char* tag) {
TMBOY 47:9e361da97763 9 if (tag == NULL) {
TMBOY 47:9e361da97763 10 tag = "main";
TMBOY 47:9e361da97763 11 }
TMBOY 47:9e361da97763 12
TMBOY 47:9e361da97763 13 mbed_stats_heap_t current;
TMBOY 47:9e361da97763 14 mbed_stats_heap_get(&current);
TMBOY 47:9e361da97763 15 printf("[%s] !!!MEMORY!!! current_size: %d, max_size: %d, total_size: %d, alloc_cnt: %d, "
TMBOY 47:9e361da97763 16 "alloc_fail_cnt: %d\n", tag, current.current_size, current.max_size, current.total_size,
TMBOY 47:9e361da97763 17 current.alloc_cnt, current.alloc_fail_cnt);
TMBOY 47:9e361da97763 18 }
TMBOY 47:9e361da97763 19 #endif
TMBOY 47:9e361da97763 20
TMBOY 47:9e361da97763 21 static rtos::Queue<int, 5> g_message_q;
TMBOY 47:9e361da97763 22 static event_handle_func g_events_handler[EVT_TOTAL];
TMBOY 47:9e361da97763 23
TMBOY 47:9e361da97763 24 void event_set_handler(uint32_t evt_id, event_handle_func handler) {
TMBOY 47:9e361da97763 25 if (evt_id < EVT_TOTAL) {
TMBOY 47:9e361da97763 26 g_events_handler[evt_id] = handler;
TMBOY 47:9e361da97763 27 }
TMBOY 47:9e361da97763 28 }
TMBOY 47:9e361da97763 29
TMBOY 47:9e361da97763 30 void event_trigger(uint32_t evt_id) {
TMBOY 47:9e361da97763 31 g_message_q.put((int*)evt_id);
TMBOY 47:9e361da97763 32 }
TMBOY 47:9e361da97763 33
TMBOY 47:9e361da97763 34 static void event_loop_run() {
TMBOY 47:9e361da97763 35 osEvent evt;
TMBOY 47:9e361da97763 36
TMBOY 47:9e361da97763 37 do {
TMBOY 47:9e361da97763 38 evt = g_message_q.get();
TMBOY 47:9e361da97763 39
TMBOY 47:9e361da97763 40 if (evt.status != osEventMessage) {
TMBOY 47:9e361da97763 41 continue;
TMBOY 47:9e361da97763 42 }
TMBOY 47:9e361da97763 43
TMBOY 47:9e361da97763 44 uint32_t evt_id = evt.value.v;
TMBOY 47:9e361da97763 45
TMBOY 47:9e361da97763 46 if (evt_id < EVT_TOTAL) {
TMBOY 47:9e361da97763 47 g_events_handler[evt_id]();
TMBOY 47:9e361da97763 48 }
TMBOY 47:9e361da97763 49 } while (true);
TMBOY 47:9e361da97763 50 }
TMBOY 47:9e361da97763 51
TMBOY 47:9e361da97763 52 void event_loop() {
TMBOY 47:9e361da97763 53 #ifdef __BAIDU_EVENT_SINGLE_TASK__
TMBOY 47:9e361da97763 54 Thread th(osPriorityHigh);
TMBOY 47:9e361da97763 55 th.start(event_loop_run);
TMBOY 47:9e361da97763 56 Thread::wait(osWaitForever);
TMBOY 47:9e361da97763 57 #else
TMBOY 47:9e361da97763 58 event_loop_run();
TMBOY 47:9e361da97763 59 #endif
TMBOY 47:9e361da97763 60 }
TMBOY 47:9e361da97763 61
TMBOY 47:9e361da97763 62 } // namespace duer