mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/driver-w25qxxx.git
synced 2025-06-12 03:25:58 +00:00
79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
#ifndef STA_UTILS_LOGGER_HPP
|
|
#define STA_UTILS_LOGGER_HPP
|
|
|
|
#include <sta/drivers/w25qxx.hpp>
|
|
#include <sta/debug/assert.hpp>
|
|
|
|
#include <cstring>
|
|
|
|
namespace sta
|
|
{
|
|
template <typename T>
|
|
class Logger
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Construct a new Logger object
|
|
*
|
|
* @param flash The flash chip to use for logging.
|
|
* @param startSector The index of the start sector (4096 bytes).
|
|
* @param endAddr The index of the end sector (4096 bytes).
|
|
*/
|
|
Logger(W25Qxx * flash, uint32_t startSector, uint32_t endSector);
|
|
|
|
/**
|
|
* @brief Write a new data point to the flash chip.
|
|
* @note If the total capacity of this logger was exceeded, it restarts at the first sector, overwriting its data.
|
|
*
|
|
* @param data The data to write to the flash chip.
|
|
*/
|
|
void write(T data);
|
|
|
|
/**
|
|
* @brief Clear the flash memory used by the logger.
|
|
*
|
|
*/
|
|
void clear();
|
|
|
|
/**
|
|
* @brief Get the number of data points currently written to the memory segment.
|
|
*
|
|
* @return size_t The number of data points.
|
|
*/
|
|
size_t occupied();
|
|
|
|
/**
|
|
* @brief Get the number of data points that can be written to the logger before an overflow occurs.
|
|
*
|
|
* @return size_t The number of data points.
|
|
*/
|
|
size_t remaining();
|
|
|
|
/**
|
|
* @brief Get the total number of data points that fit into the logger.
|
|
*
|
|
* @return size_t The number of data points.
|
|
*/
|
|
size_t length();
|
|
|
|
/**
|
|
* @brief Allows reading a single data point from the segment.
|
|
*
|
|
* @param idx The index of the segement.
|
|
* @return const T& The read data value.
|
|
*/
|
|
const T& operator[](std::size_t idx);
|
|
private:
|
|
W25Qxx * flash_;
|
|
uint32_t start_;
|
|
uint32_t end_;
|
|
uint32_t address_;
|
|
|
|
uint8_t buffer_[W25QXX_PAGE_SIZE];
|
|
uint8_t ptr_;
|
|
};
|
|
} // namespace sta
|
|
|
|
#include <sta/utils/logger.tpp>
|
|
|
|
#endif // STA_UTILS_LOGGER_HPP
|