2022-05-30 18:22:31 -03:00
|
|
|
/*
|
|
|
|
logging for block based dataflash devices on SPI
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
|
|
|
|
#include "AP_Logger_Block.h"
|
|
|
|
|
|
|
|
#if HAL_LOGGING_DATAFLASH_ENABLED
|
|
|
|
|
2024-04-24 12:45:29 -03:00
|
|
|
class AP_Logger_W25NXX : public AP_Logger_Block {
|
2022-05-30 18:22:31 -03:00
|
|
|
public:
|
2024-04-24 12:45:29 -03:00
|
|
|
AP_Logger_W25NXX(AP_Logger &front, LoggerMessageWriter_DFLogStart *writer) :
|
2022-05-30 18:22:31 -03:00
|
|
|
AP_Logger_Block(front, writer) {}
|
|
|
|
static AP_Logger_Backend *probe(AP_Logger &front,
|
|
|
|
LoggerMessageWriter_DFLogStart *ls) {
|
2024-04-24 12:45:29 -03:00
|
|
|
return new AP_Logger_W25NXX(front, ls);
|
2022-05-30 18:22:31 -03:00
|
|
|
}
|
|
|
|
void Init(void) override;
|
|
|
|
bool CardInserted() const override { return !flash_died && df_NumPages > 0; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void BufferToPage(uint32_t PageAdr) override;
|
|
|
|
void PageToBuffer(uint32_t PageAdr) override;
|
|
|
|
void SectorErase(uint32_t SectorAdr) override;
|
|
|
|
void Sector4kErase(uint32_t SectorAdr) override;
|
|
|
|
void StartErase() override;
|
|
|
|
bool InErase() override;
|
|
|
|
void send_command_addr(uint8_t cmd, uint32_t address);
|
|
|
|
void WaitReady();
|
|
|
|
bool Busy();
|
|
|
|
uint8_t ReadStatusRegBits(uint8_t bits);
|
|
|
|
void WriteStatusReg(uint8_t reg, uint8_t bits);
|
|
|
|
|
|
|
|
void WriteEnable();
|
|
|
|
bool getSectorCount(void);
|
|
|
|
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::SPIDevice> dev;
|
|
|
|
AP_HAL::Semaphore *dev_sem;
|
|
|
|
|
2024-04-24 12:23:38 -03:00
|
|
|
uint32_t flash_blockNum;
|
|
|
|
|
2022-05-30 18:22:31 -03:00
|
|
|
bool flash_died;
|
|
|
|
uint32_t erase_start_ms;
|
|
|
|
uint16_t erase_block;
|
2022-10-01 16:48:25 -03:00
|
|
|
bool read_cache_valid;
|
2022-05-30 18:22:31 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // HAL_LOGGING_DATAFLASH_ENABLED
|