shared ring buffer extended

This commit is contained in:
Robin Müller 2020-09-22 02:12:02 +02:00
parent f5d793a1cf
commit e3cbc4dfd5
4 changed files with 57 additions and 23 deletions

View File

@ -9,6 +9,7 @@ SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size,
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
} }
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer, SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer,
const size_t size, bool overwriteOld, size_t maxExcessBytes): const size_t size, bool overwriteOld, size_t maxExcessBytes):
SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld, SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld,
@ -16,6 +17,11 @@ SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer,
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
} }
void SharedRingBuffer::setToUseReceiveSizeFIFO(uint32_t fifoDepth) {
this->fifoDepth = fifoDepth;
}
ReturnValue_t SharedRingBuffer::lockRingBufferMutex( ReturnValue_t SharedRingBuffer::lockRingBufferMutex(
MutexIF::TimeoutType timeoutType, dur_millis_t timeout) { MutexIF::TimeoutType timeoutType, dur_millis_t timeout) {
return mutex->lockMutex(timeoutType, timeout); return mutex->lockMutex(timeoutType, timeout);
@ -25,6 +31,25 @@ ReturnValue_t SharedRingBuffer::unlockRingBufferMutex() {
return mutex->unlockMutex(); return mutex->unlockMutex();
} }
MutexIF* SharedRingBuffer::getMutexHandle() const { MutexIF* SharedRingBuffer::getMutexHandle() const {
return mutex; return mutex;
} }
ReturnValue_t SharedRingBuffer::initialize() {
if(fifoDepth > 0) {
receiveSizesFIFO = new DynamicFIFO<size_t>(fifoDepth);
}
return SystemObject::initialize();
}
DynamicFIFO<size_t>* SharedRingBuffer::getReceiveSizesFIFO() {
if(receiveSizesFIFO == nullptr) {
// Configuration error.
sif::warning << "SharedRingBuffer::getReceiveSizesFIFO: Ring buffer"
<< " was not configured to have sizes FIFO, returning nullptr!"
<< std::endl;
}
return receiveSizesFIFO;
}

View File

@ -1,6 +1,7 @@
#ifndef FSFW_CONTAINER_SHAREDRINGBUFFER_H_ #ifndef FSFW_CONTAINER_SHAREDRINGBUFFER_H_
#define FSFW_CONTAINER_SHAREDRINGBUFFER_H_ #define FSFW_CONTAINER_SHAREDRINGBUFFER_H_
#include <fsfw/container/DynamicFIFO.h>
#include "SimpleRingBuffer.h" #include "SimpleRingBuffer.h"
#include "../ipc/MutexIF.h" #include "../ipc/MutexIF.h"
#include "../objectmanager/SystemObject.h" #include "../objectmanager/SystemObject.h"
@ -26,6 +27,8 @@ public:
SharedRingBuffer(object_id_t objectId, const size_t size, SharedRingBuffer(object_id_t objectId, const size_t size,
bool overwriteOld, size_t maxExcessBytes); bool overwriteOld, size_t maxExcessBytes);
void setToUseReceiveSizeFIFO(uint32_t fifoDepth);
/** /**
* This constructor takes an external buffer with the specified size. * This constructor takes an external buffer with the specified size.
* @param buffer * @param buffer
@ -59,8 +62,21 @@ public:
* @return * @return
*/ */
MutexIF* getMutexHandle() const; MutexIF* getMutexHandle() const;
ReturnValue_t initialize() override;
/**
* If the shared ring buffer was configured to have a sizes FIFO, a handle
* to that FIFO can be retrieved with this function.
* Do not forget to protect access with a lock if required!
* @return
*/
DynamicFIFO<size_t>* getReceiveSizesFIFO();
private: private:
MutexIF* mutex = nullptr; MutexIF* mutex = nullptr;
size_t fifoDepth = 0;
DynamicFIFO<size_t>* receiveSizesFIFO = nullptr;
}; };

View File

@ -1,14 +1,7 @@
/** #include "Countdown.h"
* @file Countdown.cpp
* @brief This file defines the Countdown class.
* @date 21.03.2013
* @author baetz
*/
Countdown::Countdown(uint32_t initialTimeout): startTime(0),
#include "../timemanager/Countdown.h" timeout(initialTimeout) {
Countdown::Countdown(uint32_t initialTimeout) : startTime(0), timeout(initialTimeout) {
} }
Countdown::~Countdown() { Countdown::~Countdown() {

View File

@ -1,18 +1,13 @@
#ifndef FSFW_TIMEMANAGER_COUNTDOWN_H_
#define FSFW_TIMEMANAGER_COUNTDOWN_H_
#include "Clock.h"
/** /**
* @file Countdown.h
* @brief This file defines the Countdown class. * @brief This file defines the Countdown class.
* @date 21.03.2013
* @author baetz * @author baetz
*/ */
#ifndef COUNTDOWN_H_
#define COUNTDOWN_H_
#include "../timemanager/Clock.h"
class Countdown { class Countdown {
private:
uint32_t startTime;
public: public:
uint32_t timeout; uint32_t timeout;
Countdown(uint32_t initialTimeout = 0); Countdown(uint32_t initialTimeout = 0);
@ -23,9 +18,14 @@ public:
bool isBusy() const; bool isBusy() const;
ReturnValue_t resetTimer(); //!< Use last set timeout value and restart timer. //!< Use last set timeout value and restart timer.
ReturnValue_t resetTimer();
void timeOut(); //!< Make hasTimedOut() return true //!< Make hasTimedOut() return true
void timeOut();
private:
uint32_t startTime = 0;
}; };
#endif /* COUNTDOWN_H_ */ #endif /* FSFW_TIMEMANAGER_COUNTDOWN_H_ */