Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test error handling for SPI code #315

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c20e46f
Add debug messages
kamilchmela Sep 16, 2024
ff55031
Add PeripherySupervision.test.cpp
kamilchmela Sep 16, 2024
7adb357
Change CMakeLists.txt
kamilchmela Sep 16, 2024
00fa557
Fix errors
kamilchmela Sep 16, 2024
0798751
Refactor debug messages of SPI supervisor and test threads
PatrickKa Sep 16, 2024
a82ad0b
Rename PeripherySupervision.test.cpp to SpiSupervisor.test.cpp
PatrickKa Sep 16, 2024
0035f1f
Add rfLatchupDisableGpioPin to SpiSupervisor.test.cpp
PatrickKa Sep 16, 2024
e261ec7
Add missing dependency of SPI supervisor test
PatrickKa Sep 16, 2024
f53084f
Refactor SpiSupervisor.test.cpp
PatrickKa Sep 16, 2024
2fbbfee
Fix includes in SpiSupervisor.test.cpp
PatrickKa Sep 16, 2024
d4d5cf5
Add FlashMock.cpp/hpp
kamilchmela Sep 16, 2024
342a30f
Fix CmakeLists in HardwareTests
kamilchmela Sep 16, 2024
b29c4bf
Define JedecID
kamilchmela Sep 16, 2024
0466678
Undo quotations
kamilchmela Sep 16, 2024
7d63f86
Fix namespaces
kamilchmela Sep 16, 2024
15544cb
Fix format
kamilchmela Sep 16, 2024
7dde158
Fix some small things
kamilchmela Sep 16, 2024
4c4eeae
Remove delay
kamilchmela Sep 16, 2024
c3b3420
Resolve review requests
kamilchmela Sep 16, 2024
4863ed5
Fix maybe_unused bug
kamilchmela Sep 16, 2024
044db85
Add `StartupTestStubs.cpp`
kamilchmela Sep 16, 2024
bd65d5d
Use new time types and functions
PatrickKa Sep 22, 2024
e70d4eb
Use PImpl idiom for `Spi` class
kamilchmela Sep 20, 2024
595919f
Fix includes
PatrickKa Sep 21, 2024
a19eed6
Refactor time functionality into Rodos and real time parts
PatrickKa Sep 22, 2024
8675043
Add `TimeTypes.[hi]pp` again
PatrickKa Sep 22, 2024
54f7c8a
Fix includes
PatrickKa Sep 22, 2024
199a3f9
Add `SpiMock.cpp` and `SpiMock.hpp`
kamilchmela Sep 29, 2024
29c1240
Fix CMake code
PatrickKa Sep 29, 2024
609d1ed
Correctly mock SPI
PatrickKa Sep 29, 2024
09d9d18
Set `IsWorking` wariables `true` in `StartupTestThread`(s)
kamilchmela Sep 29, 2024
51e57a4
Delete TODO comment
kamilchmela Sep 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(cmake/prelude.cmake)
project(
Sts1CobcSw
VERSION 0.1.0
DESCRIPTION "Software for the Communication and onboard computer of SpaceTeamSat1"
DESCRIPTION "Software for the communication and onboard computer of SpaceTeamSat1"
HOMEPAGE_URL "https://github.com/SpaceTeam/STS1_COBC_SW"
LANGUAGES CXX
)
Expand All @@ -30,16 +30,15 @@ add_library(Sts1CobcSw_Dummy STATIC)
add_library(Sts1CobcSw_Edu STATIC)
add_library(Sts1CobcSw_FileSystem STATIC)
add_library(Sts1CobcSw_FramSections INTERFACE)
add_library(Sts1CobcSw_Hal STATIC)
add_library(Sts1CobcSw_Outcome INTERFACE)
add_library(Sts1CobcSw_ProgramId INTERFACE)
add_library(Sts1CobcSw_Periphery STATIC)
add_library(Sts1CobcSw_Serial INTERFACE)
add_library(Sts1CobcSw_Utility STATIC)
add_program(HelloDummy)
# add_program(Heartbeat)

if(CMAKE_SYSTEM_NAME STREQUAL Generic)
add_library(Sts1CobcSw_Hal STATIC)
add_program(CobcSoftware)
endif()

Expand Down
8 changes: 1 addition & 7 deletions Sts1CobcSw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
if(CMAKE_SYSTEM_NAME STREQUAL Generic)
add_subdirectory(Hal)
endif()
add_subdirectory(Edu)
add_subdirectory(FileSystem)
add_subdirectory(FramSections)
add_subdirectory(Hal)
add_subdirectory(Outcome)
add_subdirectory(Periphery)
add_subdirectory(Serial)
Expand All @@ -15,7 +13,3 @@ target_link_libraries(Sts1CobcSw_Dummy PUBLIC etl::etl Sts1CobcSw_Utility)

target_sources(Sts1CobcSw_HelloDummy PRIVATE HelloDummy.cpp)
target_link_libraries(Sts1CobcSw_HelloDummy PRIVATE Sts1CobcSw_Dummy rodos::rodos)

# target_sources(Sts1CobcSw_Heartbeat PRIVATE EduHeartbeatThread.cpp TopicsAndSubscribers.cpp)
# target_link_libraries(Sts1CobcSw_Heartbeat PRIVATE etl::etl rodos::rodos Sts1CobcSw_Hal
# Sts1CobcSw_Utility Sts1CobcSw_Periphery)
2 changes: 1 addition & 1 deletion Sts1CobcSw/CobcSoftware/EduCommunicationErrorThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <Sts1CobcSw/FramSections/FramLayout.hpp>
#include <Sts1CobcSw/FramSections/PersistentVariables.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>
#include <Sts1CobcSw/Utility/RodosTime.hpp>

#include <strong_type/difference.hpp>

Expand Down
2 changes: 1 addition & 1 deletion Sts1CobcSw/CobcSoftware/EduHeartbeatThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <Sts1CobcSw/Hal/GpioPin.hpp>
#include <Sts1CobcSw/Hal/IoNames.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>
#include <Sts1CobcSw/Utility/RodosTime.hpp>
#include <Sts1CobcSw/Utility/TimeTypes.hpp>

#include <strong_type/affine_point.hpp>
Expand Down
2 changes: 1 addition & 1 deletion Sts1CobcSw/CobcSoftware/EduListenerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <Sts1CobcSw/Edu/ProgramStatusHistory.hpp>
#include <Sts1CobcSw/Edu/Types.hpp>
#include <Sts1CobcSw/Hal/IoNames.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>
#include <Sts1CobcSw/Utility/RodosTime.hpp>

#include <strong_type/difference.hpp>
#include <strong_type/type.hpp>
Expand Down
2 changes: 1 addition & 1 deletion Sts1CobcSw/CobcSoftware/EduPowerManagementThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <Sts1CobcSw/Hal/GpioPin.hpp>
#include <Sts1CobcSw/Hal/IoNames.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>
#include <Sts1CobcSw/Utility/RodosTime.hpp>
#include <Sts1CobcSw/Utility/TimeTypes.hpp>

#include <strong_type/difference.hpp>
Expand Down
3 changes: 2 additions & 1 deletion Sts1CobcSw/CobcSoftware/EduProgramQueueThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <Sts1CobcSw/Edu/Types.hpp>
#include <Sts1CobcSw/ProgramId/ProgramId.hpp> // IWYU pragma: keep
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>
#include <Sts1CobcSw/Utility/RealTime.hpp>
#include <Sts1CobcSw/Utility/RodosTime.hpp>
#include <Sts1CobcSw/Utility/TimeTypes.hpp>

#include <strong_type/affine_point.hpp>
Expand Down
12 changes: 10 additions & 2 deletions Sts1CobcSw/CobcSoftware/FlashStartupTestThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <Sts1CobcSw/FramSections/FramLayout.hpp>
#include <Sts1CobcSw/FramSections/PersistentVariables.hpp>
#include <Sts1CobcSw/Periphery/Flash.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/RodosTime.hpp>

#include <rodos_no_using_namespace.h>

Expand All @@ -30,16 +32,22 @@ class FlashStartupTestThread : public RODOS::StaticThread<stackSize>

void run() override
{
RODOS::AT(RODOS::END_OF_TIME);
DEBUG_PRINT("Flash start-up test ...");
SuspendUntil(endOfTime);
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");
persistentVariables.template Store<"flashIsWorking">(false);
}
else
{
persistentVariables.template Store<"flashIsWorking">(true);
}
ResumeSpiStartupTestAndSupervisorThread();
RODOS::AT(RODOS::END_OF_TIME);
SuspendUntil(endOfTime);
}
} flashStartupTestThread;

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

#include <rodos_no_using_namespace.h>

Expand Down Expand Up @@ -32,17 +34,24 @@ class FramEpsStartupTestThread : public RODOS::StaticThread<stackSize>

void run() override
{
RODOS::AT(RODOS::END_OF_TIME);
DEBUG_PRINT("FRAM/EPS start-up test ...");
SuspendUntil(endOfTime);
fram::Initialize();
auto deviceId = fram::ReadDeviceId();
if(deviceId != fram::correctDeviceId)
{
DEBUG_PRINT(" failed to read correct FRAM device ID");
fram::framIsWorking.Store(false);
}
else
{
fram::framIsWorking.Store(true);
}
eps::Initialize();
(void)eps::Read();
persistentVariables.template Store<"epsIsWorking">(true);
ResumeSpiStartupTestAndSupervisorThread();
RODOS::AT(RODOS::END_OF_TIME);
SuspendUntil(endOfTime);
}
} framEpsStartupTestThread;

Expand Down
12 changes: 10 additions & 2 deletions Sts1CobcSw/CobcSoftware/RfStartupTestThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <Sts1CobcSw/FramSections/FramLayout.hpp>
#include <Sts1CobcSw/FramSections/PersistentVariables.hpp>
#include <Sts1CobcSw/Periphery/Rf.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/RodosTime.hpp>

#include <rodos_no_using_namespace.h>

Expand All @@ -29,15 +31,21 @@ class RfStartupTestThread : public RODOS::StaticThread<stackSize>

void run() override
{
RODOS::AT(RODOS::END_OF_TIME);
DEBUG_PRINT("RF start-up test ...");
SuspendUntil(endOfTime);
rf::Initialize(rf::TxType::packet);
auto partNumber = rf::ReadPartNumber();
if(partNumber != rf::correctPartNumber)
{
DEBUG_PRINT(" failed to read correct RF part number");
persistentVariables.template Store<"rfIsWorking">(false);
}
else
{
persistentVariables.template Store<"rfIsWorking">(true);
}
ResumeSpiStartupTestAndSupervisorThread();
RODOS::AT(RODOS::END_OF_TIME);
SuspendUntil(endOfTime);
}
} rfStartupTestThread;

Expand Down
59 changes: 46 additions & 13 deletions Sts1CobcSw/CobcSoftware/SpiStartupTestAndSupervisorThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,28 @@
#include <Sts1CobcSw/Periphery/Fram.hpp>
#include <Sts1CobcSw/Periphery/FramEpsSpi.hpp>
#include <Sts1CobcSw/Periphery/Rf.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/ErrorDetectionAndCorrection.hpp>
#include <Sts1CobcSw/Utility/RodosTime.hpp>
#include <Sts1CobcSw/Utility/TimeTypes.hpp>

#include <strong_type/affine_point.hpp>
#include <strong_type/difference.hpp>
#include <strong_type/ordered.hpp>
#include <strong_type/type.hpp>

#include <rodos_no_using_namespace.h>

#include <compare>


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 * ms;
// TODO: Think about how often the supervision should run
constexpr auto supervisionPeriod = 1 * RODOS::SECONDS;
constexpr auto supervisionPeriod = 1 * s;


auto ExecuteStartupTest(void (*startupTestThreadResumeFuntion)()) -> bool;
Expand All @@ -44,50 +54,73 @@ 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";

// TODO: Test if this works
auto testWasSuccessful = ExecuteStartupTest(ResumeFramEpsStartupTestThread);
DEBUG_PRINT(fram::framIsWorking.Load() ? "\n" : " and");
if(not testWasSuccessful)
{
DEBUG_PRINT("%s", errorMessage);
fram::framIsWorking.Store(false);
persistentVariables.template Store<"epsIsWorking">(false);
}
else
{
DEBUG_PRINT("%s", successMessage);
}

testWasSuccessful = ExecuteStartupTest(ResumeFlashStartupTestThread);
DEBUG_PRINT(persistentVariables.template Load<"flashIsWorking">() ? "\n" : " and");
if(not testWasSuccessful)
{
DEBUG_PRINT("%s", errorMessage);
persistentVariables.template Store<"flashIsWorking">(false);
persistentVariables.template Increment<"nFlashErrors">();
}
else
{
DEBUG_PRINT("%s", successMessage);
}

