fprime/Ref/Top/RefTopology.cpp
Moises Mata 268e168f23
Restructure core subtopologies and add Svc_Subtopologies target (#3904)
* Modify Com/Ccsds/Fprime ComDriverConfig & TopologyDefs for easier ComDriver config

* Fix BaseID collision

* Removed restrict platform, UART/TCP driver configs different files, CMake switch depending on FPRIME_HAS_SOCKETS

* Add Exclude_FROM_ALL to all subtopology cmake modules

* remove exclude from ComCcsds (needed for Ref)

* Remove exclude from all for testing

* Exclude_from_all only on comLoggerTee, comFprime (not used in Ref)

* Added Svc_Subtopologies target

* Use add_custom_target, spelling fix

* Add Configs to Svc_Subtopologies target

* Removed comDriver as instance within subtopologies, now within project topology

* Take out cmdSeq from ComSubtopologies, put in FileHandling

* Added Subtopology States for all, common pattern users can follow

* Fix Extra newline

* Moved Phased comDriver code into RefTopology.cpp

* Update metadata

check-spelling run (pull_request_target) for subtopology-config-phasing-updates

Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com>
on-behalf-of: @check-spelling <check-spelling-bot@check-spelling.dev>

* Fixed call to default stack size

* Moved cmdSeq from FileHandling subtopology to Ref Root Topology

* Fix integration test

* Remove unneeded Os includes in RefTopology.cpp

* Fix BaseIds

* Add comment for BaseIDs, comDriver configuration order fix

* Restructure of enums within Com Subtopologies

* Correct include for ComCcsds enum headers

* Using namespace syntax change

* Fix BaseIds

* Update metadata

check-spelling run (pull_request_target) for subtopology-config-phasing-updates

Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com>
on-behalf-of: @check-spelling <check-spelling-bot@check-spelling.dev>

* Remove unneeded Dependency

* Add enum at the top

* Fix RefTopology.cpp

* Update Comment

---------

Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com>
Co-authored-by: Moises Mata <moisesmata@users.noreply.github.com>
2025-07-30 10:25:29 -07:00

114 lines
4.5 KiB
C++

// ======================================================================
// \title Topology.cpp
// \author mstarch
// \brief cpp file containing the topology instantiation code
//
// \copyright
// Copyright 2009-2022, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
// ======================================================================
// Provides access to autocoded functions
#include <Ref/Top/RefTopologyAc.hpp>
// Necessary project-specified types
#include <Fw/Types/MallocAllocator.hpp>
// Allows easy reference to objects in FPP/autocoder required namespaces
using namespace Ref;
// Instantiate a malloc allocator for cmdSeq buffer allocation
Fw::MallocAllocator mallocator;
// The reference topology divides the incoming clock signal (1Hz) into sub-signals: 1Hz, 1/2Hz, and 1/4Hz and
// zero offset for all the dividers
Svc::RateGroupDriver::DividerSet rateGroupDivisorsSet{{{1, 0}, {2, 0}, {4, 0}}};
// Rate groups may supply a context token to each of the attached children whose purpose is set by the project. The
// reference topology sets each token to zero as these contexts are unused in this project.
U32 rateGroup1Context[Svc::ActiveRateGroup::CONNECTION_COUNT_MAX] = {};
U32 rateGroup2Context[Svc::ActiveRateGroup::CONNECTION_COUNT_MAX] = {};
U32 rateGroup3Context[Svc::ActiveRateGroup::CONNECTION_COUNT_MAX] = {};
enum TopologyConstants {
COMM_PRIORITY = 100,
};
/**
* \brief configure/setup components in project-specific way
*
* This is a *helper* function which configures/sets up each component requiring project specific input. This includes
* allocating resources, passing-in arguments, etc. This function may be inlined into the topology setup function if
* desired, but is extracted here for clarity.
*/
void configureTopology() {
// Rate group driver needs a divisor list
rateGroupDriverComp.configure(rateGroupDivisorsSet);
// Rate groups require context arrays. Empty for Reference example.
rateGroup1Comp.configure(rateGroup1Context, FW_NUM_ARRAY_ELEMENTS(rateGroup1Context));
rateGroup2Comp.configure(rateGroup2Context, FW_NUM_ARRAY_ELEMENTS(rateGroup2Context));
rateGroup3Comp.configure(rateGroup3Context, FW_NUM_ARRAY_ELEMENTS(rateGroup3Context));
// Command sequencer needs to allocate memory to hold contents of command sequences
cmdSeq.allocateBuffer(0, mallocator, 5 * 1024);
}
// Public functions for use in main program are namespaced with deployment name Ref
namespace Ref {
void setupTopology(const TopologyState& state) {
// Autocoded initialization. Function provided by autocoder.
initComponents(state);
// Autocoded id setup. Function provided by autocoder.
setBaseIds();
// Autocoded connection wiring. Function provided by autocoder.
connectComponents();
// Autocoded command registration. Function provided by autocoder.
regCommands();
// Autocoded configuration. Function provided by autocoder.
configComponents(state);
if (state.hostname != nullptr && state.port != 0) {
comDriver.configure(state.hostname, state.port);
}
// Project-specific component configuration. Function provided above. May be inlined, if desired.
configureTopology();
// Autocoded parameter loading. Function provided by autocoder.
loadParameters();
// Autocoded task kick-off (active components). Function provided by autocoder.
startTasks(state);
//Initialize socket client communication if and only if there is a valid specification
if (state.hostname != nullptr && state.port != 0) {
Os::TaskString name("ReceiveTask");
comDriver.start(name, COMM_PRIORITY, Default::STACK_SIZE);
}
}
void startRateGroups(Fw::TimeInterval interval) {
// This timer drives the fundamental tick rate of the system.
// Svc::RateGroupDriver will divide this down to the slower rate groups.
// This call will block until the stopRateGroups() call is made.
// For this Linux demo, that call is made from a signal handler.
linuxTimer.startTimer(interval.getSeconds()*1000+interval.getUSeconds()/1000);
}
void stopRateGroups() {
linuxTimer.quit();
}
void teardownTopology(const TopologyState& state) {
// Autocoded (active component) task clean-up. Functions provided by topology autocoder.
stopTasks(state);
freeThreads(state);
tearDownComponents(state);
//Stop the comDriver component, free thread
comDriver.stop();
(void)comDriver.join();
// Resource deallocation
cmdSeq.deallocateBuffer(mallocator);
}
} // namespace Ref