WPILibC++ 2024.3.2
timestamp.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#ifndef WPIUTIL_WPI_TIMESTAMP_H_
6#define WPIUTIL_WPI_TIMESTAMP_H_
7
8#include <stdint.h>
9
10#ifdef __cplusplus
11#include <memory> // NOLINT
12
13#endif
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/**
20 * De-initialize the on-Rio Now() implementation. No effect on non-Rio
21 * platforms.
22 */
24
25/**
26 * The default implementation used for Now().
27 * In general this is the time returned by the operating system.
28 * @return Time in microseconds.
29 */
30uint64_t WPI_NowDefault(void);
31
32/**
33 * Set the implementation used by WPI_Now().
34 * The implementation must return monotonic time in microseconds to maintain
35 * the contract of WPI_Now().
36 * @param func Function called by WPI_Now() to return the time.
37 */
38void WPI_SetNowImpl(uint64_t (*func)(void));
39
40/**
41 * Return a value representing the current time in microseconds.
42 * The epoch is not defined.
43 * @return Time in microseconds.
44 */
45uint64_t WPI_Now(void);
46
47/**
48 * Return the current system time in microseconds since the Unix epoch
49 * (January 1st, 1970 00:00 UTC).
50 *
51 * @return Time in microseconds.
52 */
53uint64_t WPI_GetSystemTime(void);
54
55#ifdef __cplusplus
56} // extern "C"
57#endif
58
59#ifdef __cplusplus
60namespace wpi {
61
62namespace impl {
63/**
64 * Initialize the on-Rio Now() implementation to use the desktop timestamp.
65 * No effect on non-Rio platforms. This should only be used for testing
66 * purposes if the HAL is not available.
67 */
69
70/**
71 * Initialize the on-Rio Now() implementation to use the FPGA timestamp.
72 * No effect on non-Rio platforms. This is called by HAL_Initialize() and
73 * thus should generally not be called by user code.
74 */
75#ifdef __FRC_ROBORIO__
76template <typename T>
77bool SetupNowRio(void* chipObjectLibrary, std::unique_ptr<T> hmbObject);
78#else
79template <typename T>
80inline bool SetupNowRio(void*, std::unique_ptr<T>) {
81 return true;
82}
83#endif
84
85/**
86 * Initialize the on-Rio Now() implementation to use the FPGA timestamp.
87 * No effect on non-Rio platforms. This take an FPGA session that has
88 * already been initialized, and is used from LabVIEW.
89 */
90bool SetupNowRio(uint32_t session);
91
92/**
93 * De-initialize the on-Rio Now() implementation. No effect on non-Rio
94 * platforms.
95 */
97} // namespace impl
98
99/**
100 * The default implementation used for Now().
101 * In general this is the time returned by the operating system.
102 * @return Time in microseconds.
103 */
104uint64_t NowDefault();
105
106/**
107 * Set the implementation used by Now().
108 * The implementation must return monotonic time in microseconds to maintain
109 * the contract of Now().
110 * @param func Function called by Now() to return the time.
111 */
112void SetNowImpl(uint64_t (*func)());
113
114/**
115 * Return a value representing the current time in microseconds.
116 * This is a monotonic clock with an undefined epoch.
117 * @return Time in microseconds.
118 */
119uint64_t Now();
120
121/**
122 * Return the current system time in microseconds since the Unix epoch
123 * (January 1st, 1970 00:00 UTC).
124 *
125 * @return Time in microseconds.
126 */
127uint64_t GetSystemTime();
128
129} // namespace wpi
130#endif
131
132#endif // WPIUTIL_WPI_TIMESTAMP_H_
void ShutdownNowRio()
De-initialize the on-Rio Now() implementation.
bool SetupNowRio(void *, std::unique_ptr< T >)
Initialize the on-Rio Now() implementation to use the FPGA timestamp.
Definition: timestamp.h:80
void SetupNowDefaultOnRio()
Initialize the on-Rio Now() implementation to use the desktop timestamp.
Definition: ntcore_cpp.h:26
uint64_t GetSystemTime()
Return the current system time in microseconds since the Unix epoch (January 1st, 1970 00:00 UTC).
uint64_t Now()
Return a value representing the current time in microseconds.
void SetNowImpl(uint64_t(*func)())
Set the implementation used by Now().
uint64_t NowDefault()
The default implementation used for Now().
void WPI_SetNowImpl(uint64_t(*func)(void))
Set the implementation used by WPI_Now().
uint64_t WPI_NowDefault(void)
The default implementation used for Now().
uint64_t WPI_Now(void)
Return a value representing the current time in microseconds.
void WPI_Impl_ShutdownNowRio(void)
De-initialize the on-Rio Now() implementation.
uint64_t WPI_GetSystemTime(void)
Return the current system time in microseconds since the Unix epoch (January 1st, 1970 00:00 UTC).