![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Backing up an unused program in case of future need
time.cpp
- Committer:
- andrewboyson
- Date:
- 2016-05-31
- Revision:
- 6:be97d38e0b01
- Parent:
- 2:06fa34661f19
- Child:
- 7:024ace6d943c
File content as of revision 6:be97d38e0b01:
#include "mbed.h" #define ONE_MILLION 1000000 static Ticker ticker; static volatile uint64_t unixTime16ths; static void tick(void) { unixTime16ths++; } void TimeSet(uint32_t t) { unixTime16ths = (uint64_t)t << 4; } uint32_t TimeGet() { return unixTime16ths >> 4; } void TimeSet16ths(uint64_t t) { unixTime16ths = t; } uint64_t TimeGet16ths() { return unixTime16ths; } static Timer timer; int TimeScanUs = 0; int TimeMain() { int scanUs = timer.read_us(); timer.reset(); timer.start(); if (scanUs > TimeScanUs) TimeScanUs++; if (scanUs < TimeScanUs) TimeScanUs--; return 0; } int TimeInit() { ticker.attach_us(&tick, ONE_MILLION >> 4); timer.stop(); timer.reset(); return 0; }