| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | |||
| 13 | #include <Fw/FPrimeBasicTypes.hpp> | ||
| 14 | #include <Svc/StaticMemory/StaticMemoryComponentImpl.hpp> | ||
| 15 | #include "Fw/Types/Assert.hpp" | ||
| 16 | |||
| 17 | namespace Svc { | ||
| 18 | |||
| 19 | // ---------------------------------------------------------------------- | ||
| 20 | // Construction, initialization, and destruction | ||
| 21 | // ---------------------------------------------------------------------- | ||
| 22 | |||
| 23 | 1 | StaticMemoryComponentImpl ::StaticMemoryComponentImpl(const char* const compName) | |
| 24 | 1 | : StaticMemoryComponentBase(compName) { | |
| 25 | static_assert( | ||
| 26 | (StaticMemoryComponentBase::NUM_BUFFERALLOCATE_INPUT_PORTS >= 0) && | ||
| 27 | (StaticMemoryComponentBase::NUM_BUFFERALLOCATE_INPUT_PORTS <= std::numeric_limits<FwIndexType>::max()), | ||
| 28 | "NUM_BUFFERALLOCATE_INPUT_PORTS must fit in the positive range of FwIndexType"); | ||
| 29 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
|
5 | for (FwIndexType i = 0; i < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(m_allocated)); i++) { |
| 30 | 4 | m_allocated[i] = false; | |
| 31 | } | ||
| 32 | 1 | } | |
| 33 | |||
| 34 | 2 | StaticMemoryComponentImpl ::~StaticMemoryComponentImpl() {} | |
| 35 | |||
| 36 | // ---------------------------------------------------------------------- | ||
| 37 | // Handler implementations for user-defined typed input ports | ||
| 38 | // ---------------------------------------------------------------------- | ||
| 39 | |||
| 40 | 4 | void StaticMemoryComponentImpl ::bufferDeallocate_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) { | |
| 41 | 4 | FW_ASSERT(portNum < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(m_static_memory))); | |
| 42 | 4 | FW_ASSERT(m_allocated[portNum], | |
| 43 | static_cast<FwAssertArgType>(portNum)); // It is also an error to deallocate before returning | ||
| 44 | // Check the memory returned is within the region | ||
| 45 | 4 | FW_ASSERT(fwBuffer.getData() >= m_static_memory[portNum]); | |
| 46 | 4 | FW_ASSERT((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 | 4 | m_allocated[portNum] = false; | |
| 50 | 4 | } | |
| 51 | |||
| 52 | 4 | Fw::Buffer StaticMemoryComponentImpl ::bufferAllocate_handler(const FwIndexType portNum, FwSizeType size) { | |
| 53 | 4 | FW_ASSERT(portNum < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(m_static_memory))); | |
| 54 | 4 | FW_ASSERT(size <= | |
| 55 | sizeof(m_static_memory[portNum])); // It is a topology error to ask for too much from this component | ||
| 56 | 4 | FW_ASSERT(not m_allocated[portNum], | |
| 57 | static_cast<FwAssertArgType>(portNum)); // It is also an error to allocate again before returning | ||
| 58 | 4 | m_allocated[portNum] = true; | |
| 59 | 4 | Fw::Buffer buffer(m_static_memory[portNum], sizeof(m_static_memory[0])); | |
| 60 | 4 | return buffer; | |
| 61 | } | ||
| 62 | |||
| 63 | } // end namespace Svc | ||
| 64 |