Skip to content

Commit 868fc66

Browse files
committed
Add com delay component
1 parent daa9740 commit 868fc66

File tree

10 files changed

+245
-7
lines changed

10 files changed

+245
-7
lines changed

FprimeZephyrReference/Components/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Include project-wide components here
22

33
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv/")
4+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ComDelay/")
45
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler")
56
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ImuManager/")
67
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/NullPrmDb/")
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}/ComDelay.fpp"
20+
SOURCES
21+
"${CMAKE_CURRENT_LIST_DIR}/ComDelay.cpp"
22+
# DEPENDS
23+
# MyPackage_MyOtherModule
24+
)
25+
26+
### Unit Tests ###
27+
# register_fprime_ut(
28+
# AUTOCODER_INPUTS
29+
# "${CMAKE_CURRENT_LIST_DIR}/ComDelay.fpp"
30+
# SOURCES
31+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/ComDelayTestMain.cpp"
32+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/ComDelayTester.cpp"
33+
# DEPENDS
34+
# STest # For rules-based testing
35+
# UT_AUTO_HELPERS
36+
# )
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// ======================================================================
2+
// \title ComDelay.cpp
3+
// \author starchmd
4+
// \brief cpp file for ComDelay component implementation class
5+
// ======================================================================
6+
7+
#include "FprimeZephyrReference/Components/ComDelay/ComDelay.hpp"
8+
#include "FprimeZephyrReference/Components/ComDelay/FppConstantsAc.hpp"
9+
10+
namespace Components {
11+
12+
// ----------------------------------------------------------------------
13+
// Component construction and destruction
14+
// ----------------------------------------------------------------------
15+
16+
ComDelay ::ComDelay(const char* const compName)
17+
: ComDelayComponentBase(compName), m_last_status_valid(false), m_last_status(Fw::Success::FAILURE) {}
18+
19+
ComDelay ::~ComDelay() {}
20+
21+
void ComDelay ::parameterUpdated(FwPrmIdType id) {
22+
switch (id) {
23+
case ComDelay::PARAMID_DIVIDER: {
24+
Fw::ParamValid is_valid;
25+
U8 new_divider = this->paramGet_DIVIDER(is_valid);
26+
if ((is_valid != Fw::ParamValid::INVALID) && (is_valid != Fw::ParamValid::UNINIT)) {
27+
this->log_ACTIVITY_HI_DividerSet(new_divider);
28+
}
29+
} break;
30+
default:
31+
FW_ASSERT(0);
32+
break; // Fallthrough from assert (static analysis)
33+
}
34+
}
35+
36+
// ----------------------------------------------------------------------
37+
// Handler implementations for typed input ports
38+
// ----------------------------------------------------------------------
39+
40+
void ComDelay ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
41+
this->m_last_status = condition;
42+
this->m_last_status_valid = true;
43+
}
44+
45+
void ComDelay ::run_handler(FwIndexType portNum, U32 context) {
46+
// On the cycle after the tick count is reset, attempt to output any current com status
47+
if (this->m_tick_count == 0) {
48+
bool expected = true;
49+
// Receive the current "last status" validity flag and atomically exchange it with false. This effectively
50+
// "consumes" a valid status. When valid, the last status is sent out.
51+
bool valid = this->m_last_status_valid.compare_exchange_strong(expected, false);
52+
if (valid) {
53+
this->comStatusOut_out(0, this->m_last_status);
54+
}
55+
}
56+
57+
// Unless there is corruption, the parameter should always be valid via its default value; however, in the interest
58+
// of failing-safe and continuing some sort of communication we default the current_divisor to the default value.
59+
Fw::ParamValid is_valid;
60+
U8 current_divisor = this->paramGet_DIVIDER(is_valid);
61+
62+
// Increment and module the tick count by the divisor
63+
if ((is_valid == Fw::ParamValid::INVALID) || (is_valid == Fw::ParamValid::UNINIT)) {
64+
current_divisor = Components::DEFAULT_DIVIDER;
65+
}
66+
// Count this new tick, resetting whenever the current count is at or higher than the current divider.
67+
this->m_tick_count = (this->m_tick_count >= current_divisor) ? 0 : this->m_tick_count + 1;
68+
}
69+
70+
} // namespace Components
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module Components {
2+
constant DEFAULT_DIVIDER = 30
3+
@ A component to delay com status until some further point
4+
passive component ComDelay {
5+
@ Rate schedule port used to trigger radio transmission
6+
sync input port run: Svc.Sched
7+
8+
@ Input comStatus from radio component
9+
sync input port comStatusIn: Fw.SuccessCondition
10+
11+
@ Output comStatus to be called on rate group
12+
output port comStatusOut: Fw.SuccessCondition
13+
14+
@ Divider of the incoming rate tick
15+
param DIVIDER: U8 default DEFAULT_DIVIDER # Start slow i.e. on a 1S tick, transmit every 30S
16+
17+
@ Divider set event
18+
event DividerSet(divider: U8) severity activity high \
19+
format "Set divider to: {}"
20+
21+
###############################################################################
22+
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
23+
###############################################################################
24+
@ Port for requesting the current time
25+
time get port timeCaller
26+
27+
@ Port for sending command registrations
28+
command reg port cmdRegOut
29+
30+
@ Port for receiving commands
31+
command recv port cmdIn
32+
33+
@ Port for sending command responses
34+
command resp port cmdResponseOut
35+
36+
@ Port for sending textual representation of events
37+
text event port logTextOut
38+
39+
@ Port for sending events to downlink
40+
event port logOut
41+
42+
@ Port to return the value of a parameter
43+
param get port prmGetOut
44+
45+
@Port to set the value of a parameter
46+
param set port prmSetOut
47+
}
48+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// ======================================================================
2+
// \title ComDelay.hpp
3+
// \author starchmd
4+
// \brief hpp file for ComDelay component implementation class
5+
// ======================================================================
6+
7+
#ifndef Components_ComDelay_HPP
8+
#define Components_ComDelay_HPP
9+
10+
#include <atomic>
11+
#include "FprimeZephyrReference/Components/ComDelay/ComDelayComponentAc.hpp"
12+
13+
namespace Components {
14+
15+
class ComDelay final : public ComDelayComponentBase {
16+
public:
17+
// ----------------------------------------------------------------------
18+
// Component construction and destruction
19+
// ----------------------------------------------------------------------
20+
21+
//! Construct ComDelay object
22+
ComDelay(const char* const compName //!< The component name
23+
);
24+
25+
//! Destroy ComDelay object
26+
~ComDelay();
27+
28+
private:
29+
void parameterUpdated(FwPrmIdType id //!< The parameter ID
30+
) override;
31+
32+
// ----------------------------------------------------------------------
33+
// Handler implementations for typed input ports
34+
// ----------------------------------------------------------------------
35+
36+
//! Handler implementation for comStatusIn
37+
//!
38+
//! Input comStatus from radio component
39+
void comStatusIn_handler(FwIndexType portNum, //!< The port number
40+
Fw::Success& condition //!< Condition success/failure
41+
) override;
42+
43+
//! Handler implementation for run
44+
//!
45+
//! Rate schedule port used to trigger radio transmission
46+
void run_handler(FwIndexType portNum, //!< The port number
47+
U32 context //!< The call order
48+
) override;
49+
50+
private:
51+
//! Count of incoming run ticks
52+
U8 m_tick_count;
53+
//! Stores if the last status is currently valid
54+
std::atomic<bool> m_last_status_valid;
55+
//! Stores the last status
56+
Fw::Success m_last_status;
57+
};
58+
59+
} // namespace Components
60+
61+
#endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Components::ComDelay
2+
3+
`Components::ComDelay` is a parameterized rate group schedule divider. On the initial run invocation and on each multiple of the divider thereafter any received com status is sent out. This effectively delays the com status until the next (divided) run call.
4+
5+
# 1 Requirements
6+
7+
| Requirement ID | Description | Validation |
8+
|----------------|----------------------------------------------------------------------|------------|
9+
| COM_DELAY_001 | The `Svc::ComDelay` component shall accept com status in. | Unit-Test |
10+
| COM_DELAY_002 | The `Svc::ComDelay` component shall emit com status once for each DIVIDER number of rate group ticks. | Unit-Test |
11+
| COM_DELAY_003 | The `Svc::ComDelay` component shall set the DIVIDER via a parameter. | Unit-Test |
12+
13+
# 2 Parameters
14+
15+
| Name | Description |
16+
|---------|-----------------------------------------------------------|
17+
| DIVIDER | Number of rate group ticks received before sending status |

FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ module ReferenceDeployment {
6969
instance lora: Zephyr.LoRa base id 0x10021000
7070

7171
instance prmDb: Components.NullPrmDb base id 0x10022000
72+
73+
instance comDelay: Components.ComDelay base id 0x10023000
7274
}

FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module ReferenceDeployment {
3333
instance lis2mdlManager
3434
instance lsm6dsoManager
3535
instance bootloaderTrigger
36+
instance comDelay
3637
# ----------------------------------------------------------------------
3738
# Pattern graph specifiers
3839
# ----------------------------------------------------------------------
@@ -77,9 +78,8 @@ module ReferenceDeployment {
7778
# ComStub <-> ComDriver (Downlink)
7879
ComCcsds.framer.dataOut -> lora.dataIn
7980
lora.dataReturnOut -> ComCcsds.framer.dataReturnIn
80-
lora.comStatusOut -> ComCcsds.framer.comStatusIn
81-
82-
81+
lora.comStatusOut -> comDelay.comStatusIn
82+
comDelay.comStatusOut ->ComCcsds.framer.comStatusIn
8383
}
8484

8585
connections RateGroups {
@@ -97,6 +97,7 @@ module ReferenceDeployment {
9797
rateGroup1Hz.RateGroupMemberOut[3] -> CdhCore.tlmSend.Run
9898
rateGroup1Hz.RateGroupMemberOut[4] -> watchdog.run
9999
rateGroup1Hz.RateGroupMemberOut[5] -> imuManager.run
100+
rateGroup1Hz.RateGroupMemberOut[6] -> comDelay.run
100101
}
101102

102103
connections Watchdog {

fprime-gds.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

fprime-gds.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
command-line-options:
2+
communication-selection: uart
3+
uart-baud: 115200
4+
no-app:
5+
dictionary: build-artifacts/zephyr/fprime-zephyr-deployment/dict/ReferenceDeploymentTopologyDictionary.json
6+
output-unframed-data: "-"

0 commit comments

Comments
 (0)