2020-09-04 15:11:53 +02:00
|
|
|
#include "SharedRingBuffer.h"
|
2020-09-04 15:10:44 +02:00
|
|
|
#include "../ipc/MutexFactory.h"
|
2021-03-09 11:30:00 +01:00
|
|
|
#include "../ipc/MutexGuard.h"
|
2020-08-18 11:25:57 +02:00
|
|
|
|
|
|
|
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size,
|
2021-01-28 11:50:33 +01:00
|
|
|
bool overwriteOld, size_t maxExcessBytes):
|
|
|
|
SystemObject(objectId), SimpleRingBuffer(size, overwriteOld,
|
|
|
|
maxExcessBytes) {
|
|
|
|
mutex = MutexFactory::instance()->createMutex();
|
2020-08-18 11:25:57 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 16:22:37 +02:00
|
|
|
|
2020-08-18 11:25:57 +02:00
|
|
|
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer,
|
2021-01-28 11:50:33 +01:00
|
|
|
const size_t size, bool overwriteOld, size_t maxExcessBytes):
|
|
|
|
SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld,
|
|
|
|
maxExcessBytes) {
|
|
|
|
mutex = MutexFactory::instance()->createMutex();
|
2020-08-18 11:25:57 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 16:22:37 +02:00
|
|
|
|
2020-09-22 16:32:59 +02:00
|
|
|
void SharedRingBuffer::setToUseReceiveSizeFIFO(size_t fifoDepth) {
|
2021-01-28 11:50:33 +01:00
|
|
|
this->fifoDepth = fifoDepth;
|
2020-09-22 16:22:37 +02:00
|
|
|
}
|
|
|
|
|
2020-08-18 11:25:57 +02:00
|
|
|
ReturnValue_t SharedRingBuffer::lockRingBufferMutex(
|
|
|
|
MutexIF::TimeoutType timeoutType, dur_millis_t timeout) {
|
|
|
|
return mutex->lockMutex(timeoutType, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t SharedRingBuffer::unlockRingBufferMutex() {
|
|
|
|
return mutex->unlockMutex();
|
|
|
|
}
|
|
|
|
|
2020-09-22 16:22:37 +02:00
|
|
|
|
|
|
|
|
2020-08-18 11:25:57 +02:00
|
|
|
MutexIF* SharedRingBuffer::getMutexHandle() const {
|
|
|
|
return mutex;
|
|
|
|
}
|
2020-09-22 16:22:37 +02:00
|
|
|
|
|
|
|
ReturnValue_t SharedRingBuffer::initialize() {
|
2021-01-28 11:50:33 +01:00
|
|
|
if(fifoDepth > 0) {
|
|
|
|
receiveSizesFIFO = new DynamicFIFO<size_t>(fifoDepth);
|
|
|
|
}
|
|
|
|
return SystemObject::initialize();
|
2020-09-22 16:22:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DynamicFIFO<size_t>* SharedRingBuffer::getReceiveSizesFIFO() {
|
2021-01-28 11:50:33 +01:00
|
|
|
if(receiveSizesFIFO == nullptr) {
|
|
|
|
// Configuration error.
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2021-01-28 11:50:33 +01:00
|
|
|
sif::warning << "SharedRingBuffer::getReceiveSizesFIFO: Ring buffer"
|
|
|
|
<< " was not configured to have sizes FIFO, returning nullptr!"
|
|
|
|
<< std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2021-01-28 11:50:33 +01:00
|
|
|
}
|
|
|
|
return receiveSizesFIFO;
|
2020-09-22 16:22:37 +02:00
|
|
|
}
|