Skip to content

Commit f97253f

Browse files
ineskhoukevinthegreat1hyuncatmoisesmataMikefly123
authored
Load switch (#86)
* Add load switch component * Fix tables * Sarah Kevin MoMata Squad Load Switch * Sarah Kevin and MoMata fixed a bug * Commit farming * Added mcp23017 to v5 dtsi * Rough initial implementation + add to topology * Ion even know any mane * Working Device Tree (But F Prime Crash) * Update CommandDispatcherImplCfg.hpp Fixed the Crashes! * Update Submodules * Revert "Update Submodules" This reverts commit b5544e7. * Initial plan * Reset m_totalAttempts in resetDeploymentState to fix integration test failures Co-authored-by: Mikefly123 <[email protected]> * Fix integration test failures - final status Co-authored-by: Mikefly123 <[email protected]> * Remove CodeQL artifact and update gitignore Co-authored-by: Mikefly123 <[email protected]> * Add Reset port functionality * Add remaining load switch instances * Small updates to extra loadSwitch instances, update max packets - Max packets from 8 to 9 * Remove output read port, add output write port * Modify LoadSwitch to use ZephyrGpioDriver Component * Modify gpioDriver name for watchdog for clarity * Instances of GPIO Drivers, connected to load switches in topology * First implementation load_switch_test * Labels for devicetree gpios fixed * Update sdd * Moises made them active lmao * corrected merge errors * appease linter * fixed the queue build error bc of linter * fixed burnwire incremnentation * changed increments * move invrement * ading inclused * remove the degugs * formal burnwire timer * switched the order of the rate grounps * reverted timer debugdding code * linter * remove the reset of the count for now * refer to the right load switch in the tests * checking a differnt conversion for the tests * missed some binary * switched the telem packets * switched the correct onces back * Very important commit --------- Co-authored-by: Kevinthegreat <[email protected]> Co-authored-by: sarah <[email protected]> Co-authored-by: Moises Mata <[email protected]> Co-authored-by: Michael Pham <[email protected]> Co-authored-by: Moises Mata <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Ethan Hu <[email protected]> Co-authored-by: robertpendergrast <[email protected]>
1 parent 0d6c100 commit f97253f

File tree

15 files changed

+612
-12
lines changed

15 files changed

+612
-12
lines changed

FprimeZephyrReference/Components/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ImuManager/")
1111
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/NullPrmDb/")
1212
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PowerMonitor/")
1313
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog")
14+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LoadSwitch/")
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}/LoadSwitch.fpp"
20+
SOURCES
21+
"${CMAKE_CURRENT_LIST_DIR}/LoadSwitch.cpp"
22+
# DEPENDS
23+
# MyPackage_MyOtherModule
24+
)
25+
26+
### Unit Tests ###
27+
# register_fprime_ut(
28+
# AUTOCODER_INPUTS
29+
# "${CMAKE_CURRENT_LIST_DIR}/LoadSwitch.fpp"
30+
# SOURCES
31+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/LoadSwitchTestMain.cpp"
32+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/LoadSwitchTester.cpp"
33+
# DEPENDS
34+
# STest # For rules-based testing
35+
# UT_AUTO_HELPERS
36+
# )
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// ======================================================================
2+
// \title LoadSwitch.cpp
3+
// \author Moises, sarah
4+
// \brief cpp file for LoadSwitch component implementation class
5+
// ======================================================================
6+
7+
#include "FprimeZephyrReference/Components/LoadSwitch/LoadSwitch.hpp"
8+
9+
#include <zephyr/drivers/gpio.h>
10+
11+
namespace Components {
12+
13+
// ----------------------------------------------------------------------
14+
// Component construction and destruction
15+
// ----------------------------------------------------------------------
16+
17+
LoadSwitch ::LoadSwitch(const char* const compName) : LoadSwitchComponentBase(compName) {}
18+
19+
LoadSwitch ::~LoadSwitch() {}
20+
21+
// ----------------------------------------------------------------------
22+
// Handler implementations for typed input ports
23+
// ----------------------------------------------------------------------
24+
25+
void LoadSwitch ::Reset_handler(FwIndexType portNum) {
26+
this->gpioSet_out(0, Fw::Logic::LOW);
27+
this->log_ACTIVITY_HI_StatusChanged(Fw::On::OFF);
28+
this->tlmWrite_IsOn(Fw::On::OFF);
29+
k_sleep(K_MSEC(100));
30+
this->gpioSet_out(0, Fw::Logic::HIGH);
31+
this->log_ACTIVITY_HI_StatusChanged(Fw::On::ON);
32+
this->tlmWrite_IsOn(Fw::On::ON);
33+
}
34+
35+
// ----------------------------------------------------------------------
36+
// Handler implementations for commands
37+
// ----------------------------------------------------------------------
38+
39+
void LoadSwitch ::TURN_ON_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
40+
this->gpioSet_out(0, Fw::Logic::HIGH);
41+
this->log_ACTIVITY_HI_StatusChanged(Fw::On::ON);
42+
this->tlmWrite_IsOn(Fw::On::ON);
43+
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
44+
}
45+
46+
void LoadSwitch ::TURN_OFF_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
47+
this->gpioSet_out(0, Fw::Logic::LOW);
48+
this->log_ACTIVITY_HI_StatusChanged(Fw::On::OFF);
49+
this->tlmWrite_IsOn(Fw::On::OFF);
50+
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
51+
}
52+
53+
} // namespace Components
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module Components {
2+
@ A generic load switch for controlling power to components
3+
passive component LoadSwitch {
4+
5+
# One async command/port is required for active components
6+
# This should be overridden by the developers with a useful command/port
7+
8+
##############################################################################
9+
#### Uncomment the following examples to start customizing your component ####
10+
##############################################################################
11+
12+
# @ Example async command
13+
# async command COMMAND_NAME(param_name: U32)
14+
sync command TURN_ON()
15+
sync command TURN_OFF()
16+
17+
# @ Example telemetry counter
18+
# telemetry ExampleCounter: U64
19+
telemetry IsOn: Fw.On
20+
21+
# @ Example event
22+
# event ExampleStateEvent(example_state: Fw.On) severity activity high id 0 format "State set to {}"
23+
event StatusChanged($state: Fw.On) severity activity high id 1 format "Load switch state changed to {}"
24+
25+
# @ Example port: receiving calls from the rate group
26+
# sync input port run: Svc.Sched
27+
#output port Status: Drv.GpioRead
28+
#We will not be putting a Drv.GpioRead port here, we are using the Gpio Driver component which has this already!
29+
30+
@ Port sending calls to the GPIO driver
31+
output port gpioSet: Drv.GpioWrite
32+
33+
34+
# Input that will be used by other components if they want to force a reset
35+
# (off and on again) of the load switch
36+
sync input port Reset: Fw.Signal
37+
38+
# @ Example parameter
39+
# param PARAMETER_NAME: U32
40+
41+
###############################################################################
42+
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
43+
###############################################################################
44+
@ Port for requesting the current time
45+
time get port timeCaller
46+
47+
@ Port for sending command registrations
48+
command reg port cmdRegOut
49+
50+
@ Port for receiving commands
51+
command recv port cmdIn
52+
53+
@ Port for sending command responses
54+
command resp port cmdResponseOut
55+
56+
@ Port for sending textual representation of events
57+
text event port logTextOut
58+
59+
@ Port for sending events to downlink
60+
event port logOut
61+
62+
@ Port for sending telemetry channels to downlink
63+
telemetry port tlmOut
64+
65+
@ Port to return the value of a parameter
66+
param get port prmGetOut
67+
68+
@Port to set the value of a parameter
69+
param set port prmSetOut
70+
71+
}
72+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// ======================================================================
2+
// \title LoadSwitch.hpp
3+
// \author Moises, sarah
4+
// \brief hpp file for LoadSwitch component implementation class
5+
// ======================================================================
6+
7+
#ifndef Components_LoadSwitch_HPP
8+
#define Components_LoadSwitch_HPP
9+
10+
#include "FprimeZephyrReference/Components/LoadSwitch/LoadSwitchComponentAc.hpp"
11+
#include <zephyr/kernel.h>
12+
13+
// Forward declare Zephyr types to avoid header conflicts
14+
struct device;
15+
16+
namespace Components {
17+
18+
class LoadSwitch final : public LoadSwitchComponentBase {
19+
public:
20+
// ----------------------------------------------------------------------
21+
// Component construction and destruction
22+
// ----------------------------------------------------------------------
23+
24+
//! Construct LoadSwitch object
25+
LoadSwitch(const char* const compName //!< The component name
26+
);
27+
28+
//! Destroy LoadSwitch object
29+
~LoadSwitch();
30+
31+
private:
32+
// ----------------------------------------------------------------------
33+
// Handler implementations for commands
34+
// ----------------------------------------------------------------------
35+
36+
//! Handler implementation for command TURN_ON
37+
void TURN_ON_cmdHandler(FwOpcodeType opCode, //!< The opcode
38+
U32 cmdSeq //!< The command sequence number
39+
) override;
40+
41+
//! Handler implementation for command TURN_OFF
42+
void TURN_OFF_cmdHandler(FwOpcodeType opCode, //!< The opcode
43+
U32 cmdSeq //!< The command sequence number
44+
) override;
45+
46+
// ----------------------------------------------------------------------
47+
// Handler implementations for typed input ports
48+
// ----------------------------------------------------------------------
49+
50+
//! Handler implementation for Reset
51+
void Reset_handler(FwIndexType portNum //!< The port number
52+
) override;
53+
};
54+
55+
} // namespace Components
56+
57+
#endif
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Components::LoadSwitch
2+
3+
![LoadSwitch](LoadSwitch.svg)
4+
5+
## Overview
6+
7+
The `LoadSwitch` component is an active F' component that controls a single load switch output
8+
through the `gpioSet` output port (connected to the platform's GPIO driver). It exposes two
9+
async commands to turn the switch on and off, telemetry reporting the current state, and an
10+
async `Reset` input which toggles the switch (off, short delay, on).
11+
12+
## Responsibility
13+
14+
- Control the power rail for a connected peripheral by asserting/deasserting a GPIO.
15+
- Report state changes via an event and telemetry channel.
16+
17+
## External interface
18+
19+
### Commands
20+
21+
| Name | Description | Implementation notes |
22+
|---|---|---|
23+
| TURN_ON | Turn on the associated power rail | `TURN_ON_cmdHandler` sets the gpio via `gpioSet_out(0, Fw::Logic::HIGH)`, emits `StatusChanged` (ON), updates `IsOn` telemetry, replies OK. |
24+
| TURN_OFF | Turn off the associated power rail | `TURN_OFF_cmdHandler` sets the gpio via `gpioSet_out(0, Fw::Logic::LOW)`, emits `StatusChanged` (OFF), updates `IsOn` telemetry, replies OK. |
25+
26+
### Telemetry
27+
28+
| Name | Type | Description |
29+
|---|---:|---|
30+
| IsOn | Fw.On | Current power state; written after commands and on Reset handling. |
31+
32+
### Events
33+
34+
| Name | Severity | ID | Format |
35+
|---|---|---:|---|
36+
| StatusChanged | activity high | 1 | "Load switch state changed to {}" |
37+
38+
The component logs the `StatusChanged` event whenever the switch transitions due to a command or a Reset.
39+
40+
### Ports
41+
42+
| Port name | Direction | Port type | Notes |
43+
|---|---|---|---|
44+
| gpioSet | output | Drv.GpioWrite | Used to write the physical GPIO. Implementation always uses index 0 (`gpioSet_out(0, ...)`). |
45+
| Reset | input (async) | Fw.Signal | Causes the component to perform a hardware reset sequence: LOW -> wait 100ms -> HIGH. |
46+
47+
48+
## Change Log
49+
50+
| Date | Description |
51+
|---|---|
52+
| 10-22-2025 | Sarah, Kevin, and MoMata's first commit |
53+
| 11-07-2025 | Updated SDD to match implementation in `LoadSwitch.cpp/.hpp/.fpp` (commands, telemetry, event, ports, reset behavior). |

FprimeZephyrReference/ReferenceDeployment/Top/ReferenceDeploymentPackets.fppi

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,18 @@ telemetry packets ReferenceDeploymentPackets {
6161
ReferenceDeployment.antennaDeployer.LastDistance
6262
}
6363

64-
packet PowerMonitor id 9 group 4 {
64+
packet LoadSwitches id 9 group 4 {
65+
ReferenceDeployment.face4LoadSwitch.IsOn
66+
ReferenceDeployment.face0LoadSwitch.IsOn
67+
ReferenceDeployment.face1LoadSwitch.IsOn
68+
ReferenceDeployment.face2LoadSwitch.IsOn
69+
ReferenceDeployment.face3LoadSwitch.IsOn
70+
ReferenceDeployment.face5LoadSwitch.IsOn
71+
ReferenceDeployment.payloadPowerLoadSwitch.IsOn
72+
ReferenceDeployment.payloadBatteryLoadSwitch.IsOn
73+
}
74+
75+
packet PowerMonitor id 10 group 4 {
6576
ReferenceDeployment.ina219SysManager.Voltage
6677
ReferenceDeployment.ina219SysManager.Current
6778
ReferenceDeployment.ina219SysManager.Power

0 commit comments

Comments
 (0)