Skip to content

Commit

Permalink
Use "new" SPI interface to make Rf.cpp compile again
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickKa committed Jun 27, 2024
1 parent a713fbe commit 0cc6cbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Sts1CobcSw/Hal/Spi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Spi

auto Initialize(RODOS::HAL_SPI * spi, std::uint32_t baudRate) -> void;

// TODO: Why are these functions still here? I think they can and should be removed.

// TODO: Maybe remove extent to reduce code bloat, or probably build time since it is just a single
// call to the Rodos function, which is trivial to inline.
template<typename T, std::size_t extent>
Expand Down
24 changes: 13 additions & 11 deletions Sts1CobcSw/Periphery/Rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ auto ClearRxFifo() -> void;
auto ClearFifos() -> void;
auto ClearInterrupts() -> void;
auto EnterStandby() -> void;
auto WriteFifo(void const * data, std::size_t nBytes) -> void;
auto WriteToFifo(std::span<Byte const> data) -> void;
auto StartTx() -> void;


Expand Down Expand Up @@ -194,6 +194,7 @@ auto Send(void const * data, std::size_t nBytes) -> void
// While the packet is longer than a single fill round, wait for the almost empty interrupt,
// afterwards for the packet sent interrupt
auto dataIndex = 0U;
auto dataSpan = std::span(static_cast<Byte const *>(data), nBytes);
while(nBytes - dataIndex > nFillBytes)
{
// Enable the almost empty interrupt in the first round
Expand All @@ -207,7 +208,7 @@ auto Send(void const * data, std::size_t nBytes) -> void

// Write nFillBytes bytes to the TX FIFO
// NOLINTNEXTLINE(*pointer-arithmetic)
WriteFifo(static_cast<Byte const *>(data) + dataIndex, nFillBytes);
WriteToFifo(dataSpan.subspan(dataIndex, nFillBytes));
dataIndex += nFillBytes;
ClearInterrupts();
StartTx();
Expand All @@ -227,7 +228,7 @@ auto Send(void const * data, std::size_t nBytes) -> void

// Write the rest of the data
// NOLINTNEXTLINE(*pointer-arithmetic)
WriteFifo(static_cast<Byte const *>(data) + dataIndex, nBytes - dataIndex);
WriteToFifo(dataSpan.subspan(dataIndex));

StartTx();

Expand Down Expand Up @@ -937,27 +938,28 @@ auto EnterStandby() -> void


// TODO: Refactor (issue #226)
auto WriteFifo(void const * data, std::size_t nBytes) -> void
auto WriteToFifo(std::span<Byte const> data) -> void
{
// TODO: Choose proper timeout value
static constexpr auto timeout = 10 * RODOS::MILLISECONDS;
csGpioPin.Reset();
AT(NOW() + 20 * MICROSECONDS);
auto buf = std::to_array<std::uint8_t>({0x66});
spi.write(std::data(buf), std::size(buf));
spi.write(data, nBytes);
WriteTo(&spi, Span(0x66), timeout);
WriteTo(&spi, data, timeout);
AT(NOW() + 2 * MICROSECONDS);
csGpioPin.Set();

auto cts = std::to_array<std::uint8_t>({0x00, 0x00});
auto req = std::to_array<std::uint8_t>({0x44, 0x00});
auto cts = 0x00_b;
do
{
AT(NOW() + 20 * MICROSECONDS);
csGpioPin.Reset();
AT(NOW() + 20 * MICROSECONDS);
spi.writeRead(std::data(req), std::size(req), std::data(cts), std::size(cts));
WriteTo(&spi, Span(0x44), timeout);
hal::ReadFrom(&spi, Span(&cts), spiTimeout);
AT(NOW() + 2 * MICROSECONDS);
csGpioPin.Set();
} while(cts[1] != 0xFF);
} while(cts != 0xFF_b);
}


Expand Down

0 comments on commit 0cc6cbe

Please sign in to comment.