Skip to content

Commit

Permalink
Use void pointers for low-level RF functions
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickKa committed Jun 27, 2024
1 parent 0682567 commit d923b37
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions Sts1CobcSw/Periphery/Fram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ auto Initialize() -> void;
[[nodiscard]] auto ReadDeviceId() -> DeviceId;
auto ActualBaudRate() -> int32_t;

// TODO: This should also work without extent and thereby without any template parameters
template<std::size_t extent>
auto WriteTo(Address address, std::span<Byte const, extent> data) -> void;

Expand Down
23 changes: 12 additions & 11 deletions Sts1CobcSw/Periphery/Rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ auto ClearRxFifo() -> void;
auto ClearFifos() -> void;
auto ClearInterrupts() -> void;
auto EnterStandby() -> void;
auto WriteFifo(std::uint8_t const * data, std::size_t length) -> void;
auto WriteFifo(void const * data, std::size_t nBytes) -> void;
auto StartTx() -> void;


Expand Down Expand Up @@ -168,18 +168,17 @@ auto SetTxType(TxType txType) -> void

// TODO: Do we need to clear all FIFOs here, should be just TX FIFO
// TODO: Refactor (issue #226)
// TODO: Replace std::uint8_t const * with void const *
auto Send(std::uint8_t const * data, std::size_t length) -> void
auto Send(void const * data, std::size_t nBytes) -> void
{
// TODO: Acc. the datasheet "fifo hardware does not need to be reset prior to use".
ClearFifos();

// Set TX Data Length
// TODO: Check if we can just set the length in START_TX
// TODO: Use Deserialize() for length bytes, but length should then be uint16_t
// TODO: Use Deserialize(), but length should then be uint16_t
static constexpr auto iPktField1Length = 0x0D_b;
auto lengthUpperBits = static_cast<Byte>(length >> 8);
auto lengthLowerBits = static_cast<Byte>(length);
auto lengthUpperBits = static_cast<Byte>(nBytes >> CHAR_BIT);
auto lengthLowerBits = static_cast<Byte>(nBytes);
SetProperties(PropertyGroup::pkt, iPktField1Length, Span({lengthUpperBits, lengthLowerBits}));

// Fill the TX FIFO with 60 bytes each "round"
Expand All @@ -191,7 +190,7 @@ auto Send(std::uint8_t const * data, std::size_t length) -> 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;
while(length - dataIndex > nFillBytes)
while(nBytes - dataIndex > nFillBytes)
{
// Enable the almost empty interrupt in the first round
if(not almostEmptyInterruptEnabled)
Expand All @@ -203,7 +202,8 @@ auto Send(std::uint8_t const * data, std::size_t length) -> void
}

// Write nFillBytes bytes to the TX FIFO
WriteFifo(data + dataIndex, nFillBytes);
// NOLINTNEXTLINE(*pointer-arithmetic)
WriteFifo(static_cast<Byte const *>(data) + dataIndex, nFillBytes);
dataIndex += nFillBytes;
ClearInterrupts();
StartTx();
Expand All @@ -222,7 +222,8 @@ auto Send(std::uint8_t const * data, std::size_t length) -> void
ClearInterrupts();

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

StartTx();

Expand Down Expand Up @@ -932,13 +933,13 @@ auto EnterStandby() -> void


// TODO: Refactor (issue #226)
auto WriteFifo(std::uint8_t const * data, std::size_t length) -> void
auto WriteFifo(void const * data, std::size_t nBytes) -> void
{
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, length);
spi.write(data, nBytes);
AT(NOW() + 2 * MICROSECONDS);
csGpioPin.Set();

Expand Down
2 changes: 1 addition & 1 deletion Sts1CobcSw/Periphery/Rf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ enum class TxType
auto Initialize(TxType txType) -> void;
auto ReadPartNumber() -> std::uint16_t;
auto SetTxType(TxType txType) -> void;
auto Send(std::uint8_t const * data, std::size_t length) -> void;
auto Send(void const * data, std::size_t nBytes) -> void;
}

0 comments on commit d923b37

Please sign in to comment.