Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
teensy_clock.cpp
Go to the documentation of this file.
1
#include "
teensy_clock.h
"
2
#include "
cycles64.h
"
3
4
void
teensy_clock::begin
(
bool
sync)
5
{
6
cycles64::begin
();
7
if
(sync)
syncToRTC
();
8
}
9
10
std::time_t
teensy_clock::to_time_t
(
const
time_point
&
t
)
11
{
12
using namespace
std::chrono;
13
return
std::time_t(duration_cast<seconds>(
t
.time_since_epoch()).count());
14
}
15
16
teensy_clock::time_point
teensy_clock::from_time_t
(std::time_t
t
)
17
{
18
using namespace
std::chrono;
19
typedef
std::chrono::time_point<teensy_clock, seconds>
from
;
20
return
time_point_cast<duration>
(
from
(
seconds
(
t
)));
21
}
22
23
void
teensy_clock::syncToRTC
()
24
{
25
t0 = ((
uint64_t
)
rtc_get
()) *
F_CPU
-
cycles64::get
();
26
}
27
28
uint64_t teensy_clock::t0 = 0;
cycles64.h
t
int t
Definition
logging.cpp:17
cycles64::get
uint64_t get()
Definition
cycle64.cpp:23
cycles64::begin
void begin()
Definition
cycle64.cpp:39
teensy_clock::to_time_t
static std::time_t to_time_t(const time_point &t)
Definition
teensy_clock.cpp:10
teensy_clock::syncToRTC
static void syncToRTC()
Definition
teensy_clock.cpp:23
teensy_clock::begin
static void begin(bool sync=true)
Definition
teensy_clock.cpp:4
teensy_clock::time_point
std::chrono::time_point< teensy_clock, duration > time_point
Definition
teensy_clock.h:14
teensy_clock::from_time_t
static time_point from_time_t(std::time_t t)
Definition
teensy_clock.cpp:16
teensy_clock.h
c1
include
teensy_clock.cpp
Generated by
1.9.8