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 
31 
32 // ----------------------------------------------------------------------
33 // Handler implementations for user-defined typed input ports
34 // ----------------------------------------------------------------------
35 
36 void StaticMemoryComponentImpl ::bufferDeallocate_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
37  FW_ASSERT(static_cast<NATIVE_UINT_TYPE>(portNum) < FW_NUM_ARRAY_ELEMENTS(m_static_memory));
38  FW_ASSERT(m_allocated[portNum], portNum); // It is also an error to deallocate before returning
39  // Check the memory returned is within the region
40  FW_ASSERT(fwBuffer.getData() >= m_static_memory[portNum]);
41  FW_ASSERT(
42  (fwBuffer.getData() + fwBuffer.getSize()) <= (m_static_memory[portNum] + sizeof(m_static_memory[0])),
43  static_cast<FwAssertArgType>(fwBuffer.getSize()),
44  static_cast<FwAssertArgType>(sizeof(m_static_memory[0])));
45  m_allocated[portNum] = false;
46 }
47 
48 Fw::Buffer StaticMemoryComponentImpl ::bufferAllocate_handler(const NATIVE_INT_TYPE portNum, U32 size) {
49  FW_ASSERT(static_cast<NATIVE_UINT_TYPE>(portNum) < FW_NUM_ARRAY_ELEMENTS(m_static_memory));
50  FW_ASSERT(size <= sizeof(m_static_memory[portNum])); // It is a topology error to ask for too much from this component
51  FW_ASSERT(not m_allocated[portNum], portNum); // It is also an error to allocate again before returning
52  m_allocated[portNum] = true;
53  Fw::Buffer buffer(m_static_memory[portNum], sizeof(m_static_memory[0]));
54  return buffer;
55 }
56 
57 } // end namespace Svc
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:70
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:56
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:39
C++-compatible configuration header for fprime configuration.
U8 * getData() const
Definition: Buffer.cpp:68
U32 getSize() const
Definition: Buffer.cpp:72
Auto-generated base for StaticMemory component.
StaticMemoryComponentImpl(const char *const compName)