Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
module;
#include <cstdint>
#include <utility>
export module Driver.PulseCounterDriver;
import Driver.DriverComponent;
import Driver.PulseCounterDriverConcept;
import Driver.PulseCounterId;
import Driver.PulseCount;
export namespace Driver
{
/**
* @class PulseCounterDriver
* @brief Hardware abstraction layer for external pulse counting via GPIO interrupts.
*
* This driver provides access to hardware pulse counters connected to BNC connectors.
* Each instance references a shared counter that is incremented atomically from
* interrupt context (EXTI handler).
*
* @note Thread-safe: Counter increments are atomic (single instruction on Cortex-M).
* @note Debouncing is done in hardware.
* @note The counter is never reset automatically - client code must call clear().
* @note Multiple instances can reference the same counter if needed.
*
* @warning Reading the counter on platforms without atomic 32-bit loads may require
* disabling interrupts briefly to ensure consistency.
*/
class PulseCounterDriver final : public DriverComponent
{
public:
/**
* @brief Constructs a pulse counter driver for the specified device.
* @param deviceId Identifier of the pulse counter (BNC connector).
*/
explicit PulseCounterDriver(PulseCounterId deviceId) noexcept;
~PulseCounterDriver() = default;
PulseCounterDriver() = delete;
PulseCounterDriver(const PulseCounterDriver &) = delete;
PulseCounterDriver &operator=(const PulseCounterDriver &) = delete;
PulseCounterDriver(PulseCounterDriver &&) = delete;
PulseCounterDriver &operator=(PulseCounterDriver &&) = delete;
/**
* @brief Reads the current pulse count.
* @return Current accumulated pulse count since last clear().
* @note This is a non-blocking read of a shared volatile counter.
* @note On STM32F1 (Cortex-M3), 32-bit reads are atomic.
*/
[[nodiscard]] auto fetchAndReset() const noexcept -> PulseCount;
/**
* @brief Resets the pulse counter to zero.
* @note This does not disable interrupts - new pulses may arrive immediately.
*/
auto clear() noexcept -> void;
/**
* @brief Starts pulse counting by clearing the counter.
* @return Always returns true (API constraints).
* @note Interrupts are already enabled - this just resets the count.
*/
[[nodiscard]] auto onStart() noexcept -> bool;
private:
PulseCounterId deviceId;
};
static_assert(Concepts::PulseCounterDriverConcept<PulseCounterDriver>,
"PulseCounterDriver must satisfy the concept requirements");
} // namespace Driver1292c910cThis file is pinned to the selected release. Download the original to open it in your design tool.