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 user-defined typed input ports
128  // ----------------------------------------------------------------------
129 
132  void bufferQueueIn_handler(const FwIndexType portNum,
133  Fw::Buffer& fwBuffer ) override;
134 
137  void comPacketQueueIn_handler(const FwIndexType portNum,
138  Fw::ComBuffer& data,
139  U32 context
140  ) override;
141 
144  void comStatusIn_handler(const FwIndexType portNum,
145  Fw::Success& condition
146  ) override;
147 
150  void run_handler(const FwIndexType portNum,
151  U32 context
152  ) override;
153 
157  void dataReturnIn_handler(FwIndexType portNum,
158  Fw::Buffer& data,
159  const ComCfg::FrameContext& context) override;
160 
161  // ----------------------------------------------------------------------
162  // Hook implementations for typed async input ports
163  // ----------------------------------------------------------------------
164 
167  void bufferQueueIn_overflowHook(FwIndexType portNum,
168  Fw::Buffer& fwBuffer
169  ) override;
170 
171  // ----------------------------------------------------------------------
172  // Helper Functions
173  // ----------------------------------------------------------------------
174 
177  bool enqueue(const FwIndexType queueNum,
178  QueueType queueType,
179  const U8* data,
180  const FwSizeType size
181  );
182 
185  void sendComBuffer(Fw::ComBuffer& comBuffer,
186  FwIndexType queueIndex
187  );
188 
191  void sendBuffer(Fw::Buffer& buffer,
192  FwIndexType queueIndex
193  );
194 
197  void processQueue();
198 
199  private:
200  // ----------------------------------------------------------------------
201  // Member variables
202  // ----------------------------------------------------------------------
203  Fw::ComBuffer m_dequeued_com_buffer;
204  Types::Queue m_queues[TOTAL_PORT_COUNT];
205  QueueMetadata m_prioritizedList[TOTAL_PORT_COUNT];
206  bool m_throttle[TOTAL_PORT_COUNT];
207  SendState m_state;
208  BufferState m_buffer_state;
209 
210  // Storage for Fw::MemAllocator properties
211  FwEnumStoreType m_allocationId;
212  Fw::MemAllocator* m_allocator;
213  void* m_allocation;
214 };
215 
216 } // end namespace Svc
217 
218 #endif
configuration data for each queue
Definition: ComQueue.hpp:51
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
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.