mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/driver-w25qxxx.git
synced 2025-08-01 20:21:53 +00:00
Added mutex and more doxygen
This commit is contained in:
parent
9dd2a8da9c
commit
007ed46363
@ -2,6 +2,8 @@
|
||||
#define STA_SENSORS_W25Q128_HPP
|
||||
|
||||
#include <sta/bus/spi/device.hpp>
|
||||
#include <sta/mutex.hpp>
|
||||
|
||||
#include <sta/drivers/w25qxx_defs.hpp>
|
||||
|
||||
#include <functional>
|
||||
@ -60,12 +62,14 @@ namespace sta
|
||||
using DelayUsFunc = void (*)(uint32_t);
|
||||
|
||||
/**
|
||||
* @brief Construct a new W25Qxx object
|
||||
* @brief Driver class for the W25QXX flash storage series.
|
||||
*
|
||||
* @param device
|
||||
* @param addrMode
|
||||
* @param device A SPI device handle from sta-core.
|
||||
* @param delay A microsecond delay function.
|
||||
* @param addrMode Choose between 24 Bit and 32 Bit addressing.
|
||||
* @param mutex A mutex for thread safety if the flash chip is used by multiple threads. Defaults to a always free mutex.
|
||||
*/
|
||||
W25Qxx(SPIDevice * device, DelayUsFunc delay, AddressMode addrMode = AddressMode::_24BIT);
|
||||
W25Qxx(SPIDevice * device, DelayUsFunc delay, AddressMode addrMode = AddressMode::_24BIT, Mutex * mutex = Mutex::ALWAYS_FREE);
|
||||
|
||||
/**
|
||||
* @brief Initialize the flash chip.
|
||||
@ -318,6 +322,7 @@ namespace sta
|
||||
private:
|
||||
SPIDevice * device_;
|
||||
DelayUsFunc delay_;
|
||||
Mutex * mutex_;
|
||||
ChipState state_;
|
||||
AddressMode addrMode_;
|
||||
};
|
||||
|
@ -33,6 +33,12 @@ namespace sta
|
||||
// If the written data exceeds the remaining bytes in the page.
|
||||
if (ptr_ + length >= W25QXX_PAGE_SIZE)
|
||||
{
|
||||
// If the segment is full, stop writing data to it.
|
||||
if (address_ / W25QXX_SECTOR_SIZE == end_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::memcpy(buffer_ + ptr_, bytes, remaining);
|
||||
flash_->pageProgram(address_, buffer_, W25QXX_PAGE_SIZE);
|
||||
|
||||
@ -43,15 +49,9 @@ namespace sta
|
||||
|
||||
address_ += W25QXX_PAGE_SIZE;
|
||||
|
||||
// If a new sector was started, erase the new sector.
|
||||
// If a new sector has to be started, erase the new sector.
|
||||
if (address_ % W25QXX_SECTOR_SIZE == 0)
|
||||
{
|
||||
// If the size of the logger segment was exceeded, restart at the first sector.
|
||||
if (address_ / W25QXX_SECTOR_SIZE == end_)
|
||||
{
|
||||
address_ = start_ * W25QXX_SECTOR_SIZE;
|
||||
}
|
||||
|
||||
flash_->sectorErase(address_);
|
||||
}
|
||||
}
|
||||
@ -81,7 +81,7 @@ namespace sta
|
||||
template <typename T>
|
||||
size_t Logger<T>::remaining()
|
||||
{
|
||||
return (end_ * W25QXX_SECTOR_SIZE - address_) / sizeof(T);
|
||||
return (end_ * W25QXX_SECTOR_SIZE - address_) / sizeof(T);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -9,13 +9,15 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
W25Qxx::W25Qxx(SPIDevice * device, DelayUsFunc delay, AddressMode addrMode /* = AddressMode::_24BIT */)
|
||||
W25Qxx::W25Qxx(SPIDevice * device, DelayUsFunc delay, AddressMode addrMode /* = AddressMode::_24BIT */, Mutex * mutex /* = Mutex::ALWAYS_FREE */)
|
||||
: device_{device},
|
||||
delay_{delay},
|
||||
mutex_{mutex},
|
||||
state_{ChipState::POWERED_DOWN},
|
||||
addrMode_{addrMode}
|
||||
{
|
||||
STA_ASSERT(device != nullptr);
|
||||
STA_ASSERT(mutex != nullptr);
|
||||
}
|
||||
|
||||
uint8_t W25Qxx::init()
|
||||
|
Loading…
x
Reference in New Issue
Block a user