Skip to content

Commit

Permalink
Use ComStub and ComQueue (#145)
Browse files Browse the repository at this point in the history
* Usage ComStub and ComQueue

* formatting

* spelling

* Review recommendations

* rename (de)framer

* replace staticMemory with bufferManager

* comStatus through framer

* Fix buffer sizes
  • Loading branch information
thomas-bc committed Jun 8, 2023
1 parent 249cc72 commit 4e7c6ab
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 56 deletions.
5 changes: 3 additions & 2 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cmake
cmakelists
cmp
commonprefix
Comms
config
configparser
configs
Expand All @@ -32,7 +33,7 @@ datetime
dedent
deduplicated
deepcopy
Deframer
deframer
deframing
DEPS
deser
Expand All @@ -50,7 +51,7 @@ dirone
dirs
distutils
doctest
Drv
drv
dumpable
Dxyz
elif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,22 @@ module {{cookiecutter.deployment_name}} {
stack size Default.STACK_SIZE \
priority 100

instance fileDownlink: Svc.FileDownlink base id 0x0700 \
instance comQueue: Svc.ComQueue base id 0x0700 \
queue size Default.QUEUE_SIZE \
stack size Default.STACK_SIZE \
priority 100 \

instance fileDownlink: Svc.FileDownlink base id 0x0800 \
queue size 30 \
stack size Default.STACK_SIZE \
priority 100

instance fileManager: Svc.FileManager base id 0x0800 \
instance fileManager: Svc.FileManager base id 0x0900 \
queue size 30 \
stack size Default.STACK_SIZE \
priority 100

instance fileUplink: Svc.FileUplink base id 0x0900 \
instance fileUplink: Svc.FileUplink base id 0x0A00 \
queue size 30 \
stack size Default.STACK_SIZE \
priority 100
Expand Down Expand Up @@ -95,30 +100,30 @@ module {{cookiecutter.deployment_name}} {

@ Communications driver. May be swapped with other comm drivers like UART
@ Note: Here we have TCP reliable uplink and UDP (low latency) downlink
instance comm: Drv.ByteStreamDriverModel base id 0x4000 \
instance comDriver: Drv.ByteStreamDriverModel base id 0x4000 \
type "Drv::TcpClient" \ # type specified to select implementor of ByteStreamDriverModel
at "../../Drv/TcpClient/TcpClient.hpp" # location of above implementor must also be specified

instance downlink: Svc.Framer base id 0x4100
instance framer: Svc.Framer base id 0x4100

instance fatalAdapter: Svc.AssertFatalAdapter base id 0x4200

instance fatalHandler: Svc.FatalHandler base id 0x4300

instance fileUplinkBufferManager: Svc.BufferManager base id 0x4400
instance bufferManager: Svc.BufferManager base id 0x4400

instance linuxTime: Svc.Time base id 0x4500 \
type "Svc::LinuxTime" \
at "../../Svc/LinuxTime/LinuxTime.hpp"

instance rateGroupDriver: Svc.RateGroupDriver base id 0x4600

instance staticMemory: Svc.StaticMemory base id 0x4700

instance textLogger: Svc.PassiveTextLogger base id 0x4800

instance uplink: Svc.Deframer base id 0x4900
instance deframer: Svc.Deframer base id 0x4900

instance systemResources: Svc.SystemResources base id 0x4A00

instance comStub: Svc.ComStub base id 0x4B00

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ module {{cookiecutter.deployment_name}} {
rateGroup3
}

enum Ports_StaticMemory {
downlink
uplink
}

topology {{cookiecutter.deployment_name}} {

# ----------------------------------------------------------------------
Expand All @@ -26,24 +21,25 @@ module {{cookiecutter.deployment_name}} {
instance tlmSend
instance cmdDisp
instance cmdSeq
instance comm
instance downlink
instance comDriver
instance comQueue
instance comStub
instance deframer
instance eventLogger
instance fatalAdapter
instance fatalHandler
instance fileDownlink
instance fileManager
instance fileUplink
instance fileUplinkBufferManager
instance bufferManager
instance framer
instance linuxTime
instance prmDb
instance rateGroup1
instance rateGroup2
instance rateGroup3
instance rateGroupDriver
instance staticMemory
instance textLogger
instance uplink
instance systemResources

# ----------------------------------------------------------------------
Expand All @@ -70,15 +66,23 @@ module {{cookiecutter.deployment_name}} {

connections Downlink {

tlmSend.PktSend -> downlink.comIn
eventLogger.PktSend -> downlink.comIn
fileDownlink.bufferSendOut -> downlink.bufferIn
eventLogger.PktSend -> comQueue.comQueueIn[0]
tlmSend.PktSend -> comQueue.comQueueIn[1]
fileDownlink.bufferSendOut -> comQueue.buffQueueIn[0]

comQueue.comQueueSend -> framer.comIn
comQueue.buffQueueSend -> framer.bufferIn

downlink.framedAllocate -> staticMemory.bufferAllocate[Ports_StaticMemory.downlink]
downlink.framedOut -> comm.send
downlink.bufferDeallocate -> fileDownlink.bufferReturn
framer.framedAllocate -> bufferManager.bufferGetCallee
framer.framedOut -> comStub.comDataIn
framer.bufferDeallocate -> fileDownlink.bufferReturn

comm.deallocate -> staticMemory.bufferDeallocate[Ports_StaticMemory.downlink]
comDriver.deallocate -> bufferManager.bufferSendIn
comDriver.ready -> comStub.drvConnected

comStub.comStatus -> framer.comStatusIn
framer.comStatusOut -> comQueue.comStatusIn
comStub.drvDataOut -> comDriver.send

}

Expand All @@ -104,7 +108,7 @@ module {{cookiecutter.deployment_name}} {
rateGroupDriver.CycleOut[Ports_RateGroups.rateGroup3] -> rateGroup3.CycleIn
rateGroup3.RateGroupMemberOut[0] -> $health.Run
rateGroup3.RateGroupMemberOut[1] -> blockDrv.Sched
rateGroup3.RateGroupMemberOut[2] -> fileUplinkBufferManager.schedIn
rateGroup3.RateGroupMemberOut[2] -> bufferManager.schedIn
}

connections Sequencer {
Expand All @@ -114,17 +118,19 @@ module {{cookiecutter.deployment_name}} {

connections Uplink {

comm.allocate -> staticMemory.bufferAllocate[Ports_StaticMemory.uplink]
comm.$recv -> uplink.framedIn
uplink.framedDeallocate -> staticMemory.bufferDeallocate[Ports_StaticMemory.uplink]
comDriver.allocate -> bufferManager.bufferGetCallee
comDriver.$recv -> comStub.drvDataIn
comStub.comDataOut -> deframer.framedIn

deframer.framedDeallocate -> bufferManager.bufferSendIn
deframer.comOut -> cmdDisp.seqCmdBuff

uplink.comOut -> cmdDisp.seqCmdBuff
cmdDisp.seqCmdStatus -> uplink.cmdResponseIn
cmdDisp.seqCmdStatus -> deframer.cmdResponseIn

uplink.bufferAllocate -> fileUplinkBufferManager.bufferGetCallee
uplink.bufferOut -> fileUplink.bufferSendIn
uplink.bufferDeallocate -> fileUplinkBufferManager.bufferSendIn
fileUplink.bufferSendOut -> fileUplinkBufferManager.bufferSendIn
deframer.bufferAllocate -> bufferManager.bufferGetCallee
deframer.bufferOut -> fileUplink.bufferSendIn
deframer.bufferDeallocate -> bufferManager.bufferSendIn
fileUplink.bufferSendOut -> bufferManager.bufferSendIn
}

connections {{cookiecutter.deployment_name}} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<channel name="cmdSeq.CS_SequencesCompleted"/>
<channel name="fileUplink.FilesReceived"/>
<channel name="fileUplink.PacketsReceived"/>
<channel name="fileUplinkBufferManager.TotalBuffs"/>
<channel name="fileUplinkBufferManager.CurrBuffs"/>
<channel name="fileUplinkBufferManager.HiBuffs"/>
<channel name="bufferManager.TotalBuffs"/>
<channel name="bufferManager.CurrBuffs"/>
<channel name="bufferManager.HiBuffs"/>
<channel name="fileDownlink.FilesSent"/>
<channel name="fileDownlink.PacketsSent"/>
<channel name="fileManager.CommandsExecuted"/>
Expand All @@ -32,15 +32,20 @@
<channel name="fileDownlink.Warnings"/>
<channel name="health.PingLateWarnings"/>
<channel name="fileManager.Errors"/>
<channel name="fileUplinkBufferManager.NoBuffs"/>
<channel name="fileUplinkBufferManager.EmptyBuffs"/>
<channel name="bufferManager.NoBuffs"/>
<channel name="bufferManager.EmptyBuffs"/>
<channel name="fileManager.Errors"/>
</packet>

<packet name="DriveTlm" id="3" level="1">
<channel name="blockDrv.BD_Cycles"/>
</packet>

<packet name="Comms" id="4" level="1">
<channel name="comQueue.comQueueDepth"/>
<channel name="comQueue.buffQueueDepth"/>
</packet>

<packet name="SystemRes1" id="5" level="2">
<channel name="systemResources.MEMORY_TOTAL"/>
<channel name="systemResources.MEMORY_USED"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Fw::MallocAllocator mallocator;
Svc::FprimeFraming framing;
Svc::FprimeDeframing deframing;

Svc::ComQueue::QueueConfigurationTable configurationTable;

// The reference topology divides the incoming clock signal (1Hz) into sub-signals: 1Hz, 1/2Hz, and 1/4Hz
NATIVE_INT_TYPE rateGroupDivisors[Svc::RateGroupDriver::DIVIDER_SIZE] = {1, 2, 4};

Expand All @@ -48,9 +50,14 @@ enum TopologyConstants {
FILE_DOWNLINK_FILE_QUEUE_DEPTH = 10,
HEALTH_WATCHDOG_CODE = 0x123,
COMM_PRIORITY = 100,
UPLINK_BUFFER_MANAGER_STORE_SIZE = 3000,
UPLINK_BUFFER_MANAGER_QUEUE_SIZE = 30,
UPLINK_BUFFER_MANAGER_ID = 200
// bufferManager constants
FRAMER_BUFFER_SIZE = FW_MAX(FW_COM_BUFFER_MAX_SIZE, FW_FILE_BUFFER_MAX_SIZE + sizeof(U32)) + HASH_DIGEST_LENGTH + Svc::FpFrameHeader::SIZE,
FRAMER_BUFFER_COUNT = 30,
DEFRAMER_BUFFER_SIZE = FW_MAX(FW_COM_BUFFER_MAX_SIZE, FW_FILE_BUFFER_MAX_SIZE + sizeof(U32)),
DEFRAMER_BUFFER_COUNT = 30,
COM_DRIVER_BUFFER_SIZE = 3000,
COM_DRIVER_BUFFER_COUNT = 30,
BUFFER_MANAGER_ID = 200
};

// Ping entries are autocoded, however; this code is not properly exported. Thus, it is copied here.
Expand Down Expand Up @@ -102,16 +109,29 @@ void configureTopology() {
// Buffer managers need a configured set of buckets and an allocator used to allocate memory for those buckets.
Svc::BufferManager::BufferBins upBuffMgrBins;
memset(&upBuffMgrBins, 0, sizeof(upBuffMgrBins));
upBuffMgrBins.bins[0].bufferSize = UPLINK_BUFFER_MANAGER_STORE_SIZE;
upBuffMgrBins.bins[0].numBuffers = UPLINK_BUFFER_MANAGER_QUEUE_SIZE;
fileUplinkBufferManager.setup(UPLINK_BUFFER_MANAGER_ID, 0, mallocator, upBuffMgrBins);
upBuffMgrBins.bins[0].bufferSize = FRAMER_BUFFER_SIZE;
upBuffMgrBins.bins[0].numBuffers = FRAMER_BUFFER_COUNT;
upBuffMgrBins.bins[1].bufferSize = DEFRAMER_BUFFER_SIZE;
upBuffMgrBins.bins[1].numBuffers = DEFRAMER_BUFFER_COUNT;
upBuffMgrBins.bins[2].bufferSize = COM_DRIVER_BUFFER_SIZE;
upBuffMgrBins.bins[2].numBuffers = COM_DRIVER_BUFFER_COUNT;
bufferManager.setup(BUFFER_MANAGER_ID, 0, mallocator, upBuffMgrBins);

// Framer and Deframer components need to be passed a protocol handler
downlink.setup(framing);
uplink.setup(deframing);
framer.setup(framing);
deframer.setup(deframing);

// Note: Uncomment when using Svc:TlmPacketizer
//tlmSend.setPacketList({{cookiecutter.deployment_name}}PacketsPkts, {{cookiecutter.deployment_name}}PacketsIgnore, 1);

// Events (highest-priority)
configurationTable.entries[0] = {.depth = 100, .priority = 0};
// Telemetry
configurationTable.entries[1] = {.depth = 500, .priority = 2};
// File Downlink
configurationTable.entries[2] = {.depth = 100, .priority = 1};
// Allocation identifier is 0 as the MallocAllocator discards it
comQueue.configure(configurationTable, 0, mallocator);
}

// Public functions for use in main program are namespaced with deployment name {{cookiecutter.deployment_name}}
Expand All @@ -135,8 +155,8 @@ void setupTopology(const TopologyState& state) {
if (state.hostname != nullptr && state.port != 0) {
Os::TaskString name("ReceiveTask");
// Uplink is configured for receive so a socket task is started
comm.configure(state.hostname, state.port);
comm.startSocketTask(name, true, COMM_PRIORITY, Default::STACK_SIZE);
comDriver.configure(state.hostname, state.port);
comDriver.startSocketTask(name, true, COMM_PRIORITY, Default::STACK_SIZE);
}
}

Expand Down Expand Up @@ -172,11 +192,11 @@ void teardownTopology(const TopologyState& state) {
freeThreads(state);

// Other task clean-up.
comm.stopSocketTask();
(void)comm.joinSocketTask(nullptr);
comDriver.stopSocketTask();
(void)comDriver.joinSocketTask(nullptr);

// Resource deallocation
cmdSeq.deallocateBuffer(mallocator);
fileUplinkBufferManager.cleanup();
bufferManager.cleanup();
}
}; // namespace {{cookiecutter.deployment_name}}

0 comments on commit 4e7c6ab

Please sign in to comment.