From d923b375d8a98b3474b3e6efcdeeca826c238d31 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 27 Jun 2024 12:59:41 +0000 Subject: [PATCH] Use void pointers for low-level RF functions --- Sts1CobcSw/Periphery/Fram.hpp | 1 + Sts1CobcSw/Periphery/Rf.cpp | 23 ++++++++++++----------- Sts1CobcSw/Periphery/Rf.hpp | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Sts1CobcSw/Periphery/Fram.hpp b/Sts1CobcSw/Periphery/Fram.hpp index 1d18a212..fabe2e94 100644 --- a/Sts1CobcSw/Periphery/Fram.hpp +++ b/Sts1CobcSw/Periphery/Fram.hpp @@ -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 auto WriteTo(Address address, std::span data) -> void; diff --git a/Sts1CobcSw/Periphery/Rf.cpp b/Sts1CobcSw/Periphery/Rf.cpp index a4ff82d1..a2105b02 100644 --- a/Sts1CobcSw/Periphery/Rf.cpp +++ b/Sts1CobcSw/Periphery/Rf.cpp @@ -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; @@ -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(length >> 8); - auto lengthLowerBits = static_cast(length); + auto lengthUpperBits = static_cast(nBytes >> CHAR_BIT); + auto lengthLowerBits = static_cast(nBytes); SetProperties(PropertyGroup::pkt, iPktField1Length, Span({lengthUpperBits, lengthLowerBits})); // Fill the TX FIFO with 60 bytes each "round" @@ -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) @@ -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(data) + dataIndex, nFillBytes); dataIndex += nFillBytes; ClearInterrupts(); StartTx(); @@ -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(data) + dataIndex, nBytes - dataIndex); StartTx(); @@ -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({0x66}); spi.write(std::data(buf), std::size(buf)); - spi.write(data, length); + spi.write(data, nBytes); AT(NOW() + 2 * MICROSECONDS); csGpioPin.Set(); diff --git a/Sts1CobcSw/Periphery/Rf.hpp b/Sts1CobcSw/Periphery/Rf.hpp index 913a4fda..b8056ba5 100644 --- a/Sts1CobcSw/Periphery/Rf.hpp +++ b/Sts1CobcSw/Periphery/Rf.hpp @@ -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; }