Skip to content

Commit

Permalink
Take rebase into account
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromehue committed Jul 31, 2024
1 parent 06729c0 commit 049ac75
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 52 deletions.
16 changes: 9 additions & 7 deletions Sts1CobcSw/Edu/ProgramStatusHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using sts1cobcsw::SerializeTo;


template<std::endian endianness>
auto DeserializeFrom(void const * source, ProgramStatusHistoryEntry * data) -> void const *
auto DeserializeFrom(void const * source, edu::ProgramStatusHistoryEntry * data) -> void const *
{
source = DeserializeFrom<endianness>(source, &(data->programId));
source = DeserializeFrom<endianness>(source, &(data->startTime));
Expand All @@ -39,14 +39,14 @@ auto DeserializeFrom(void const * source, ProgramStatusHistoryEntry * data) -> v
}


template auto DeserializeFrom<std::endian::big>(void const *, ProgramStatusHistoryEntry *)
template auto DeserializeFrom<std::endian::big>(void const *, edu::ProgramStatusHistoryEntry *)
-> void const *;
template auto DeserializeFrom<std::endian::little>(void const *, ProgramStatusHistoryEntry *)
template auto DeserializeFrom<std::endian::little>(void const *, edu::ProgramStatusHistoryEntry *)
-> void const *;


template<std::endian endianness>
auto SerializeTo(void * destination, ProgramStatusHistoryEntry const & data) -> void *
auto SerializeTo(void * destination, edu::ProgramStatusHistoryEntry const & data) -> void *
{
destination = SerializeTo<endianness>(destination, data.programId);
destination = SerializeTo<endianness>(destination, data.startTime);
Expand All @@ -55,6 +55,8 @@ auto SerializeTo(void * destination, ProgramStatusHistoryEntry const & data) ->
}


template auto SerializeTo<std::endian::big>(void *, ProgramStatusHistoryEntry const &) -> void *;
template auto SerializeTo<std::endian::little>(void *, ProgramStatusHistoryEntry const &) -> void *;
}
template auto SerializeTo<std::endian::big>(void *, edu::ProgramStatusHistoryEntry const &)
-> void *;
template auto SerializeTo<std::endian::little>(void *, edu::ProgramStatusHistoryEntry const &)
-> void *;
}
27 changes: 9 additions & 18 deletions Sts1CobcSw/Edu/ProgramStatusHistory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
#include <cstddef>


namespace sts1cobcsw
{
namespace edu
using sts1cobcsw::ProgramId;


namespace sts1cobcsw::edu
{
enum class ProgramStatus : std::uint8_t
{
Expand All @@ -42,32 +43,23 @@ struct ProgramStatusHistoryEntry
};
}

namespace sts1cobcsw
{
template<>
inline constexpr std::size_t serialSize<edu::ProgramStatusHistoryEntry> =
totalSerialSize<decltype(edu::ProgramStatusHistoryEntry::programId),
decltype(edu::ProgramStatusHistoryEntry::startTime),
decltype(edu::ProgramStatusHistoryEntry::status)>;
}


namespace edu
namespace sts1cobcsw::edu
{
inline constexpr auto programStatusHistorySize = 20;

static_assert(programStatusHistorySize * totalSerialSize<ProgramStatusHistoryEntry>
<= fram::EduProgramStatusHistory::size,
"Size of EDU program status history exceeds size of FRAM section");


template<>
inline constexpr std::size_t serialSize<edu::ProgramStatusHistoryEntry> =
totalSerialSize<decltype(edu::ProgramStatusHistoryEntry::programId),
decltype(edu::ProgramStatusHistoryEntry::startTime),
decltype(edu::ProgramStatusHistoryEntry::status)>;

namespace edu
{
inline constexpr auto programStatusHistorySize = 20;

template<std::endian endianness>
[[nodiscard]] auto DeserializeFrom(void const * source, ProgramStatusHistoryEntry * data)
-> void const *;
Expand All @@ -81,5 +73,4 @@ extern RODOS::RingBuffer<ProgramStatusHistoryEntry, programStatusHistorySize> pr
auto UpdateProgramStatusHistory(ProgramId programId,
std::int32_t startTime,
ProgramStatus newStatus) -> void;
}
}
}
1 change: 1 addition & 0 deletions Sts1CobcSw/Periphery/FramRingBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RingBuffer
//! @brief Returns the capacity of the ringbuffer
auto Capacity() -> std::size_t;


