11 #include <type_traits> 21 ComQueue ::QueueConfigurationTable ::QueueConfigurationTable() {
22 static_assert(static_cast<FwUnsignedIndexType>(std::numeric_limits<FwIndexType>::max()) >=
FW_NUM_ARRAY_ELEMENTS(this->entries),
23 "Number of entries must fit into FwIndexType");
25 this->entries[i].priority = 0;
26 this->entries[i].depth = 0;
35 m_allocation(nullptr) {
38 this->m_throttle[i] =
false;
46 if ((this->m_allocator !=
nullptr) && (this->m_allocation !=
nullptr)) {
47 this->m_allocator->
deallocate(this->m_allocationId, this->m_allocation);
58 this->m_allocator = &allocator;
59 this->m_allocationId = allocationId;
60 this->m_allocation =
nullptr;
78 static_cast<FwAssertArgType>(entryIndex));
84 QueueMetadata& entry = this->m_prioritizedList[currentPriorityIndex];
87 entry.index = entryIndex;
92 FW_ASSERT((std::numeric_limits<FwSizeType>::max()/entry.depth) >= entry.msgSize,
93 static_cast<FwAssertArgType>(entry.depth),
94 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));
115 (allocationSize + allocationOffset) <= totalAllocation,
116 static_cast<FwAssertArgType>(allocationSize),
117 static_cast<FwAssertArgType>(allocationOffset),
118 static_cast<FwAssertArgType>(totalAllocation));
121 if (allocationSize > 0) {
122 this->m_queues[this->m_prioritizedList[i].index].
setup(
123 reinterpret_cast<U8*>(this->m_allocation) + allocationOffset, allocationSize,
124 this->m_prioritizedList[i].depth, this->m_prioritizedList[i].msgSize);
126 allocationOffset += allocationSize;
130 allocationOffset == totalAllocation,
131 static_cast<FwAssertArgType>(allocationOffset),
132 static_cast<FwAssertArgType>(totalAllocation));
158 switch (this->m_state) {
162 this->m_state = READY;
163 this->processQueue();
165 FW_ASSERT((this->m_state == WAITING || this->m_state == READY), static_cast<FwAssertArgType>(this->m_state));
167 this->m_state = WAITING;
173 FW_ASSERT(0, static_cast<FwAssertArgType>(this->m_state));
178 void ComQueue::run_handler(
const FwIndexType portNum, U32 context) {
180 ComQueueDepth comQueueDepth;
181 for (U32 i = 0; i < comQueueDepth.SIZE; i++) {
188 BuffQueueDepth buffQueueDepth;
189 for (U32 i = 0; i < buffQueueDepth.SIZE; i++) {
196 void ComQueue ::dataReturnIn_handler(
FwIndexType portNum,
199 static_assert(std::numeric_limits<FwIndexType>::is_signed,
"FwIndexType must be signed");
207 if (bufferReturnPortNum >= 0) {
228 bool ComQueue::enqueue(
const FwIndexType queueNum, QueueType queueType,
const U8* data,
const FwSizeType size) {
233 static_cast<FwAssertArgType>(queueType), static_cast<FwAssertArgType>(queueNum));
235 bool rvStatus =
true;
237 expectedSize == size,
238 static_cast<FwAssertArgType>(size),
239 static_cast<FwAssertArgType>(expectedSize));
240 FW_ASSERT(portNum >= 0, static_cast<FwAssertArgType>(portNum));
243 if (!this->m_throttle[queueNum]) {
245 this->m_throttle[queueNum] =
true;
251 if (this->m_state == READY) {
252 this->processQueue();
267 context.
setapid(static_cast<ComCfg::APID::T>(descriptor));
272 this->m_state = WAITING;
284 context.
setapid(static_cast<ComCfg::APID::T>(descriptor));
289 this->m_state = WAITING;
292 void ComQueue::processQueue() {
300 for (priorityIndex = 0; priorityIndex <
TOTAL_PORT_COUNT; priorityIndex++) {
301 QueueMetadata& entry = this->m_prioritizedList[priorityIndex];
312 queue.
dequeue(reinterpret_cast<U8*>(&comBuffer),
sizeof(comBuffer));
313 this->sendComBuffer(comBuffer, entry.index);
316 queue.
dequeue(reinterpret_cast<U8*>(&buffer),
sizeof(buffer));
317 this->sendBuffer(buffer, entry.index);
321 this->m_throttle[entry.index] =
false;
324 sendPriority = entry.priority;
331 for (priorityIndex++;
332 priorityIndex <
TOTAL_PORT_COUNT && (this->m_prioritizedList[priorityIndex].priority == sendPriority);
335 QueueMetadata temp = this->m_prioritizedList[priorityIndex];
336 this->m_prioritizedList[priorityIndex] = this->m_prioritizedList[priorityIndex - 1];
337 this->m_prioritizedList[priorityIndex - 1] = temp;
Serialization/Deserialization operation was successful.
void setapid(ComCfg::APID::T apid)
Set member apid.
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
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
FwSizeType get_high_water_mark() const
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
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.
FwIndexType getcomQueueIndex() const
Get member comQueueIndex.
void setcomQueueIndex(FwIndexType comQueueIndex)
Set member comQueueIndex.
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)
Auto-generated base for ComQueue component.
void bufferReturnOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferReturnOut.