10 #include <type_traits> 21 ComQueue ::QueueConfigurationTable ::QueueConfigurationTable() {
22 static_assert(static_cast<FwUnsignedIndexType>(std::numeric_limits<FwIndexType>::max()) >=
24 "Number of entries must fit into FwIndexType");
26 this->entries[i].priority = 0;
27 this->entries[i].depth = 0;
36 m_allocation(nullptr) {
39 this->m_throttle[i] =
false;
47 if ((this->m_allocator !=
nullptr) && (this->m_allocation !=
nullptr)) {
48 this->m_allocator->
deallocate(this->m_allocationId, this->m_allocation);
59 this->m_allocator = &allocator;
60 this->m_allocationId = allocationId;
61 this->m_allocation =
nullptr;
79 static_cast<FwAssertArgType>(
TOTAL_PORT_COUNT), static_cast<FwAssertArgType>(entryIndex));
85 QueueMetadata& entry = this->m_prioritizedList[currentPriorityIndex];
88 entry.index = entryIndex;
93 FW_ASSERT((std::numeric_limits<FwSizeType>::max() / entry.depth) >= entry.msgSize,
94 static_cast<FwAssertArgType>(entry.depth), static_cast<FwAssertArgType>(entry.msgSize));
95 FW_ASSERT(std::numeric_limits<FwSizeType>::max() - (entry.depth * entry.msgSize) >= totalAllocation);
96 totalAllocation += entry.depth * entry.msgSize;
97 currentPriorityIndex++;
102 bool recoverable =
false;
103 this->m_allocation = this->m_allocator->
allocate(this->m_allocationId, totalAllocation, recoverable);
111 FwSizeType allocationSize = this->m_prioritizedList[i].depth * this->m_prioritizedList[i].msgSize;
113 static_cast<FwAssertArgType>(this->m_prioritizedList[i].index));
114 FW_ASSERT((allocationSize + allocationOffset) <= totalAllocation, static_cast<FwAssertArgType>(allocationSize),
115 static_cast<FwAssertArgType>(allocationOffset), static_cast<FwAssertArgType>(totalAllocation));
118 if (allocationSize > 0) {
119 this->m_queues[this->m_prioritizedList[i].index].
setup(
120 reinterpret_cast<U8*>(this->m_allocation) + allocationOffset, allocationSize,
121 this->m_prioritizedList[i].depth, this->m_prioritizedList[i].msgSize);
123 allocationOffset += allocationSize;
126 FW_ASSERT(allocationOffset == totalAllocation, static_cast<FwAssertArgType>(allocationOffset),
127 static_cast<FwAssertArgType>(totalAllocation));
153 switch (this->m_state) {
157 this->m_state = READY;
158 this->processQueue();
160 FW_ASSERT((this->m_state == WAITING || this->m_state == READY),
161 static_cast<FwAssertArgType>(this->m_state));
163 this->m_state = WAITING;
169 FW_ASSERT(0, static_cast<FwAssertArgType>(this->m_state));
174 void ComQueue::run_handler(
const FwIndexType portNum, U32 context) {
176 ComQueueDepth comQueueDepth;
177 for (U32 i = 0; i < comQueueDepth.SIZE; i++) {
184 BuffQueueDepth buffQueueDepth;
185 for (U32 i = 0; i < buffQueueDepth.SIZE; i++) {
193 static_assert(std::numeric_limits<FwIndexType>::is_signed,
"FwIndexType must be signed");
201 if (bufferReturnPortNum >= 0) {
204 static_cast<FwAssertArgType>(bufferReturnPortNum));
223 bool ComQueue::enqueue(
const FwIndexType queueNum, QueueType queueType,
const U8* data,
const FwSizeType size) {
228 static_cast<FwAssertArgType>(queueType), static_cast<FwAssertArgType>(queueNum));
231 bool rvStatus =
true;
232 FW_ASSERT(expectedSize == size, static_cast<FwAssertArgType>(size), static_cast<FwAssertArgType>(expectedSize));
233 FW_ASSERT(portNum >= 0, static_cast<FwAssertArgType>(portNum));
236 if (!this->m_throttle[queueNum]) {
238 this->m_throttle[queueNum] =
true;
244 if (this->m_state == READY) {
245 this->processQueue();
260 context.
set_apid(static_cast<ComCfg::APID::T>(descriptor));
265 this->m_state = WAITING;
277 context.
set_apid(static_cast<ComCfg::APID::T>(descriptor));
282 this->m_state = WAITING;
285 void ComQueue::processQueue() {
293 for (priorityIndex = 0; priorityIndex <
TOTAL_PORT_COUNT; priorityIndex++) {
294 QueueMetadata& entry = this->m_prioritizedList[priorityIndex];
305 queue.
dequeue(reinterpret_cast<U8*>(&comBuffer),
sizeof(comBuffer));
306 this->sendComBuffer(comBuffer, entry.index);
309 queue.
dequeue(reinterpret_cast<U8*>(&buffer),
sizeof(buffer));
310 this->sendBuffer(buffer, entry.index);
314 this->m_throttle[entry.index] =
false;
317 sendPriority = entry.priority;
324 for (priorityIndex++;
325 priorityIndex <
TOTAL_PORT_COUNT && (this->m_prioritizedList[priorityIndex].priority == sendPriority);
328 QueueMetadata temp = this->m_prioritizedList[priorityIndex];
329 this->m_prioritizedList[priorityIndex] = this->m_prioritizedList[priorityIndex - 1];
330 this->m_prioritizedList[priorityIndex - 1] = temp;
Serialization/Deserialization operation was successful.
FwIdType FwPacketDescriptorType
The type of a com packet descriptor.
std::make_unsigned< FwIndexType >::type FwUnsignedIndexType
PlatformSizeType FwSizeType
void tlmWrite_buffQueueDepth(const Svc::BuffQueueDepth &arg, Fw::Time _tlmTime=Fw::Time()) const
QueueConfigurationEntry entries[TOTAL_PORT_COUNT]
configuration table for each queue
virtual void * allocate(const FwEnumStoreType identifier, FwSizeType &size, bool &recoverable)=0
Allocate memory.
static const FwIndexType TOTAL_PORT_COUNT
Total count of input buffer ports and thus total queues.
ComQueue(const char *const compName)
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataOut.
No room left in the buffer to serialize data.
void clear_high_water_mark()
bool isConnected_bufferReturnOut_OutputPort(FwIndexType portNum)
static const FwIndexType BUFFER_PORT_COUNT
static const FwIndexType COM_PORT_COUNT
< Count of Fw::Com input ports and thus Fw::Com queues
void setup(U8 *const storage, const FwSizeType storage_size, const FwSizeType depth, const FwSizeType message_size)
setup the queue object to setup storage
FwIndexType get_comQueueIndex() const
Get member comQueueIndex.
SerializeStatus
forward declaration for string
ExternalSerializeBufferWithMemberCopy getDeserializer()
Serializable::SizeType getBuffLength() const
returns current buffer size
FwIndexType priority
Priority of the queue [0, TOTAL_PORT_COUNT)
Fw::SerializeStatus enqueue(const U8 *const message, const FwSizeType size)
pushes a fixed-size message onto the back of the queue
FwSizeType depth
Depth of the queue [0, infinity)
void log_WARNING_HI_QueueOverflow(Svc::QueueType queueType, U32 index) const
U8 * getBuffAddr()
gets buffer address for data filling
uint8_t U8
8-bit unsigned integer
void set_comQueueIndex(FwIndexType comQueueIndex)
Set member comQueueIndex.
FwSizeType get_high_water_mark() const
PlatformIndexType FwIndexType
FwSizeType SizeType
The size type for a buffer - for backwards compatibility.
C++ header for working with basic fprime types.
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Type used to pass context info between components during framing/deframing.
void tlmWrite_comQueueDepth(const Svc::ComQueueDepth &arg, Fw::Time _tlmTime=Fw::Time()) const
void set_apid(ComCfg::APID::T apid)
Set member apid.
RateGroupDivider component implementation.
virtual void deallocate(const FwEnumStoreType identifier, void *ptr)=0
Deallocate memory.
FwSizeType getQueueSize() const
Fw::SerializeStatus dequeue(U8 *const message, const FwSizeType size)
pops a fixed-size message off the front of the queue
void configure(QueueConfigurationTable queueConfig, FwEnumStoreType allocationId, Fw::MemAllocator &allocator)
SerializeStatus deserializeTo(U8 &val)
deserialize 8-bit unsigned int
Auto-generated base for ComQueue component.
void bufferReturnOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferReturnOut.