mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
Update Spi component to return a status on device access (#4452)
* Update Spi component to return a status on device access * Format LinuxSpiDriver files and update comments from TODO to DEPRECATED * Add assertions to LinuxSpiDriver * Add assertions to LinuxSpiDriver --------- Co-authored-by: djbyrne <djbyrne@jpl.nasa.gov>
This commit is contained in:
parent
08f43279da
commit
9fbf5800ab
@ -1,5 +1,9 @@
|
||||
module Drv {
|
||||
interface Spi {
|
||||
@ Port to perform a synchronous write/read operation over the SPI bus
|
||||
guarded input port SpiWriteRead: Drv.SpiWriteRead
|
||||
|
||||
@ DEPRECATED Use SpiWriteRead port instead (same operation with a return value)
|
||||
@ Port to perform a synchronous read/write operation over the SPI bus
|
||||
sync input port SpiReadWrite: Drv.SpiReadWrite
|
||||
}
|
||||
|
||||
@ -34,13 +34,26 @@ namespace Drv {
|
||||
// Handler implementations for user-defined typed input ports
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// @ DEPRECATED: Use SpiWriteRead port instead (same operation with a return value)
|
||||
void LinuxSpiDriverComponentImpl::SpiReadWrite_handler(const FwIndexType portNum,
|
||||
Fw::Buffer& writeBuffer,
|
||||
Fw::Buffer& readBuffer) {
|
||||
FW_ASSERT(portNum >= 0, static_cast<FwAssertArgType>(portNum));
|
||||
FW_ASSERT(writeBuffer.isValid());
|
||||
FW_ASSERT(readBuffer.isValid());
|
||||
(void)SpiWriteRead_handler(portNum, writeBuffer, readBuffer);
|
||||
}
|
||||
|
||||
SpiStatus LinuxSpiDriverComponentImpl::SpiWriteRead_handler(const FwIndexType portNum,
|
||||
Fw::Buffer& writeBuffer,
|
||||
Fw::Buffer& readBuffer) {
|
||||
FW_ASSERT(portNum >= 0, static_cast<FwAssertArgType>(portNum));
|
||||
FW_ASSERT(writeBuffer.isValid());
|
||||
FW_ASSERT(readBuffer.isValid());
|
||||
FW_ASSERT(writeBuffer.getSize() == readBuffer.getSize());
|
||||
|
||||
if (this->m_fd == -1) {
|
||||
return;
|
||||
return SpiStatus::SPI_OPEN_ERR;
|
||||
}
|
||||
|
||||
spi_ioc_transfer tr;
|
||||
@ -64,9 +77,12 @@ void LinuxSpiDriverComponentImpl::SpiReadWrite_handler(const FwIndexType portNum
|
||||
|
||||
if (stat < 1) {
|
||||
this->log_WARNING_HI_SPI_WriteError(this->m_device, this->m_select, stat);
|
||||
return SpiStatus::SPI_OTHER_ERR;
|
||||
}
|
||||
this->m_bytes += readBuffer.getSize();
|
||||
this->tlmWrite_SPI_Bytes(this->m_bytes);
|
||||
|
||||
return SpiStatus::SPI_OK;
|
||||
}
|
||||
|
||||
bool LinuxSpiDriverComponentImpl::open(FwIndexType device, FwIndexType select, SpiFrequency clock, SpiMode spiMode) {
|
||||
|
||||
@ -76,6 +76,13 @@ class LinuxSpiDriverComponentImpl final : public LinuxSpiDriverComponentBase {
|
||||
// Handler implementations for user-defined typed input ports
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
//! Handler implementation for SpiWriteRead
|
||||
//!
|
||||
SpiStatus SpiWriteRead_handler(const FwIndexType portNum, /*!< The port number*/
|
||||
Fw::Buffer& WriteBuffer,
|
||||
Fw::Buffer& readBuffer);
|
||||
|
||||
// @ DEPRECATED: Use SpiWriteRead port instead (same operation with a return value)
|
||||
//! Handler implementation for SpiReadWrite
|
||||
//!
|
||||
void SpiReadWrite_handler(const FwIndexType portNum, /*!< The port number*/
|
||||
|
||||
@ -23,6 +23,13 @@ bool LinuxSpiDriverComponentImpl::open(FwIndexType device, FwIndexType select, S
|
||||
// Handler implementations for user-defined typed input ports
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
SpiStatus LinuxSpiDriverComponentImpl::SpiWriteRead_handler(const FwIndexType portNum,
|
||||
Fw::Buffer& WriteBuffer,
|
||||
Fw::Buffer& readBuffer) {
|
||||
return SpiStatus::SPI_OK;
|
||||
}
|
||||
|
||||
// @ DEPRECATED: Use SpiWriteRead port instead (same operation with a return value)
|
||||
void LinuxSpiDriverComponentImpl::SpiReadWrite_handler(const FwIndexType portNum,
|
||||
Fw::Buffer& WriteBuffer,
|
||||
Fw::Buffer& readBuffer) {}
|
||||
|
||||
@ -1,8 +1,28 @@
|
||||
module Drv {
|
||||
|
||||
port SpiWriteRead(
|
||||
ref writeBuffer: Fw.Buffer
|
||||
ref readBuffer: Fw.Buffer
|
||||
) -> Drv.SpiStatus
|
||||
|
||||
@ DEPRECATED: Use SpiWriteRead port instead (same operation with a return value)
|
||||
port SpiReadWrite(
|
||||
ref writeBuffer: Fw.Buffer
|
||||
ref readBuffer: Fw.Buffer
|
||||
ref readBuffer: Fw.Buffer
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
module Drv {
|
||||
|
||||
enum SpiStatus : U8 {
|
||||
SPI_OK = 0 @< Transaction okay
|
||||
SPI_OPEN_ERR = 1 @< SPI driver failed to open device
|
||||
SPI_CONFIG_ERR = 2 @< SPI read failed
|
||||
SPI_MISMATCH_ERR = 3 @< SPI read failed
|
||||
SPI_WRITE_ERR = 4 @< SPI write failed
|
||||
SPI_OTHER_ERR = 5 @< Other errors that do not fit
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user