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;
34 m_buffer_state(OWNED),
37 m_allocation(nullptr) {
40 this->m_throttle[i] =
false;
48 if ((this->m_allocator !=
nullptr) && (this->m_allocation !=
nullptr)) {
49 this->m_allocator->
deallocate(this->m_allocationId, this->m_allocation);
60 this->m_allocator = &allocator;
61 this->m_allocationId = allocationId;
62 this->m_allocation =
nullptr;
80 static_cast<FwAssertArgType>(
TOTAL_PORT_COUNT), static_cast<FwAssertArgType>(entryIndex));
86 QueueMetadata& entry = this->m_prioritizedList[currentPriorityIndex];
89 entry.index = entryIndex;
94 FW_ASSERT((std::numeric_limits<FwSizeType>::max() / entry.depth) >= entry.msgSize,
95 static_cast<FwAssertArgType>(entry.depth), static_cast<FwAssertArgType>(entry.msgSize));
96 FW_ASSERT(std::numeric_limits<FwSizeType>::max() - (entry.depth * entry.msgSize) >= totalAllocation);
97 totalAllocation += entry.depth * entry.msgSize;
98 currentPriorityIndex++;
103 bool recoverable =
false;
104 this->m_allocation = this->m_allocator->
allocate(this->m_allocationId, totalAllocation, recoverable);
112 FwSizeType allocationSize = this->m_prioritizedList[i].depth * this->m_prioritizedList[i].msgSize;
114 static_cast<FwAssertArgType>(this->m_prioritizedList[i].index));
115 FW_ASSERT((allocationSize + allocationOffset) <= totalAllocation, static_cast<FwAssertArgType>(allocationSize),
116 static_cast<FwAssertArgType>(allocationOffset), static_cast<FwAssertArgType>(totalAllocation));
119 if (allocationSize > 0) {
120 this->m_queues[this->m_prioritizedList[i].index].
setup(
121 reinterpret_cast<U8*>(this->m_allocation) + allocationOffset, allocationSize,
122 this->m_prioritizedList[i].depth, this->m_prioritizedList[i].msgSize);
124 allocationOffset += allocationSize;
127 FW_ASSERT(allocationOffset == totalAllocation, static_cast<FwAssertArgType>(allocationOffset),
128 static_cast<FwAssertArgType>(totalAllocation));
154 switch (this->m_state) {
158 this->m_state = READY;
159 this->processQueue();
161 FW_ASSERT((this->m_state == WAITING || this->m_state == READY),
162 static_cast<FwAssertArgType>(this->m_state));
164 this->m_state = WAITING;
170 FW_ASSERT(0, static_cast<FwAssertArgType>(this->m_state));
175 void ComQueue::run_handler(
const FwIndexType portNum, U32 context) {
177 ComQueueDepth comQueueDepth;
178 for (U32 i = 0; i < comQueueDepth.SIZE; i++) {
185 BuffQueueDepth buffQueueDepth;
186 for (U32 i = 0; i < buffQueueDepth.SIZE; i++) {
194 static_assert(std::numeric_limits<FwIndexType>::is_signed,
"FwIndexType must be signed");
195 FW_ASSERT(this->m_buffer_state == UNOWNED);
196 this->m_buffer_state = OWNED;
204 if (bufferReturnPortNum >= 0) {
207 static_cast<FwAssertArgType>(bufferReturnPortNum));
226 bool ComQueue::enqueue(
const FwIndexType queueNum, QueueType queueType,
const U8* data,
const FwSizeType size) {
231 static_cast<FwAssertArgType>(queueType), static_cast<FwAssertArgType>(queueNum));
234 bool rvStatus =
true;
235 FW_ASSERT(expectedSize == size, static_cast<FwAssertArgType>(size), static_cast<FwAssertArgType>(expectedSize));
236 FW_ASSERT(portNum >= 0, static_cast<FwAssertArgType>(portNum));
239 if (!this->m_throttle[queueNum]) {
241 this->m_throttle[queueNum] =
true;
247 if (this->m_state == READY) {
248 this->processQueue();
263 context.
set_apid(static_cast<ComCfg::Apid::T>(descriptor));
265 FW_ASSERT(this->m_buffer_state == OWNED);
266 this->m_buffer_state = UNOWNED;
269 this->m_state = WAITING;
281 context.
set_apid(static_cast<ComCfg::Apid::T>(descriptor));
283 FW_ASSERT(this->m_buffer_state == OWNED);
284 this->m_buffer_state = UNOWNED;
287 this->m_state = WAITING;
290 void ComQueue::processQueue() {
298 for (priorityIndex = 0; priorityIndex <
TOTAL_PORT_COUNT; priorityIndex++) {
299 QueueMetadata& entry = this->m_prioritizedList[priorityIndex];
311 FW_ASSERT(this->m_buffer_state == OWNED);
312 auto dequeue_status =
313 queue.
dequeue(reinterpret_cast<U8*>(&this->m_dequeued_com_buffer),
sizeof(this->m_dequeued_com_buffer));
315 static_cast<FwAssertArgType>(dequeue_status));
316 this->sendComBuffer(this->m_dequeued_com_buffer, entry.index);
319 auto dequeue_status = queue.
dequeue(reinterpret_cast<U8*>(&buffer),
sizeof(buffer));
321 static_cast<FwAssertArgType>(dequeue_status));
322 this->sendBuffer(buffer, entry.index);
326 this->m_throttle[entry.index] =
false;
329 sendPriority = entry.priority;
336 for (priorityIndex++;
337 priorityIndex <
TOTAL_PORT_COUNT && (this->m_prioritizedList[priorityIndex].priority == sendPriority);
340 QueueMetadata temp = this->m_prioritizedList[priorityIndex];
341 this->m_prioritizedList[priorityIndex] = this->m_prioritizedList[priorityIndex - 1];
342 this->m_prioritizedList[priorityIndex - 1] = temp;
Serialization/Deserialization operation was successful.
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
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
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.
SerializeStatus deserializeTo(U8 &val, Endianness mode=Endianness::BIG)
deserialize 8-bit unsigned int
No room left in the buffer to serialize data.
void set_apid(ComCfg::Apid::T apid)
Set member apid.
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
Memory Allocation base class.
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
RateGroupDivider component implementation.
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 front of 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.