Skip to content

Commit

Permalink
Add abstraction for FRAM ring array (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickKa committed Sep 15, 2024
2 parents c97b363 + 740db96 commit ba7f400
Show file tree
Hide file tree
Showing 24 changed files with 615 additions and 284 deletions.
1 change: 1 addition & 0 deletions .codespell-ignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tust
fram
framlayout
framBuffer
3 changes: 2 additions & 1 deletion Sts1CobcSw/CobcSoftware/CommandParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include <Sts1CobcSw/Serial/Serial.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>

#include <cinttypes> // IWYU pragma: keep
#include <strong_type/type.hpp>

#include <cinttypes> // IWYU pragma: keep

namespace sts1cobcsw
{
Expand Down
1 change: 1 addition & 0 deletions Sts1CobcSw/CobcSoftware/EduCommunicationErrorThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Sts1CobcSw/CobcSoftware/TopicsAndSubscribers.hpp>
#include <Sts1CobcSw/Edu/Edu.hpp>
#include <Sts1CobcSw/FramSections/FramLayout.hpp>
#include <Sts1CobcSw/FramSections/PersistentVariables.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

Expand Down
3 changes: 0 additions & 3 deletions Sts1CobcSw/CobcSoftware/EduCommunicationErrorThread.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#pragma once


#include <cstdint>


namespace sts1cobcsw
{
auto ResumeEduCommunicationErrorThread() -> void;
Expand Down
2 changes: 1 addition & 1 deletion Sts1CobcSw/Edu/Edu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ auto ReceiveDataPacket() -> Result<void>
template<typename T>
auto Receive() -> Result<T>
{
auto buffer = Buffer<T>{};
auto buffer = SerialBuffer<T>{};
OUTCOME_TRY(Receive(buffer));
return Deserialize<T>(buffer);
}
Expand Down
2 changes: 2 additions & 0 deletions Sts1CobcSw/Edu/EduMock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <Sts1CobcSw/Edu/Types.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>

#include <strong_type/type.hpp>

#include <cinttypes> // IWYU pragma: keep


Expand Down
32 changes: 32 additions & 0 deletions Sts1CobcSw/Edu/ProgramStatusHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,36 @@ auto UpdateProgramStatusHistory(ProgramId programId, RealTime startTime, Program
}
}
}


using sts1cobcsw::DeserializeFrom;
using sts1cobcsw::SerializeTo;


template<std::endian endianness>
auto DeserializeFrom(void const * source, ProgramStatusHistoryEntry * data) -> void const *
{
source = DeserializeFrom<endianness>(source, &(data->programId));
source = DeserializeFrom<endianness>(source, &(data->startTime));
source = DeserializeFrom<endianness>(source, &(data->status));
return source;
}


template<std::endian endianness>
auto SerializeTo(void * destination, ProgramStatusHistoryEntry const & data) -> void *
{
destination = SerializeTo<endianness>(destination, data.programId);
destination = SerializeTo<endianness>(destination, data.startTime);
destination = SerializeTo<endianness>(destination, data.status);
return destination;
}


template auto DeserializeFrom<std::endian::big>(void const *, ProgramStatusHistoryEntry *)
-> void const *;
template auto DeserializeFrom<std::endian::little>(void const *, ProgramStatusHistoryEntry *)
-> void const *;
template auto SerializeTo<std::endian::big>(void *, ProgramStatusHistoryEntry const &) -> void *;
template auto SerializeTo<std::endian::little>(void *, ProgramStatusHistoryEntry const &) -> void *;
}
8 changes: 8 additions & 0 deletions Sts1CobcSw/Edu/ProgramStatusHistory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <rodos/support/support-libs/ringbuffer.h>
// clang-format on

#include <bit>
#include <cstddef>


Expand Down Expand Up @@ -64,5 +65,12 @@ extern RODOS::RingBuffer<ProgramStatusHistoryEntry, nProgramStatusHistoryEntries

auto UpdateProgramStatusHistory(ProgramId programId, RealTime startTime, ProgramStatus newStatus)
-> void;

