HardFOC Flux V1 HAL
Unified HAL API for the HardFOC Flux valve-control platform (ESP32-S3)
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CommChannelsManager Class Reference

Singleton managing all board communication channels for Flux V1. More...

#include <CommChannelsManager.h>

Collaboration diagram for CommChannelsManager:
[legend]

Classes

struct  UartAcquireConfig
 Lazy-acquire configuration for a hardware UART port. More...
 

Public Member Functions

 CommChannelsManager (const CommChannelsManager &)=delete
 
CommChannelsManager & operator= (const CommChannelsManager &)=delete
 
 CommChannelsManager (CommChannelsManager &&)=delete
 
CommChannelsManager & operator= (CommChannelsManager &&)=delete
 
bool EnsureInitialized () noexcept
 Initialise all communication buses if not already initialised.
 
bool IsInitialized () const noexcept
 Check whether the communication subsystem has been initialised.
 
CommError GetLastError () const noexcept
 Get the most recent error code.
 
flux::hal::ManagerError GetManagerError () const noexcept
 Lifecycle / bind error of the last EnsureInitialized() (shared catalog).
 
bool IsPressureBusReady () const noexcept
 The pressure SPI bus and its ADS7952 chip select are up.
 
bool IsCanReady () const noexcept
 The CAN controller object exists (configured, not started).
 
CommError GetSystemDiagnostics (CommSystemDiagnostics &diagnostics) const noexcept
 Fill a diagnostics snapshot with current system state.
 
bool Deinitialize () noexcept
 Release all bus resources and reset to uninitialized state.
 
BaseSpi * GetSpiDevice (SpiDeviceId device_id) noexcept
 Get an SPI device handle by enum identifier.
 
BaseSpi * GetSpiDevice (uint8_t device_index) noexcept
 Get an SPI device handle by raw index.
 
BaseI2c * GetI2cBus () noexcept
 Flux V1 does not bring up an I²C bus in CommChannelsManager.
 
BaseCan * GetCanBus () noexcept
 Get the TWAI/CAN bus.
 
BaseUart * AcquireUart (const UartAcquireConfig &cfg) noexcept
 Acquire (lazy-create + cache) a UART on the given hardware port.
 
BaseUart * GetUart (uint8_t port_number) noexcept
 Look up a previously-acquired UART by port number.
 
BaseUsbSerialJtag * AcquireUsbSerialJtag (const hf_usb_serial_jtag_config_t &cfg={}) noexcept
 Lazy-acquire the built-in USB Serial/JTAG controller.
 
BaseUsbSerialJtag * GetUsbSerialJtag () noexcept
 Look up a previously-acquired USB Serial/JTAG instance.
 
void DumpStatistics () const noexcept
 Log communication channel statistics and bus health to the console.
 

Static Public Member Functions

static CommChannelsManager & GetInstance () noexcept
 Return the singleton CommChannelsManager instance.
 

Static Public Attributes

static constexpr uint8_t kMaxUartPorts = 3
 

Private Member Functions

 CommChannelsManager () noexcept=default
 
 ~CommChannelsManager ()=default
 
bool Initialize () noexcept
 
void ReleaseLocked () noexcept
 
void UpdateLastError (CommError error) noexcept
 

Private Attributes

bool spi_bus_valid_ {false}
 Valve bus (MAX22200 + TLE92466ED) up.
 
bool spi3_bus_valid_ {false}
 Pressure bus (ADS7952) up.
 
std::array< BaseSpi *, kSpiDeviceCount > spi_devices_ {}
 One device per SpiDeviceId; nullptr when its bus or chip select failed.
 
BaseCan * can_bus_ {nullptr}
 CAN controller (configured, not started)
 
bool can_bus_valid_ {false}
 
std::array< BaseUart *, kMaxUartPorts > uarts_ {}
 
BaseUsbSerialJtag * usb_serial_jtag_ {nullptr}
 
std::atomic< bool > initialized_ {false}
 
std::atomic< CommError > last_error_ {CommError::SUCCESS}
 
std::atomic< flux::hal::ManagerError > manager_error_ {flux::hal::ManagerError::NotInitialized}
 
RtosMutex mutex_
 

Static Private Attributes

static constexpr uint8_t kSpiDeviceCount = static_cast<uint8_t>(SpiDeviceId::DEVICE_COUNT)
 

Detailed Description

Singleton managing all board communication channels for Flux V1.

Design decisions vs. Vortex:

Constructor & Destructor Documentation

◆ CommChannelsManager() [1/3]

CommChannelsManager::CommChannelsManager ( const CommChannelsManager &  )
delete

◆ CommChannelsManager() [2/3]

CommChannelsManager::CommChannelsManager ( CommChannelsManager &&  )
delete

◆ CommChannelsManager() [3/3]

CommChannelsManager::CommChannelsManager ( )
privatedefaultnoexcept

◆ ~CommChannelsManager()

CommChannelsManager::~CommChannelsManager ( )
privatedefault

Member Function Documentation

◆ AcquireUart()

BaseUart * CommChannelsManager::AcquireUart ( const UartAcquireConfig &  cfg)
noexcept

Acquire (lazy-create + cache) a UART on the given hardware port.

First call wins the configuration; subsequent calls with the same port_number return the cached BaseUart& and ignore further config requests (a warning is logged if the new config differs from what was cached). Returns nullptr on configuration error.

RS-485 half-duplex is enabled automatically when rts_pin >= 0.

Here is the call graph for this function:

◆ AcquireUsbSerialJtag()

BaseUsbSerialJtag * CommChannelsManager::AcquireUsbSerialJtag ( const hf_usb_serial_jtag_config_t &  cfg = {})
noexcept

Lazy-acquire the built-in USB Serial/JTAG controller.

The ESP32-S3 has exactly one USB Serial/JTAG block, hard-wired to GPIO19/20 — there are no pins or baud rate to configure, only the driver-side TX/RX ring sizes. The first caller wins the ring sizes; subsequent calls reuse the same BaseUsbSerialJtag&.

If the IDF console (CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y) has already installed the underlying driver, this just shares it — both printf / ESP_LOG and our wrapper push to the same TX ring.

Parameters
cfgRing buffer / policy configuration (defaults are sane: 256-byte TX, 256-byte RX). Honoured only on the first call.
Returns
Pointer to the cached BaseUsbSerialJtag, or nullptr if the host platform has no USB Serial/JTAG block or driver install failed.
Here is the call graph for this function:

◆ Deinitialize()

bool CommChannelsManager::Deinitialize ( )
noexcept

Release all bus resources and reset to uninitialized state.

Returns
true on success
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DumpStatistics()

void CommChannelsManager::DumpStatistics ( ) const
noexcept

Log communication channel statistics and bus health to the console.

Here is the caller graph for this function:

◆ EnsureInitialized()

bool CommChannelsManager::EnsureInitialized ( )
noexcept

Initialise all communication buses if not already initialised.

Returns
true on success or if already initialised.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCanBus()

BaseCan * CommChannelsManager::GetCanBus ( )
noexcept

Get the TWAI/CAN bus.

Returns
Pointer to BaseCan, or nullptr if not initialised.

◆ GetI2cBus()

BaseI2c * CommChannelsManager::GetI2cBus ( )
inlinenoexcept

Flux V1 does not bring up an I²C bus in CommChannelsManager.

Returns
Always nullptr (API retained for portable example code).

◆ GetInstance()

CommChannelsManager & CommChannelsManager::GetInstance ( )
staticnoexcept

Return the singleton CommChannelsManager instance.

Here is the caller graph for this function:

◆ GetLastError()

CommError CommChannelsManager::GetLastError ( ) const
inlinenoexcept

Get the most recent error code.

Returns
Last CommError set by any API call

◆ GetManagerError()

flux::hal::ManagerError CommChannelsManager::GetManagerError ( ) const
inlinenoexcept

Lifecycle / bind error of the last EnsureInitialized() (shared catalog).

Required set (fail-closed): the valve SPI bus and both valve chip selects. The pressure bus and CAN are reported by IsPressureBusReady() / IsCanReady(); their users (AdcManager, the application) fail closed on them.

◆ GetSpiDevice() [1/2]

BaseSpi * CommChannelsManager::GetSpiDevice ( SpiDeviceId  device_id)
noexcept

Get an SPI device handle by enum identifier.

Parameters
device_idSPI device identifier.
Returns
Pointer to BaseSpi, or nullptr on invalid id or uninitialised.

◆ GetSpiDevice() [2/2]

