Skip to content

Commit

Permalink
Resolve dependencies and use Time.hpp in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilchmela committed Sep 16, 2024
1 parent deabd51 commit e6a9150
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Sts1CobcSw/FramSections/PersistentVariables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PersistentVariables
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 * ms;
static constexpr auto spiTimeout = 1 * Duration(RODOS::MILLISECONDS);

static RODOS::Semaphore semaphore;
};
Expand Down
5 changes: 2 additions & 3 deletions Sts1CobcSw/Hal/Spi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <Sts1CobcSw/Hal/IoNames.hpp>
#include <Sts1CobcSw/Hal/Spi.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos_no_using_namespace.h>

Expand All @@ -15,7 +14,7 @@ Spi::Spi(RODOS::SPI_IDX spiIndex,
RODOS::GPIO_PIN mosiPin)
: spi_(spiIndex, sckPin, misoPin, mosiPin, spiNssDummyPin)
{
transferEnd_.put(value_of(endOfTime));
transferEnd_.put(RODOS::END_OF_TIME);
}


Expand All @@ -24,7 +23,7 @@ auto Initialize(Spi * spi, std::uint32_t baudRate) -> void
// spi.init() only returns -1 if the SPI_IDX is out of range. Since we can check that statically
// we do not need to report that error at runtime.
spi->spi_.init(baudRate, /*slave=*/false, /*tiMode=*/false);
spi->transferEnd_.put(value_of(endOfTime));
spi->transferEnd_.put(RODOS::END_OF_TIME);
}


Expand Down
11 changes: 6 additions & 5 deletions Sts1CobcSw/Hal/Spi.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@


#include <Sts1CobcSw/Hal/Spi.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos_no_using_namespace.h>

#include "Sts1CobcSw/Utility/TimeTypes.hpp"


namespace sts1cobcsw::hal
{
Expand All @@ -15,9 +16,9 @@ auto WriteTo(Spi * spi, std::span<T const, extent> data, Duration timeout) -> vo
// spi.write() only returns -1 or the given buffer length. It only returns -1 if the SPI is not
// initialized, which we can check/ensure statically. Therefore, we do not need to check the
// return value at runtime.
spi->transferEnd_.put(value_of(CurrentRodosTime() + timeout));
spi->transferEnd_.put(RODOS::NOW() + value_of(timeout));
spi->spi_.write(data.data(), data.size_bytes());
spi->transferEnd_.put(value_of(endOfTime));
spi->transferEnd_.put(RODOS::END_OF_TIME);
}


Expand All @@ -27,9 +28,9 @@ auto ReadFrom(Spi * spi, std::span<T, extent> data, Duration timeout) -> void
// spi.read() only returns -1 or the given buffer length. It only returns -1 if the SPI is not
// initialized, which we can check/ensure statically. Therefore, we do not need to check the
// return value at runtime.
spi->transferEnd_.put(value_of(CurrentRodosTime() + timeout));
spi->transferEnd_.put(RODOS::NOW() + value_of(timeout));
spi->spi_.read(data.data(), data.size_bytes());
spi->transferEnd_.put(value_of(endOfTime));
spi->transferEnd_.put(RODOS::END_OF_TIME);
}


Expand Down
2 changes: 1 addition & 1 deletion Sts1CobcSw/Periphery/Fram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ EdacVariable<bool> framIsWorking(true);

// --- Private globals ---

constexpr auto spiTimeout = 1 * ms;
constexpr auto spiTimeout = 1 * Duration(RODOS::MILLISECONDS);
constexpr auto endianness = std::endian::big;

// Command opcodes according to section 4.1 in CY15B108QN-40SXI datasheet. I couldn't use an enum
Expand Down
3 changes: 2 additions & 1 deletion Sts1CobcSw/Periphery/Fram.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@


#include <Sts1CobcSw/Periphery/Fram.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include "Sts1CobcSw/Utility/TimeTypes.hpp"

namespace sts1cobcsw::fram
{
Expand Down
28 changes: 13 additions & 15 deletions Tests/HardwareTests/Flash.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Sts1CobcSw/Hal/GpioPin.hpp>
#include <Sts1CobcSw/Periphery/Flash.hpp>
#include <Sts1CobcSw/Serial/Byte.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos_no_using_namespace.h>

Expand Down Expand Up @@ -89,24 +90,22 @@ class FlashTest : public RODOS::StaticThread<stackSize>
std::fill(page.begin(), page.end(), 0x00_b);
PRINTF("Programming page at address 0x%08x:\n", static_cast<unsigned int>(pageAddress));
Print(page);
auto begin = RODOS::NOW();
auto begin = CurrentRodosTime();
flash::ProgramPage(pageAddress, page);
auto endPage = RODOS::NOW();
auto endPage = CurrentRodosTime();

auto const programPageTimeout = 10 * RODOS::MILLISECONDS;
auto const programPageTimeout = 10 * ms;
auto waitWhileBusyResult = flash::WaitWhileBusy(programPageTimeout);
auto end = RODOS::NOW();
PRINTF("ProgrammPage took %d us\n",
static_cast<int>((endPage - begin) / RODOS::MICROSECONDS));
auto end = CurrentRodosTime();
PRINTF("ProgrammPage took %d us\n", static_cast<int>((endPage - begin) / us));
if(waitWhileBusyResult.has_error())
{
PRINTF("WaitWhileBusy failed because it didn't finish in %d us\n",
static_cast<int>(programPageTimeout / RODOS::MICROSECONDS));
static_cast<int>(programPageTimeout / us));
}
else
{
PRINTF("WaitWhileBusy took %d us\n",
static_cast<int>((end - endPage) / RODOS::MICROSECONDS));
PRINTF("WaitWhileBusy took %d us\n", static_cast<int>((end - endPage) / us));
}

PRINTF("\n");
Expand All @@ -119,19 +118,18 @@ class FlashTest : public RODOS::StaticThread<stackSize>
static_cast<unsigned int>(pageAddress));
flash::EraseSector(pageAddress);

auto const eraseSectorTimeout = 500 * RODOS::MILLISECONDS;
begin = RODOS::NOW();
auto const eraseSectorTimeout = 500 * ms;
begin = CurrentRodosTime();
waitWhileBusyResult = flash::WaitWhileBusy(eraseSectorTimeout);
end = RODOS::NOW();
end = CurrentRodosTime();
if(waitWhileBusyResult.has_error())
{
PRINTF("WaitWhileBusy failed because it didn't finish in %d us\n",
static_cast<int>(eraseSectorTimeout / RODOS::MICROSECONDS));
static_cast<int>(eraseSectorTimeout / us));
}
else
{
PRINTF("WaitWhileBusy took %d us\n",
static_cast<int>((end - begin) / RODOS::MICROSECONDS));
PRINTF("WaitWhileBusy took %d us\n", static_cast<int>((end - begin) / us));
}

PRINTF("\n");
Expand Down
3 changes: 2 additions & 1 deletion Tests/HardwareTests/Fram.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 <strong_type/type.hpp>

Expand All @@ -30,7 +31,7 @@ auto testData = std::array<Byte, testDataSize>{};
auto readData = std::array<Byte, testDataSize>{};
// Baud rate = 6 MHz, largest data transfer = 11 KiB -> spiTimeout = 30 ms is enough for all
// transfers
constexpr auto spiTimeout = 30 * RODOS::MILLISECONDS;
constexpr auto spiTimeout = 30 * ms;


auto PrintDeviceId(fram::DeviceId const & deviceId) -> void;
Expand Down

0 comments on commit e6a9150

Please sign in to comment.