mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
113 lines
4.5 KiB
C++
113 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(const 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);
|
|
}
|
|
|
|
void stopRateGroups() {
|
|
linuxTimer.quit();
|
|
}
|
|
|
|
void teardownTopology(const TopologyState& state) {
|
|
// Autocoded (active component) task clean-up. Functions provided by topology autocoder.
|
|
stopTasks(state);
|
|
freeThreads(state);
|
|
|
|
// Stop the comDriver component, free thread
|
|
comDriver.stop();
|
|
(void)comDriver.join();
|
|
|
|
// Resource deallocation
|
|
cmdSeq.deallocateBuffer(mallocator);
|
|
tearDownComponents(state);
|
|
}
|
|
} // namespace Ref
|