Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
minar_hal_timer.cpp
00001 /* 00002 * Copyright (c) 2016 ARM Limited, All Rights Reserved 00003 */ 00004 00005 // Include before mbed.h to properly get UINT*_C() 00006 00007 #include "ns_types.h" 00008 00009 #include "platform/arm_hal_timer.h" 00010 #include "platform/arm_hal_interrupt.h" 00011 00012 #if defined(NS_EVENTLOOP_USE_TICK_TIMER) && defined(YOTTA_CFG_MINAR) 00013 00014 #include "minar/minar.h" 00015 #include "mbed-drivers/mbed.h" 00016 #include "core-util/FunctionPointer.h" 00017 #include "core-util/Event.h" 00018 00019 #define TICK_TIMER_ID 1 00020 00021 using minar::Scheduler; 00022 using minar::milliseconds; 00023 using minar::callback_handle_t; 00024 using namespace mbed::util; 00025 00026 static callback_handle_t sys_timer_handle; 00027 static void (*tick_timer_callback)(void); 00028 00029 void timer_callback(void const *funcArgument) 00030 { 00031 (void)funcArgument; 00032 if (NULL != tick_timer_callback) { 00033 tick_timer_callback(); 00034 } 00035 } 00036 00037 // Low precision platform tick timer 00038 int8_t platform_tick_timer_register(void (*tick_timer_cb_handler)(void)) 00039 { 00040 tick_timer_callback = tick_timer_cb_handler; 00041 return TICK_TIMER_ID; 00042 } 00043 00044 int8_t platform_tick_timer_start(uint32_t period_ms) 00045 { 00046 int8_t retval = -1; 00047 if (sys_timer_handle != NULL) { 00048 return 0; // Timer already started already so return success 00049 } 00050 Event e = FunctionPointer1<void, void const *>(timer_callback).bind(NULL); 00051 if (e != NULL) { 00052 sys_timer_handle = Scheduler::postCallback(e).period(milliseconds(period_ms)).getHandle(); 00053 if (sys_timer_handle != NULL) { 00054 retval = 0; 00055 } 00056 } 00057 return retval; 00058 } 00059 00060 int8_t platform_tick_timer_stop(void) 00061 { 00062 int8_t retval = -1; 00063 if (sys_timer_handle != NULL) { 00064 Scheduler::cancelCallback(sys_timer_handle); 00065 sys_timer_handle = NULL; 00066 retval = 0; 00067 } 00068 return retval; 00069 } 00070 00071 #endif // defined(NS_EVENTLOOP_USE_TICK_TIMER) && defined(YOTTA_CFG)
Generated on Sun Jul 17 2022 08:25:28 by 1.7.2