F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
StaticMemoryComponentImpl.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title StaticMemoryComponentImpl.cpp
3 // \author mstarch
4 // \brief cpp file for StaticMemory component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
14 #include <Fw/FPrimeBasicTypes.hpp>
15 #include "Fw/Types/Assert.hpp"
16 
17 namespace Svc {
18 
19 // ----------------------------------------------------------------------
20 // Construction, initialization, and destruction
21 // ----------------------------------------------------------------------
22 
24  : StaticMemoryComponentBase(compName) {
26  (StaticMemoryComponentBase::NUM_BUFFERALLOCATE_INPUT_PORTS <= std::numeric_limits<FwIndexType>::max()),
27  "NUM_BUFFERALLOCATE_INPUT_PORTS must fit in the positive range of FwIndexType");
28  for (FwIndexType i = 0; i < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(m_allocated)); i++) {
29  m_allocated[i] = false;
30  }
31 }
32 
34 
35 // ----------------------------------------------------------------------
36 // Handler implementations for user-defined typed input ports
37 // ----------------------------------------------------------------------
38 
39 void StaticMemoryComponentImpl ::bufferDeallocate_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) {
40  FW_ASSERT(portNum < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(m_static_memory)));
41  FW_ASSERT(m_allocated[portNum], static_cast<FwAssertArgType>(portNum)); // It is also an error to deallocate before returning
42  // Check the memory returned is within the region
43  FW_ASSERT(fwBuffer.getData() >= m_static_memory[portNum]);
44  FW_ASSERT(
45  (fwBuffer.getData() + fwBuffer.getSize()) <= (m_static_memory[portNum] + sizeof(m_static_memory[0])),
46  static_cast<FwAssertArgType>(fwBuffer.getSize()),
47  static_cast<FwAssertArgType>(sizeof(m_static_memory[0])));
48  m_allocated[portNum] = false;
49 }
50 
51 Fw::Buffer StaticMemoryComponentImpl ::bufferAllocate_handler(const FwIndexType portNum, Fw::Buffer::SizeType size) {
52  FW_ASSERT(portNum < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(m_static_memory)));
53  FW_ASSERT(size <= sizeof(m_static_memory[portNum])); // It is a topology error to ask for too much from this component
54  FW_ASSERT(not m_allocated[portNum], static_cast<FwAssertArgType>(portNum)); // It is also an error to allocate again before returning
55  m_allocated[portNum] = true;
56  Fw::Buffer buffer(m_static_memory[portNum], sizeof(m_static_memory[0]));
57  return buffer;
58 }
59 
60 } // end namespace Svc
U8 * getData() const
Definition: Buffer.cpp:68
PlatformIndexType FwIndexType
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:93
RateGroupDivider component implementation.
Auto-generated base for StaticMemory component.
StaticMemoryComponentImpl(const char *const compName)
SizeType getSize() const
Definition: Buffer.cpp:72
U32 SizeType
The size type for a buffer.
Definition: Buffer.hpp:47
#define FW_ASSERT(...)
Definition: Assert.hpp:14