HAL_ChibiOS: implement erase() method on Storage in HAL_ChibiOS
This commit is contained in:
parent
12b6f73d83
commit
8fdbb88827
@ -21,6 +21,7 @@
|
|||||||
#include "hwdef/common/flash.h"
|
#include "hwdef/common/flash.h"
|
||||||
#include <AP_Filesystem/AP_Filesystem.h>
|
#include <AP_Filesystem/AP_Filesystem.h>
|
||||||
#include "sdcard.h"
|
#include "sdcard.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
using namespace ChibiOS;
|
using namespace ChibiOS;
|
||||||
|
|
||||||
@ -78,12 +79,12 @@ void Storage::_storage_open(void)
|
|||||||
|
|
||||||
log_fd = AP::FS().open(HAL_STORAGE_FILE, O_RDWR|O_CREAT);
|
log_fd = AP::FS().open(HAL_STORAGE_FILE, O_RDWR|O_CREAT);
|
||||||
if (log_fd == -1) {
|
if (log_fd == -1) {
|
||||||
hal.console->printf("open failed of " HAL_STORAGE_FILE "\n");
|
::printf("open failed of " HAL_STORAGE_FILE "\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int ret = AP::FS().read(log_fd, _buffer, CH_STORAGE_SIZE);
|
int ret = AP::FS().read(log_fd, _buffer, CH_STORAGE_SIZE);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
hal.console->printf("read failed for " HAL_STORAGE_FILE "\n");
|
::printf("read failed for " HAL_STORAGE_FILE "\n");
|
||||||
AP::FS().close(log_fd);
|
AP::FS().close(log_fd);
|
||||||
log_fd = -1;
|
log_fd = -1;
|
||||||
return;
|
return;
|
||||||
@ -91,7 +92,7 @@ void Storage::_storage_open(void)
|
|||||||
// pre-fill to full size
|
// pre-fill to full size
|
||||||
if (AP::FS().lseek(log_fd, ret, SEEK_SET) != ret ||
|
if (AP::FS().lseek(log_fd, ret, SEEK_SET) != ret ||
|
||||||
AP::FS().write(log_fd, &_buffer[ret], CH_STORAGE_SIZE-ret) != CH_STORAGE_SIZE-ret) {
|
AP::FS().write(log_fd, &_buffer[ret], CH_STORAGE_SIZE-ret) != CH_STORAGE_SIZE-ret) {
|
||||||
hal.console->printf("setup failed for " HAL_STORAGE_FILE "\n");
|
::printf("setup failed for " HAL_STORAGE_FILE "\n");
|
||||||
AP::FS().close(log_fd);
|
AP::FS().close(log_fd);
|
||||||
log_fd = -1;
|
log_fd = -1;
|
||||||
return;
|
return;
|
||||||
@ -222,7 +223,7 @@ void Storage::_flash_load(void)
|
|||||||
#ifdef STORAGE_FLASH_PAGE
|
#ifdef STORAGE_FLASH_PAGE
|
||||||
_flash_page = STORAGE_FLASH_PAGE;
|
_flash_page = STORAGE_FLASH_PAGE;
|
||||||
|
|
||||||
hal.console->printf("Storage: Using flash pages %u and %u\n", _flash_page, _flash_page+1);
|
::printf("Storage: Using flash pages %u and %u\n", _flash_page, _flash_page+1);
|
||||||
|
|
||||||
if (!_flash.init()) {
|
if (!_flash.init()) {
|
||||||
AP_HAL::panic("unable to init flash storage");
|
AP_HAL::panic("unable to init flash storage");
|
||||||
@ -265,7 +266,7 @@ bool Storage::_flash_write_data(uint8_t sector, uint32_t offset, const uint8_t *
|
|||||||
if (now - _last_re_init_ms > 5000) {
|
if (now - _last_re_init_ms > 5000) {
|
||||||
_last_re_init_ms = now;
|
_last_re_init_ms = now;
|
||||||
bool ok = _flash.re_initialise();
|
bool ok = _flash.re_initialise();
|
||||||
hal.console->printf("Storage: failed at %u:%u for %u - re-init %u\n",
|
::printf("Storage: failed at %u:%u for %u - re-init %u\n",
|
||||||
(unsigned)sector, (unsigned)offset, (unsigned)length, (unsigned)ok);
|
(unsigned)sector, (unsigned)offset, (unsigned)length, (unsigned)ok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,4 +319,26 @@ bool Storage::healthy(void)
|
|||||||
return _initialised && AP_HAL::millis() - _last_empty_ms < 2000;
|
return _initialised && AP_HAL::millis() - _last_empty_ms < 2000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
erase all storage
|
||||||
|
*/
|
||||||
|
bool Storage::erase(void)
|
||||||
|
{
|
||||||
|
#if HAL_WITH_RAMTRON
|
||||||
|
if (using_fram) {
|
||||||
|
return AP_HAL::Storage::erase();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_POSIX
|
||||||
|
if (using_filesystem) {
|
||||||
|
return AP_HAL::Storage::erase();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef STORAGE_FLASH_PAGE
|
||||||
|
return _flash.erase();
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endif // HAL_USE_EMPTY_STORAGE
|
#endif // HAL_USE_EMPTY_STORAGE
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
class ChibiOS::Storage : public AP_HAL::Storage {
|
class ChibiOS::Storage : public AP_HAL::Storage {
|
||||||
public:
|
public:
|
||||||
void init() override {}
|
void init() override {}
|
||||||
|
bool erase() override;
|
||||||
void read_block(void *dst, uint16_t src, size_t n) override;
|
void read_block(void *dst, uint16_t src, size_t n) override;
|
||||||
void write_block(uint16_t dst, const void* src, size_t n) override;
|
void write_block(uint16_t dst, const void* src, size_t n) override;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user