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));
90 QueueMetadata& entry = this->m_prioritizedList[currentPriorityIndex];
95 entry.index = entryIndex;
100 FW_ASSERT((std::numeric_limits<FwSizeType>::max() / entry.depth) >= entry.msgSize,
101 static_cast<FwAssertArgType>(entry.depth), static_cast<FwAssertArgType>(entry.msgSize));
102 FW_ASSERT(std::numeric_limits<FwSizeType>::max() - (entry.depth * entry.msgSize) >= totalAllocation);
103 totalAllocation += entry.depth * entry.msgSize;
104 currentPriorityIndex++;
109 bool recoverable =
false;
110 this->m_allocation = this->m_allocator->
allocate(this->m_allocationId, totalAllocation, recoverable);
118 FwSizeType allocationSize = this->m_prioritizedList[i].depth * this->m_prioritizedList[i].msgSize;
120 static_cast<FwAssertArgType>(this->m_prioritizedList[i].index));
121 FW_ASSERT((allocationSize + allocationOffset) <= totalAllocation, static_cast<FwAssertArgType>(allocationSize),
122 static_cast<FwAssertArgType>(allocationOffset), static_cast<FwAssertArgType>(totalAllocation));
125 if (allocationSize > 0) {
126 this->m_queues[this->m_prioritizedList[i].index].
setup(
127 reinterpret_cast<U8*>(this->m_allocation) + allocationOffset, allocationSize,
128 this->m_prioritizedList[i].depth, this->m_prioritizedList[i].msgSize, this->m_prioritizedList[i].mode,
129 this->m_prioritizedList[i].overflowMode);
131 allocationOffset += allocationSize;
134 FW_ASSERT(allocationOffset == totalAllocation, static_cast<FwAssertArgType>(allocationOffset),
135 static_cast<FwAssertArgType>(totalAllocation));
144 FwIndexType queueIndex = this->getQueueNum(queueType, index);
152 this->drainQueue(queueIndex);
156 void ComQueue ::FLUSH_ALL_QUEUES_cmdHandler(
FwOpcodeType opCode, U32 cmdSeq) {
163 void ComQueue::SET_QUEUE_PRIORITY_cmdHandler(
FwOpcodeType opCode,
169 FwIndexType queueIndex = this->getQueueNum(queueType, index);
186 if (m_prioritizedList[prioIndex].index == queueIndex) {
187 m_prioritizedList[prioIndex].priority = newPriority;
196 if (m_prioritizedList[j].priority > m_prioritizedList[j + 1].priority) {
198 QueueMetadata temp = m_prioritizedList[j];
199 m_prioritizedList[j] = m_prioritizedList[j + 1];
200 m_prioritizedList[j + 1] = temp;
236 switch (this->m_state) {
240 this->m_state = READY;
241 this->processQueue();
243 FW_ASSERT((this->m_state == WAITING || this->m_state == READY),
244 static_cast<FwAssertArgType>(this->m_state));
246 this->m_state = WAITING;
252 FW_ASSERT(0, static_cast<FwAssertArgType>(this->m_state));
257 void ComQueue::run_handler(
const FwIndexType portNum, U32 context) {
259 ComQueueDepth comQueueDepth;
260 for (U32 i = 0; i < comQueueDepth.SIZE; i++) {
267 BuffQueueDepth buffQueueDepth;
268 for (U32 i = 0; i < buffQueueDepth.SIZE; i++) {
276 static_assert(std::numeric_limits<FwIndexType>::is_signed,
"FwIndexType must be signed");
277 FW_ASSERT(this->m_buffer_state == UNOWNED);
278 this->m_buffer_state = OWNED;
286 if (bufferReturnPortNum >= 0) {
289 static_cast<FwAssertArgType>(bufferReturnPortNum));
308 bool ComQueue::enqueue(
const FwIndexType queueNum, QueueType queueType,
const U8* data,
const FwSizeType size) {
313 static_cast<FwAssertArgType>(queueType), static_cast<FwAssertArgType>(queueNum));
316 FW_ASSERT(expectedSize == size, static_cast<FwAssertArgType>(size), static_cast<FwAssertArgType>(expectedSize));
317 FW_ASSERT(portNum >= 0, static_cast<FwAssertArgType>(portNum));
320 if (!this->m_throttle[queueNum]) {
322 this->m_throttle[queueNum] =
true;
327 if (this->m_state == READY) {
328 this->processQueue();
344 context.
set_apid(static_cast<ComCfg::Apid::T>(descriptor));
346 FW_ASSERT(this->m_buffer_state == OWNED);
347 this->m_buffer_state = UNOWNED;
350 this->m_state = WAITING;
362 context.
set_apid(static_cast<ComCfg::Apid::T>(descriptor));
364 FW_ASSERT(this->m_buffer_state == OWNED);
365 this->m_buffer_state = UNOWNED;
368 this->m_state = WAITING;
383 status = queue.
dequeue(reinterpret_cast<U8*>(&comBuffer),
sizeof(comBuffer));
388 status = queue.
dequeue(reinterpret_cast<U8*>(&buffer),
sizeof(buffer));
394 void ComQueue::processQueue() {
402 for (priorityIndex = 0; priorityIndex <
TOTAL_PORT_COUNT; priorityIndex++) {
403 QueueMetadata& entry = this->m_prioritizedList[priorityIndex];
415 FW_ASSERT(this->m_buffer_state == OWNED);
416 auto dequeue_status =
417 queue.
dequeue(reinterpret_cast<U8*>(&this->m_dequeued_com_buffer),
sizeof(this->m_dequeued_com_buffer));
419 static_cast<FwAssertArgType>(dequeue_status));
420 this->sendComBuffer(this->m_dequeued_com_buffer, entry.index);
423 auto dequeue_status = queue.
dequeue(reinterpret_cast<U8*>(&buffer),
sizeof(buffer));
425 static_cast<FwAssertArgType>(dequeue_status));
426 this->sendBuffer(buffer, entry.index);
430 this->m_throttle[entry.index] =
false;
433 sendPriority = entry.priority;
440 for (priorityIndex++;
441 priorityIndex <
TOTAL_PORT_COUNT && (this->m_prioritizedList[priorityIndex].priority == sendPriority);
444 QueueMetadata temp = this->m_prioritizedList[priorityIndex];
445 this->m_prioritizedList[priorityIndex] = this->m_prioritizedList[priorityIndex - 1];
446 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
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
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.
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataOut.
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(Svc::QueueType queueType, FwIndexType indexType, FwIndexType newPriority) const
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
An enumeration of queue data types.
FwIndexType get_comQueueIndex() const
Get member comQueueIndex.
SerializeStatus
forward declaration for string
void log_WARNING_HI_QueueOverflow(Svc::QueueType queueType, FwIndexType index) const
ExternalSerializeBufferWithMemberCopy getDeserializer()
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
FwSizeType depth
Depth of the queue [0, infinity)
U8 * getBuffAddr()
Get buffer address for data filling (non-const version)
Command successfully executed.
uint8_t U8
8-bit unsigned integer
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.
void tlmWrite_comQueueDepth(const Svc::ComQueueDepth &arg, Fw::Time _tlmTime=Fw::Time()) const
Command failed validation.
RateGroupDivider component implementation.
SerializeStatus deserializeTo(U8 &val, Endianness mode=Endianness::BIG) override
Deserialize an 8-bit unsigned integer value.
virtual void deallocate(const FwEnumStoreType identifier, void *ptr)=0
FwSizeType getQueueSize() const
Fw::SerializeStatus dequeue(U8 *const message, const FwSizeType size)
pops a fixed-size message off the queue
void configure(QueueConfigurationTable queueConfig, FwEnumStoreType allocationId, Fw::MemAllocator &allocator)
Auto-generated base for ComQueue component.
void bufferReturnOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferReturnOut.