Skip to content

Commit

Permalink
Use new time types
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilchmela committed Sep 4, 2024
1 parent 72944b6 commit ee5999c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
5 changes: 3 additions & 2 deletions Sts1CobcSw/CobcSoftware/FlashStartupTestThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Sts1CobcSw/FramSections/PersistentVariables.hpp>
#include <Sts1CobcSw/Periphery/Flash.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos_no_using_namespace.h>

Expand Down Expand Up @@ -32,7 +33,7 @@ class FlashStartupTestThread : public RODOS::StaticThread<stackSize>
void run() override
{
DEBUG_PRINT("Flash start-up test ...");
RODOS::AT(RODOS::END_OF_TIME);
SuspendUntil(endOfTime);
flash::Initialize();
auto jedecId = flash::ReadJedecId();
if(jedecId.deviceId != flash::correctJedecId.deviceId
Expand All @@ -42,7 +43,7 @@ class FlashStartupTestThread : public RODOS::StaticThread<stackSize>
persistentVariables.template Store<"flashIsWorking">(false);
}
ResumeSpiStartupTestAndSupervisorThread();
RODOS::AT(RODOS::END_OF_TIME);
SuspendUntil(endOfTime);
}
} flashStartupTestThread;

Expand Down
5 changes: 3 additions & 2 deletions Sts1CobcSw/CobcSoftware/FramEpsStartupTestThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Sts1CobcSw/Periphery/Fram.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/ErrorDetectionAndCorrection.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos_no_using_namespace.h>

Expand Down Expand Up @@ -34,7 +35,7 @@ class FramEpsStartupTestThread : public RODOS::StaticThread<stackSize>
void run() override
{
DEBUG_PRINT("FRAM/EPS start-up test ...");
RODOS::AT(RODOS::END_OF_TIME);
SuspendUntil(endOfTime);
fram::Initialize();
auto deviceId = fram::ReadDeviceId();
if(deviceId != fram::correctDeviceId)
Expand All @@ -45,7 +46,7 @@ class FramEpsStartupTestThread : public RODOS::StaticThread<stackSize>
eps::Initialize();
(void)eps::Read();
ResumeSpiStartupTestAndSupervisorThread();
RODOS::AT(RODOS::END_OF_TIME);
SuspendUntil(endOfTime);
}
} framEpsStartupTestThread;

Expand Down
5 changes: 3 additions & 2 deletions Sts1CobcSw/CobcSoftware/RfStartupTestThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Sts1CobcSw/FramSections/PersistentVariables.hpp>
#include <Sts1CobcSw/Periphery/Rf.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos_no_using_namespace.h>

Expand All @@ -31,7 +32,7 @@ class RfStartupTestThread : public RODOS::StaticThread<stackSize>
void run() override
{
DEBUG_PRINT("RF start-up test ...");
RODOS::AT(RODOS::END_OF_TIME);
SuspendUntil(endOfTime);
rf::Initialize(rf::TxType::packet);
auto partNumber = rf::ReadPartNumber();
if(partNumber != rf::correctPartNumber)
Expand All @@ -40,7 +41,7 @@ class RfStartupTestThread : public RODOS::StaticThread<stackSize>
persistentVariables.template Store<"rfIsWorking">(false);
}
ResumeSpiStartupTestAndSupervisorThread();
RODOS::AT(RODOS::END_OF_TIME);
SuspendUntil(endOfTime);
}
} rfStartupTestThread;

Expand Down
24 changes: 11 additions & 13 deletions Sts1CobcSw/CobcSoftware/SpiStartupTestAndSupervisorThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Sts1CobcSw/Periphery/Rf.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/ErrorDetectionAndCorrection.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos_no_using_namespace.h>

