Skip to content

Instantly share code, notes, and snippets.

@martinandrovich
Created March 7, 2019 18:24
Show Gist options
  • Save martinandrovich/92c0980abb2626b198dfe842cff77440 to your computer and use it in GitHub Desktop.
Save martinandrovich/92c0980abb2626b198dfe842cff77440 to your computer and use it in GitHub Desktop.
Demo of TIMEPOINT module
// initialize systick to 200ns per systick
tp.init_systick(200, ns);
// call this only from the SYSTICK ISR
tp.systick();
// init test TIMEPOINT instances
TIMEPOINT* tp_test1 = tp.new();
TIMEPOINT* tp_test2 = tp.new();
TIMEPOINT* tp_test3 = tp.new();
// set tp_test1 to current (global) time (value of SYSTICK)
tp.set(tp_test1, tp.now());
// set tp_test2 to 0ns:0us:10ms:2s
tp.set(tp_test2, (uint64_t[]){ 0, 0, 10, 2 });
// copy value of tp_test2 into tp_test3
tp.copy(tp_test3, tp_test2);
// get absolute difference between tp_test1 and tp_test3 in ms
int32_t diff1 = tp.delta(tp_test1, tp_test3, ms);
// get absolute difference between current time and tp_test2 in ms
int32_t diff2 = tp.delta_now(tp_test2, ms);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment