Skip to content

Commit

Permalink
refactor: support exfat, mount status fix
Browse files Browse the repository at this point in the history
* chore/fix: support exfat, fix mount status

* chore: update save_jpeg docs

* chore: use larger tx buffer

* chore: refine fail logs
  • Loading branch information
iChizer0 authored Apr 18, 2024
1 parent d717626 commit 1cfc671
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/protocol/at_protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ Note:
- Compare operator.
- Logic operator.
1. Save JPEG specific:
- External TF card may required to be formatted as FAT32 (cluster size at 8192), the maximum supported capacity may limited to 32GB.
- External TF card may required to be formatted as FAT32 (cluster size at 8192) or exFat.
- The default **save path** is `<Device(Product) Name> Export`, if the directory is not exist, it will be created automatically.
- Inside the **save path**, each boot with this action triggered may create a new **save foler** named by a incremented number, the lastest folder name is stored in a hidden file named `.sscma` in the save path, user should not modify this file, otherwise error may occur.
- Inside the **save folder**, each file is named in numeric format with the `.jpeg` extension, the number is the timestamp (the up time of the device in milliseconds) when the file is triggered to save, so it only guarantees the saved files will not be overwritten in at most 49 days (`max(uint32_t) / 1000 / 60 / 60 / 24` = 49.7 days).
Expand Down
7 changes: 5 additions & 2 deletions porting/himax/we2/configs/ffconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@
#if defined(CONFIG_FATFS_FF_MAX_SS)
#define FF_MAX_SS CONFIG_FATFS_FF_MAX_SS
#else
#define FF_MAX_SS 512

#define FF_MAX_SS 4096 // for exFAT

#endif
/* This set of options configures the range of sector size to be supported. (512,
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
Expand Down Expand Up @@ -235,7 +237,8 @@
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */


#define FF_FS_EXFAT 0
#define FF_FS_EXFAT 1

/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
Expand Down
28 changes: 15 additions & 13 deletions porting/himax/we2/el_extfs_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,14 @@ static Status STATUS_FROM_FRESULT(FRESULT res) {
}
}

FileWE2::~FileWE2() {}
FileWE2::~FileWE2() { close(); }

void FileWE2::close() {
if (_file != nullptr) {
f_close(static_cast<FIL*>(_file));
delete static_cast<FIL*>(_file);
_file = nullptr;
}
_fs_mount_times = 0;
_mounted = false;
}

Status FileWE2::write(const uint8_t* data, size_t size, size_t* written) {
Expand All @@ -117,22 +115,22 @@ FileWE2::FileWE2(const void* f) {
*static_cast<FIL*>(_file) = *static_cast<const FIL*>(f);
}

int ExtfsWE2::_fs_mount_times = 0;
bool ExtfsWE2::_mounted = false;
int ExtfsWE2::_fs_mount_times = 0;

ExtfsWE2::ExtfsWE2() { _fs = new (std::nothrow) FATFS{}; }

ExtfsWE2::~ExtfsWE2() {
unmount();

delete static_cast<FATFS*>(_fs);
_fs = nullptr;
if (_fs != nullptr) delete static_cast<FATFS*>(_fs);
}

Status ExtfsWE2::mount(const char* path) {
if (_mounted) {
return {true, ""};
// a middle layer bug exist on we2, this is only a dirty workaround to avoid creash we2 system
static bool failed_before = false;
if (failed_before) {
return {false, "Please ensure the SD card is in slot and reset the board to mount the filesystem again"};
}

if (_fs_mount_times > CONFIG_FS_MAX_MOUNT_TIMES) {
return {false, "Filesystem mount times exceed the limit"};
}
Expand Down Expand Up @@ -187,14 +185,18 @@ Status ExtfsWE2::mount(const char* path) {
curdir = nullptr;
}

if (res == FR_OK) {
_mounted = true;
if (res != FR_OK) {
failed_before = true;
}

return STATUS_FROM_FRESULT(res);
}

void ExtfsWE2::unmount() { f_unmount(""); }
void ExtfsWE2::unmount() {
f_unmount("");

_fs_mount_times = 0;
}

bool ExtfsWE2::exists(const char* f) {
FILINFO fno;
Expand Down
2 changes: 0 additions & 2 deletions porting/himax/we2/el_extfs_we2.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class ExtfsWE2 final : public Extfs {
private:
static int _fs_mount_times;
void* _fs;

static bool _mounted;
};

} // namespace edgelab
Expand Down
4 changes: 2 additions & 2 deletions porting/himax/we2/el_wire_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ el_err_code_t WireWE2::init() {

this->_is_present = this->i2c ? true : false;

this->rx_ring_buffer = new lwRingBuffer(512);
this->tx_ring_buffer = new lwRingBuffer(16384);
this->rx_ring_buffer = new lwRingBuffer(1024 * 4);
this->tx_ring_buffer = new lwRingBuffer(1024 * 64);

this->wire_read_enable(sizeof(this->tx_buffer));

Expand Down
3 changes: 3 additions & 0 deletions sscma/callback/extension/contents_export.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class ContentsExport {
delete[] _data;
_data = nullptr;
}
if (_extfs != nullptr) {
_extfs->unmount();
}
};

bool cache(const uint8_t* data, size_t size, size_t realloc_trigger = 1024 * 10) {
Expand Down

0 comments on commit 1cfc671

Please sign in to comment.