STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
board_time.h
Go to the documentation of this file.
1#ifndef STAR_BOARD_TIME_H
2#define STAR_BOARD_TIME_H
3
4/*
5 * Microsecond timebase: TIM2, a 32-bit counter at 1 MHz (prescaler 63 in the
6 * .ioc at today's 64 MHz timer clock), free running, wrapping every ~71.6 min.
7 * Every sample is stamped with it. TIM2 CH4 captures the GPS TIMEPULSE (PB11)
8 * on the same counter, so samples can be placed on GPS time.
9 */
10
11#include <stdbool.h>
12#include <stdint.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18/* Start the counter and the CH4 capture interrupt. Returns false if TIM2 does
19 * not actually tick at 1 MHz (e.g. the clock tree changed but the .ioc
20 * prescaler did not), in which case timestamps are not trustworthy. */
21bool board_time_start(void);
22
23/* Microseconds since board_time_start(), modulo 2^32. ISR-safe. */
24uint32_t board_time_us(void);
25
26/* Most recent GPS TIMEPULSE edge (rising), in board_time_us() units, and how
27 * many have been captured. count == 0 means none yet. */
28typedef struct {
29 uint32_t edge_us;
30 uint32_t count;
32
34
35#ifdef __cplusplus
36}
37#endif
38#endif
board_pps_t board_time_last_pps(void)
Definition board_time.c:38
uint32_t board_time_us(void)
Definition board_time.c:34
bool board_time_start(void)
Definition board_time.c:27
uint32_t count
Definition board_time.h:30
uint32_t edge_us
Definition board_time.h:29