fprime/Svc/ActivePhaser/ActivePhaser.hpp
Shaokai (Jerry) Lin c8e2d44877
Add ActivePhaser to Svc (#3974)
* Initial open source review of active phaser

* Start working on ActivePhaser's FPP model

* Add ActivePhaser implementation

* Start working on unit tests

* Fill in test logic

* Add comments

* Guard against writing outside of container

* Add comment

* Update comments

* Fix comment on overflow

* Comment on the use of actual_start and others

* Add comments and max connection count

* Add comments

* Phaser updates

* Add telemetry channels

* Update comments, fix FPP, update API calls in tester

* Apply formatter

* Minor comment change

* Fix spelling

* First draft of SDD

* Revert "Add telemetry channels"

This reverts commit 1690e51e125477d032e07fa8cd3882d6db2b8b3b.

* PRIVATE -> private

* Add friend class declaration for ActivePhaserTester

* Fix FIXMEs where possible

* Formatting

* Fix minor UT issues

* Remove (void)

---------

Co-authored-by: ZIIIKT <shaokail@jpl.nasa.gov>
Co-authored-by: M Starch <LeStarch@googlemail.com>
Co-authored-by: Michael D Starch <Michael.D.Starch@jpl.nasa.gov>
2025-09-10 09:39:39 -07:00

131 lines
4.1 KiB
C++

// ======================================================================
// \title ActivePhaser.hpp
// \author mstarch
// \brief cpp file for ActivePhaser component implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef Svc_ActivePhaser_HPP
#define Svc_ActivePhaser_HPP
#include "Svc/ActivePhaser/ActivePhaserComponentAc.hpp"
namespace Svc {
class ActivePhaser final : public ActivePhaserComponentBase {
friend class ActivePhaserTester;
public:
static const U32 MAX_CHILDREN = 100;
static const U32 DONT_CARE = 0xFFFFFFFFlu;
static constexpr FwIndexType CONNECTION_COUNT_MAX = NUM_PHASERMEMBEROUT_OUTPUT_PORTS;
enum PhaserContextType {
SEQUENTIAL, // Context stores the number of times a port is called from the beginning of execution.
COUNT // Context stores the number of phaser cycles elapsed within a user-specified time window.
};
//! Finish status
enum FinishStatus {
UNKNOWN, //!< Improper finish call: child not running, no child, etc.
ON_TIME, //!< Child finished on time
LATE //!< Child finished late
};
/**
* \brief configuration for phasing
*/
struct PhaserStateEntry {
FwIndexType port;
U32 start;
U32 length;
U32 context;
PhaserContextType contextType;
bool started;
};
struct PhaserStateTable {
U32 used; //!< The number of registered tasks (the last registered task is at used - 1)
U32 current; //!< The current child task entry index
PhaserStateEntry entries[MAX_CHILDREN];
};
// ----------------------------------------------------------------------
// Component construction and destruction
// ----------------------------------------------------------------------
//! Construct ActivePhaser object
ActivePhaser(const char* const compName //!< The component name
);
//! Initialize ActivePhaser object
//!
void init(const FwSizeType queueDepth, /*!< The queue depth*/
const FwIndexType instance = 0 /*!< The instance number*/
);
//! Configure ActivePhaser object
//!
void configure(U32 cycle_ticks);
//! Register a phased port call
//!
void register_phased(FwIndexType port, U32 length, U32 start = DONT_CARE, U32 context = DONT_CARE);
//! Destroy ActivePhaser object
~ActivePhaser();
private:
// ----------------------------------------------------------------------
// Handler implementations for typed input ports
// ----------------------------------------------------------------------
//! Handler implementation for CycleIn
void CycleIn_handler(FwIndexType portNum, //!< The port number
Os::RawTime& cycleStart //!< Cycle start timestamp
) override;
// ----------------------------------------------------------------------
// Handler implementations for user-defined internal interfaces
// ----------------------------------------------------------------------
//! Handler implementation for Tick
//!
//! An internal port for sending data of type T
void Tick_internalInterfaceHandler() override;
//! Handle a finishing task
//!
FinishStatus finishChild(U32 current_ticks);
//! Handle a starting task
//!
void startChild(U32 current_ticks);
//! Auto-incrementing context helper
//!
U32 getNextContext(FwIndexType port);
//! Calculating the time in cycle
//!
U32 timeInCycle(U32 full_ticks);
Os::Mutex m_lock;
U32 m_cycle; // The number of ticks that makes up a phaser cycle
U32 m_ticks; // The current tick count
U32 m_ticks_rollover; // Roll-over value for ticks
U32 m_last_start_ticks;
U32 m_last_cycle_ticks;
U32 m_cycle_count;
PhaserStateTable m_state;
};
} // namespace Svc
#endif