37#ifndef FLUX_VALVE_MANAGER_H_
38#define FLUX_VALVE_MANAGER_H_
48#include "handlers/max22200/Max22200Handler.h"
49#include "handlers/tle92466ed/Tle92466edHandler.h"
129 default:
return "Unknown valve error";
450 uint16_t hit_ma, uint16_t hold_ma,
451 float hit_time_ms) noexcept;
462 float hit_duty_pct,
float hold_duty_pct,
463 float hit_time_ms) noexcept;
492 float frequency_hz) noexcept;
507 float frequency_hz) noexcept;
517 [[nodiscard]]
bool HasFault() noexcept;
632 last_error_.store(result, std::memory_order_release);
640 uint8_t& hw_channel)
noexcept;
constexpr hf_valve_err_t TleDriverErrorToValveError(tle92466ed::DriverError e) noexcept
Map TLE92466ED DriverError to the unified hf_valve_err_t domain.
Definition ValveManager.h:149
constexpr hf_valve_err_t MaxDriverStatusToValveError(max22200::DriverStatus s) noexcept
Map MAX22200 DriverStatus to the unified hf_valve_err_t domain.
Definition ValveManager.h:175
constexpr const char * HfValveErrToString(hf_valve_err_t err) noexcept
Convert hf_valve_err_t to a human-readable description string.
Definition ValveManager.h:104
ValveManager & GetValveManager() noexcept
Convenience accessor — equivalent to ValveManager::GetInstance().
Definition ValveManager.h:674
static constexpr ValveChannelInfo kValveChannelMap[]
Compile-time mapping table for all valve channels.
Definition ValveManager.h:231
ValveChannel
Unified valve channel identifier — covers all 14 channels.
Definition ValveManager.h:206
ValveDriverType
Identifies which driver IC backend a valve channel belongs to.
Definition ValveManager.h:194
@ MAX22200
MAX22200 octal solenoid driver.
@ TLE92466
TLE92466ED six-channel proportional driver.
static constexpr size_t kValveChannelCount
Total number of valve channels defined in the mapping table.
Definition ValveManager.h:249
hf_valve_err_t
Unified valve error codes for the HardFOC Flux V1 platform.
Definition ValveManager.h:62
@ VALVE_ERR_WRITE_TO_READ_ONLY
@ VALVE_ERR_MUTEX_TIMEOUT
@ VALVE_ERR_HARDWARE_FAULT
@ VALVE_ERR_DRIVER_NOT_AVAILABLE
@ VALVE_ERR_SPI_TRANSFER_FAILED
@ VALVE_ERR_SPI_FRAME_ERROR
@ VALVE_ERR_SPI_BUS_ERROR
@ VALVE_ERR_WRONG_DEVICE_ID
@ VALVE_ERR_INVALID_PARAMETER
@ VALVE_ERR_INVALID_CHANNEL
@ VALVE_ERR_SPI_CRC_ERROR
@ VALVE_ERR_REGISTER_ERROR
@ VALVE_ERR_CHANNEL_TYPE_MISMATCH
@ VALVE_ERR_DEVICE_NOT_RESPONDING
@ VALVE_ERR_CONFIGURATION_ERROR
@ VALVE_ERR_DEPENDENCY_NOT_READY
@ VALVE_ERR_NOT_INITIALIZED
constexpr bool HfValveErrOk(hf_valve_err_t err) noexcept
Check if a valve error code indicates success.
Definition ValveManager.h:138
Unified singleton for controlling all valve channels on the Flux board.
Definition ValveManager.h:296
Max22200Handler * GetMax22200Handler() noexcept
Get the MAX22200 handler for advanced solenoid operations.
Definition ValveManager.cpp:734
hf_valve_err_t GetSolenoidFaults(max22200::FaultStatus &faults) noexcept
Retrieve the MAX22200 fault status.
Definition ValveManager.cpp:692
Tle92466edHandler * GetTle92466Handler() noexcept
Get the TLE92466ED handler for advanced proportional operations.
Definition ValveManager.cpp:738
hf_valve_err_t GetSystemDiagnostics(ValveSystemDiagnostics &diag) const noexcept
Populate a ValveSystemDiagnostics snapshot.
Definition ValveManager.cpp:746
hf_valve_err_t EnableChannelsMask(uint16_t mask) noexcept
Enable multiple channels by bitmask.
Definition ValveManager.cpp:418
bool HasProportionalFault() noexcept
Check for TLE92466ED-specific faults.
Definition ValveManager.cpp:687
bool IsBankReady(ValveDriverType bank) const noexcept
Whether one driver IC came up during the last bring-up attempt.
Definition ValveManager.cpp:98
ValveManager & operator=(const ValveManager &)=delete
bool IsOutputInhibited() const noexcept
The enable pins were dropped and not re-armed since.
Definition ValveManager.h:388
bool IsChannelEnabled(ValveChannel channel) const noexcept
Check if a channel is currently enabled.
Definition ValveManager.cpp:493
ValveManager(ValveManager &&)=delete
bool IsInitialized() const noexcept
Check whether the valve subsystem has been initialised.
Definition ValveManager.h:324
std::array< ValveChannelState, static_cast< size_t >(ValveChannel::CHANNEL_COUNT)> channel_states_
Definition ValveManager.h:657
static ValveManager & GetInstance() noexcept
Return the singleton ValveManager instance.
Definition ValveManager.cpp:25
bool max22200_valid_
Definition ValveManager.h:648
std::atomic< bool > initialized_
Definition ValveManager.h:659
hf_valve_err_t DisableChannel(ValveChannel channel) noexcept
Disable a valve channel output.
Definition ValveManager.cpp:384
std::atomic< bool > outputs_inhibited_
DropEnablePins() latched, until re-armed.
Definition ValveManager.h:660
ValveManager(const ValveManager &)=delete
void DumpStatistics() const noexcept
Log valve channel statistics and driver health to the console.
Definition ValveManager.cpp:768
std::optional< Tle92466edHandler > tle92466_
Definition ValveManager.h:650
flux::hal::ManagerError InitializeMax22200() noexcept
Definition ValveManager.cpp:159
bool tle92466_valid_
Definition ValveManager.h:651
bool Deinitialize() noexcept
Turn every channel off, release both driver handlers and reset to uninitialised.
Definition ValveManager.cpp:810
void ReleaseDriversLocked() noexcept
Destroy both handlers and clear the bank flags (mutex held by the caller).
Definition ValveManager.cpp:836
hf_valve_err_t GetLastError() const noexcept
Get the most recent failed valve operation's error code.
Definition ValveManager.h:603
bool EnsureInitialized() noexcept
Ensure the valve manager system is initialized.
Definition ValveManager.cpp:38
ValveChannel FindChannel(std::string_view name) const noexcept
Find a channel enum by name.
Definition ValveManager.cpp:723
hf_valve_err_t ConfigureSolenoidCdr(ValveChannel channel, uint16_t hit_ma, uint16_t hold_ma, float hit_time_ms) noexcept
Configure a solenoid channel with CDR (current drive regulation).
Definition ValveManager.cpp:503
static bool ResolveChannel(ValveChannel channel, ValveDriverType &driver_type, uint8_t &hw_channel) noexcept
Resolve channel enum to hw channel index and driver type.
Definition ValveManager.cpp:332
hf_valve_err_t Initialize() noexcept
Definition ValveManager.cpp:106
bool DropEnablePins() noexcept
Drive MAX22200 ENABLE and TLE92466ED EN low: both banks de-energised in hardware.
Definition ValveManager.cpp:62
hf_valve_err_t EnableChannel(ValveChannel channel) noexcept
Enable a valve channel output.
Definition ValveManager.cpp:346
hf_valve_err_t GetProportionalFaults(tle92466ed::FaultReport &report) noexcept
Retrieve the TLE92466ED fault report.
Definition ValveManager.cpp:698
const ValveChannelInfo * GetChannelInfo(std::string_view name) const noexcept
Get channel info (driver type, hw channel, name) by string name.
Definition ValveManager.cpp:716
hf_valve_err_t ClearAllFaults() noexcept
Clear faults on both drivers.
Definition ValveManager.cpp:661
bool RearmEnablePins() noexcept
Leave SafeHold: full re-bring-up of both banks, which raises the enable pins again.
Definition ValveManager.cpp:84
ValveManager & operator=(ValveManager &&)=delete
hf_valve_err_t SetProportionalCurrent(ValveChannel channel, uint16_t current_ma) noexcept
Set current setpoint for a proportional valve channel.
Definition ValveManager.cpp:552
void GetEnablePinStates(bool &max_enable, bool &tle_enable) const noexcept
Read back the two enable outputs.
Definition ValveManager.cpp:89
flux::hal::ManagerError InitializeTle92466() noexcept
Definition ValveManager.cpp:224
std::atomic< flux::hal::ManagerError > manager_error_
Definition ValveManager.h:661
RtosMutex mutex_
Definition ValveManager.h:663
hf_valve_err_t DisableAllLocked() noexcept
Disable every channel on every bank that is up (mutex held by the caller).
Definition ValveManager.cpp:472
bool HasFault() noexcept
Check if any driver reports a fault.
Definition ValveManager.cpp:657
const ValveChannelState * GetChannelState(ValveChannel channel) const noexcept
Get channel runtime state by enum.
Definition ValveManager.cpp:710
std::optional< Max22200Handler > max22200_
Definition ValveManager.h:647
flux::hal::ManagerError GetManagerError() const noexcept
Lifecycle / bind error of the last EnsureInitialized() (shared catalog).
Definition ValveManager.h:338
hf_valve_err_t Record(hf_valve_err_t result) const noexcept
Remember a failed operation result for GetLastError(); pass the result through.
Definition ValveManager.h:630
hf_valve_err_t ConfigureProportionalPwm(ValveChannel channel, float frequency_hz) noexcept
Configure PWM frequency for a proportional channel.
Definition ValveManager.cpp:573
hf_valve_err_t DisableAllChannels() noexcept
Disable all channels on both drivers.
Definition ValveManager.cpp:465
bool HasSolenoidFault() noexcept
Check for MAX22200-specific faults.
Definition ValveManager.cpp:682
hf_valve_err_t ConfigureSolenoidVdr(ValveChannel channel, float hit_duty_pct, float hold_duty_pct, float hit_time_ms) noexcept
Configure a solenoid channel with VDR (voltage drive regulation).
Definition ValveManager.cpp:525
hf_valve_err_t ConfigureProportionalDither(ValveChannel channel, float amplitude_ma, float frequency_hz) noexcept
Configure dither for a proportional channel.
Definition ValveManager.cpp:613
std::atomic< hf_valve_err_t > last_error_
Definition ValveManager.h:662
Shared HAL types for Flux V1: the manager error catalog and the facade result.
ManagerError
Lifecycle / bind failure catalog shared by every manager (GetManagerError()).
Definition flux_hal_types.hpp:37
@ NotInitialized
Manager not initialised (or shut down)
Definition flux_hal_types.hpp:29
Compile-time channel metadata for the mapping table.
Definition ValveManager.h:221
std::string_view name
Human-readable name.
Definition ValveManager.h:225
ValveChannel channel
Unified channel enum.
Definition ValveManager.h:222
ValveDriverType driver_type
Which driver IC.
Definition ValveManager.h:223
uint8_t hw_channel
Channel index within the driver (0-based)
Definition ValveManager.h:224
Per-channel runtime state tracked by the manager.
Definition ValveManager.h:258
bool enabled
Whether channel output is currently active.
Definition ValveManager.h:259
float duty_percent
Last-set duty cycle (for VDR solenoids)
Definition ValveManager.h:262
uint32_t activation_count
Total number of enable events.
Definition ValveManager.h:266
uint32_t error_count
Total errors on this channel.
Definition ValveManager.h:267
float dither_amplitude_ma
Last-set dither amplitude (for proportional)
Definition ValveManager.h:264
float pwm_frequency_hz
Last-set PWM frequency (for proportional)
Definition ValveManager.h:263
float dither_frequency_hz
Last-set dither frequency (for proportional)
Definition ValveManager.h:265
bool configured
Whether channel has been configured.
Definition ValveManager.h:260
uint16_t current_ma
Last-set current setpoint (for proportional)
Definition ValveManager.h:261
Diagnostics snapshot for the entire valve subsystem.
Definition ValveManager.h:273
uint8_t configured_channels
Number of channels that have been configured.
Definition ValveManager.h:278
bool tle92466_initialized
TLE92466ED handler initialised and ready.
Definition ValveManager.h:276
bool system_healthy
True when both driver ICs are operational.
Definition ValveManager.h:274
uint32_t total_activations
Cumulative enable-event count across all channels.
Definition ValveManager.h:280
uint8_t total_channels
Total channel slots in the mapping table.
Definition ValveManager.h:277
bool max22200_initialized
MAX22200 handler initialised and ready.
Definition ValveManager.h:275
uint8_t active_channels
Number of channels currently enabled.
Definition ValveManager.h:279
uint32_t total_errors
Cumulative error count across all channels.
Definition ValveManager.h:281