49 if (not this->m_cleaned) {
51 for (U16 entry = 0; entry < this->m_numStructs; entry++) {
52 this->m_buffers[entry].buff.~Buffer();
54 this->m_cleaned =
true;
56 this->m_allocator->
deallocate(this->m_memId, this->m_buffers);
57 this->m_setup =
false;
65 void BufferManagerComponentImpl ::bufferSendIn_handler(
const FwIndexType portNum,
Fw::Buffer& fwBuffer) {
80 U32
id = context & 0xFFFF;
81 U32 mgrId = context >> 16;
83 FW_ASSERT(id < this->m_numStructs, static_cast<FwAssertArgType>(
id),
84 static_cast<FwAssertArgType>(this->m_numStructs));
85 FW_ASSERT(mgrId == this->m_mgrId, static_cast<FwAssertArgType>(mgrId), static_cast<FwAssertArgType>(
id),
86 static_cast<FwAssertArgType>(this->m_mgrId));
87 FW_ASSERT(
true == this->m_buffers[
id].allocated, static_cast<FwAssertArgType>(
id),
88 static_cast<FwAssertArgType>(this->m_mgrId));
89 FW_ASSERT(reinterpret_cast<U8*>(fwBuffer.
getData()) >= this->m_buffers[
id].memory, static_cast<FwAssertArgType>(
id),
91 FW_ASSERT(reinterpret_cast<U8*>(fwBuffer.
getData()) < (this->m_buffers[
id].memory + this->m_buffers[
id].size),
92 static_cast<FwAssertArgType>(id), static_cast<FwAssertArgType>(this->m_mgrId));
95 static_cast<FwAssertArgType>(this->m_mgrId));
97 this->m_buffers[id].allocated =
false;
106 for (U16 buff = 0; buff < this->m_numStructs; buff++) {
107 if ((not this->m_buffers[buff].allocated) and (size <= this->m_buffers[buff].size)) {
108 this->m_buffers[buff].allocated =
true;
110 if (this->m_currBuffs > this->m_highWater) {
111 this->m_highWater = this->m_currBuffs;
131 this->m_mgrId = mgrId;
132 this->m_memId = memId;
133 this->m_allocator = &allocator;
135 memset(&this->m_bufferBins, 0,
sizeof(this->m_bufferBins));
137 this->m_bufferBins = bins;
141 this->m_numStructs = 0;
147 (static_cast<FwSizeType>(
sizeof(AllocatedBuffer)) *
150 FW_ASSERT((std::numeric_limits<U16>::max() - this->m_numStructs) >=
152 this->m_numStructs =
static_cast<U16
>(this->m_numStructs + this->m_bufferBins.
bins[bin].
numBuffers);
157 bool recoverable =
false;
160 void* memory = allocator.
allocate(memId, allocatedSize, recoverable);
162 FW_ASSERT(memory !=
nullptr && memorySize == allocatedSize, static_cast<FwAssertArgType>(mgrId),
163 static_cast<FwAssertArgType>(memId),
164 static_cast<FwAssertArgType>(reinterpret_cast<PlatformPointerCastType>(memory)),
165 static_cast<FwAssertArgType>(memorySize), static_cast<FwAssertArgType>(allocatedSize));
167 this->m_buffers =
static_cast<AllocatedBuffer*
>(memory);
170 U8* bufferMem =
reinterpret_cast<U8*
>(&this->m_buffers[this->m_numStructs]);
176 for (U16 binEntry = 0; binEntry < this->m_bufferBins.
bins[bin].
numBuffers; binEntry++) {
179 U32 context = (
static_cast<U32
>(this->m_mgrId) << 16) |
static_cast<U32
>(currStruct);
180 (void)
new (&this->m_buffers[currStruct].buff)
182 this->m_buffers[currStruct].allocated =
false;
183 this->m_buffers[currStruct].memory = bufferMem;
184 this->m_buffers[currStruct].size = this->m_bufferBins.
bins[bin].
bufferSize;
192 U8*
const CURR_PTR = bufferMem;
193 U8*
const END_PTR =
static_cast<U8*
>(memory) + memorySize;
194 FW_ASSERT(CURR_PTR == END_PTR, static_cast<FwAssertArgType>(mgrId), static_cast<FwAssertArgType>(memId),
195 static_cast<FwAssertArgType>(reinterpret_cast<PlatformPointerCastType>(CURR_PTR)),
196 static_cast<FwAssertArgType>(reinterpret_cast<PlatformPointerCastType>(END_PTR)));
198 FW_ASSERT(currStruct == this->m_numStructs, static_cast<FwAssertArgType>(mgrId),
199 static_cast<FwAssertArgType>(memId), static_cast<FwAssertArgType>(currStruct),
200 static_cast<FwAssertArgType>(this->m_numStructs));
202 this->m_setup =
true;
205 void BufferManagerComponentImpl ::schedIn_handler(
const FwIndexType portNum, U32 context) {
void log_WARNING_HI_NoBuffsAvailable(FwSizeType size)
~BufferManagerComponentImpl()
PlatformSizeType FwSizeType
BufferBin bins[BUFFERMGR_MAX_NUM_BINS]
set of bins to define buffers
void setSize(FwSizeType size)
virtual void * allocate(const FwEnumStoreType identifier, FwSizeType &size, bool &recoverable)=0
Allocate memory.
Fw::Buffer::SizeType bufferSize
size of the buffers in this bin. Set to zero for unused bins.
static const U16 BUFFERMGR_MAX_NUM_BINS
BufferManagerComponentImpl(const char *const compName)
void log_WARNING_HI_NullEmptyBuffer()
void tlmWrite_NoBuffs(U32 arg, Fw::Time _tlmTime=Fw::Time())
void tlmWrite_CurrBuffs(U32 arg, Fw::Time _tlmTime=Fw::Time())
void tlmWrite_HiBuffs(U32 arg, Fw::Time _tlmTime=Fw::Time())
uint8_t U8
8-bit unsigned integer
void tlmWrite_TotalBuffs(U32 arg, Fw::Time _tlmTime=Fw::Time())
void setup(U16 mgrID, FwEnumStoreType memID, Fw::MemAllocator &allocator, const BufferBins &bins)
set up configuration
FwSizeType getSize() const
void tlmWrite_EmptyBuffs(U32 arg, Fw::Time _tlmTime=Fw::Time())
PlatformIndexType FwIndexType
FwSizeType SizeType
The size type for a buffer - for backwards compatibility.
RateGroupDivider component implementation.
virtual void deallocate(const FwEnumStoreType identifier, void *ptr)=0
Deallocate memory.
Auto-generated base for BufferManager component.
U16 numBuffers
number of buffers in this bin. Set to zero for unused bins.
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.