private:
std::uint32_t nextWriteIndex_ = 0;
std::uint32_t nextReadIndex_ = 0;
Expand Down
18 changes: 9 additions & 9 deletions Sts1CobcSw/Periphery/FramRingBuffer.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ namespace sts1cobcsw::fram
template<typename T, std::size_t size, Address startAddress>
void RingBuffer<T, size, startAddress>::Push(T const & newData)
{
auto const address = startAddress + nextWriteIndex_ * serialSize<T>;
fram::WriteTo(address, Span(Serialize(newData)), 0);

auto const rawaddress = value_of(startAddress) + (nextWriteIndex_ * serialSize<T>);
fram::WriteTo(fram::Address(rawaddress), Span(Serialize(newData)), 0);

++nextWriteIndex_;
if(nextWriteIndex_ == bufferSize_)
Expand All @@ -33,8 +32,8 @@ void RingBuffer<T, size, startAddress>::Push(T const & newData)
template<typename T, std::size_t size, Address startAddress>
auto RingBuffer<T, size, startAddress>::Front() -> T
{
auto const address = startAddress + nextReadIndex_ * serialSize<T>;
auto readData = fram::ReadFrom<serialSize<T>>(address, 0);
auto const rawAddress = value_of(startAddress) + (nextReadIndex_ * serialSize<T>);
auto readData = fram::ReadFrom<serialSize<T>>(fram::Address(rawAddress), 0);
auto fromRing = Deserialize<T>(std::span(readData));

return fromRing;
Expand All @@ -54,8 +53,8 @@ auto RingBuffer<T, size, startAddress>::Back() -> T
readIndex = nextWriteIndex_ - 1;
}

auto const address = startAddress + readIndex * serialSize<T>;
auto readData = fram::ReadFrom<serialSize<T>>(address, 0);
auto const rawaddress = value_of(startAddress) + readIndex * serialSize<T>;
auto readData = fram::ReadFrom<serialSize<T>>(fram::Address(rawaddress), 0);
auto fromRing = Deserialize<T>(std::span(readData));

return fromRing;
Expand All @@ -65,8 +64,9 @@ auto RingBuffer<T, size, startAddress>::Back() -> T
template<typename T, std::size_t size, Address startAddress>
auto RingBuffer<T, size, startAddress>::operator[](std::size_t index) -> T
{
auto const address = startAddress + ((nextReadIndex_ + index) % bufferSize_) * serialSize<T>;
auto readData = fram::ReadFrom<serialSize<T>>(address, 0);
auto const rawaddress =
value_of(startAddress) + ((nextReadIndex_ + index) % bufferSize_) * serialSize<T>;
auto readData = fram::ReadFrom<serialSize<T>>(fram::Address(rawaddress), 0);
return Deserialize<T>(std::span(readData));
}

Expand Down
42 changes: 24 additions & 18 deletions Tests/UnitTests/FramRingBuffer.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,24 @@ TEST_CASE("FramRingBuffer Push function")
TEMPLATE_TEST_CASE_SIG("FramRingBuffer Front Address",
"",
((typename T, size_t S, fram::Address A), T, S, A),
(int, 10, fram::Address{0}),
(int, 10, fram::Address{31415}))
(int, 10U, fram::Address{0}),
(int, 10U, fram::Address{31415}))
{
fram::ram::SetAllDoFunctions();
fram::ram::storage.fill(0x00_b);
fram::ram::memory.fill(0x00_b);
fram::Initialize();

fram::RingBuffer<T, S, A> buffer;

// FIXME: [] not working
buffer.Push(10);
REQUIRE(buffer[0] == 10);

buffer.Push(20);
buffer.Push(30);
REQUIRE(buffer[0] == 10);
REQUIRE(buffer[1] == 20);

buffer.Push(30);
REQUIRE(buffer[0] == 10);
REQUIRE(buffer[1] == 20);
REQUIRE(buffer[2] == 30);
Expand All @@ -61,10 +66,10 @@ TEMPLATE_TEST_CASE_SIG("FramRingBuffer Front Address",
TEST_CASE("FramRingBuffer Back() and Front() methods")
{
fram::ram::SetAllDoFunctions();
fram::ram::storage.fill(0x00_b);
fram::ram::memory.fill(0x00_b);
fram::Initialize();

fram::RingBuffer<int, 5U, 0U> buffer;
auto buffer = fram::RingBuffer<int, 5, fram::Address{0}>();
etl::circular_buffer<int, 5U> etlBuffer;

// NOLINTNEXTLINE (readability-container-size-empty)
Expand All @@ -74,21 +79,22 @@ TEST_CASE("FramRingBuffer Back() and Front() methods")

buffer.Push(1);
buffer.Push(2);
REQUIRE(buffer.Front() == 1);
buffer.Push(3);

etlBuffer.push(1);
etlBuffer.push(2);
etlBuffer.push(3);

REQUIRE(etlBuffer.front() == 1);
REQUIRE(etlBuffer.back() == 3);
REQUIRE(etlBuffer.size() == 3);
REQUIRE(etlBuffer.capacity() == 5);
REQUIRE(etlBuffer.back() == 3);
REQUIRE(etlBuffer.front() == 1);

REQUIRE(buffer.Front() == 1);
REQUIRE(buffer.Back() == 3);
REQUIRE(buffer.Size() == 3);
REQUIRE(buffer.Capacity() == 5);
REQUIRE(buffer.Back() == 3);
REQUIRE(buffer.Front() == 1);

etlBuffer.push(4);
etlBuffer.push(5);
Expand Down Expand Up @@ -118,10 +124,10 @@ TEST_CASE("FramRingBuffer Back() and Front() methods")
TEST_CASE("FramRingBuffer Full and Empty conditions")
{
fram::ram::SetAllDoFunctions();
fram::ram::storage.fill(0x00_b);
fram::ram::memory.fill(0x00_b);
fram::Initialize();

fram::RingBuffer<int, 3, 0U> buffer;
auto buffer = fram::RingBuffer<int, 3, fram::Address(0)>{};

REQUIRE(buffer.Size() == 0);
REQUIRE(buffer.Capacity() == 3);
Expand Down Expand Up @@ -150,10 +156,10 @@ TEST_CASE("FramRingBuffer Full and Empty conditions")
TEST_CASE("FramRingBuffer and ETL Circular Buffer")
{
fram::ram::SetAllDoFunctions();
fram::ram::storage.fill(0x00_b);
fram::ram::memory.fill(0x00_b);
fram::Initialize();

fram::RingBuffer<int, 5U, 0U> framBuffer;
fram::RingBuffer<int, 5U, fram::Address{0}> framBuffer{};
etl::circular_buffer<int, 5U> etlBuffer;

for(int i = 0; i < 5; ++i)
Expand All @@ -178,10 +184,10 @@ TEST_CASE("FramRingBuffer and ETL Circular Buffer")
TEST_CASE("FramRingBuffer Stress Test")
{
fram::ram::SetAllDoFunctions();
fram::ram::storage.fill(0x00_b);
fram::ram::memory.fill(0x00_b);
fram::Initialize();

fram::RingBuffer<int, 10000, 0U> buffer;
auto buffer = fram::RingBuffer<int, 10000, fram::Address{0}>();

for(int i = 0; i < 10000; ++i)
{
Expand All @@ -199,11 +205,11 @@ TEST_CASE("FramRingBuffer Stress Test")
TEST_CASE("Custom Type")
{
fram::ram::SetAllDoFunctions();
fram::ram::storage.fill(0x00_b);
fram::ram::memory.fill(0x00_b);
fram::Initialize();


fram::RingBuffer<sts1cobcsw::edu::ProgramStatusHistoryEntry, 10U, 0U> buffer;
fram::RingBuffer<sts1cobcsw::edu::ProgramStatusHistoryEntry, 10U, fram::Address{0}> buffer;

auto pshEntry = sts1cobcsw::edu::ProgramStatusHistoryEntry{
.programId = sts1cobcsw::ProgramId(0),
Expand Down

0 comments on commit 049ac75

Please sign in to comment.