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

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

#include <CommChannelsManager.h>

Collaboration diagram for CommChannelsManager:
[legend]

Classes

struct  RuntimeI2cSlot
 

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.
 
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 * GetI2cDevice (I2cDeviceId device_id) noexcept
 Get a built-in I²C device by enum identifier.
 
BaseI2c * GetI2cDevice (uint8_t bus_index, int device_index) noexcept
 Get I2C device by bus index and device index.
 
int CreateI2cDevice (uint8_t device_address, uint32_t speed_hz=400000) noexcept
 Create an I2C device on the primary bus at runtime.
 
bool HasI2cDeviceAtAddress (uint8_t bus_index, uint8_t device_address) const noexcept
 Check if an I2C device exists at the specified address.
 
bool RemoveI2cDevice (int device_index) noexcept
 Remove a runtime-created I2C device.
 
bool I2cProbeAddress (uint8_t address, uint32_t timeout_ms=25) noexcept
 Probe a single 7-bit address on the primary I²C bus.
 
size_t I2cScanBus (uint8_t *out, size_t max_results) noexcept
 Scan the primary I²C bus and copy ACKing addresses into out.
 
bool I2cResetBus () noexcept
 Reset the I²C peripheral / clear-bus sequence (only attempts when bus is up).
 
BaseUart * GetUartBus () noexcept
 Get the UART bus (TMC9660 TMCL).
 
BaseCan * GetCanBus () noexcept
 Get the TWAI/CAN bus.
 
BaseCan * GetCanOpenBus () noexcept
 TWAI bus used for CANopen / hf-utils-canopen framing (HfUtilsCanOpenTransport).
 
uint32_t GetCanBitRate () const noexcept
 Nominal bit rate the TWAI bus was configured with (bit/s).
 
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.
 

Private Member Functions

 CommChannelsManager () noexcept
 
 ~CommChannelsManager ()
 
bool Initialize () noexcept
 
void ReleaseLocked () noexcept
 Close every bus through the binding and forget the indices. Caller holds mutex_.
 
void UpdateLastError (CommError error) noexcept
 

Private Attributes

std::array< int, kSpiDeviceCount > spi_device_indices_ {}
 
bool spi_bus_valid_ {false}
 
bool uart_bus_valid_ {false}
 
bool can_bus_valid_ {false}
 
std::array< int, kI2cBuiltinCount > i2c_builtin_indices_ {}
 
bool i2c_bus_valid_ {false}
 
std::array< RuntimeI2cSlot, kMaxI2cRuntimeDevices > i2c_runtime_slots_ {}
 
BaseUart * uart_bus_ {nullptr}
 
BaseCan * can_bus_ {nullptr}
 
std::atomic< bool > initialized_ {false}
 
std::atomic< CommError > last_error_ {CommError::SUCCESS}
 
RtosMutex mutex_
 

Static Private Attributes

static constexpr uint8_t kSpiDeviceCount
 
static constexpr uint8_t kI2cBuiltinCount
 
static constexpr uint8_t kMaxI2cRuntimeDevices = 4
 

Detailed Description

Singleton managing all board communication channels for Vortex V1.

Design decisions :

Constructor & Destructor Documentation

◆ CommChannelsManager() [1/3]

CommChannelsManager::CommChannelsManager ( const CommChannelsManager &  )
delete

◆ CommChannelsManager() [2/3]

CommChannelsManager::CommChannelsManager ( CommChannelsManager &&  )
delete

◆ CommChannelsManager() [3/3]

CommChannelsManager::CommChannelsManager ( )
privatenoexcept

◆ ~CommChannelsManager()

CommChannelsManager::~CommChannelsManager ( )
privatedefault

Member Function Documentation

◆ CreateI2cDevice()

int CommChannelsManager::CreateI2cDevice ( uint8_t  device_address,
uint32_t  speed_hz = 400000 
)
noexcept

Create an I2C device on the primary bus at runtime.

Parameters
device_address7-bit I2C address
speed_hzI2C clock speed (default 400 kHz)
Returns
Device index on success, -1 on failure
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:

◆ GetCanBitRate()

uint32_t CommChannelsManager::GetCanBitRate ( ) const
noexcept

Nominal bit rate the TWAI bus was configured with (bit/s).

◆ GetCanBus()

BaseCan * CommChannelsManager::GetCanBus ( )
noexcept

Get the TWAI/CAN bus.

Returns
Pointer to BaseCan, or nullptr if not initialised.
Here is the caller graph for this function:

◆ GetCanOpenBus()

BaseCan * CommChannelsManager::GetCanOpenBus ( )
inlinenoexcept

TWAI bus used for CANopen / hf-utils-canopen framing (HfUtilsCanOpenTransport).

Vortex V1: same instance as GetCanBus(). Prefer this name in app code that wires CANOpenBLDCThread / CanOpenHostServiceThread so ownership stays with CommChannelsManager.

Here is the call graph for this function:

◆ GetI2cDevice() [1/2]

