| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | ||
| 16 | #include <Fw/Types/MallocAllocator.hpp> | ||
| 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 | ||
| 22 | Fw::MallocAllocator mallocator; | ||
| 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 | ||
| 26 | Svc::RateGroupDriver::DividerSet rateGroupDivisorsSet{{{1, 0}, {2, 0}, {4, 0}}}; | ||
| 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. | ||
| 30 | Svc::ActiveRateGroup::ContextArray rateGroup1Context(0); | ||
| 31 | Svc::ActiveRateGroup::ContextArray rateGroup2Context(0); | ||
| 32 | Svc::ActiveRateGroup::ContextArray rateGroup3Context(0); | ||
| 33 | |||
| 34 | enum TopologyConstants { | ||
| 35 | COMM_PRIORITY = 34, | ||
| 36 | }; | ||
| 37 | |||
| 38 | /** | ||
| 39 | * \brief configure/setup components in project-specific way | ||
| 40 | * | ||
| 41 | * This is a *helper* function which configures/sets up each component requiring project specific input. This includes | ||
| 42 | * allocating resources, passing-in arguments, etc. This function may be inlined into the topology setup function if | ||
| 43 | * desired, but is extracted here for clarity. | ||
| 44 | */ | ||
| 45 | 1 | void configureTopology() { | |
| 46 | // Rate group driver needs a divisor list | ||
| 47 | 1 | rateGroupDriverComp.configure(rateGroupDivisorsSet); | |
| 48 | |||
| 49 | // Rate groups require context arrays. Empty for Reference example. | ||
| 50 | 1 | rateGroup1Comp.configure(rateGroup1Context); | |
| 51 | 1 | rateGroup2Comp.configure(rateGroup2Context); | |
| 52 | 1 | rateGroup3Comp.configure(rateGroup3Context); | |
| 53 | |||
| 54 | // Command sequencer needs to allocate memory to hold contents of command sequences | ||
| 55 | 1 | cmdSeq.allocateBuffer(0, mallocator, 5 * 1024); | |
| 56 | |||
| 57 | // Restrict uplinked files to a sandbox directory to prevent path-traversal writes | ||
| 58 | 1 | FileHandling::fileUplink.configure("/tmp/uplink/"); | |
| 59 | 1 | } | |
| 60 | |||
| 61 | // Public functions for use in main program are namespaced with deployment name Ref | ||
| 62 | namespace Ref { | ||
| 63 | 1 | void setupTopology(const TopologyState& state) { | |
| 64 | // Autocoded initialization. Function provided by autocoder. | ||
| 65 | 1 | initComponents(state); | |
| 66 | // Autocoded id setup. Function provided by autocoder. | ||
| 67 | 1 | setBaseIds(); | |
| 68 | // Autocoded connection wiring. Function provided by autocoder. | ||
| 69 | 1 | connectComponents(); | |
| 70 | // Autocoded configuration. Function provided by autocoder. | ||
| 71 | 1 | configComponents(state); | |
| 72 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | if (state.hostname != nullptr && state.port != 0) { |
| 73 | 1 | comDriver.configure(state.hostname, state.port); | |
| 74 | } | ||
| 75 | // Project-specific component configuration. Function provided above. May be inlined, if desired. | ||
| 76 | 1 | configureTopology(); | |
| 77 | // Autocoded command registration. Function provided by autocoder. | ||
| 78 | 1 | regCommands(); | |
| 79 | // Autocoded parameter loading. Function provided by autocoder. | ||
| 80 | 1 | loadParameters(); | |
| 81 | // Autocoded task kick-off (active components). Function provided by autocoder. | ||
| 82 | 1 | startTasks(state); | |
| 83 | // Initialize socket client communication if and only if there is a valid specification | ||
| 84 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | if (state.hostname != nullptr && state.port != 0) { |
| 85 |
1/1✓ Branch 1 taken 1 times.
|
1 | Os::TaskString name("ReceiveTask"); |
| 86 |
1/1✓ Branch 1 taken 1 times.
|
1 | comDriver.start(name, COMM_PRIORITY, Default::STACK_SIZE); |
| 87 | 1 | } | |
| 88 | 1 | } | |
| 89 | |||
| 90 | 1 | void startRateGroups(const Fw::TimeInterval& interval) { | |
| 91 | // This timer drives the fundamental tick rate of the system. | ||
| 92 | // Svc::RateGroupDriver will divide this down to the slower rate groups. | ||
| 93 | // This call will block until the stopRateGroups() call is made. | ||
| 94 | // For this Linux demo, that call is made from a signal handler. | ||
| 95 | 1 | linuxTimer.startTimer(interval); | |
| 96 | 1 | } | |
| 97 | |||
| 98 | 1 | void stopRateGroups() { | |
| 99 | 1 | linuxTimer.quit(); | |
| 100 | 1 | } | |
| 101 | |||
| 102 | 1 | void teardownTopology(const TopologyState& state) { | |
| 103 | // Autocoded (active component) task clean-up. Functions provided by topology autocoder. | ||
| 104 | 1 | stopTasks(state); | |
| 105 | 1 | freeThreads(state); | |
| 106 | |||
| 107 | // Stop the comDriver component, free thread | ||
| 108 | 1 | comDriver.stop(); | |
| 109 | 1 | (void)comDriver.join(); | |
| 110 | |||
| 111 | // Resource deallocation | ||
| 112 | 1 | cmdSeq.deallocateBuffer(mallocator); | |
| 113 | 1 | tearDownComponents(state); | |
| 114 | 1 | deinitComponents(state); | |
| 115 | 1 | } | |
| 116 | } // namespace Ref | ||
| 117 |