65 lines
include/reset_sequencer.h
Declares ResetSequencer, ResetConfig, and the reset/isReady contract.
// ResetSequencer: GPIO-driven peripheral reset with calibrated timing.#pragma once#include <cstdint>#include <map>#include <string>// Timing configuration for one peripheral model's reset sequence.// powerdown_us: microseconds to hold the reset line asserted (minimum assert time).// Loaded from config key "reset_hold_us".// powerup_us: microseconds to wait after deassert for DEVICE_READY (startup window).// Loaded from config key "boot_wait_us".struct ResetConfig { uint32_t powerdown_us; // hold time while reset is asserted; from "reset_hold_us" uint32_t powerup_us; // maximum startup window after deassert; from "boot_wait_us"};
// Validates that the timing values meet the hardware minimums.// Parameters:// cfg - timing parameters to check// Returns: true if powerdown_us >= 50 and powerup_us >= 100bool validateConfig(const ResetConfig& cfg);// Drives the GPIO reset sequence for a single peripheral.class ResetSequencer {public: // Parameters: // gpioResetPin - GPIO pin number used to assert/deassert hardware reset // gpioReadyPin - GPIO pin number connected to the peripheral DEVICE_READY output ResetSequencer(int gpioResetPin, int gpioReadyPin); // Loads timing parameters from the provided config map. // Expected keys: "reset_hold_us" and "boot_wait_us". // Parameters: // params - key-value map of timing parameters for this peripheral model // Returns: true if both keys are present and pass validateConfig() bool configure(const std::map<std::string, uint32_t>& params); // Executes the full reset sequence using the loaded timing configuration. // Sequence: assert reset -> hold powerdown_us -> deassert -> poll DEVICE_READY // Parameters: none // Returns: true if DEVICE_READY goes high within powerup_us; false on timeout bool reset(); // Samples the current state of the DEVICE_READY pin. // Parameters: none // Returns: true if the peripheral is currently signalling ready bool isReady() const;private: int gpioResetPin_; // GPIO used to drive the reset line int gpioReadyPin_; // GPIO used to read DEVICE_READY ResetConfig cfg_{}; // loaded timing parameters // Parameters: none // Returns: void void assertReset() const; // Parameters: none // Returns: void void deassertReset() const; // Polls readyPin for up to timeoutUs microseconds. // Parameters: // timeoutUs - maximum poll duration in microseconds // Returns: true if DEVICE_READY observed high within the window bool pollReady(uint32_t timeoutUs) const;};