leo hendrickson / Mbed OS example-Ethernet-mbed-Cloud-connect
Committer:
leothedragon
Date:
Tue May 04 08:55:12 2021 +0000
Revision:
0:8f0bb79ddd48
nmn

Who changed what in which revision?

UserRevisionLine numberNew contents of line
leothedragon 0:8f0bb79ddd48 1 /*
leothedragon 0:8f0bb79ddd48 2 * Copyright (c) 2016 ARM Limited, All Rights Reserved
leothedragon 0:8f0bb79ddd48 3 */
leothedragon 0:8f0bb79ddd48 4
leothedragon 0:8f0bb79ddd48 5 // Include before mbed.h to properly get UINT*_C()
leothedragon 0:8f0bb79ddd48 6
leothedragon 0:8f0bb79ddd48 7 #include "ns_types.h"
leothedragon 0:8f0bb79ddd48 8
leothedragon 0:8f0bb79ddd48 9 #include "platform/arm_hal_timer.h"
leothedragon 0:8f0bb79ddd48 10 #include "platform/arm_hal_interrupt.h"
leothedragon 0:8f0bb79ddd48 11
leothedragon 0:8f0bb79ddd48 12 #if defined(NS_EVENTLOOP_USE_TICK_TIMER) && defined(YOTTA_CFG_MINAR)
leothedragon 0:8f0bb79ddd48 13
leothedragon 0:8f0bb79ddd48 14 #include "minar/minar.h"
leothedragon 0:8f0bb79ddd48 15 #include "mbed-drivers/mbed.h"
leothedragon 0:8f0bb79ddd48 16 #include "core-util/FunctionPointer.h"
leothedragon 0:8f0bb79ddd48 17 #include "core-util/Event.h"
leothedragon 0:8f0bb79ddd48 18
leothedragon 0:8f0bb79ddd48 19 #define TICK_TIMER_ID 1
leothedragon 0:8f0bb79ddd48 20
leothedragon 0:8f0bb79ddd48 21 using minar::Scheduler;
leothedragon 0:8f0bb79ddd48 22 using minar::milliseconds;
leothedragon 0:8f0bb79ddd48 23 using minar::callback_handle_t;
leothedragon 0:8f0bb79ddd48 24 using namespace mbed::util;
leothedragon 0:8f0bb79ddd48 25
leothedragon 0:8f0bb79ddd48 26 static callback_handle_t sys_timer_handle;
leothedragon 0:8f0bb79ddd48 27 static void (*tick_timer_callback)(void);
leothedragon 0:8f0bb79ddd48 28
leothedragon 0:8f0bb79ddd48 29 void timer_callback(void const *funcArgument)
leothedragon 0:8f0bb79ddd48 30 {
leothedragon 0:8f0bb79ddd48 31 (void)funcArgument;
leothedragon 0:8f0bb79ddd48 32 if (NULL != tick_timer_callback) {
leothedragon 0:8f0bb79ddd48 33 tick_timer_callback();
leothedragon 0:8f0bb79ddd48 34 }
leothedragon 0:8f0bb79ddd48 35 }
leothedragon 0:8f0bb79ddd48 36
leothedragon 0:8f0bb79ddd48 37 // Low precision platform tick timer
leothedragon 0:8f0bb79ddd48 38 int8_t platform_tick_timer_register(void (*tick_timer_cb_handler)(void))
leothedragon 0:8f0bb79ddd48 39 {
leothedragon 0:8f0bb79ddd48 40 tick_timer_callback = tick_timer_cb_handler;
leothedragon 0:8f0bb79ddd48 41 return TICK_TIMER_ID;
leothedragon 0:8f0bb79ddd48 42 }
leothedragon 0:8f0bb79ddd48 43
leothedragon 0:8f0bb79ddd48 44 int8_t platform_tick_timer_start(uint32_t period_ms)
leothedragon 0:8f0bb79ddd48 45 {
leothedragon 0:8f0bb79ddd48 46 int8_t retval = -1;
leothedragon 0:8f0bb79ddd48 47 if (sys_timer_handle != NULL) {
leothedragon 0:8f0bb79ddd48 48 return 0; // Timer already started already so return success
leothedragon 0:8f0bb79ddd48 49 }
leothedragon 0:8f0bb79ddd48 50 Event e = FunctionPointer1<void, void const *>(timer_callback).bind(NULL);
leothedragon 0:8f0bb79ddd48 51 if (e != NULL) {
leothedragon 0:8f0bb79ddd48 52 sys_timer_handle = Scheduler::postCallback(e).period(milliseconds(period_ms)).getHandle();
leothedragon 0:8f0bb79ddd48 53 if (sys_timer_handle != NULL) {
leothedragon 0:8f0bb79ddd48 54 retval = 0;
leothedragon 0:8f0bb79ddd48 55 }
leothedragon 0:8f0bb79ddd48 56 }
leothedragon 0:8f0bb79ddd48 57 return retval;
leothedragon 0:8f0bb79ddd48 58 }
leothedragon 0:8f0bb79ddd48 59
leothedragon 0:8f0bb79ddd48 60 int8_t platform_tick_timer_stop(void)
leothedragon 0:8f0bb79ddd48 61 {
leothedragon 0:8f0bb79ddd48 62 int8_t retval = -1;
leothedragon 0:8f0bb79ddd48 63 if (sys_timer_handle != NULL) {
leothedragon 0:8f0bb79ddd48 64 Scheduler::cancelCallback(sys_timer_handle);
leothedragon 0:8f0bb79ddd48 65 sys_timer_handle = NULL;
leothedragon 0:8f0bb79ddd48 66 retval = 0;
leothedragon 0:8f0bb79ddd48 67 }
leothedragon 0:8f0bb79ddd48 68 return retval;
leothedragon 0:8f0bb79ddd48 69 }
leothedragon 0:8f0bb79ddd48 70
leothedragon 0:8f0bb79ddd48 71 #endif // defined(NS_EVENTLOOP_USE_TICK_TIMER) && defined(YOTTA_CFG)