-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Implement some requested changes for ringbuffer
- Loading branch information
Showing
7 changed files
with
177 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#pragma once | ||
|
||
|
||
#include <Sts1CobcSw/Periphery/FramRingBuffer.hpp> | ||
|
||
|
||
namespace sts1cobcsw::fram | ||
{ | ||
template<typename T, std::size_t size, Address startAddress> | ||
void RingBuffer<T, size, startAddress>::Push(T const & newData) | ||
{ | ||
currentWriteIndex_ = writeIndex_; | ||
auto const address = startAddress + writeIndex_ * serialSize<T>; | ||
fram::WriteTo(address, Span(Serialize(newData)), 0); | ||
writeIndex_++; | ||
|
||
if(writeIndex_ >= size) | ||
{ | ||
writeIndex_ = 0; | ||
} | ||
if(occupiedCount_ < size) | ||
{ | ||
occupiedCount_++; | ||
} | ||
writeCount_++; | ||
// TODO: iwyu | ||
currentWriteIndex_ = UINT32_MAX; | ||
} | ||
|
||
|
||
template<typename T, std::size_t size, Address startAddress> | ||
auto RingBuffer<T, size, startAddress>::Front() -> T | ||
{ | ||
// TODO: Check if using RODOS ringbuffer logic is right | ||
|
||
// Jump the current being written record | ||
if(readIndex_ == currentWriteIndex_) | ||
{ | ||
readIndex_++; | ||
} | ||
if(readIndex_ >= size) | ||
{ | ||
readIndex_ = 0; | ||
} | ||
|
||
// readIndex should not pass write index if there is no data after it | ||
if(writeCount_ < size && readIndex_ >= writeIndex_) | ||
{ | ||
readIndex_ = 0; | ||
} | ||
|
||
auto const address = startAddress + readIndex_ * serialSize<T>; | ||
// TODO: Add a real timeout value (spiTimeout in hw tests is 30ms, but for much more data) | ||
auto readData = fram::ReadFrom<serialSize<T>>(address, 0); | ||
auto fromRing = Deserialize<T>(std::span(readData)); | ||
|
||
readIndex_++; | ||
if(readIndex_ >= size) | ||
{ | ||
readIndex_ = 0; | ||
} | ||
|
||
if(occupiedCount_ > 0) | ||
{ | ||
occupiedCount_--; | ||
} | ||
readCount_++; | ||
|
||
return fromRing; | ||
} | ||
|
||
template<typename T, std::size_t size, Address startAddress> | ||
auto RingBuffer<T, size, startAddress>::operator[](std::size_t index) -> T | ||
{ | ||
// TODO: This assume that index not out of bounds | ||
auto const address = startAddress + index * serialSize<T>; | ||
auto readData = fram::ReadFrom<serialSize<T>>(address, 0); | ||
return Deserialize<T>(std::span(readData)); | ||
} | ||
} |
Oops, something went wrong.