F´ Flight Software - C/C++ Documentation  devel
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 <FpConfig.hpp>
15 #include "Fw/Types/Assert.hpp"
16 
17 namespace Svc {
18 
19 // ----------------------------------------------------------------------
20 // Construction, initialization, and destruction
21 // ----------------------------------------------------------------------
22 
24  : StaticMemoryComponentBase(compName) {
25  for (U32 i = 0; i < FW_NUM_ARRAY_ELEMENTS(m_allocated); i++) {
26  m_allocated[i] = false;
27  }
28 }
29 
32 }
33 
35 
36 // ----------------------------------------------------------------------
37 // Handler implementations for user-defined typed input ports
38 // ----------------------------------------------------------------------
39 
40 void StaticMemoryComponentImpl ::bufferDeallocate_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
41  FW_ASSERT(static_cast<NATIVE_UINT_TYPE>(portNum) < FW_NUM_ARRAY_ELEMENTS(m_static_memory));
42  FW_ASSERT(m_allocated[portNum], portNum); // It is also an error to deallocate before returning
43  // Check the memory returned is within the region
44  FW_ASSERT(fwBuffer.getData() >= m_static_memory[portNum]);
45  FW_ASSERT(
46  (fwBuffer.getData() + fwBuffer.getSize()) <= (m_static_memory[portNum] + sizeof(m_static_memory[0])),
47  static_cast<FwAssertArgType>(fwBuffer.getSize()),
48  static_cast<FwAssertArgType>(sizeof(m_static_memory[0])));
49  m_allocated[portNum] = false;
50 }
51 
52 Fw::Buffer StaticMemoryComponentImpl ::bufferAllocate_handler(const NATIVE_INT_TYPE portNum, U32 size) {
53  FW_ASSERT(static_cast<NATIVE_UINT_TYPE>(portNum) < FW_NUM_ARRAY_ELEMENTS(m_static_memory));
54  FW_ASSERT(size <= sizeof(m_static_memory[portNum])); // It is a topology error to ask for too much from this component
55  FW_ASSERT(not m_allocated[portNum], portNum); // It is also an error to allocate again before returning
56  m_allocated[portNum] = true;
57  Fw::Buffer buffer(m_static_memory[portNum], sizeof(m_static_memory[0]));
58  return buffer;
59 }
60 
61 } // end namespace Svc
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:66
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:52
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:34
C++-compatible configuration header for fprime configuration.
U8 * getData() const
Definition: Buffer.cpp:68
U32 getSize() const
Definition: Buffer.cpp:72
void init()
Object initializer.
Definition: ObjBase.cpp:27
Auto-generated base for StaticMemory component.
StaticMemoryComponentImpl(const char *const compName)