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_buffer_state(OWNED),
39 m_allocation(nullptr) {
42 this->m_throttle[i] =
false;
45 static_assert(
TOTAL_PORT_COUNT >= 1,
"ComQueue must have more than one port");
52 if ((this->m_allocator !=
nullptr) && (this->m_allocation !=
nullptr)) {
53 this->m_allocator->
deallocate(this->m_allocationId, this->m_allocation);
64 this->m_allocator = &allocator;
65 this->m_allocationId = allocationId;
66 this->m_allocation =
nullptr;
84 static_cast<FwAssertArgType>(
TOTAL_PORT_COUNT), static_cast<FwAssertArgType>(entryIndex));
89 QueueMetadata& entry = this->m_prioritizedList[currentPriorityIndex];
94 entry.index = entryIndex;
100 if (entry.depth > 0) {
101 FW_ASSERT((std::numeric_limits<FwSizeType>::max() / entry.depth) >= entry.msgSize,
102 static_cast<FwAssertArgType>(entry.depth), static_cast<FwAssertArgType>(entry.msgSize));
103 FW_ASSERT(std::numeric_limits<FwSizeType>::max() - (entry.depth * entry.msgSize) >=
105 totalAllocation += entry.depth * entry.msgSize;
107 currentPriorityIndex++;
114 bool recoverable =
false;
115 FwSizeType actualAllocation = totalAllocation;
116 this->m_allocation = this->m_allocator->
allocate(this->m_allocationId, actualAllocation, recoverable);
117 FW_ASSERT(this->m_allocation !=
nullptr);
118 FW_ASSERT(actualAllocation >= totalAllocation, static_cast<FwAssertArgType>(actualAllocation),
119 static_cast<FwAssertArgType>(totalAllocation));
127 FwSizeType allocationSize = this->m_prioritizedList[i].depth * this->m_prioritizedList[i].msgSize;
129 static_cast<FwAssertArgType>(this->m_prioritizedList[i].index));
130 FW_ASSERT((allocationSize + allocationOffset) <= totalAllocation, static_cast<FwAssertArgType>(allocationSize),
131 static_cast<FwAssertArgType>(allocationOffset), static_cast<FwAssertArgType>(totalAllocation));
134 if (this->m_prioritizedList[i].depth > 0) {
135 this->m_queues[this->m_prioritizedList[i].index].
setup(
136 reinterpret_cast<U8*>(this->m_allocation) + allocationOffset, allocationSize,
137 this->m_prioritizedList[i].depth, this->m_prioritizedList[i].msgSize, this->m_prioritizedList[i].mode,
138 this->m_prioritizedList[i].overflowMode);
140 allocationOffset += allocationSize;
143 FW_ASSERT(allocationOffset == totalAllocation, static_cast<FwAssertArgType>(allocationOffset),
144 static_cast<FwAssertArgType>(totalAllocation));
151 void ComQueue ::FLUSH_QUEUE_cmdHandler(
FwOpcodeType opCode,
156 FwIndexType queueIndex = this->getQueueNum(queueType, index);
165 this->drainQueue(queueIndex);
169 void ComQueue ::FLUSH_ALL_QUEUES_cmdHandler(
FwOpcodeType opCode, U32 cmdSeq) {
176 void ComQueue::SET_QUEUE_PRIORITY_cmdHandler(
FwOpcodeType opCode,
182 FwIndexType queueIndex = this->getQueueNum(queueType, index);
200 static_cast<FwAssertArgType>(m_prioritizedList[prioIndex].index));
202 if (m_prioritizedList[prioIndex].index == queueIndex) {
203 m_prioritizedList[prioIndex].priority = newPriority;
212 if (m_prioritizedList[j].priority > m_prioritizedList[j + 1].priority) {
214 QueueMetadata temp = m_prioritizedList[j];
215 m_prioritizedList[j] = m_prioritizedList[j + 1];
216 m_prioritizedList[j + 1] = temp;
235 (void)this->enqueue(portNum, data);
244 bool success = this->enqueue(queueNum, fwBuffer);
251 switch (this->m_state) {
255 this->m_state = READY;
256 this->processQueue();
258 FW_ASSERT((this->m_state == WAITING || this->m_state == READY),
259 static_cast<FwAssertArgType>(this->m_state));
261 this->m_state = WAITING;
267 FW_ASSERT(
false, static_cast<FwAssertArgType>(this->m_state));
272 void ComQueue::run_handler(
const FwIndexType portNum, U32 context) {
274 ComQueueDepth comQueueDepth;
276 for (U32 i = 0; i < comQueueDepth.SIZE; i++) {
278 comQueueDepth[i] = 0;
279 if (this->getQueueDepth(queueNum) > 0) {
287 BuffQueueDepth buffQueueDepth;
289 static_cast<FwAssertArgType>(buffQueueDepth.SIZE));
290 for (U32 i = 0; i < buffQueueDepth.SIZE; i++) {
292 buffQueueDepth[i] = 0;
293 if (this->getQueueDepth(queueNum) > 0) {
302 static_assert(std::numeric_limits<FwIndexType>::is_signed,
"FwIndexType must be signed");
304 const BufferState previousState = this->m_buffer_state.exchange(OWNED);
305 FW_ASSERT(previousState == UNOWNED, static_cast<FwAssertArgType>(previousState));
313 if (bufferReturnPortNum >= 0) {
316 static_cast<FwAssertArgType>(bufferReturnPortNum));
339 if (this->getQueueDepth(queueNum) == 0) {
353 if (this->getQueueDepth(queueNum) == 0) {
361 bool preEmptiveOverflow =
false;
364 if (this->m_prioritizedList[i].index == queueNum &&
366 queue.
getQueueSize() >= this->m_prioritizedList[i].depth) {
374 preEmptiveOverflow =
true;
383 bool ComQueue::handleEnqueueStatus(
const FwIndexType queueNum,
386 const bool preEmptiveOverflow,
390 if (!this->m_throttle[queueNum]) {
392 this->m_throttle[queueNum] =
true;
397 if (this->m_state == READY) {
398 this->processQueue();
414 context.
set_apid(static_cast<ComCfg::Apid::T>(descriptor));
416 const BufferState previousState = this->m_buffer_state.exchange(UNOWNED);
417 FW_ASSERT(previousState == OWNED, static_cast<FwAssertArgType>(previousState));
420 this->m_state = WAITING;
432 context.
set_apid(static_cast<ComCfg::Apid::T>(descriptor));
434 const BufferState previousState = this->m_buffer_state.exchange(UNOWNED);
435 FW_ASSERT(previousState == OWNED, static_cast<FwAssertArgType>(previousState));
438 this->m_state = WAITING;
444 if (this->getQueueDepth(index) == 0) {
456 status = queue.
dequeue(comBuffer);
461 status = queue.
dequeue(buffer);
467 void ComQueue::processQueue() {
475 for (priorityIndex = 0; priorityIndex <
TOTAL_PORT_COUNT; priorityIndex++) {
476 QueueMetadata& entry = this->m_prioritizedList[priorityIndex];
480 if ((entry.depth == 0) || (queue.
getQueueSize() == 0)) {
487 FW_ASSERT(this->m_buffer_state.load() == OWNED);
488 auto dequeue_status = queue.
dequeue(this->m_dequeued_com_buffer);
490 static_cast<FwAssertArgType>(dequeue_status));
491 this->sendComBuffer(this->m_dequeued_com_buffer, entry.index);
494 auto dequeue_status = queue.
dequeue(buffer);
496 static_cast<FwAssertArgType>(dequeue_status));
497 this->sendBuffer(buffer, entry.index);
501 this->m_throttle[entry.index] =
false;
504 sendPriority = entry.priority;
511 for (priorityIndex++;
512 priorityIndex <
TOTAL_PORT_COUNT && (this->m_prioritizedList[priorityIndex].priority == sendPriority);
515 QueueMetadata temp = this->m_prioritizedList[priorityIndex];
516 this->m_prioritizedList[priorityIndex] = this->m_prioritizedList[priorityIndex - 1];
517 this->m_prioritizedList[priorityIndex - 1] = temp;
529 if (this->m_prioritizedList[i].index == queueNum) {
530 return this->m_prioritizedList[i].depth;
534 FW_ASSERT(
false, static_cast<FwAssertArgType>(queueNum));
Serialization/Deserialization operation was successful.
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
U16 FwPacketDescriptorType
The width of packet descriptors when they are serialized by the framework.
virtual void * allocate(const FwEnumStoreType identifier, FwSizeType &size, bool &recoverable, FwSizeType alignment=alignof(std::max_align_t))=0
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context) const
Invoke output port dataOut.
FwIdType FwOpcodeType
The type of a command opcode.
std::make_unsigned< FwIndexType >::type FwUnsignedIndexType
PlatformSizeType FwSizeType
void tlmWrite_buffQueueDepth(const Svc::BuffQueueDepth &arg, Fw::Time _tlmTime=Fw::Time()) const
void configure(const QueueConfigurationTable &queueConfig, FwEnumStoreType allocationId, Fw::MemAllocator &allocator)
Serialization succeeded, but deleted old data.
QueueConfigurationEntry entries[TOTAL_PORT_COUNT]
configuration table for each queue
static const FwIndexType TOTAL_PORT_COUNT
Total count of input buffer ports and thus total queues.
ComQueue(const char *const compName)
Serializable::SizeType getSize() const override
Get current buffer size.
SerializeStatus deserializeTo(U8 &val, Endianness mode=Endianness::BIG) override
Deserialize an 8-bit unsigned integer value.
void setup(U8 *const storage, const FwSizeType storage_size, const FwSizeType depth, const FwSizeType message_size, const QueueMode mode=QUEUE_FIFO, const QueueOverflowMode overflow_mode=QUEUE_DROP_NEWEST)
setup the queue object to setup storage
No room left in the buffer to serialize data.
void set_apid(ComCfg::Apid::T apid)
Set member apid.
void log_ACTIVITY_HI_QueuePriorityChanged(const Svc::QueueType &queueType, FwIndexType indexType, FwIndexType newPriority) const
void clear_high_water_mark()
size when serialized: buffer + stored size
static const FwIndexType BUFFER_PORT_COUNT
static const FwIndexType COM_PORT_COUNT
< Count of Fw::Com input ports and thus Fw::Com queues
An enumeration of queue data types.
FwIndexType get_comQueueIndex() const
Get member comQueueIndex.
SerializeStatus
forward declaration for string
ExternalSerializeBufferWithMemberCopy getDeserializer()
void log_WARNING_HI_QueueOverflow(const Svc::QueueType &queueType, FwIndexType index) const
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 queue
U8 * getBuffAddr()
Get buffer address for data filling (non-const version)
FwSizeType depth
Depth of the queue [0, infinity)
void bufferReturnOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer) const
Invoke output port bufferReturnOut.
Command successfully executed.
Size of Fw::Buffer when serialized.
Memory Allocation base class.
void set_comQueueIndex(FwIndexType comQueueIndex)
Set member comQueueIndex.
Types::QueueOverflowMode overflowMode
Overflow handling mode (DROP_NEWEST or DROP_OLDEST)
First-In-First-Out: dequeue from front.
enum T e
The raw enum value.
FwSizeType get_high_water_mark() const
PlatformIndexType FwIndexType
Drop the newest (incoming) message on overflow.
FwSizeType SizeType
The size type for a buffer - for backwards compatibility.
Types::QueueMode mode
Queue mode (FIFO or LIFO)
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.
bool isConnected_bufferReturnOut_OutputPort(FwIndexType portNum) const
void tlmWrite_comQueueDepth(const Svc::ComQueueDepth &arg, Fw::Time _tlmTime=Fw::Time()) const
Command failed validation.
RateGroupDivider component implementation.
virtual void deallocate(const FwEnumStoreType identifier, void *ptr)=0
Drop the oldest (front) message on overflow.
Fw::SerializeStatus popFront(U8 *const message, const FwSizeType size)
removes and returns the oldest (front) message regardless of queue mode
FwSizeType getQueueSize() const
Fw::SerializeStatus dequeue(U8 *const message, const FwSizeType size)
pops a fixed-size message off the queue
Auto-generated base for ComQueue component.