BaseSpi * CommChannelsManager::GetSpiDevice ( uint8_t  device_index)
noexcept

Get an SPI device handle by raw index.

Parameters
device_indexZero-based device index.
Returns
Pointer to BaseSpi, or nullptr on invalid index or uninitialised.

◆ GetSystemDiagnostics()

CommError CommChannelsManager::GetSystemDiagnostics ( CommSystemDiagnostics &  diagnostics) const
noexcept

Fill a diagnostics snapshot with current system state.

Parameters
diagnosticsOutput structure to populate
Returns
CommError::SUCCESS on success, CommError::NOT_INITIALIZED if not init

◆ GetUart()

BaseUart * CommChannelsManager::GetUart ( uint8_t  port_number)
noexcept

Look up a previously-acquired UART by port number.

Returns
Pointer to the cached BaseUart, or nullptr if no UART has been acquired on that port yet.

◆ GetUsbSerialJtag()

BaseUsbSerialJtag * CommChannelsManager::GetUsbSerialJtag ( )
noexcept

Look up a previously-acquired USB Serial/JTAG instance.

Returns
Pointer to the cached BaseUsbSerialJtag, or nullptr if AcquireUsbSerialJtag() has never been called.

◆ Initialize()

bool CommChannelsManager::Initialize ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsCanReady()

bool CommChannelsManager::IsCanReady ( ) const
inlinenoexcept

The CAN controller object exists (configured, not started).

◆ IsInitialized()

bool CommChannelsManager::IsInitialized ( ) const
inlinenoexcept

Check whether the communication subsystem has been initialised.

Returns
true if initialised.

◆ IsPressureBusReady()

bool CommChannelsManager::IsPressureBusReady ( ) const
inlinenoexcept

The pressure SPI bus and its ADS7952 chip select are up.

◆ operator=() [1/2]

CommChannelsManager & CommChannelsManager::operator= ( CommChannelsManager &&  )
delete

◆ operator=() [2/2]

CommChannelsManager & CommChannelsManager::operator= ( const CommChannelsManager &  )
delete

◆ ReleaseLocked()

void CommChannelsManager::ReleaseLocked ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateLastError()

void CommChannelsManager::UpdateLastError ( CommError  error)
inlineprivatenoexcept
Here is the caller graph for this function:

Member Data Documentation

◆ can_bus_

BaseCan* CommChannelsManager::can_bus_ {nullptr}
private

CAN controller (configured, not started)

◆ can_bus_valid_

bool CommChannelsManager::can_bus_valid_ {false}
private

◆ initialized_

std::atomic<bool> CommChannelsManager::initialized_ {false}
private

◆ kMaxUartPorts

constexpr uint8_t CommChannelsManager::kMaxUartPorts = 3
staticconstexpr

Maximum number of UART ports the manager will track (one slot per ESP32-S3 hardware UART; UART0 is normally the IDF console, UART2 the operator console — pick a free port for app use).

◆ kSpiDeviceCount

constexpr uint8_t CommChannelsManager::kSpiDeviceCount = static_cast<uint8_t>(SpiDeviceId::DEVICE_COUNT)
staticconstexprprivate

◆ last_error_

std::atomic<CommError> CommChannelsManager::last_error_ {CommError::SUCCESS}
private

◆ manager_error_

std::atomic<flux::hal::ManagerError> CommChannelsManager::manager_error_ {flux::hal::ManagerError::NotInitialized}
private

◆ mutex_

RtosMutex CommChannelsManager::mutex_
mutableprivate

◆ spi3_bus_valid_

bool CommChannelsManager::spi3_bus_valid_ {false}
private

Pressure bus (ADS7952) up.

◆ spi_bus_valid_

bool CommChannelsManager::spi_bus_valid_ {false}
private

Valve bus (MAX22200 + TLE92466ED) up.

◆ spi_devices_

std::array<BaseSpi*, kSpiDeviceCount> CommChannelsManager::spi_devices_ {}
private

One device per SpiDeviceId; nullptr when its bus or chip select failed.

◆ uarts_

std::array<BaseUart*, kMaxUartPorts> CommChannelsManager::uarts_ {}
private

◆ usb_serial_jtag_

BaseUsbSerialJtag* CommChannelsManager::usb_serial_jtag_ {nullptr}
private

The documentation for this class was generated from the following files: