Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Drv/Interfaces/Spi.fpp
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
18 changes: 17 additions & 1 deletion Drv/LinuxSpiDriver/LinuxSpiDriverComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,26 @@
// 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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be ok; but also Googling around seems to suggest there might be use cases for unidirectional SPI, so I wonder if we really should assert here? I'd like to get someone else's eyes on this to confirm, since we weren't asserting before.

(void)SpiWriteRead_handler(portNum, writeBuffer, readBuffer);
}

SpiStatus LinuxSpiDriverComponentImpl::SpiWriteRead_handler(const FwIndexType portNum,

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
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;
Expand All @@ -64,9 +77,12 @@

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) {
Expand Down
7 changes: 7 additions & 0 deletions Drv/LinuxSpiDriver/LinuxSpiDriverComponentImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand Down
7 changes: 7 additions & 0 deletions Drv/LinuxSpiDriver/LinuxSpiDriverComponentImplStub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
22 changes: 21 additions & 1 deletion Drv/Ports/SpiDriverPorts.fpp
Original file line number Diff line number Diff line change
@@ -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