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
18 
19 // Allows easy reference to objects in FPP/autocoder required namespaces
20 using namespace Ref;
21 
22 // Instantiate a malloc allocator for cmdSeq buffer allocation
24 
25 namespace Ref {
27 }
28 
29 // The reference topology divides the incoming clock signal (1Hz) into sub-signals: 1Hz, 1/2Hz, and 1/4Hz and
30 // zero offset for all the dividers
32 
33 // Rate groups may supply a context token to each of the attached children whose purpose is set by the project. The
34 // reference topology sets each token to zero as these contexts are unused in this project.
38 
41 };
42 
51  // Rate group driver needs a divisor list
52  rateGroupDriverComp.configure(rateGroupDivisorsSet);
53 
54  // Rate groups require context arrays. Empty for Reference example.
55  rateGroup1Comp.configure(rateGroup1Context);
56  rateGroup2Comp.configure(rateGroup2Context);
57  rateGroup3Comp.configure(rateGroup3Context);
58 
59  // Command sequencer needs to allocate memory to hold contents of command sequences
60  cmdSeq.allocateBuffer(0, mallocator, 5 * 1024);
61 
62  // Restrict file access to the working directory (where PrmDb.dat lives)
63  FileHandling::fileUplink.configure(".");
64  FileHandling::fileDownlink.configure(".");
65  FileHandling::prmDb.configureSandbox(".");
66 }
67 
68 // Public functions for use in main program are namespaced with deployment name Ref
69 namespace Ref {
70 void setupTopology(const TopologyState& state) {
71  // Autocoded initialization. Function provided by autocoder.
72  initComponents(state);
73  // Autocoded id setup. Function provided by autocoder.
74  setBaseIds();
75  // Autocoded connection wiring. Function provided by autocoder.
76  connectComponents();
77  // Autocoded configuration. Function provided by autocoder.
78  configComponents(state);
79  if (state.hostname != nullptr && state.port != 0) {
80  comDriver.configure(state.hostname, state.port);
81  }
82  // Project-specific component configuration. Function provided above. May be inlined, if desired.
84  // Autocoded command registration. Function provided by autocoder.
85  regCommands();
86  // Autocoded parameter file read (prmDb). Function provided by autocoder.
87  readParameters();
88  // Autocoded parameter loading. Function provided by autocoder.
89  loadParameters();
90  // Autocoded task kick-off (active components). Function provided by autocoder.
91  startTasks(state);
92  // Initialize socket client communication if and only if there is a valid specification
93  if (state.hostname != nullptr && state.port != 0) {
94  Os::TaskString name("ReceiveTask");
95  comDriver.start(name, COMM_PRIORITY, Default::STACK_SIZE);
96  }
97 }
98 
99 void startRateGroups(const Fw::TimeInterval& interval) {
100  // This timer drives the fundamental tick rate of the system.
101  // Svc::RateGroupDriver will divide this down to the slower rate groups.
102  // This call will block until the stopRateGroups() call is made.
103  // For this Linux demo, that call is made from a signal handler.
104  linuxTimer.startTimer(interval);
105 }
106 
108  linuxTimer.quit();
109 }
110 
111 void teardownTopology(const TopologyState& state) {
112  // Autocoded (active component) task clean-up. Functions provided by topology autocoder.
113  stopTasks(state);
114  freeThreads(state);
115 
116  // Stop the comDriver component, free thread
117  comDriver.stop();
118  (void)comDriver.join();
119 
120  // Resource deallocation
121  cmdSeq.deallocateBuffer(mallocator);
122  tearDownComponents(state);
123  deinitComponents(state);
124 }
125 } // namespace Ref
void startRateGroups(const Fw::TimeInterval &interval)
cycle the rate group driver based in a system timer
Definition: RefTopology.cpp:99
Svc::RateGroupDriver::DividerSet rateGroupDivisorsSet
Definition: RefTopology.cpp:31
required type definition to carry state
A MemAllocator implementation class that uses malloc.
Svc::ActiveRateGroup::ContextArray rateGroup3Context(0)
void configureTopology()
configure/setup components in project-specific way
Definition: RefTopology.cpp:50
void teardownTopology(const TopologyState &state)
teardown the F´ topology
TopologyConstants
Definition: RefTopology.cpp:39
U16 port
Port for TCP communication.
malloc based memory allocator
const char * hostname
Hostname for TCP communication.
Fw::MemAllocator & memAllocator
Definition: RefTopology.cpp:26
Memory Allocation base class.
Svc::ActiveRateGroup::ContextArray rateGroup1Context(0)
void stopRateGroups()
stop the rate groups
void setupTopology(const TopologyState &state)
initialize and run the F´ topology
Definition: RefTopology.cpp:70
Fw::MallocAllocator mallocator
Definition: RefTopology.cpp:23
Defines a base class for a memory allocator for classes.
Struct containing an array of dividers.
Svc::ActiveRateGroup::ContextArray rateGroup2Context(0)