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));
92 QueueMetadata& entry = this->m_prioritizedList[currentPriorityIndex];
97 entry.index = entryIndex;
103 FW_ASSERT((std::numeric_limits<FwSizeType>::max() / entry.depth) >= entry.msgSize,
104 static_cast<FwAssertArgType>(entry.depth), static_cast<FwAssertArgType>(entry.msgSize));
105 FW_ASSERT(std::numeric_limits<FwSizeType>::max() - (entry.depth * entry.msgSize) >= totalAllocation);
106 totalAllocation += entry.depth * entry.msgSize;
107 currentPriorityIndex++;
112 bool recoverable =
false;
113 FwSizeType actualAllocation = totalAllocation;
114 this->m_allocation = this->m_allocator->
allocate(this->m_allocationId, actualAllocation, recoverable);
115 FW_ASSERT(this->m_allocation !=
nullptr);
116 FW_ASSERT(actualAllocation >= totalAllocation, static_cast<FwAssertArgType>(actualAllocation),
117 static_cast<FwAssertArgType>(totalAllocation));
125 FwSizeType allocationSize = this->m_prioritizedList[i].depth * this->m_prioritizedList[i].msgSize;
127 static_cast<FwAssertArgType>(this->m_prioritizedList[i].index));
128 FW_ASSERT((allocationSize + allocationOffset) <= totalAllocation, static_cast<FwAssertArgType>(allocationSize),
129 static_cast<FwAssertArgType>(allocationOffset), static_cast<FwAssertArgType>(totalAllocation));
132 if (allocationSize > 0) {
133 this->m_queues[this->m_prioritizedList[i].index].
setup(
134 reinterpret_cast<U8*>(this->m_allocation) + allocationOffset, allocationSize,
135 this->m_prioritizedList[i].depth, this->m_prioritizedList[i].msgSize, this->m_prioritizedList[i].mode,
136 this->m_prioritizedList[i].overflowMode);
138 allocationOffset += allocationSize;
141 FW_ASSERT(allocationOffset == totalAllocation, static_cast<FwAssertArgType>(allocationOffset),
142 static_cast<FwAssertArgType>(totalAllocation));
149 void ComQueue ::FLUSH_QUEUE_cmdHandler(
FwOpcodeType opCode,
154 FwIndexType queueIndex = this->getQueueNum(queueType, index);
163 this->drainQueue(queueIndex);
167 void ComQueue ::FLUSH_ALL_QUEUES_cmdHandler(
FwOpcodeType opCode, U32 cmdSeq) {
174 void ComQueue::SET_QUEUE_PRIORITY_cmdHandler(
FwOpcodeType opCode,
180 FwIndexType queueIndex = this->getQueueNum(queueType, index);
198 static_cast<FwAssertArgType>(m_prioritizedList[prioIndex].index));
200 if (m_prioritizedList[prioIndex].index == queueIndex) {
201 m_prioritizedList[prioIndex].priority = newPriority;
210 if (m_prioritizedList[j].priority > m_prioritizedList[j + 1].priority) {
212 QueueMetadata temp = m_prioritizedList[j];
213 m_prioritizedList[j] = m_prioritizedList[j + 1];
214 m_prioritizedList[j + 1] = temp;
233 (void)this->enqueue(portNum, data);
242 bool success = this->enqueue(queueNum, fwBuffer);
249 switch (this->m_state) {
253 this->m_state = READY;
254 this->processQueue();
256 FW_ASSERT((this->m_state == WAITING || this->m_state == READY),
257 static_cast<FwAssertArgType>(this->m_state));
259 this->m_state = WAITING;
265 FW_ASSERT(
false, static_cast<FwAssertArgType>(this->m_state));
270 void ComQueue::run_handler(
const FwIndexType portNum, U32 context) {
272 ComQueueDepth comQueueDepth;
274 for (U32 i = 0; i < comQueueDepth.SIZE; i++) {
281 BuffQueueDepth buffQueueDepth;
283 static_cast<FwAssertArgType>(buffQueueDepth.SIZE));
284 for (U32 i = 0; i < buffQueueDepth.SIZE; i++) {
292 static_assert(std::numeric_limits<FwIndexType>::is_signed,
"FwIndexType must be signed");
294 const BufferState previousState = this->m_buffer_state.exchange(OWNED);
295 FW_ASSERT(previousState == UNOWNED, static_cast<FwAssertArgType>(previousState));
303 if (bufferReturnPortNum >= 0) {
306 static_cast<FwAssertArgType>(bufferReturnPortNum));
343 bool preEmptiveOverflow =
false;
346 if (this->m_prioritizedList[i].index == queueNum &&
348 queue.
getQueueSize() >= this->m_prioritizedList[i].depth) {
356 preEmptiveOverflow =
true;
365 bool ComQueue::handleEnqueueStatus(
const FwIndexType queueNum,
368 const bool preEmptiveOverflow,
372 if (!this->m_throttle[queueNum]) {
374 this->m_throttle[queueNum] =
true;
379 if (this->m_state == READY) {
380 this->processQueue();
396 context.
set_apid(static_cast<ComCfg::Apid::T>(descriptor));
398 const BufferState previousState = this->m_buffer_state.exchange(UNOWNED);
399 FW_ASSERT(previousState == OWNED, static_cast<FwAssertArgType>(previousState));
402 this->m_state = WAITING;
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;
434 status = queue.
dequeue(comBuffer);
439 status = queue.
dequeue(buffer);
445 void ComQueue::processQueue() {
453 for (priorityIndex = 0; priorityIndex <
TOTAL_PORT_COUNT; priorityIndex++) {
454 QueueMetadata& entry = this->m_prioritizedList[priorityIndex];
465 FW_ASSERT(this->m_buffer_state.load() == OWNED);
466 auto dequeue_status = queue.
dequeue(this->m_dequeued_com_buffer);
468 static_cast<FwAssertArgType>(dequeue_status));
469 this->sendComBuffer(this->m_dequeued_com_buffer, entry.index);
472 auto dequeue_status = queue.
dequeue(buffer);
474 static_cast<FwAssertArgType>(dequeue_status));
475 this->sendBuffer(buffer, entry.index);
479 this->m_throttle[entry.index] =
false;
482 sendPriority = entry.priority;
489 for (priorityIndex++;
490 priorityIndex <
TOTAL_PORT_COUNT && (this->m_prioritizedList[priorityIndex].priority == sendPriority);
493 QueueMetadata temp = this->m_prioritizedList[priorityIndex];
494 this->m_prioritizedList[priorityIndex] = this->m_prioritizedList[priorityIndex - 1];
495 this->m_prioritizedList[priorityIndex - 1] = temp;
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()
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 when serialized: buffer + stored size
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
Size of Fw::Buffer when serialized.
Auto-generated base for ComQueue component.