75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
#ifndef __FLASH_MANAGER_H__
|
|
#define __FLASH_MANAGER_H__
|
|
|
|
#include <cstdint>
|
|
#include "common_types.h"
|
|
|
|
class FlashManager {
|
|
public:
|
|
static FlashManager &instance();
|
|
|
|
RetCode init();
|
|
RetCode erase(uint32_t address, uint32_t size);
|
|
RetCode write(uint32_t address, const void *data, uint32_t length);
|
|
RetCode read(uint32_t address, void *buffer, uint32_t length);
|
|
RetCode self_test(uint32_t test_size);
|
|
|
|
uint32_t total_size() const { return total_size_; }
|
|
uint32_t sector_size() const { return sector_size_; }
|
|
bool is_initialized() const { return initialized_; }
|
|
|
|
private:
|
|
FlashManager();
|
|
~FlashManager() = default;
|
|
FlashManager(const FlashManager &) = delete;
|
|
FlashManager &operator=(const FlashManager &) = delete;
|
|
|
|
enum FlashType : uint8_t {
|
|
FLASH_TYPE_INTERNAL = 0,
|
|
FLASH_TYPE_EXTERNAL_SPI,
|
|
FLASH_TYPE_EXTERNAL_NOR,
|
|
};
|
|
|
|
struct FlashInfo {
|
|
uint32_t total_size;
|
|
uint32_t sector_size;
|
|
uint32_t page_size;
|
|
uint32_t block_size;
|
|
uint32_t manufacturer_id;
|
|
uint32_t device_id;
|
|
};
|
|
|
|
RetCode waitFlashOperation();
|
|
RetCode unlockInternalFlash();
|
|
RetCode lockInternalFlash();
|
|
uint32_t addressToSectorCode(uint32_t address);
|
|
RetCode eraseInternalFlashSector(uint32_t sector_address);
|
|
RetCode writeInternalFlash(uint32_t address, const void *data, uint32_t length);
|
|
RetCode initInternalFlash();
|
|
|
|
RetCode spiFlashSelect();
|
|
RetCode spiFlashDeselect();
|
|
RetCode spiFlashSendCommand(uint8_t cmd);
|
|
RetCode spiFlashReadStatus(uint8_t *status);
|
|
RetCode spiFlashWaitIdle();
|
|
RetCode spiFlashWriteEnable();
|
|
RetCode initExternalSpiFlash();
|
|
RetCode readExternalSpiFlash(uint32_t address, void *buffer, uint32_t length);
|
|
RetCode writeExternalSpiFlash(uint32_t address, const void *data, uint32_t length);
|
|
RetCode eraseExternalSpiFlashSector(uint32_t address);
|
|
|
|
RetCode initExternalNorFlash();
|
|
RetCode readExternalNorFlash(uint32_t address, void *buffer, uint32_t length);
|
|
RetCode writeExternalNorFlash(uint32_t address, const void *data, uint32_t length);
|
|
RetCode eraseExternalNorFlashSector(uint32_t address);
|
|
|
|
FlashType type_;
|
|
FlashInfo info_;
|
|
uint32_t total_size_;
|
|
uint32_t sector_size_;
|
|
bool initialized_;
|
|
bool write_enabled_;
|
|
};
|
|
|
|
#endif
|