F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
RefTopology.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Topology.cpp
3 // \author mstarch
4 // \brief cpp file containing the topology instantiation code
5 //
6 // \copyright
7 // Copyright 2009-2022, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 // ======================================================================
11 
12 // Provides access to autocoded functions
13 #include <Ref/Top/RefTopologyAc.hpp>
14 
15 // Necessary project-specified types
17 
18 // Allows easy reference to objects in FPP/autocoder required namespaces
19 using namespace Ref;
20 
21 // Instantiate a malloc allocator for cmdSeq buffer allocation
23 
24 // The reference topology divides the incoming clock signal (1Hz) into sub-signals: 1Hz, 1/2Hz, and 1/4Hz and
25 // zero offset for all the dividers
27 
28 // Rate groups may supply a context token to each of the attached children whose purpose is set by the project. The
29 // reference topology sets each token to zero as these contexts are unused in this project.
33 
36 };
37 
46  // Rate group driver needs a divisor list
47  rateGroupDriverComp.configure(rateGroupDivisorsSet);
48 
49  // Rate groups require context arrays. Empty for Reference example.
50  rateGroup1Comp.configure(rateGroup1Context, FW_NUM_ARRAY_ELEMENTS(rateGroup1Context));
51  rateGroup2Comp.configure(rateGroup2Context, FW_NUM_ARRAY_ELEMENTS(rateGroup2Context));
52  rateGroup3Comp.configure(rateGroup3Context, FW_NUM_ARRAY_ELEMENTS(rateGroup3Context));
53 
54  // Command sequencer needs to allocate memory to hold contents of command sequences
55  cmdSeq.allocateBuffer(0, mallocator, 5 * 1024);
56 }
57 
58 // Public functions for use in main program are namespaced with deployment name Ref
59 namespace Ref {
60 void setupTopology(const TopologyState& state) {
61  // Autocoded initialization. Function provided by autocoder.
62  initComponents(state);
63  // Autocoded id setup. Function provided by autocoder.
64  setBaseIds();
65  // Autocoded connection wiring. Function provided by autocoder.
66  connectComponents();
67  // Autocoded command registration. Function provided by autocoder.
68  regCommands();
69  // Autocoded configuration. Function provided by autocoder.
70  configComponents(state);
71  if (state.hostname != nullptr && state.port != 0) {
72  comDriver.configure(state.hostname, state.port);
73  }
74  // Project-specific component configuration. Function provided above. May be inlined, if desired.
76  // Autocoded parameter loading. Function provided by autocoder.
77  loadParameters();
78  // Autocoded task kick-off (active components). Function provided by autocoder.
79  startTasks(state);
80  // Initialize socket client communication if and only if there is a valid specification
81  if (state.hostname != nullptr && state.port != 0) {
82  Os::TaskString name("ReceiveTask");
83  comDriver.start(name, COMM_PRIORITY, Default::STACK_SIZE);
84  }
85 }
86 
87 void startRateGroups(const Fw::TimeInterval& interval) {
88  // This timer drives the fundamental tick rate of the system.
89  // Svc::RateGroupDriver will divide this down to the slower rate groups.
90  // This call will block until the stopRateGroups() call is made.
91  // For this Linux demo, that call is made from a signal handler.
92  linuxTimer.startTimer(interval);
93 }
94 
96  linuxTimer.quit();
97 }
98 
99 void teardownTopology(const TopologyState& state) {
100  // Autocoded (active component) task clean-up. Functions provided by topology autocoder.
101  stopTasks(state);
102  freeThreads(state);
103 
104  // Stop the comDriver component, free thread
105  comDriver.stop();
106  (void)comDriver.join();
107 
108  // Resource deallocation
109  cmdSeq.deallocateBuffer(mallocator);
110  tearDownComponents(state);
111  deinitComponents(state);
112 }
113 } // namespace Ref
void startRateGroups(const Fw::TimeInterval &interval)
cycle the rate group driver based in a system timer
Definition: RefTopology.cpp:87
Svc::RateGroupDriver::DividerSet rateGroupDivisorsSet
Definition: RefTopology.cpp:26
required type definition to carry state
A MemAllocator implementation class that uses malloc.
void configureTopology()
configure/setup components in project-specific way
Definition: RefTopology.cpp:45
void teardownTopology(const TopologyState &state)
teardown the F´ topology
Definition: RefTopology.cpp:99
TopologyConstants
Definition: RefTopology.cpp:34
U16 port
Port for TCP communication.
malloc based memory allocator
const char * hostname
Hostname for TCP communication.
static constexpr FwIndexType CONNECTION_COUNT_MAX
void stopRateGroups()
stop the rate groups
Definition: RefTopology.cpp:95
void setupTopology(const TopologyState &state)
initialize and run the F´ topology
Definition: RefTopology.cpp:60
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:94
Fw::MallocAllocator mallocator
Definition: RefTopology.cpp:22
U32 rateGroup2Context[Svc::ActiveRateGroup::CONNECTION_COUNT_MAX]
Definition: RefTopology.cpp:31
Struct containing an array of dividers.
U32 rateGroup3Context[Svc::ActiveRateGroup::CONNECTION_COUNT_MAX]
Definition: RefTopology.cpp:32
U32 rateGroup1Context[Svc::ActiveRateGroup::CONNECTION_COUNT_MAX]
Definition: RefTopology.cpp:30