9 #if CONFIG_HAL_BOARD == HAL_BOARD_F4LIGHT && defined(BOARD_DATAFLASH_CS_PIN) && !defined(BOARD_DATAFLASH_FATFS) 16 #include <sys/types.h> 25 #pragma GCC diagnostic ignored "-Wunused-result" 31 static uint8_t cmd[4];
41 #define DF_LOGGING_FORMAT 0x28122013L 115 if (df_BufferIdx == 0) {
123 df_BufferIdx += n +
sizeof(ph);
130 pBuffer = (
const void *)(n + (uintptr_t)pBuffer);
168 struct PageHeader ph;
171 df_FilePage = ph.FilePage;
189 pBuffer = (
void *)(n + (uintptr_t)pBuffer);
191 df_Read_BufferIdx += n;
201 struct PageHeader ph;
206 df_FilePage = ph.FilePage;
208 df_Read_BufferIdx =
sizeof(ph);
239 uint32_t version = DF_LOGGING_FORMAT;
275 uint32_t version = 0;
280 if(version == DF_LOGGING_FORMAT)
return false;
282 printf(
"Need to erase: version is %lx required %lx\n", version, DF_LOGGING_FORMAT);
292 uint16_t data_page_size =
df_PageSize -
sizeof(
struct PageHeader);
294 if (offset >= data_page_size) {
295 page += offset / data_page_size;
296 offset = offset % data_page_size;
306 df_Read_BufferIdx = offset +
sizeof(
struct PageHeader);
330 while (offset < fmt_header_size && len > 0) {
332 uint8_t t = offset /
sizeof(pkt);
333 uint8_t ofs = offset %
sizeof(pkt);
335 uint8_t n =
sizeof(pkt) - ofs;
339 memcpy(data, ofs + (uint8_t *)&pkt, n);
345 offset -= fmt_header_size;
362 #if BOARD_DATAFLASH_ERASE_SIZE >= 65536 373 Scheduler::_delay(1);
385 AP_HAL::panic(
"PANIC: DataFlash SPIDeviceDriver semaphore is null");
477 const char * mfg=
NULL;
481 if (memtype == 0x40) {
483 size = (1 << ((capacity & 0x0f) + 8));
493 if (memtype == 0x25) {
495 size = (1 << ((capacity & 0x07) + 12));
500 if (memtype == 0xba){
502 size = (1 << ((capacity & 0x0f) + 8));
505 }
else if(memtype==0x20) {
507 size = (1 << ((capacity & 0x0f) + 8));
512 if (memtype == 0x20) {
514 size = (1 << ((capacity & 0x0f) + 8));
521 if (memtype == 0x40 || memtype == 0x30) {
523 size = (1 << ((capacity & 0x0f) + 8));
532 printf(
"%s SPI Flash found sectors=%ld\n", mfg, size);
534 printf(
"\nUnknown Flash! SPI Flash codes: mfg=%x type=%x cap=%x\n ",
df_manufacturer, memtype, capacity);
591 cmd[1] = (PageAdr >> 16) & 0xff;
592 cmd[2] = (PageAdr >> 8) & 0xff;
593 cmd[3] = (PageAdr >> 0) & 0xff;
609 cmd[1] = (PageAdr >> 16) & 0xff;
610 cmd[2] = (PageAdr >> 8) & 0xff;
611 cmd[3] = (PageAdr >> 0) & 0xff;
625 buffer[BufferNum][IntPageAdr] = (uint8_t)Data;
629 const void *pHeader, uint8_t hdr_size,
630 const void *pBuffer, uint16_t size)
633 memcpy(&
buffer[BufferNum][IntPageAdr],
637 memcpy(&
buffer[BufferNum][IntPageAdr+hdr_size],
647 memcpy(pBuffer, &
buffer[BufferNum][IntPageAdr], size);
665 cmd[1] = (PageAdr >> 16) & 0xff;
666 cmd[2] = (PageAdr >> 8) & 0xff;
667 cmd[3] = (PageAdr >> 0) & 0xff;
740 return (last - first + 1);
762 uint16_t new_log_num;
773 if (last_page == 0xFFFF) {
790 if (df_BufferIdx != 0) {
804 start_page = end_page + 1;
823 }
while (start_page <= 0 && look >=1);
827 if (start_page ==
df_NumPages+1 || start_page == 0) {
832 end_page = start_page;
863 uint32_t bottom_hash;
869 while(top-bottom > 1) {
870 look = (top+bottom)/2;
873 if (look_hash >= 0xFFFF0000) look_hash = 0;
875 if(look_hash < bottom_hash) {
881 bottom_hash = look_hash;
887 if (top_hash >= 0xFFFF0000) {
890 if (top_hash > bottom_hash) {
909 if (bottom > log_number)
922 check_hash = (int32_t)log_number<<16 | 0xFFFF;
924 while(top-bottom > 1)
926 look = (top+bottom)/2;
929 if (look_hash >= 0xFFFF0000) look_hash = 0;
931 if(look_hash > check_hash) {
int printf(const char *fmt,...)
bool get_soft_armed() const
uint8_t num_types() const
bool getSectorCount(uint32_t *ptr)
static AP_HAL::OwnPtr< AP_HAL::SPIDevice > _spi
static uint8_t buffer[SRXL_FRAMELEN_MAX]
static AP_HAL::Semaphore * _spi_sem
uint16_t GetWritePage(void)
#define JEDEC_STATUS_BUSY
void get_log_boundaries(uint16_t log_num, uint16_t &start_page, uint16_t &end_page)
#define BOARD_DATAFLASH_PAGES
#define HAL_SEMAPHORE_BLOCK_FOREVER
bool WritesOK() const override
virtual bool take(uint32_t timeout_ms) WARN_IF_UNUSED=0
const struct LogStructure * structure(uint8_t structure) const
bool BlockRead(uint8_t BufferNum, uint16_t IntPageAdr, void *pBuffer, uint16_t size)
#define JEDEC_WRITE_ENABLE
uint32_t bufferspace_available()
#define BOARD_DATAFLASH_ERASE_SIZE
virtual void delay(uint16_t ms)=0
virtual OwnPtr< SPIDevice > get_device(const char *name)
int _write(int fd, const char *buf, size_t cnt)
virtual Semaphore * get_semaphore() override=0
bool CardInserted(void) const
virtual bool WriteBlockCheckStartupMessages()
void get_log_info(uint16_t log_num, uint32_t &size, uint32_t &time_utc)
#define JEDEC_SECTOR_ERASE
void spi_write(uint8_t b)
void StartRead(uint16_t PageAdr)
uint16_t get_num_logs() override
int16_t get_log_data_raw(uint16_t log_num, uint16_t page, uint32_t offset, uint16_t len, uint8_t *data)
AP_HAL::SPIDeviceManager * spi
int16_t get_log_data(uint16_t log_num, uint16_t page, uint32_t offset, uint16_t len, uint8_t *data)
void ReadManufacturerID()
virtual bool set_speed(Device::Speed speed) override=0
void BlockWrite(uint8_t BufferNum, uint16_t IntPageAdr, const void *pHeader, uint8_t hdr_size, const void *pBuffer, uint16_t size)
void BufferWrite(uint8_t BufferNum, uint16_t IntPageAdr, uint8_t Data)
virtual bool transfer(const uint8_t *send, uint32_t send_len, uint8_t *recv, uint32_t recv_len) override=0
void Log_Fill_Format(const struct LogStructure *structure, struct log_Format &pkt)
void PageToBuffer(uint8_t BufferNum, uint16_t PageAdr)
bool ReadBlock(void *pBuffer, uint16_t size)
void Flash_Jedec_WriteEnable()
void StartWrite(uint16_t PageAdr)
uint8_t df_Read_BufferNum
static bool _sem_take(uint8_t timeout)
uint16_t find_last_page_of_log(uint16_t log_number)
void BufferToPage(uint8_t BufferNum, uint16_t PageAdr, uint8_t wait)
#define JEDEC_READ_STATUS
uint16_t df_Read_BufferIdx
uint16_t find_last_page(void)
uint16_t find_last_log() override
void panic(const char *errormsg,...) FMT_PRINTF(1
uint16_t start_new_log(void)
void PageErase(uint16_t PageAdr)
bool _WritePrioritisedBlock(const void *pBuffer, uint16_t size, bool is_critical)
AP_HAL::Scheduler * scheduler
static bool log_write_started
void SetFileNumber(uint16_t FileNumber)