Skip to content

Commit da683fb

Browse files
Create Reset Manager (#98)
* Create Reset Manger * Add integration tests --------- Co-authored-by: Sam S. Yu <[email protected]>
1 parent e32e621 commit da683fb

File tree

9 files changed

+370
-2
lines changed

9 files changed

+370
-2
lines changed

FprimeZephyrReference/Components/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv/")
88
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler")
99
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FsSpace/")
1010
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ImuManager/")
11+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LoadSwitch/")
1112
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/NullPrmDb/")
1213
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PowerMonitor/")
13-
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog")
14+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ResetManager/")
1415
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/StartupManager/")
15-
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LoadSwitch/")
16+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
####
2+
# F Prime CMakeLists.txt:
3+
#
4+
# SOURCES: list of source files (to be compiled)
5+
# AUTOCODER_INPUTS: list of files to be passed to the autocoders
6+
# DEPENDS: list of libraries that this module depends on
7+
#
8+
# More information in the F´ CMake API documentation:
9+
# https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/
10+
#
11+
####
12+
13+
# Module names are derived from the path from the nearest project/library/framework
14+
# root when not specifically overridden by the developer. i.e. The module defined by
15+
# `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`.
16+
17+
register_fprime_library(
18+
AUTOCODER_INPUTS
19+
"${CMAKE_CURRENT_LIST_DIR}/ResetManager.fpp"
20+
SOURCES
21+
"${CMAKE_CURRENT_LIST_DIR}/ResetManager.cpp"
22+
# DEPENDS
23+
# MyPackage_MyOtherModule
24+
)
25+
26+
### Unit Tests ###
27+
# register_fprime_ut(
28+
# AUTOCODER_INPUTS
29+
# "${CMAKE_CURRENT_LIST_DIR}/ResetManager.fpp"
30+
# SOURCES
31+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/ResetManagerTestMain.cpp"
32+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/ResetManagerTester.cpp"
33+
# DEPENDS
34+
# STest # For rules-based testing
35+
# UT_AUTO_HELPERS
36+
# )
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// ======================================================================
2+
// \title ResetManager.cpp
3+
// \author nate
4+
// \brief cpp file for ResetManager component implementation class
5+
// ======================================================================
6+
7+
#include "FprimeZephyrReference/Components/ResetManager/ResetManager.hpp"
8+
9+
#include <zephyr/sys/reboot.h>
10+
11+
namespace Components {
12+
13+
// ----------------------------------------------------------------------
14+
// Component construction and destruction
15+
// ----------------------------------------------------------------------
16+
17+
ResetManager ::ResetManager(const char* const compName) : ResetManagerComponentBase(compName) {}
18+
19+
ResetManager ::~ResetManager() {}
20+
21+
// ----------------------------------------------------------------------
22+
// Handler implementations for typed input ports
23+
// ----------------------------------------------------------------------
24+
25+
void ResetManager ::coldReset_handler(FwIndexType portNum) {
26+
this->handleColdReset();
27+
}
28+
29+
void ResetManager ::warmReset_handler(FwIndexType portNum) {
30+
this->handleWarmReset();
31+
}
32+
33+
// ----------------------------------------------------------------------
34+
// Handler implementations for commands
35+
// ----------------------------------------------------------------------
36+
37+
void ResetManager ::COLD_RESET_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
38+
this->handleColdReset();
39+
40+
// The command response will not be received since the system is resetting
41+
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
42+
}
43+
44+
void ResetManager ::WARM_RESET_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
45+
this->handleWarmReset();
46+
47+
// The command response will not be received since the system is resetting
48+
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
49+
}
50+
51+
// ----------------------------------------------------------------------
52+
// Private helper methods
53+
// ----------------------------------------------------------------------
54+
55+
void ResetManager ::handleColdReset() {
56+
// Log the cold reset event
57+
this->log_ACTIVITY_HI_INITIATE_COLD_RESET();
58+
59+
sys_reboot(SYS_REBOOT_COLD);
60+
}
61+
62+
void ResetManager ::handleWarmReset() {
63+
// Log the warm reset event
64+
this->log_ACTIVITY_HI_INITIATE_WARM_RESET();
65+
66+
sys_reboot(SYS_REBOOT_WARM);
67+
}
68+
69+
} // namespace Components
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module Components {
2+
@ Component to soft reset the satellite
3+
passive component ResetManager {
4+
5+
@ Command to initiate a cold reset
6+
sync command COLD_RESET()
7+
8+
@ Command to initiate a warm reset
9+
sync command WARM_RESET()
10+
11+
@ Event indicating that a cold reset has been initiated
12+
event INITIATE_COLD_RESET() severity activity high id 0 format "Initiating cold reset"
13+
14+
@ Event indicating that a warm reset has been initiated
15+
event INITIATE_WARM_RESET() severity activity high id 1 format "Initiating warm reset"
16+
17+
@ Port to invoke a cold reset
18+
sync input port coldReset: Fw.Signal
19+
20+
@ Port to invoke a warm reset
21+
sync input port warmReset: Fw.Signal
22+
23+
###############################################################################
24+
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
25+
###############################################################################
26+
@ Port for requesting the current time
27+
time get port timeCaller
28+
29+
@ Port for sending command registrations
30+
command reg port cmdRegOut
31+
32+
@ Port for receiving commands
33+
command recv port cmdIn
34+
35+
@ Port for sending command responses
36+
command resp port cmdResponseOut
37+
38+
@ Port for sending textual representation of events
39+
text event port logTextOut
40+
41+
@ Port for sending events to downlink
42+
event port logOut
43+
44+
}
45+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// ======================================================================
2+
// \title ResetManager.hpp
3+
// \author nate
4+
// \brief hpp file for ResetManager component implementation class
5+
// ======================================================================
6+
7+
#ifndef Components_ResetManager_HPP
8+
#define Components_ResetManager_HPP
9+
10+
#include "FprimeZephyrReference/Components/ResetManager/ResetManagerComponentAc.hpp"
11+
12+
namespace Components {
13+
14+
class ResetManager final : public ResetManagerComponentBase {
15+
public:
16+
// ----------------------------------------------------------------------
17+
// Component construction and destruction
18+
// ----------------------------------------------------------------------
19+
20+
//! Construct ResetManager object
21+
ResetManager(const char* const compName //!< The component name
22+
);
23+
24+
//! Destroy ResetManager object
25+
~ResetManager();
26+
27+
private:
28+
// ----------------------------------------------------------------------
29+
// Handler implementations for typed input ports
30+
// ----------------------------------------------------------------------
31+
32+
//! Handler implementation for coldReset
33+
//!
34+
//! Port to invoke a cold reset
35+
void coldReset_handler(FwIndexType portNum //!< The port number
36+
) override;
37+
38+
//! Handler implementation for warmReset
39+
//!
40+
//! Port to invoke a warm reset
41+
void warmReset_handler(FwIndexType portNum //!< The port number
42+
) override;
43+
44+
private:
45+
// ----------------------------------------------------------------------
46+
// Handler implementations for commands
47+
// ----------------------------------------------------------------------
48+
49+
//! Handler implementation for command COLD_RESET
50+
//!
51+
//! Command to initiate a cold reset
52+
void COLD_RESET_cmdHandler(FwOpcodeType opCode, //!< The opcode
53+
U32 cmdSeq //!< The command sequence number
54+
) override;
55+
56+
//! Handler implementation for command WARM_RESET
57+
//!
58+
//! Command to initiate a warm reset
59+
void WARM_RESET_cmdHandler(FwOpcodeType opCode, //!< The opcode
60+
U32 cmdSeq //!< The command sequence number
61+
) override;
62+
63+
private:
64+
// ----------------------------------------------------------------------
65+
// Private helper methods
66+
// ----------------------------------------------------------------------
67+
68+
//! Handler for cold reset
69+
void handleColdReset();
70+
71+
//! Handler for warm reset
72+
void handleWarmReset();
73+
};
74+
75+
} // namespace Components
76+
77+
#endif
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Components::ResetManager
2+
3+
The ResetManager component provides system reset functionality, allowing the satellite to perform both cold and warm resets through commands or direct port calls.
4+
5+
## Usage Examples
6+
7+
The ResetManager component can be triggered in two ways:
8+
1. Through ground commands (`COLD_RESET` or `WARM_RESET`)
9+
2. Through direct port calls (`coldReset` or `warmReset`)
10+
11+
### Typical Usage
12+
13+
1. The component is instantiated and initialized during system startup
14+
2. When a reset is needed:
15+
- **Via Command**: Ground station sends `COLD_RESET` or `WARM_RESET` command
16+
- **Via Port**: Another component calls the `coldReset` or `warmReset` port
17+
3. The component:
18+
- Logs the appropriate event (`INITIATE_COLD_RESET` or `INITIATE_WARM_RESET`)
19+
- Calls the Zephyr `sys_reboot()` function with the appropriate reset type
20+
- System resets (command response is not received)
21+
22+
**Note**: After initiating a reset, the command response will indicate `EXECUTION_ERROR` since the system will reset before the response can be transmitted.
23+
24+
## Class Diagram
25+
26+
```mermaid
27+
classDiagram
28+
namespace Components {
29+
class ResetManagerComponentBase {
30+
<<Auto-generated>>
31+
}
32+
class ResetManager {
33+
+ ResetManager(const char* compName)
34+
+ ~ResetManager()
35+
- coldReset_handler(const FwIndexType portNum)
36+
- warmReset_handler(const FwIndexType portNum)
37+
- COLD_RESET_cmdHandler(FwOpcodeType opCode, U32 cmdSeq)
38+
- WARM_RESET_cmdHandler(FwOpcodeType opCode, U32 cmdSeq)
39+
- handleColdReset()
40+
- handleWarmReset()
41+
}
42+
}
43+
ResetManagerComponentBase <|-- ResetManager : inherits
44+
```
45+
46+
## Port Descriptions
47+
| Name | Type | Description |
48+
|---|---|---|
49+
| coldReset | sync input | Triggers a cold reset of the system |
50+
| warmReset | sync input | Triggers a warm reset of the system |
51+
52+
## Sequence Diagrams
53+
54+
### Cold Reset via Command
55+
```mermaid
56+
sequenceDiagram
57+
participant Ground Station
58+
participant ResetManager
59+
participant Zephyr RTOS
60+
participant Hardware
61+
62+
Ground Station->>ResetManager: COLD_RESET command
63+
ResetManager->>ResetManager: Log INITIATE_COLD_RESET event
64+
ResetManager->>Zephyr RTOS: sys_reboot(SYS_REBOOT_COLD)
65+
Zephyr RTOS->>Hardware: Initiate cold reset
66+
Note over Hardware: System resets
67+
ResetManager-->>Ground Station: EXECUTION_ERROR response (not received)
68+
```
69+
70+
### Warm Reset via Port
71+
```mermaid
72+
sequenceDiagram
73+
participant Component
74+
participant ResetManager
75+
participant Zephyr RTOS
76+
participant Hardware
77+
78+
Component->>ResetManager: warmReset port call
79+
ResetManager->>ResetManager: Log INITIATE_WARM_RESET event
80+
ResetManager->>Zephyr RTOS: sys_reboot(SYS_REBOOT_WARM)
81+
Zephyr RTOS->>Hardware: Initiate warm reset
82+
Note over Hardware: System resets
83+
```
84+
85+
## Commands
86+
| Name | Description |
87+
|---|---|
88+
| COLD_RESET | Command to initiate a cold reset (full hardware reset) |
89+
| WARM_RESET | Command to initiate a warm reset (software reset, preserves some state) |
90+
91+
## Events
92+
| Name | Severity | Description |
93+
|---|---|---|
94+
| INITIATE_COLD_RESET | ACTIVITY_HI | Event indicating that a cold reset has been initiated |
95+
| INITIATE_WARM_RESET | ACTIVITY_HI | Event indicating that a warm reset has been initiated |
96+
97+
## Requirements
98+
| Name | Description | Validation |
99+
|---|---|---|
100+
| Cold Reset Command | The component shall provide a command to initiate a cold reset of the system | Verify system performs full hardware reset when command is issued |
101+
| Warm Reset Command | The component shall provide a command to initiate a warm reset of the system | Verify system performs software reset when command is issued |
102+
| Cold Reset Port | The component shall provide a port to trigger a cold reset programmatically | Verify system resets when port is called |
103+
| Warm Reset Port | The component shall provide a port to trigger a warm reset programmatically | Verify system resets when port is called |
104+
| Reset Event Logging | The component shall log an event before initiating any reset | Verify appropriate event is logged before reset occurs |
105+
| Zephyr Integration | The component shall use Zephyr's `sys_reboot()` function for reset operations | Verify `sys_reboot()` is called with correct parameters |
106+
107+
## Change Log
108+
| Date | Description |
109+
|---|---|
110+
| 2025-11-12 | Initial ResetManager component |

FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ module ReferenceDeployment {
127127

128128
instance payloadBatteryLoadSwitch: Components.LoadSwitch base id 0x1003A000
129129

130+
instance resetManager: Components.ResetManager base id 0x1003B000
131+
130132
instance powerMonitor: Components.PowerMonitor base id 0x1003C000
131133

132134
instance ina219SysManager: Drv.Ina219Manager base id 0x1003D000

FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ module ReferenceDeployment {
6666
instance powerMonitor
6767
instance ina219SysManager
6868
instance ina219SolManager
69+
instance resetManager
6970

7071

7172
# ----------------------------------------------------------------------
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
reset_manager_test.py:
3+
4+
Integration tests for the Reset Manager component.
5+
"""
6+
7+
from fprime_gds.common.testing_fw.api import IntegrationTestAPI
8+
9+
resetManager = "ReferenceDeployment.resetManager"
10+
11+
12+
def test_01_cold_reset(fprime_test_api: IntegrationTestAPI, start_gds):
13+
"""Test that we can initiate a cold reset"""
14+
15+
fprime_test_api.send_command(f"{resetManager}.COLD_RESET")
16+
17+
# Assert FPrime restarted by checking for FrameworkVersion event
18+
fprime_test_api.assert_event("CdhCore.version.FrameworkVersion", timeout=10)
19+
20+
21+
def test_02_warm_reset(fprime_test_api: IntegrationTestAPI, start_gds):
22+
"""Test that we can initiate a warm reset"""
23+
24+
fprime_test_api.send_command(f"{resetManager}.WARM_RESET")
25+
26+
# Assert FPrime restarted by checking for FrameworkVersion event
27+
fprime_test_api.assert_event("CdhCore.version.FrameworkVersion", timeout=10)

0 commit comments

Comments
 (0)