Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
teensy_clock.h
Go to the documentation of this file.
1#pragma once
2
3#include "Arduino.h"
4#include <chrono>
5
6#include "cycles64.h"
7
9{
10 // required typdefs:
11 using duration = std::chrono::duration<uint64_t, std::ratio<1, F_CPU>>; // use a uint64_t representation with a time step of 1/F_CPU (=1.667ns @600MHz)
12 using rep = duration::rep; // uint64_t
13 using period = duration::period; // std::ratio<1,600>
14 using time_point = std::chrono::time_point<teensy_clock, duration>;
15
16 static constexpr bool is_steady = false; // can not be guaranteed to be steady (could be readjusted by syncToRTC)
17
18 static time_point now()
19 {
20 duration t = duration(t0 + cycles64::get()); // adds the current 64bit cycle counter to an offset set by syncToRTC() (default: t0=0)
21 return time_point(t); // ... and returns the correspoinging time point.
22 }
23
24 static void begin(bool sync = true); // starts the 64bit cycle counter update interrupt. Sync=true sycns the clock to the RTC
25 static void syncToRTC(); // Sync to RTC whenever needed (e.g. after adjusting the RTC)
26
27 //Map to C API
28 static std::time_t to_time_t(const time_point& t); // returns the time_t value (seconds since 1.1.1970) to be used with standard C-API functions
29 static time_point from_time_t(std::time_t t); // converts a time_t value to a time_point
30
31 private:
32 static uint64_t t0; // offset to adjust time (seconds from 1.1.1970 to now).
33};
34
int t
Definition logging.cpp:17
uint64_t get()
Definition cycle64.cpp:23
static std::time_t to_time_t(const time_point &t)
static void syncToRTC()
duration::period period
static constexpr bool is_steady
duration::rep rep
std::chrono::duration< uint64_t, std::ratio< 1, F_CPU > > duration
static time_point now()
static void begin(bool sync=true)
std::chrono::time_point< teensy_clock, duration > time_point
static time_point from_time_t(std::time_t t)