BaseI2c * CommChannelsManager::GetI2cDevice ( I2cDeviceId  device_id)
noexcept

Get a built-in I²C device by enum identifier.

Parameters
device_idI²C device identifier.
Returns
Pointer to BaseI2c, or nullptr on invalid id or uninitialised.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetI2cDevice() [2/2]

BaseI2c * CommChannelsManager::GetI2cDevice ( uint8_t  bus_index,
int  device_index 
)
noexcept

Get I2C device by bus index and device index.

Parameters
bus_indexBus index (only 0 supported)
device_indexDevice index returned by CreateI2cDevice or bus init
Returns
Pointer to BaseI2c device, or nullptr if invalid
Here is the call graph for this function:

◆ 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

◆ 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.
Here is the caller graph for this function:

◆ 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.
Here is the call graph for this function:

◆ 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

◆ GetUartBus()

BaseUart * CommChannelsManager::GetUartBus ( )
noexcept

Get the UART bus (TMC9660 TMCL).

Returns
Pointer to BaseUart, or nullptr if not initialised.
Here is the caller graph for this function:

◆ HasI2cDeviceAtAddress()

bool CommChannelsManager::HasI2cDeviceAtAddress ( uint8_t  bus_index,
uint8_t  device_address 
) const
noexcept

Check if an I2C device exists at the specified address.

Parameters
bus_indexBus index (only 0 supported)
device_address7-bit I2C address
Returns
true if device exists

◆ I2cProbeAddress()

bool CommChannelsManager::I2cProbeAddress ( uint8_t  address,
uint32_t  timeout_ms = 25 
)
noexcept

Probe a single 7-bit address on the primary I²C bus.

Parameters
address7-bit slave address (0x08 .. 0x77).
timeout_msPer-probe timeout in ms (default 25 ms).
Returns
true if the device ACKs.
Here is the call graph for this function:

◆ I2cResetBus()

bool CommChannelsManager::I2cResetBus ( )
noexcept

Reset the I²C peripheral / clear-bus sequence (only attempts when bus is up).

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

◆ I2cScanBus()

size_t CommChannelsManager::I2cScanBus ( uint8_t *  out,
size_t  max_results 
)
noexcept

Scan the primary I²C bus and copy ACKing addresses into out.

Parameters
outBuffer to receive the discovered addresses.
max_resultsMaximum number of entries to write into out.
Returns
Number of devices that ACKed (also size of out written).
Here is the call graph for this function:

◆ Initialize()

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

◆ IsInitialized()

bool CommChannelsManager::IsInitialized ( ) const
inlinenoexcept

Check whether the communication subsystem has been initialised.

Returns
true if initialised.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ ReleaseLocked()

void CommChannelsManager::ReleaseLocked ( )
privatenoexcept

Close every bus through the binding and forget the indices. Caller holds mutex_.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveI2cDevice()

bool CommChannelsManager::RemoveI2cDevice ( int  device_index)
noexcept

Remove a runtime-created I2C device.

Parameters
device_indexDevice index returned by CreateI2cDevice
Returns
true if removed successfully
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_bus_valid_

bool CommChannelsManager::can_bus_valid_ {false}
private

◆ i2c_builtin_indices_

std::array<int, kI2cBuiltinCount> CommChannelsManager::i2c_builtin_indices_ {}
private

◆ i2c_bus_valid_

bool CommChannelsManager::i2c_bus_valid_ {false}
private

◆ i2c_runtime_slots_

std::array<RuntimeI2cSlot, kMaxI2cRuntimeDevices> CommChannelsManager::i2c_runtime_slots_ {}
private

◆ initialized_

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

◆ kI2cBuiltinCount

constexpr uint8_t CommChannelsManager::kI2cBuiltinCount
staticconstexprprivate
Initial value:
=
static_cast<uint8_t>(I2cDeviceId::DEVICE_COUNT)
@ DEVICE_COUNT
Sentinel — total number of built-in I2C devices.

◆ kMaxI2cRuntimeDevices

constexpr uint8_t CommChannelsManager::kMaxI2cRuntimeDevices = 4
staticconstexprprivate

◆ kSpiDeviceCount

constexpr uint8_t CommChannelsManager::kSpiDeviceCount
staticconstexprprivate
Initial value:
=
static_cast<uint8_t>(SpiDeviceId::DEVICE_COUNT)
@ DEVICE_COUNT
Sentinel — total number of SPI devices.

◆ last_error_

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

◆ mutex_

RtosMutex CommChannelsManager::mutex_
mutableprivate

◆ spi_bus_valid_

bool CommChannelsManager::spi_bus_valid_ {false}
private

◆ spi_device_indices_

std::array<int, kSpiDeviceCount> CommChannelsManager::spi_device_indices_ {}
private

◆ uart_bus_

BaseUart* CommChannelsManager::uart_bus_ {nullptr}
private

◆ uart_bus_valid_

bool CommChannelsManager::uart_bus_valid_ {false}
private

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