mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-12-13 07:28:03 +00:00
Added timeout to bus communication and added error handling via return values
This commit is contained in:
@@ -6,6 +6,11 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief The maximum timeout for bus communication in sta-core.
|
||||
*/
|
||||
#define STA_MAX_TIMEOUT 0xFFFFFFFFU
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
@@ -24,27 +29,46 @@ namespace sta
|
||||
*
|
||||
* @param value 8-bit value
|
||||
*/
|
||||
virtual void transfer(uint8_t value) = 0;
|
||||
virtual bool transfer(uint8_t value, uint32_t timeout = STA_MAX_TIMEOUT) = 0;
|
||||
/**
|
||||
* @brief Send two bytes of data.
|
||||
*
|
||||
* @param value 16-bit value
|
||||
*/
|
||||
virtual void transfer16(uint16_t value) = 0;
|
||||
virtual bool transfer16(uint16_t value, uint32_t timeout = STA_MAX_TIMEOUT) = 0;
|
||||
/**
|
||||
* @brief Send data from buffer.
|
||||
*
|
||||
* @param buffer Source buffer
|
||||
* @param size Number of bytes to transfer
|
||||
*/
|
||||
virtual void transfer(const uint8_t * buffer, size_t size) = 0;
|
||||
virtual bool transfer(const uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT) = 0;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
virtual bool writeMemory(uint8_t regAddr, const uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT) = 0;
|
||||
|
||||
/**
|
||||
* @brief Read incoming data to buffer.
|
||||
*
|
||||
* @param buffer Destination buffer
|
||||
* @param size Number of bytes to read
|
||||
*/
|
||||
virtual void receive(uint8_t * buffer, size_t size) = 0;
|
||||
virtual bool receive(uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT) = 0;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
virtual bool readMemory(uint8_t regAddr, uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT) = 0;
|
||||
|
||||
/**
|
||||
* @brief Send byte value repeatedly.
|
||||
@@ -52,25 +76,26 @@ namespace sta
|
||||
* @param value 8-bit value to repeat
|
||||
* @param count Number of repetitions
|
||||
*/
|
||||
virtual void fill(uint8_t value, size_t count) = 0;
|
||||
virtual bool fill(uint8_t value, size_t count, uint32_t timeout = STA_MAX_TIMEOUT) = 0;
|
||||
|
||||
/**
|
||||
* @brief Acquire usage rights to use the interface.
|
||||
*
|
||||
* Must be called before any I/O operations are executed.
|
||||
*/
|
||||
virtual void acquire();
|
||||
virtual void acquire(uint32_t timeout = STA_MAX_TIMEOUT);
|
||||
/**
|
||||
* @brief Release usage rights for interface.
|
||||
*
|
||||
* Must be called after last I/O operation.
|
||||
*/
|
||||
virtual void release();
|
||||
virtual void release(uint32_t timeout = STA_MAX_TIMEOUT);
|
||||
|
||||
/**
|
||||
* @returns true if the interface has been aquired.
|
||||
*/
|
||||
bool isAcquired();
|
||||
|
||||
private:
|
||||
Mutex * mutex_;
|
||||
bool acquired_ = false;
|
||||
|
||||
Reference in New Issue
Block a user