testWasSuccessful = ExecuteStartupTest(ResumeRfStartupTestThread);
DEBUG_PRINT(persistentVariables.template Load<"rfIsWorking">() ? "\n" : " and");
if(not testWasSuccessful)
{
DEBUG_PRINT("%s", errorMessage);
persistentVariables.template Store<"rfIsWorking">(false);
persistentVariables.template Increment<"nRfErrors">();
AT(NOW() + 2 * RODOS::SECONDS);
SuspendFor(2 * s);
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() > framEpsSpi.TransferEnd())
{
DEBUG_PRINT("FRAM/EPS SPI timeout occurred\n");
timeoutHappened = true;
}
if(NOW() > flash::spi.TransferEnd())
if(CurrentRodosTime() > flash::spi.TransferEnd())
{
DEBUG_PRINT("Flash SPI timeout occurred\n");
timeoutHappened = true;
persistentVariables.template Increment<"nFlashErrors">();
}
if(NOW() > rf::spi.TransferEnd())
if(CurrentRodosTime() > rf::spi.TransferEnd())
{
DEBUG_PRINT("RF SPI timeout occurred\n");
timeoutHappened = true;
persistentVariables.template Increment<"nRfErrors">();
}
if(timeoutHappened)
{
DEBUG_PRINT("Hardware reset and reboot");
RODOS::hwResetAndReboot();
}
}
Expand All @@ -103,9 +136,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;
}
}
26 changes: 26 additions & 0 deletions Sts1CobcSw/CobcSoftware/StartupTestStubs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <Sts1CobcSw/CobcSoftware/SpiStartupTestAndSupervisorThread.hpp>


namespace sts1cobcsw
{
auto ResumeFlashStartupTestThread() -> void
{
persistentVariables.template Store<"flashIsWorking">(true);
ResumeSpiStartupTestAndSupervisorThread();
}


auto ResumeFramEpsStartupTestThread() -> void
{
fram::framIsWorking.Store(true);
persistentVariables.template Store<"epsIsWorking">(true);
ResumeSpiStartupTestAndSupervisorThread();
}


auto ResumeRfStartupTestThread() -> void
{
persistentVariables.template Store<"rfIsWorking">(true);
ResumeSpiStartupTestAndSupervisorThread();
}
}
2 changes: 1 addition & 1 deletion Sts1CobcSw/Edu/Edu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <Sts1CobcSw/Serial/Serial.hpp>
#include <Sts1CobcSw/Utility/Crc32Software.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/RodosTime.hpp>
#include <Sts1CobcSw/Utility/Span.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <strong_type/difference.hpp>

Expand Down
1 change: 0 additions & 1 deletion Sts1CobcSw/Edu/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <Sts1CobcSw/ProgramId/ProgramId.hpp>
#include <Sts1CobcSw/Serial/Byte.hpp>
#include <Sts1CobcSw/Serial/Serial.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>
#include <Sts1CobcSw/Utility/TimeTypes.hpp>

#include <cstddef>
Expand Down
7 changes: 5 additions & 2 deletions Sts1CobcSw/FileSystem/FileSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <Sts1CobcSw/FileSystem/FileSystem.hpp>
#include <Sts1CobcSw/Periphery/Flash.hpp>
#include <Sts1CobcSw/Serial/Byte.hpp>
#include <Sts1CobcSw/Utility/RodosTime.hpp>

#include <strong_type/difference.hpp>

#include <rodos_no_using_namespace.h>

Expand Down Expand Up @@ -64,9 +67,9 @@ lfs_config const lfsConfig{.context = nullptr,

// TODO: Test with real HW
// max. 3.5 ms acc. W25Q01JV datasheet
constexpr auto pageProgramTimeout = 5 * RODOS::MILLISECONDS;
constexpr auto pageProgramTimeout = 5 * ms;
// max. 400 ms acc. W25Q01JV datasheet (lfs_config.block_size = flash::sectorSize)
constexpr auto blockEraseTimeout = 500 * RODOS::MILLISECONDS;
constexpr auto blockEraseTimeout = 500 * ms;


// --- Public function definitions ---
Expand Down
Loading
Loading