Added mutex protection and re-arranged some methods

This commit is contained in:
dario
2024-06-04 16:00:18 +02:00
parent 007ed46363
commit a15b2398ab
2 changed files with 66 additions and 41 deletions

View File

@@ -78,18 +78,38 @@ namespace sta
*/
uint8_t init();
/**
* @brief Checks if the flash is busy writing or erasing.
*
* @return bool Returns true if the flash is busy, false otherwise.
*/
bool isBusy();
uint32_t getChunkBytes(ChunkSize size);
/**
* @brief
*
* @note
*
* @param criterion
* @param size
* @return uint32_t
*/
/**
* @brief Find the first memory section not satisfying a given criterion using a binary search.
*
* @note This function assume that there is a page n such that every page before n satisfies the criterion, while every page after that doesn't
* @note This function assumes that there is a page n such that every page before n satisfies the criterion, while every page after that doesn't.
*
* @param criterion A function evaluating the criterion on a page.
* @param size The size of the memory section. Has to be one of the predefined sizes.
* @param startAddr The start address of the segment to search. Defaults to the chip's start address.
* @param endAddr The end address of the segment to search. Defaults to the chip's end address.
* @return uint32_t The last address such that the criterion is satisfied.
*/
uint32_t findLast(std::function<bool(uint8_t*)> criterion, ChunkSize size);
uint32_t findLast(std::function<bool(uint8_t*)> criterion, ChunkSize size, uint32_t startAddr = 0, uint32_t endAddr = W25QXX_32B_MEM_SIZE);
/**
* @brief Set the Address Mode object
@@ -150,41 +170,7 @@ namespace sta
// reset device
// Extended address register read / write?
// Enter 4-Byte address mode
// Exit 4-Byte address mode
public:
/*
* Status registers.
*/
/**
* @brief Read one of the flash's status registers.
*
* @param regID The ID of the status register. Can only be 1, 2 or 3.
* @param status_byte A pointer to the variable to write the state into.
* @return uint8_t Returns 1 if successful, 0 otherwise.
*/
uint8_t readStatusRegister(uint8_t regID, uint8_t * status_byte);
/**
* @brief Write into one of the chip's status registers.
*
* @param regID The ID of the status register. Can only be 1, 2 or 3.
* @param status_byte The byte to write into the status register.
* @param nonvolatile If set to true, this setting will be restored after power off.
* @return uint8_t Returns 1 if successful, 0 otherwise.
*/
uint8_t writeStatusRegister(uint8_t regID, uint8_t * status_byte, bool nonvolatile = false);
/**
* @brief Checks if the flash is busy writing or erasing.
*
* @return bool Returns true if the flash is busy, false otherwise.
*/
bool isBusy();
// Extended address register read / write?
public:
/*
* Read / Write operations
@@ -319,6 +305,24 @@ namespace sta
uint8_t writeVolatileEnable();
/**
* @brief Read one of the flash's status registers.
*
* @param regID The ID of the status register. Can only be 1, 2 or 3.
* @param status_byte A pointer to the variable to write the state into.
* @return uint8_t Returns 1 if successful, 0 otherwise.
*/
uint8_t readStatusRegister(uint8_t regID, uint8_t * status_byte);
/**
* @brief Write into one of the chip's status registers.
*
* @param regID The ID of the status register. Can only be 1, 2 or 3.
* @param status_byte The byte to write into the status register.
* @param nonvolatile If set to true, this setting will be restored after power off.
* @return uint8_t Returns 1 if successful, 0 otherwise.
*/
uint8_t writeStatusRegister(uint8_t regID, uint8_t * status_byte, bool nonvolatile = false);
private:
SPIDevice * device_;
DelayUsFunc delay_;