test

Committer:
peyo
Date:
Wed Apr 12 14:09:46 2017 +0200
Revision:
1:3f75eb8d46f4
Parent:
0:cd5404401c2f
add main

Who changed what in which revision?

UserRevisionLine numberNew contents of line
peyo 0:cd5404401c2f 1 /**
peyo 0:cd5404401c2f 2 * @file timer.c
peyo 0:cd5404401c2f 3 * @brief mbed-os implementation of the timer interface needed for AWS.
peyo 0:cd5404401c2f 4 */
peyo 0:cd5404401c2f 5 #ifdef __cplusplus
peyo 0:cd5404401c2f 6 extern "C" {
peyo 0:cd5404401c2f 7 #endif
peyo 0:cd5404401c2f 8
peyo 0:cd5404401c2f 9 #include <stddef.h>
peyo 0:cd5404401c2f 10 #include "timer_interface.h"
peyo 0:cd5404401c2f 11
peyo 0:cd5404401c2f 12 TimerExt::TimerExt() : mbed::Timer(){
peyo 0:cd5404401c2f 13
peyo 0:cd5404401c2f 14 }
peyo 0:cd5404401c2f 15
peyo 0:cd5404401c2f 16 bool has_timer_expired(TimerAWS* timer) {
peyo 0:cd5404401c2f 17 return (timer->read_ms() > timer->timeout_ms);
peyo 0:cd5404401c2f 18 }
peyo 0:cd5404401c2f 19
peyo 0:cd5404401c2f 20 void countdown_ms(TimerAWS *timer, uint32_t timeout) {
peyo 0:cd5404401c2f 21 timer->timeout_ms = timeout;
peyo 0:cd5404401c2f 22 timer->reset();
peyo 0:cd5404401c2f 23 timer->start();
peyo 0:cd5404401c2f 24 }
peyo 0:cd5404401c2f 25
peyo 0:cd5404401c2f 26 void countdown_sec(TimerAWS *timer, uint32_t timeout) {
peyo 0:cd5404401c2f 27 timer->timeout_ms = (timeout * 1000);
peyo 0:cd5404401c2f 28 timer->reset();
peyo 0:cd5404401c2f 29 timer->start();
peyo 0:cd5404401c2f 30 }
peyo 0:cd5404401c2f 31
peyo 0:cd5404401c2f 32 uint32_t left_ms(TimerAWS* timer) {
peyo 0:cd5404401c2f 33 if (timer->read_ms() < timer->timeout_ms)
peyo 0:cd5404401c2f 34 return (timer->timeout_ms - timer->read_ms());
peyo 0:cd5404401c2f 35 return 0;
peyo 0:cd5404401c2f 36 }
peyo 0:cd5404401c2f 37
peyo 0:cd5404401c2f 38 void init_timer(TimerAWS * timer){
peyo 0:cd5404401c2f 39 timer->stop();
peyo 0:cd5404401c2f 40 timer->reset();
peyo 0:cd5404401c2f 41 timer->timeout_ms = 0;
peyo 0:cd5404401c2f 42 }
peyo 0:cd5404401c2f 43 #ifdef __cplusplus
peyo 0:cd5404401c2f 44 }
peyo 0:cd5404401c2f 45 #endif