F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ComQueue.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title ComQueue.hpp
3 // \author vbai
4 // \brief hpp file for ComQueue component implementation class
5 // ======================================================================
6 
7 #ifndef Svc_ComQueue_HPP
8 #define Svc_ComQueue_HPP
9 
10 #include <Fw/Buffer/Buffer.hpp>
11 #include <Fw/Com/ComBuffer.hpp>
13 #include <Utils/Types/Queue.hpp>
14 #include <limits>
16 #include "Os/Mutex.hpp"
17 
18 namespace Svc {
19 
20 // ----------------------------------------------------------------------
21 // Types
22 // ----------------------------------------------------------------------
23 
24 class ComQueue final : public ComQueueComponentBase {
26  enum BufferState { OWNED, UNOWNED };
27 
28  public:
31 
34 
35  static_assert((COM_PORT_COUNT + BUFFER_PORT_COUNT) <= std::numeric_limits<FwIndexType>::max(),
36  "FwIndexType not large enough to hold com and buffer ports");
39 
54  };
55 
71  };
72 
73  private:
74  // ----------------------------------------------------------------------
75  // Internal data structures
76  // ----------------------------------------------------------------------
77 
83  struct QueueMetadata {
84  FwSizeType depth;
85  FwIndexType priority;
86  FwIndexType index;
87  FwSizeType msgSize;
88  };
89 
93  enum SendState {
94  READY,
95  WAITING
96  };
97 
98  public:
99  // ----------------------------------------------------------------------
100  // Construction, initialization, and destruction
101  // ----------------------------------------------------------------------
102 
105  ComQueue(const char* const compName
106  );
107 
110  ~ComQueue();
111 
116  void configure(QueueConfigurationTable queueConfig,
117  FwEnumStoreType allocationId,
118  Fw::MemAllocator& allocator
119  );
120 
123  void cleanup();
124 
125  private:
126  // ----------------------------------------------------------------------
127  // Handler implementations for commands
128  // ----------------------------------------------------------------------
129 
134  void FLUSH_QUEUE_cmdHandler(FwOpcodeType opCode,
135  U32 cmdSeq,
136  Svc::QueueType queueType,
137  FwIndexType indexType
138  ) override;
139 
144  void FLUSH_ALL_QUEUES_cmdHandler(FwOpcodeType opCode,
145  U32 cmdSeq
146  ) override;
147 
148  private:
149  // ----------------------------------------------------------------------
150  // Handler implementations for user-defined typed input ports
151  // ----------------------------------------------------------------------
152 
155  void bufferQueueIn_handler(const FwIndexType portNum,
156  Fw::Buffer& fwBuffer ) override;
157 
160  void comPacketQueueIn_handler(const FwIndexType portNum,
161  Fw::ComBuffer& data,
162  U32 context
163  ) override;
164 
167  void comStatusIn_handler(const FwIndexType portNum,
168  Fw::Success& condition
169  ) override;
170 
173  void run_handler(const FwIndexType portNum,
174  U32 context
175  ) override;
176 
180  void dataReturnIn_handler(FwIndexType portNum,
181  Fw::Buffer& data,
182  const ComCfg::FrameContext& context) override;
183 
184  // ----------------------------------------------------------------------
185  // Hook implementations for typed async input ports
186  // ----------------------------------------------------------------------
187 
190  void bufferQueueIn_overflowHook(FwIndexType portNum,
191  Fw::Buffer& fwBuffer
192  ) override;
193 
194  // ----------------------------------------------------------------------
195  // Helper Functions
196  // ----------------------------------------------------------------------
197 
200  bool enqueue(const FwIndexType queueNum,
201  QueueType queueType,
202  const U8* data,
203  const FwSizeType size
204  );
205 
208  void sendComBuffer(Fw::ComBuffer& comBuffer,
209  FwIndexType queueIndex
210  );
211 
214  void sendBuffer(Fw::Buffer& buffer,
215  FwIndexType queueIndex
216  );
217 
218  void drainQueue(FwIndexType queueNum
219  );
220 
223  void processQueue();
224 
225  private:
226  // ----------------------------------------------------------------------
227  // Member variables
228  // ----------------------------------------------------------------------
229  Fw::ComBuffer m_dequeued_com_buffer;
230  Types::Queue m_queues[TOTAL_PORT_COUNT];
231  QueueMetadata m_prioritizedList[TOTAL_PORT_COUNT];
232  bool m_throttle[TOTAL_PORT_COUNT];
233  SendState m_state;
234  BufferState m_buffer_state;
235 
236  // Storage for Fw::MemAllocator properties
237  FwEnumStoreType m_allocationId;
238  Fw::MemAllocator* m_allocator;
239  void* m_allocation;
240 };
241 
242 } // end namespace Svc
243 
244 #endif
configuration data for each queue
Definition: ComQueue.hpp:51
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
I32 FwEnumStoreType
QueueConfigurationEntry entries[TOTAL_PORT_COUNT]
Definition: ComQueue.hpp:66
configuration table for each queue
Definition: ComQueue.hpp:65
static const FwIndexType TOTAL_PORT_COUNT
Total count of input buffer ports and thus total queues.
Definition: ComQueue.hpp:38
ComQueue(const char *const compName)
Definition: ComQueue.cpp:31
void cleanup()
Definition: ComQueue.cpp:46
static const FwIndexType BUFFER_PORT_COUNT
Definition: ComQueue.hpp:33
static const FwIndexType COM_PORT_COUNT
< Count of Fw::Com input ports and thus Fw::Com queues
Definition: ComQueue.hpp:30
QueueConfigurationTable()
constructs a basic un-prioritized table with depth 0
Definition: ComQueue.cpp:21
An enumeration of queue data types.
FwIndexType priority
Priority of the queue [0, TOTAL_PORT_COUNT)
Definition: ComQueue.hpp:53
FwSizeType depth
Depth of the queue [0, infinity)
Definition: ComQueue.hpp:52
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
Memory Allocation base class.
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
Defines a base class for a memory allocator for classes.
Success/Failure.
void configure(QueueConfigurationTable queueConfig, FwEnumStoreType allocationId, Fw::MemAllocator &allocator)
Definition: ComQueue.cpp:53
Auto-generated base for ComQueue component.