blob: 25c1d9f33e483b25ece15aba569b67716a9c82fe [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#include <atomic>
9#include <chrono>
10#include <cstdio>
11#include <thread>
12
13#include <wpi/timestamp.h>
14
15#include "MockHooksInternal.h"
16
17static std::atomic<bool> programStarted{false};
18
19static std::atomic<uint64_t> programStartTime{0};
20
21namespace hal {
22namespace init {
23void InitializeMockHooks() {}
24} // namespace init
25} // namespace hal
26
27namespace hal {
28void RestartTiming() { programStartTime = wpi::Now(); }
29
30int64_t GetFPGATime() {
31 auto now = wpi::Now();
32 auto currentTime = now - programStartTime;
33 return currentTime;
34}
35
36double GetFPGATimestamp() { return GetFPGATime() * 1.0e-6; }
37
38void SetProgramStarted() { programStarted = true; }
39bool GetProgramStarted() { return programStarted; }
40} // namespace hal
41
42using namespace hal;
43
44extern "C" {
45void HALSIM_WaitForProgramStart(void) {
46 int count = 0;
47 while (!programStarted) {
48 count++;
49 std::printf("Waiting for program start signal: %d\n", count);
50 std::this_thread::sleep_for(std::chrono::milliseconds(500));
51 }
52}
53
54void HALSIM_SetProgramStarted(void) { SetProgramStarted(); }
55
56HAL_Bool HALSIM_GetProgramStarted(void) { return GetProgramStarted(); }
57
58void HALSIM_RestartTiming(void) { RestartTiming(); }
59} // extern "C"