template<std::endian endianness>
[[nodiscard]] auto DeserializeFrom(void const * source, ProgramStatusHistoryEntry * data)
-> void const *;
template<std::endian endianness>
[[nodiscard]] auto SerializeTo(void * destination, ProgramStatusHistoryEntry const & data)
-> void *;
}
}
7 changes: 1 addition & 6 deletions Sts1CobcSw/FramSections/FramLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@
namespace sts1cobcsw
{
inline constexpr auto framMemory = Section<fram::Address(0), fram::memorySize>{};
inline constexpr auto persistentVariablesSize = fram::Size(100);
inline constexpr auto framSections =
Subsections<framMemory,
SubsectionInfo<"persistentVariables0", persistentVariablesSize>,
SubsectionInfo<"persistentVariables1", persistentVariablesSize>,
SubsectionInfo<"persistentVariables2", persistentVariablesSize>,
SubsectionInfo<"persistentVariables0", fram::Size(300)>,
SubsectionInfo<"eduProgramQueue", fram::Size(20 * 8)>,
SubsectionInfo<"eduProgramStatusHistory", fram::Size(50 * 7)>,
SubsectionInfo<"testMemory", fram::Size(1000)>,
SubsectionInfo<"telemetry", fram::Size(26'168 * 40)>>{};
inline constexpr auto persistentVariables =
PersistentVariables<framSections.Get<"persistentVariables0">(),
framSections.Get<"persistentVariables1">(),
framSections.Get<"persistentVariables2">(),
PersistentVariableInfo<"nResetsSinceRf", std::uint16_t>,
PersistentVariableInfo<"activeSecondaryFwPartition", std::int8_t>,
PersistentVariableInfo<"backupSecondaryFwPartition", std::int8_t>,
Expand Down
27 changes: 15 additions & 12 deletions Sts1CobcSw/FramSections/PersistentVariables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@

namespace sts1cobcsw
{
template<Section parentSection0,
Section parentSection1,
Section parentSection2,
APersistentVariableInfo... PersistentVariableInfos>
requires(sizeof...(PersistentVariableInfos) > 0 && parentSection0.end <= parentSection1.begin
&& parentSection1.end <= parentSection2.begin)
template<Section persistentVariablesSection, APersistentVariableInfo... PersistentVariableInfos>
requires(sizeof...(PersistentVariableInfos) > 0)
class PersistentVariables
{
public:
static constexpr auto section = persistentVariablesSection;

template<StringLiteral name>
using ValueType = std::tuple_element_t<
Subsections<parentSection0, PersistentVariableInfos...>::template Index<name>(),
Subsections<section, PersistentVariableInfos...>::template Index<name>(),
std::tuple<typename PersistentVariableInfos::ValueType...>>;

constexpr PersistentVariables() = default;

template<StringLiteral name>
[[nodiscard]] static auto Load() -> ValueType<name>;
template<StringLiteral name>
Expand All @@ -52,9 +48,16 @@ class PersistentVariables
static std::tuple<typename PersistentVariableInfos::ValueType...> cache1;
static std::tuple<typename PersistentVariableInfos::ValueType...> cache2;

static constexpr auto subsections0 = Subsections<parentSection0, PersistentVariableInfos...>();
static constexpr auto subsections1 = Subsections<parentSection1, PersistentVariableInfos...>();
static constexpr auto subsections2 = Subsections<parentSection2, PersistentVariableInfos...>();
static constexpr auto subsections = Subsections<section,
SubsectionInfo<"0", section.size / 3>,
SubsectionInfo<"1", section.size / 3>,
SubsectionInfo<"2", section.size / 3>>{};
static constexpr auto variables0 =
Subsections<subsections.template Get<"0">(), PersistentVariableInfos...>();
static constexpr auto variables1 =
Subsections<subsections.template Get<"1">(), PersistentVariableInfos...>();
static constexpr auto variables2 =
Subsections<subsections.template Get<"2">(), PersistentVariableInfos...>();

// With a baud rate of 48 MHz we can read 6000 bytes in 1 ms, which should be more than enough
static constexpr auto spiTimeout = 1 * RODOS::MILLISECONDS;
Expand Down
Loading

0 comments on commit ba7f400

Please sign in to comment.