Added timeout to bus communication and added error handling via return values

This commit is contained in:
dario
2024-11-03 18:22:34 +01:00
parent 53567724f1
commit bbb8f3505e
14 changed files with 212 additions and 109 deletions

View File

@@ -35,14 +35,14 @@ namespace sta
*
* @param value 8-bit value
*/
void transfer(uint8_t value);
bool transfer(uint8_t value, uint32_t timeout = STA_MAX_TIMEOUT);
/**
* @brief Send two bytes of data.
*
* @param value 16-bit value
*/
void transfer16(uint16_t value);
bool transfer16(uint16_t value, uint32_t timeout = STA_MAX_TIMEOUT);
/**
* @brief Send data from buffer.
@@ -50,7 +50,16 @@ namespace sta
* @param buffer Source buffer
* @param size Number of bytes to transfer
*/
void transfer(const uint8_t * buffer, size_t size);
bool transfer(const uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT);
/**
* @brief Write data to a specific memory address of the peripheral.
*
* @param regAddr The memory address.
* @param buffer The buffer of data to write to the address
* @param size The number of bytes to write to the peripheral.
*/
bool writeMemory(uint8_t regAddr, const uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT);
/**
* @brief Read incoming data to buffer.
@@ -58,7 +67,16 @@ namespace sta
* @param buffer Destination buffer
* @param size Number of bytes to read
*/
void receive(uint8_t * buffer, size_t size);
bool receive(uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT);
/**
* @brief Read data from a specific memory address of the peripheral.
*
* @param regAddr The memory address.
* @param buffer The buffer of data to write the received data to.
* @param size The number of bytes to receive from the peripheral.
*/
bool readMemory(uint8_t regAddr, uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT);
/**
* @brief Send byte value repeatedly.
@@ -66,7 +84,7 @@ namespace sta
* @param value 8-bit value to repeat
* @param count Number of repetitions
*/
void fill(uint8_t value, size_t count);
void fill(uint8_t value, size_t count, uint32_t timeout = STA_MAX_TIMEOUT);
protected:
/**
@@ -78,7 +96,6 @@ namespace sta
* @brief Deactivate device..
*/
virtual void deselect() = 0;
private:
Interface * intf_;
bool selected_ = false;