Dependencies:   MMA7660 LM75B

Committer:
MACRUM
Date:
Sat Jun 30 01:40:30 2018 +0000
Revision:
0:119624335925
Initial commit

Who changed what in which revision?

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