Expand All @@ -20,9 +21,9 @@ namespace sts1cobcsw
{
constexpr auto stackSize = 100U;
// TODO: Measure how long the startup tests really take to determine the correct timeout
constexpr auto startupTestTimeout = 100 * RODOS::MILLISECONDS;
constexpr auto startupTestTimeout = 100 * milliseconds;
// TODO: Think about how often the supervision should run
constexpr auto supervisionPeriod = 1 * RODOS::SECONDS;
constexpr auto supervisionPeriod = 1 * seconds;


auto ExecuteStartupTest(void (*startupTestThreadResumeFuntion)()) -> bool;
Expand All @@ -45,9 +46,6 @@ class SpiStartupTestAndSupervisorThread : public RODOS::StaticThread<stackSize>

void run() override
{
using RODOS::AT;
using RODOS::NOW;

static constexpr auto errorMessage = " failed to complete in time\n";
static constexpr auto successMessage = " completed in time\n";

Expand Down Expand Up @@ -84,29 +82,29 @@ class SpiStartupTestAndSupervisorThread : public RODOS::StaticThread<stackSize>
DEBUG_PRINT("%s", errorMessage);
persistentVariables.template Store<"rfIsWorking">(false);
persistentVariables.template Increment<"nRfErrors">();
AT(NOW() + 2 * RODOS::SECONDS);
SuspendFor(2 * seconds);
RODOS::hwResetAndReboot();
}
else
{
DEBUG_PRINT("%s", successMessage);
}

TIME_LOOP(0, supervisionPeriod)
TIME_LOOP(0, value_of(supervisionPeriod))
{
auto timeoutHappened = false;
if(NOW() > framEpsSpi.TransferEnd())
if(CurrentRodosTime() > RodosTime(framEpsSpi.TransferEnd()))
{
DEBUG_PRINT("FRAM/EPS SPI timeout occurred\n");
timeoutHappened = true;
}
if(NOW() > flash::spi.TransferEnd())
if(CurrentRodosTime() > RodosTime(flash::spi.TransferEnd()))
{
DEBUG_PRINT("Flash SPI timeout occurred\n");
timeoutHappened = true;
persistentVariables.template Increment<"nFlashErrors">();
}
if(NOW() > rf::spi.TransferEnd())
if(CurrentRodosTime() > RodosTime(rf::spi.TransferEnd()))
{
DEBUG_PRINT("RF SPI timeout occurred\n");
timeoutHappened = true;
Expand All @@ -130,9 +128,9 @@ auto ResumeSpiStartupTestAndSupervisorThread() -> void

auto ExecuteStartupTest(void (*startupTestThreadResumeFuntion)()) -> bool
{
auto testEnd = RODOS::NOW() + startupTestTimeout;
auto testEnd = CurrentRodosTime() + startupTestTimeout;
startupTestThreadResumeFuntion();
RODOS::AT(testEnd);
return RODOS::NOW() <= testEnd;
SuspendUntil(testEnd);
return CurrentRodosTime() <= testEnd;
}
}
5 changes: 3 additions & 2 deletions Tests/HardwareTests/SpiSupervisor.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Sts1CobcSw/Periphery/Fram.hpp>
#include <Sts1CobcSw/Serial/Byte.hpp>
#include <Sts1CobcSw/Utility/Span.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos/support/support-libs/random.h>
#include <rodos_no_using_namespace.h>
Expand Down Expand Up @@ -49,7 +50,7 @@ class SpiSupervisorTest : public RODOS::StaticThread<>
PRINTF("Writing flash page ...\n");
flash::ProgramPage(flashAddress, Span(page));

RODOS::AT(2 * RODOS::SECONDS);
SuspendFor(2 * seconds);

PRINTF("\n");
RODOS::setRandSeed(static_cast<std::uint64_t>(RODOS::NOW()));
Expand All @@ -58,7 +59,7 @@ class SpiSupervisorTest : public RODOS::StaticThread<>

auto framTestData = std::array<Byte, 11 * 1024>{};
// Baud rate = 6 MHz, data size = 11 KiB -> transfer time ~ 15 ms
constexpr auto spiTimeout = 30 * RODOS::MILLISECONDS;
constexpr auto spiTimeout = 30 * milliseconds;
PRINTF("Writing %d B to FRAM ...\n", static_cast<int>(framTestData.size()));
fram::WriteTo(framAddress, Span(framTestData), spiTimeout);
}
Expand Down

0 comments on commit ee5999c

Please sign in to comment.