From 60b60fd2b72a41a669a97a2164ec657ad3a1336a Mon Sep 17 00:00:00 2001 From: kamilchmela Date: Thu, 25 Jul 2024 07:28:45 +0000 Subject: [PATCH 01/12] Add debug messages --- Sts1CobcSw/FlashStartupTestThread.cpp | 2 ++ Sts1CobcSw/FramEpsStartupTestThread.cpp | 2 ++ Sts1CobcSw/RfStartupTestThread.cpp | 2 ++ .../SpiStartupTestAndSupervisorThread.cpp | 20 +++++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/Sts1CobcSw/FlashStartupTestThread.cpp b/Sts1CobcSw/FlashStartupTestThread.cpp index bcebc774..3d25d6b5 100644 --- a/Sts1CobcSw/FlashStartupTestThread.cpp +++ b/Sts1CobcSw/FlashStartupTestThread.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -29,6 +30,7 @@ class FlashStartupTestThread : public RODOS::StaticThread void run() override { + DEBUG_PRINT("FlashStartupTest ..."); RODOS::AT(RODOS::END_OF_TIME); flash::Initialize(); auto jedecId = flash::ReadJedecId(); diff --git a/Sts1CobcSw/FramEpsStartupTestThread.cpp b/Sts1CobcSw/FramEpsStartupTestThread.cpp index a598fc7d..c0cd53f6 100644 --- a/Sts1CobcSw/FramEpsStartupTestThread.cpp +++ b/Sts1CobcSw/FramEpsStartupTestThread.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -32,6 +33,7 @@ class FramEpsStartupTestThread : public RODOS::StaticThread void run() override { + DEBUG_PRINT("FramEpsStartupTest ..."); RODOS::AT(RODOS::END_OF_TIME); fram::Initialize(); auto deviceId = fram::ReadDeviceId(); diff --git a/Sts1CobcSw/RfStartupTestThread.cpp b/Sts1CobcSw/RfStartupTestThread.cpp index 051c045a..35264dd5 100644 --- a/Sts1CobcSw/RfStartupTestThread.cpp +++ b/Sts1CobcSw/RfStartupTestThread.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -28,6 +29,7 @@ class RfStartupTestThread : public RODOS::StaticThread void run() override { + DEBUG_PRINT("RfStartupTest ..."); RODOS::AT(RODOS::END_OF_TIME); rf::Initialize(rf::TxType::packet); auto partNumber = rf::ReadPartNumber(); diff --git a/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp b/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp index 11110aa1..c51892ed 100644 --- a/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp +++ b/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -48,43 +49,62 @@ class SpiStartupTestAndSupervisorThread : public RODOS::StaticThread auto testWasSuccessful = ExecuteStartupTest(ResumeFramEpsStartupTestThread); if(not testWasSuccessful) { + DEBUG_PRINT("FramEpsStartupTest was not completed in time"); persistentstate::FramIsWorking(false); persistentstate::EpsIsWorking(false); } + else + { + DEBUG_PRINT("FramEpsStartupTest completed in time"); + } testWasSuccessful = ExecuteStartupTest(ResumeFlashStartupTestThread); if(not testWasSuccessful) { + DEBUG_PRINT("FlashStartupTest was not completed in time"); persistentstate::FlashIsWorking(false); persistentstate::FlashErrorCounter(persistentstate::FlashErrorCounter() + 1); } + else + { + DEBUG_PRINT("FlashStartupTest completed in time"); + } testWasSuccessful = ExecuteStartupTest(ResumeRfStartupTestThread); if(not testWasSuccessful) { + DEBUG_PRINT("RfStartupTest was not completed in time"); persistentstate::RfIsWorking(false); persistentstate::RfErrorCounter(persistentstate::RfErrorCounter() + 1); AT(NOW() + 2 * RODOS::SECONDS); RODOS::hwResetAndReboot(); } + else + { + DEBUG_PRINT("RfStartupTest completed in time"); + } TIME_LOOP(0, supervisionPeriod) { auto timeoutHappened = false; if(NOW() > framEpsSpi.TransferEnd()) { + DEBUG_PRINT("FramEps timeout occurred"); timeoutHappened = true; } if(NOW() > flash::spi.TransferEnd()) { + DEBUG_PRINT("Flash timeout occurred"); timeoutHappened = true; persistentstate::FlashErrorCounter(persistentstate::FlashErrorCounter() + 1); } if(NOW() > rf::spi.TransferEnd()) { + DEBUG_PRINT("Rf timeout occurred"); timeoutHappened = true; persistentstate::RfErrorCounter(persistentstate::RfErrorCounter() + 1); } if(timeoutHappened) { + DEBUG_PRINT("Hardware reset and reboot"); RODOS::hwResetAndReboot(); } } From a2fe724c93e87efb7e0f6d0f8999a67cb1ff4eb4 Mon Sep 17 00:00:00 2001 From: kamilchmela Date: Thu, 25 Jul 2024 15:50:00 +0000 Subject: [PATCH 02/12] Add PeripherySupervision.test.cpp --- .../PeripherySupervision.test.cpp | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Tests/HardwareTests/PeripherySupervision.test.cpp diff --git a/Tests/HardwareTests/PeripherySupervision.test.cpp b/Tests/HardwareTests/PeripherySupervision.test.cpp new file mode 100644 index 00000000..a71b3de7 --- /dev/null +++ b/Tests/HardwareTests/PeripherySupervision.test.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include + + +namespace sts1cobcsw +{ +auto delay = 1 * RODOS::SECONDS; + +std::uint32_t const flashAddress = 0x00'01'00'00U; + +RODOS::setRandSeed(static_cast(RODOS::NOW())); +constexpr std::uint32_t nAdressBits = 20U; +auto framAddress = fram::Address{RODOS::uint32Rand() % (1U << nAdressBits)}; + +constexpr std::size_t testDataSize = 11 * 1024; +auto framTestData = std::array{}; +// Baud rate = 6 MHz, largest data transfer = 11 KiB -> spiTimeout = 30 ms is enough for all +// transfers +constexpr auto spiTimeout = 30 * RODOS::MILLISECONDS; + +class PeripherySupervisionTest : public RODOS::StaticThread<> +{ +private: + PeripherySupervisionTest() : StaticThread("PeripherySupervisionTest") + { + } + + +public: + void init() override + { + } + + + void run() override + { + using RODOS::PRINTF; + + RODOS::AT(delay); + + PRINTF("Testing Flash writing\n") + auto page = flash::ReadPage(flashAddress); + flash::ProgramPage(flashAddress, Span(page)); + + PRINTF("Testing Fram writing and reading\n") + fram::WriteTo(framAddress, Span(framTestData), spiTimeout); + + PRINTF("Testing Rf writing\n") + rf::SendCommand(Span(page)); + } + +} PeripherySupervisionTest; +} \ No newline at end of file From a369782056cd5e5c7c233d540a78a1071a28583c Mon Sep 17 00:00:00 2001 From: kamilchmela Date: Thu, 25 Jul 2024 15:51:12 +0000 Subject: [PATCH 03/12] Change CMakeLists.txt --- Tests/HardwareTests/CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Tests/HardwareTests/CMakeLists.txt b/Tests/HardwareTests/CMakeLists.txt index 390cf176..a7b52fe1 100644 --- a/Tests/HardwareTests/CMakeLists.txt +++ b/Tests/HardwareTests/CMakeLists.txt @@ -82,6 +82,21 @@ target_link_libraries( ) add_watchdog_version_of(MaxPower) +add_program(PeripherySupervision PeripherySupervision.test.cpp) +target_sources( + Sts1CobcSwTests_PeripherySupervision + PRIVATE ${CMAKE_SOURCE_DIR}/Sts1CobcSw/FlashStartupTestThread.cpp + ${CMAKE_SOURCE_DIR}/Sts1CobcSw/FramEpsStartupTestThread.cpp + ${CMAKE_SOURCE_DIR}/Sts1CobcSw/RfStartupTestThread.cpp + ${CMAKE_SOURCE_DIR}/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp +) +target_link_libraries( + Sts1CobcSwTests_PeripherySupervision + PRIVATE rodos::rodos Sts1CobcSw_Periphery Sts1CobcSw_Utility + Sts1CobcSwTests_RfLatchupDisablePin +) +add_watchdog_version_of(PeripherySupervision) + add_program(Gpio Gpio.test.cpp) target_link_libraries( Sts1CobcSwTests_Gpio PRIVATE rodos::rodos Sts1CobcSw_Hal Sts1CobcSwTests_RfLatchupDisablePin From dd08818a7e96d539b799d8bd68e975ad066f52f8 Mon Sep 17 00:00:00 2001 From: kamilchmela Date: Thu, 25 Jul 2024 16:28:39 +0000 Subject: [PATCH 04/12] Fix errors --- .../PeripherySupervision.test.cpp | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Tests/HardwareTests/PeripherySupervision.test.cpp b/Tests/HardwareTests/PeripherySupervision.test.cpp index a71b3de7..83333737 100644 --- a/Tests/HardwareTests/PeripherySupervision.test.cpp +++ b/Tests/HardwareTests/PeripherySupervision.test.cpp @@ -3,34 +3,25 @@ #include #include +#include #include namespace sts1cobcsw { -auto delay = 1 * RODOS::SECONDS; - -std::uint32_t const flashAddress = 0x00'01'00'00U; -RODOS::setRandSeed(static_cast(RODOS::NOW())); -constexpr std::uint32_t nAdressBits = 20U; -auto framAddress = fram::Address{RODOS::uint32Rand() % (1U << nAdressBits)}; -constexpr std::size_t testDataSize = 11 * 1024; -auto framTestData = std::array{}; -// Baud rate = 6 MHz, largest data transfer = 11 KiB -> spiTimeout = 30 ms is enough for all -// transfers -constexpr auto spiTimeout = 30 * RODOS::MILLISECONDS; +auto delay = 1 * RODOS::SECONDS; class PeripherySupervisionTest : public RODOS::StaticThread<> { -private: +public: PeripherySupervisionTest() : StaticThread("PeripherySupervisionTest") { } -public: +private: void init() override { } @@ -40,18 +31,27 @@ class PeripherySupervisionTest : public RODOS::StaticThread<> { using RODOS::PRINTF; + std::uint32_t const flashAddress = 0x00'01'00'00U; + + RODOS::setRandSeed(static_cast(RODOS::NOW())); + constexpr std::uint32_t nAdressBits = 20U; + auto framAddress = fram::Address{RODOS::uint32Rand() % (1U << nAdressBits)}; + + constexpr std::size_t testDataSize = 11 * 1024; + auto framTestData = std::array{}; + // Baud rate = 6 MHz, largest data transfer = 11 KiB -> spiTimeout = 30 ms is enough for all + // transfers + constexpr auto spiTimeout = 30 * RODOS::MILLISECONDS; + RODOS::AT(delay); - PRINTF("Testing Flash writing\n") + PRINTF("Testing Flash writing\n"); auto page = flash::ReadPage(flashAddress); flash::ProgramPage(flashAddress, Span(page)); - PRINTF("Testing Fram writing and reading\n") + PRINTF("Testing Fram writing and reading\n"); fram::WriteTo(framAddress, Span(framTestData), spiTimeout); - - PRINTF("Testing Rf writing\n") - rf::SendCommand(Span(page)); } -} PeripherySupervisionTest; +} peripherySupervisionTest; } \ No newline at end of file From 346358271042881b5cabe917e82c7798b502277a Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Sat, 27 Jul 2024 10:03:11 +0000 Subject: [PATCH 05/12] Refactor debug messages of SPI supervisor and test threads - Use proper English grammar and spelling - Add missing line breaks --- Sts1CobcSw/FlashStartupTestThread.cpp | 3 ++- Sts1CobcSw/FramEpsStartupTestThread.cpp | 3 ++- Sts1CobcSw/RfStartupTestThread.cpp | 3 ++- .../SpiStartupTestAndSupervisorThread.cpp | 27 ++++++++++++------- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Sts1CobcSw/FlashStartupTestThread.cpp b/Sts1CobcSw/FlashStartupTestThread.cpp index 3d25d6b5..e3f7044c 100644 --- a/Sts1CobcSw/FlashStartupTestThread.cpp +++ b/Sts1CobcSw/FlashStartupTestThread.cpp @@ -30,13 +30,14 @@ class FlashStartupTestThread : public RODOS::StaticThread void run() override { - DEBUG_PRINT("FlashStartupTest ..."); + DEBUG_PRINT("Flash start-up test ..."); RODOS::AT(RODOS::END_OF_TIME); flash::Initialize(); auto jedecId = flash::ReadJedecId(); if(jedecId.deviceId != flash::correctJedecId.deviceId || jedecId.manufacturerId != flash::correctJedecId.manufacturerId) { + DEBUG_PRINT(" failed to read correct flash JEDEC ID"); persistentstate::FlashIsWorking(false); } ResumeSpiStartupTestAndSupervisorThread(); diff --git a/Sts1CobcSw/FramEpsStartupTestThread.cpp b/Sts1CobcSw/FramEpsStartupTestThread.cpp index c0cd53f6..832ece86 100644 --- a/Sts1CobcSw/FramEpsStartupTestThread.cpp +++ b/Sts1CobcSw/FramEpsStartupTestThread.cpp @@ -33,12 +33,13 @@ class FramEpsStartupTestThread : public RODOS::StaticThread void run() override { - DEBUG_PRINT("FramEpsStartupTest ..."); + DEBUG_PRINT("FRAM/EPS start-up test ..."); RODOS::AT(RODOS::END_OF_TIME); fram::Initialize(); auto deviceId = fram::ReadDeviceId(); if(deviceId != fram::correctDeviceId) { + DEBUG_PRINT(" failed to read correct FRAM device ID"); persistentstate::FramIsWorking(false); } eps::Initialize(); diff --git a/Sts1CobcSw/RfStartupTestThread.cpp b/Sts1CobcSw/RfStartupTestThread.cpp index 35264dd5..4fecbf74 100644 --- a/Sts1CobcSw/RfStartupTestThread.cpp +++ b/Sts1CobcSw/RfStartupTestThread.cpp @@ -29,12 +29,13 @@ class RfStartupTestThread : public RODOS::StaticThread void run() override { - DEBUG_PRINT("RfStartupTest ..."); + DEBUG_PRINT("RF start-up test ..."); RODOS::AT(RODOS::END_OF_TIME); rf::Initialize(rf::TxType::packet); auto partNumber = rf::ReadPartNumber(); if(partNumber != rf::correctPartNumber) { + DEBUG_PRINT(" failed to read correct RF part number"); persistentstate::RfIsWorking(false); } ResumeSpiStartupTestAndSupervisorThread(); diff --git a/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp b/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp index c51892ed..faa129d2 100644 --- a/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp +++ b/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp @@ -45,33 +45,40 @@ class SpiStartupTestAndSupervisorThread : public RODOS::StaticThread using RODOS::AT; using RODOS::NOW; - // TODO: Test if this works + static constexpr auto errorMessage = " failed to complete in time\n"; + static constexpr auto successMessage = " completed in time\n"; + auto testWasSuccessful = ExecuteStartupTest(ResumeFramEpsStartupTestThread); + DEBUG_PRINT(persistentstate::FramIsWorking() ? "\n" : " and"); if(not testWasSuccessful) { - DEBUG_PRINT("FramEpsStartupTest was not completed in time"); + DEBUG_PRINT("%s", errorMessage); persistentstate::FramIsWorking(false); persistentstate::EpsIsWorking(false); } else { - DEBUG_PRINT("FramEpsStartupTest completed in time"); + DEBUG_PRINT("%s", successMessage); } + testWasSuccessful = ExecuteStartupTest(ResumeFlashStartupTestThread); + DEBUG_PRINT(persistentstate::FlashIsWorking() ? "\n" : " and"); if(not testWasSuccessful) { - DEBUG_PRINT("FlashStartupTest was not completed in time"); + DEBUG_PRINT("%s", errorMessage); persistentstate::FlashIsWorking(false); persistentstate::FlashErrorCounter(persistentstate::FlashErrorCounter() + 1); } else { - DEBUG_PRINT("FlashStartupTest completed in time"); + DEBUG_PRINT("%s", successMessage); } + testWasSuccessful = ExecuteStartupTest(ResumeRfStartupTestThread); + DEBUG_PRINT(persistentstate::RfIsWorking() ? "\n" : " and"); if(not testWasSuccessful) { - DEBUG_PRINT("RfStartupTest was not completed in time"); + DEBUG_PRINT("%s", errorMessage); persistentstate::RfIsWorking(false); persistentstate::RfErrorCounter(persistentstate::RfErrorCounter() + 1); AT(NOW() + 2 * RODOS::SECONDS); @@ -79,7 +86,7 @@ class SpiStartupTestAndSupervisorThread : public RODOS::StaticThread } else { - DEBUG_PRINT("RfStartupTest completed in time"); + DEBUG_PRINT("%s", successMessage); } TIME_LOOP(0, supervisionPeriod) @@ -87,18 +94,18 @@ class SpiStartupTestAndSupervisorThread : public RODOS::StaticThread auto timeoutHappened = false; if(NOW() > framEpsSpi.TransferEnd()) { - DEBUG_PRINT("FramEps timeout occurred"); + DEBUG_PRINT("FRAM/EPS SPI timeout occurred\n"); timeoutHappened = true; } if(NOW() > flash::spi.TransferEnd()) { - DEBUG_PRINT("Flash timeout occurred"); + DEBUG_PRINT("Flash SPI timeout occurred\n"); timeoutHappened = true; persistentstate::FlashErrorCounter(persistentstate::FlashErrorCounter() + 1); } if(NOW() > rf::spi.TransferEnd()) { - DEBUG_PRINT("Rf timeout occurred"); + DEBUG_PRINT("RF timeout occurred\n"); timeoutHappened = true; persistentstate::RfErrorCounter(persistentstate::RfErrorCounter() + 1); } From a148d64143e96657ec89653ab99ba9e73b7c183a Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Sat, 27 Jul 2024 10:18:44 +0000 Subject: [PATCH 06/12] Rename PeripherySupervision.test.cpp to SpiSupervisor.test.cpp Rename PeripherySupervision to SpiSupervisor, part 2 --- Tests/HardwareTests/CMakeLists.txt | 8 ++++---- ...ripherySupervision.test.cpp => SpiSupervisor.test.cpp} | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) rename Tests/HardwareTests/{PeripherySupervision.test.cpp => SpiSupervisor.test.cpp} (88%) diff --git a/Tests/HardwareTests/CMakeLists.txt b/Tests/HardwareTests/CMakeLists.txt index a7b52fe1..a001d4e1 100644 --- a/Tests/HardwareTests/CMakeLists.txt +++ b/Tests/HardwareTests/CMakeLists.txt @@ -82,20 +82,20 @@ target_link_libraries( ) add_watchdog_version_of(MaxPower) -add_program(PeripherySupervision PeripherySupervision.test.cpp) +add_program(SpiSupervisor SpiSupervisor.test.cpp) target_sources( - Sts1CobcSwTests_PeripherySupervision + Sts1CobcSwTests_SpiSupervisor PRIVATE ${CMAKE_SOURCE_DIR}/Sts1CobcSw/FlashStartupTestThread.cpp ${CMAKE_SOURCE_DIR}/Sts1CobcSw/FramEpsStartupTestThread.cpp ${CMAKE_SOURCE_DIR}/Sts1CobcSw/RfStartupTestThread.cpp ${CMAKE_SOURCE_DIR}/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp ) target_link_libraries( - Sts1CobcSwTests_PeripherySupervision + Sts1CobcSwTests_SpiSupervisor PRIVATE rodos::rodos Sts1CobcSw_Periphery Sts1CobcSw_Utility Sts1CobcSwTests_RfLatchupDisablePin ) -add_watchdog_version_of(PeripherySupervision) +add_watchdog_version_of(SpiSupervisor) add_program(Gpio Gpio.test.cpp) target_link_libraries( diff --git a/Tests/HardwareTests/PeripherySupervision.test.cpp b/Tests/HardwareTests/SpiSupervisor.test.cpp similarity index 88% rename from Tests/HardwareTests/PeripherySupervision.test.cpp rename to Tests/HardwareTests/SpiSupervisor.test.cpp index 83333737..f5b59d3b 100644 --- a/Tests/HardwareTests/PeripherySupervision.test.cpp +++ b/Tests/HardwareTests/SpiSupervisor.test.cpp @@ -13,10 +13,10 @@ namespace sts1cobcsw auto delay = 1 * RODOS::SECONDS; -class PeripherySupervisionTest : public RODOS::StaticThread<> +class SpiSupervisorTest : public RODOS::StaticThread<> { public: - PeripherySupervisionTest() : StaticThread("PeripherySupervisionTest") + SpiSupervisorTest() : StaticThread("SpiSupervisorTest") { } @@ -53,5 +53,5 @@ class PeripherySupervisionTest : public RODOS::StaticThread<> fram::WriteTo(framAddress, Span(framTestData), spiTimeout); } -} peripherySupervisionTest; -} \ No newline at end of file +} spiSupervisorTest; +} From 56323008504415647c167ec1d8564b7ff29c0be4 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Sat, 27 Jul 2024 10:19:40 +0000 Subject: [PATCH 07/12] Add rfLatchupDisableGpioPin to SpiSupervisor.test.cpp --- Tests/HardwareTests/SpiSupervisor.test.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tests/HardwareTests/SpiSupervisor.test.cpp b/Tests/HardwareTests/SpiSupervisor.test.cpp index f5b59d3b..d667ad14 100644 --- a/Tests/HardwareTests/SpiSupervisor.test.cpp +++ b/Tests/HardwareTests/SpiSupervisor.test.cpp @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -24,6 +26,9 @@ class SpiSupervisorTest : public RODOS::StaticThread<> private: void init() override { +#if HW_VERSION >= 27 + rfLatchupDisableGpioPin.Direction(hal::PinDirection::out); +#endif } @@ -31,6 +36,10 @@ class SpiSupervisorTest : public RODOS::StaticThread<> { using RODOS::PRINTF; +#if HW_VERSION >= 27 + rfLatchupDisableGpioPin.Reset(); +#endif + std::uint32_t const flashAddress = 0x00'01'00'00U; RODOS::setRandSeed(static_cast(RODOS::NOW())); From bf5fc6079065f9e94ff16196d96be80492f1aeaf Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Sat, 27 Jul 2024 10:23:25 +0000 Subject: [PATCH 08/12] Add missing dependency of SPI supervisor test --- Tests/HardwareTests/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Tests/HardwareTests/CMakeLists.txt b/Tests/HardwareTests/CMakeLists.txt index a001d4e1..fb6646c9 100644 --- a/Tests/HardwareTests/CMakeLists.txt +++ b/Tests/HardwareTests/CMakeLists.txt @@ -91,9 +91,8 @@ target_sources( ${CMAKE_SOURCE_DIR}/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp ) target_link_libraries( - Sts1CobcSwTests_SpiSupervisor - PRIVATE rodos::rodos Sts1CobcSw_Periphery Sts1CobcSw_Utility - Sts1CobcSwTests_RfLatchupDisablePin + Sts1CobcSwTests_SpiSupervisor PRIVATE rodos::rodos Sts1CobcSw_Periphery Sts1CobcSw_Utility + Sts1CobcSw_Hal Sts1CobcSwTests_RfLatchupDisablePin ) add_watchdog_version_of(SpiSupervisor) From aad5d7720dea93920aebf1c7fc58d12861e0801d Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Sat, 27 Jul 2024 10:23:44 +0000 Subject: [PATCH 09/12] Fix using wrong option name to disable ccache in CI --- CMakePresets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index e91c11f3..8fa2e80e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -95,7 +95,7 @@ ], "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", - "ENABLE_CCACHE": "OFF" + "USE_CCACHE": "OFF" } }, { From e50fff6b5854cf3c790113df07603355fe1639d2 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Sat, 27 Jul 2024 10:41:36 +0000 Subject: [PATCH 10/12] Refactor SpiSupervisor.test.cpp --- Tests/HardwareTests/SpiSupervisor.test.cpp | 33 ++++++++++------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/Tests/HardwareTests/SpiSupervisor.test.cpp b/Tests/HardwareTests/SpiSupervisor.test.cpp index d667ad14..de0a6374 100644 --- a/Tests/HardwareTests/SpiSupervisor.test.cpp +++ b/Tests/HardwareTests/SpiSupervisor.test.cpp @@ -11,10 +11,6 @@ namespace sts1cobcsw { - - -auto delay = 1 * RODOS::SECONDS; - class SpiSupervisorTest : public RODOS::StaticThread<> { public: @@ -40,25 +36,26 @@ class SpiSupervisorTest : public RODOS::StaticThread<> rfLatchupDisableGpioPin.Reset(); #endif - std::uint32_t const flashAddress = 0x00'01'00'00U; + PRINTF("\nSPI supervisor test\n\n"); + + PRINTF("\n"); + std::uint32_t const flashAddress = 0x00'01'10'00U; + PRINTF("Reading flash page ...\n"); + auto page = flash::ReadPage(flashAddress); + PRINTF("Writing flash page ...\n"); + flash::ProgramPage(flashAddress, Span(page)); + + RODOS::AT(2 * RODOS::SECONDS); + PRINTF("\n"); RODOS::setRandSeed(static_cast(RODOS::NOW())); constexpr std::uint32_t nAdressBits = 20U; - auto framAddress = fram::Address{RODOS::uint32Rand() % (1U << nAdressBits)}; + auto framAddress = fram::Address(RODOS::uint32Rand() % (1U << nAdressBits)); - constexpr std::size_t testDataSize = 11 * 1024; - auto framTestData = std::array{}; - // Baud rate = 6 MHz, largest data transfer = 11 KiB -> spiTimeout = 30 ms is enough for all - // transfers + auto framTestData = std::array{}; + // Baud rate = 6 MHz, data size = 11 KiB -> transfer time ~ 15 ms constexpr auto spiTimeout = 30 * RODOS::MILLISECONDS; - - RODOS::AT(delay); - - PRINTF("Testing Flash writing\n"); - auto page = flash::ReadPage(flashAddress); - flash::ProgramPage(flashAddress, Span(page)); - - PRINTF("Testing Fram writing and reading\n"); + PRINTF("Writing %d B to FRAM ...\n", static_cast(framTestData.size())); fram::WriteTo(framAddress, Span(framTestData), spiTimeout); } From 994e1bb5b7530b022442ae7828ecf092be05d855 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Sat, 27 Jul 2024 10:46:18 +0000 Subject: [PATCH 11/12] Fix includes in SpiSupervisor.test.cpp --- Tests/HardwareTests/SpiSupervisor.test.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/HardwareTests/SpiSupervisor.test.cpp b/Tests/HardwareTests/SpiSupervisor.test.cpp index de0a6374..f6471476 100644 --- a/Tests/HardwareTests/SpiSupervisor.test.cpp +++ b/Tests/HardwareTests/SpiSupervisor.test.cpp @@ -1,13 +1,17 @@ #include +#include #include #include -#include +#include #include #include #include +#include +#include + namespace sts1cobcsw { From 9c45efc8a32380f589f7ddcda867c0f312b8a027 Mon Sep 17 00:00:00 2001 From: kamilchmela Date: Sun, 18 Aug 2024 12:27:38 +0000 Subject: [PATCH 12/12] Add FlashMoc --- Sts1CobcSw/Periphery/CMakeLists.txt | 1 + Sts1CobcSw/Periphery/FlashMock.cpp | 188 ++++++++++++++++++++++++++++ Sts1CobcSw/Periphery/FlashMock.hpp | 78 ++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 Sts1CobcSw/Periphery/FlashMock.cpp create mode 100644 Sts1CobcSw/Periphery/FlashMock.hpp diff --git a/Sts1CobcSw/Periphery/CMakeLists.txt b/Sts1CobcSw/Periphery/CMakeLists.txt index deb48f95..e228d648 100644 --- a/Sts1CobcSw/Periphery/CMakeLists.txt +++ b/Sts1CobcSw/Periphery/CMakeLists.txt @@ -9,4 +9,5 @@ if(CMAKE_SYSTEM_NAME STREQUAL Generic) target_link_libraries(Sts1CobcSw_Periphery PUBLIC Sts1CobcSw_Hal) else() target_sources(Sts1CobcSw_Periphery PRIVATE FramMock.cpp) + target_sources(Sts1CobcSw_Periphery PRIVATE FlashMock.cpp) endif() diff --git a/Sts1CobcSw/Periphery/FlashMock.cpp b/Sts1CobcSw/Periphery/FlashMock.cpp new file mode 100644 index 00000000..55b6caef --- /dev/null +++ b/Sts1CobcSw/Periphery/FlashMock.cpp @@ -0,0 +1,188 @@ +#include + +#include + +#include + + +namespace sts1cobcsw::flash +{ +std::int64_t initializeDelay = 0; + + +auto doInitialize = empty::DoInitialize; +auto doReadJedecId = empty::DoReadJedecId; +auto doReadStatusRegister = empty::DoReadStatusRegister; + +auto doReadPage = empty::DoReadPage; +auto doProgramPage = empty::DoProgramPage; +auto doEraseSector = empty::DoEraseSector; +auto doWaitWhileBusy = empty::DoWaitWhileBusy; +auto doActualBaudRate = empty::DoActualBaudRate; + + +// --- Mocked functions --- + +auto Initialize() -> void +{ + return doInitialize(); +} + + +auto ReadJedecId() -> JedecId +{ + return doReadJedecId(); +} + + +auto ReadStatusRegister(std::int8_t registerNo) -> Byte +{ + return doReadStatusRegister(registerNo); +} + + +auto ReadPage(std::uint32_t address) -> Page +{ + return doReadPage(address); +} + + +auto ProgramPage(std::uint32_t address, PageSpan data) -> void +{ + return doProgramPage(address, data); +} + + +auto EraseSector(std::uint32_t address) -> void +{ + return doEraseSector(address); +} + + +auto WaitWhileBusy(std::int64_t timeout) -> Result +{ + return doWaitWhileBusy(timeout); +} + + +auto ActualBaudRate() -> std::int32_t +{ + return doActualBaudRate(); +} + + +// --- Set functions --- + +auto SetDoInitialize(void (*doInitializeFunction)()) -> void +{ + doInitialize = doInitializeFunction; +} + + +auto SetDoReadJedecId(JedecId (*doReadJedecIdFunction)()) -> void +{ + doReadJedecId = doReadJedecIdFunction; +} + + +auto SetDoReadStatusRegister(Byte (*doReadStatusRegisterFunction)(std::int8_t registerNo)) -> void +{ + doReadStatusRegister = doReadStatusRegisterFunction; +} + + +auto SetDoReadPage(Page (*doReadPageFunction)(std::uint32_t address)) -> void +{ + doReadPage = doReadPageFunction; +} + + +auto SetDoProgramPage(void (*doProgramPageFunction)(std::uint32_t address, PageSpan data)) -> void +{ + doProgramPage = doProgramPageFunction; +} + + +auto SetDoEraseSector(void (*doEraseSectorFunction)(std::uint32_t address)) -> void +{ + doEraseSector = doEraseSectorFunction; +} + + +auto SetDoWaitWhileBusyFunction(Result (*doWaitWhileBusy)(std::int64_t timeout)) -> void +{ + doWaitWhileBusy = doWaitWhileBusyFunction; +} + + +auto SetDoActualBaudRate(std::int32_t (*doActualBaudRateFunction)()) -> void +{ + doActualBaudRate = doActualBaudRateFunction; +} + + +// --- Predefined do functions --- + +namespace empty +{ +auto SetAllDoFunctions() -> void +{ + SetDoInitialize(DoInitialize); + SetDoReadJedecId(DoReadJedecId); + SetDoReadStatusRegister(DoReadStatusRegister); + + SetDoReadPage(DoReadPage); + SetDoProgramPage(DoProgramPage); + SetDoEraseSector(DoEraseSector); + SetDoWaitWhileBusy(DoWaitWhileBusy); + SetDoActualBaudRate(DoActualBaudRate); +} + + +auto DoInitialize() -> void +{ + RODOS::AT(initializeDelay); +} + + +auto DoReadJedecId() -> JedecId +{ + return JedecId; +} + + +auto DoReadStatusRegister(std::int8_t registerNo) -> Byte +{ + return 0x0000; +} + + +auto DoReadPage(std::uint32_t address) -> Page +{ + return 0; +} + + +auto DoProgramPage(std::uint32_t address, PageSpan data) -> void +{ +} + + +auto DoEraseSector(std::uint32_t address) -> void +{ +} + + +auto DoWaitWhileBusy(std::int64_t timeout) -> Result +{ + return outcome_v2::success(); +} + + +auto DoActualBaudRate() -> std::int32_t +{ + return 0; +} + +} +} \ No newline at end of file diff --git a/Sts1CobcSw/Periphery/FlashMock.hpp b/Sts1CobcSw/Periphery/FlashMock.hpp new file mode 100644 index 00000000..d8fbb505 --- /dev/null +++ b/Sts1CobcSw/Periphery/FlashMock.hpp @@ -0,0 +1,78 @@ +//! @file +//! @brief Driver for the flash memory W25Q01JV. + +#pragma once + + +#include +#include +#include + +#include +#include +#include +#include + + +namespace sts1cobcsw::flash +{ +/*struct JedecId +{ + std::uint8_t manufacturerId = 0; + std::uint16_t deviceId = 0; +}; + + +enum class ErrorCode +{ + timeout = 1 +}; + + +template +using Result = outcome_v2::experimental::status_result; + + +[[maybe_unused]] constexpr std::size_t pageSize = 256; // bytes +[[maybe_unused]] constexpr std::size_t sectorSize = 4 * 1024; // bytes +[[maybe_unused]] constexpr std::size_t smallBlockSize = 32 * 1024; // bytes +[[maybe_unused]] constexpr std::size_t largeBlockSize = 64 * 1024; // bytes +[[maybe_unused]] constexpr std::size_t flashSize = 128 * 1024 * 1024; // bytes +[[maybe_unused]] constexpr std::size_t nSectors = flashSize / sectorSize; +[[maybe_unused]] constexpr std::size_t nSmallBlocks = flashSize / smallBlockSize; +[[maybe_unused]] constexpr std::size_t nLargeBlocks = flashSize / largeBlockSize; + + +using Page = std::array; +using PageSpan = std::span; + + +inline constexpr auto correctJedecId = JedecId{.manufacturerId = 0xEF, .deviceId = 0x4021}; + +extern hal::Spi spi;*/ + +auto SetDoInitialize(void (*doInitializeFunction)()) -> void; +auto SetDoReadJedecId(JedecId (*doReadJedecIdFunction)()) -> void; +auto SetDoReadStatusRegister(Byte (*doReadStatusRegisterFunction)(std::int8_t registerNo)) -> void; + +auto SetDoReadPage(Page (*doReadPageFunction)(std::uint32_t address)) -> void; +auto SetDoProgramPage(void (*doProgramPageFunction)(std::uint32_t address, PageSpan data)) -> void; +auto SetDoEraseSector(void (*doEraseSectorFunction)(std::uint32_t address)) -> void; +auto SetDoWaitWhileBusyFunction(Result (*doWaitWhileBusy)(std::int64_t timeout)) -> void; +auto SetDoActualBaudRate(std::int32_t (*doActualBaudRateFunction)()) -> void; +} + +namespace empty +{ +auto SetAllDoFunctions() -> void; + +auto DoInitialize() -> void; +auto DoReadJedecId() -> JedecId; +auto DoReadStatusRegister(std::int8_t registerNo) -> Byte; + +auto DoReadPage(std::uint32_t address) -> Page; +auto DoProgramPage(std::uint32_t address, PageSpan data) -> void; +auto DoEraseSector(std::uint32_t address) -> void; +auto DoWaitWhileBusy(std::int64_t timeout) -> Result; +auto DoActualBaudRate() -> std::int32_t; +} \ No newline at end of file