Loop Timing Witness
Native controller and runtime interfaces; hardware qualification pending
Loading...
Searching...
No Matches
power_journal.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Commercial license available
3// © Concepts 1996–2026 Miroslav Šotek. All rights reserved.
4// © Code 2020–2026 Miroslav Šotek. All rights reserved.
5// ORCID: 0009-0009-3560-0851
6// Contact: www.anulum.li | protoscience@anulum.li
7// Loop Timing Witness — bracketed real IIO acquisition journal
8
12
13#ifndef WITNESS_POWER_JOURNAL_H
14#define WITNESS_POWER_JOURNAL_H
15#include "pac1934_device.h"
16#include "../run_control.h"
17#include "../exclusive_output.h"
18#include <atomic>
19#include <condition_variable>
20#include <future>
21#include <mutex>
22#include <thread>
23
24namespace witness {
26class PowerJournal {
27 const PowerConfiguration configuration;
28 Pac1934Device &sensor;
29 const std::function<std::uint64_t()> host_time;
30 const std::function<std::uint32_t(std::uint8_t)> register_read;
31 ExclusiveOutput output;
32 std::thread worker;
33 std::mutex mutex;
34 std::condition_variable wake;
35 bool stopping = false;
36 std::atomic<bool> failed{false};
37 std::exception_ptr failure;
38 std::array<std::uint64_t, 4> previous_energy{};
39 bool have_energy = false;
40 std::uint64_t snapshot = 0;
42 std::uint64_t ticks();
44 void acquire();
46 void collect(std::promise<void> ready) noexcept;
48 void stop() noexcept;
51 PowerJournal(const char *path, const PowerConfiguration &config, Pac1934Device &device,
52 std::function<std::uint64_t()> clock,
53 std::function<std::uint32_t(std::uint8_t)> read);
54
55 public:
57 template <class Device>
58 PowerJournal(const char *path, const PowerConfiguration &config, Pac1934Device &device,
59 Device &fabric)
60 : PowerJournal(
61 path, config, device, [&fabric] { return fabric.time(); },
62 [&fabric](std::uint8_t address) { return read_register(fabric, address); }) {}
63
65 PowerJournal(const PowerJournal &) = delete;
66 PowerJournal &operator=(const PowerJournal &) = delete;
68 void start();
70 void check();
72 void finish();
75};
76} // namespace witness
77#endif
PowerJournal(const char *path, const PowerConfiguration &config, Pac1934Device &device, Device &fabric)
std::uint32_t read_register(Device &device, std::uint8_t address)
Definition run_control.h:41