Fixed libc and SPIFFS integration. Test passes on ESP-12E module.
This commit is contained in:
parent
b71a7ad237
commit
0f9d991ba7
3 changed files with 26 additions and 9 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 983ed830a8d2bd1a3eaa586ed608530f9d29201e
|
Subproject commit 218c5235584429f407d619e5e35f90732ad505f3
|
|
@ -25,7 +25,7 @@ void test_task(void *pvParameters)
|
||||||
while (1) {
|
while (1) {
|
||||||
vTaskDelay(5000 / portTICK_RATE_MS);
|
vTaskDelay(5000 / portTICK_RATE_MS);
|
||||||
|
|
||||||
if (fs_test_run(10000)) {
|
if (fs_test_run(1000)) {
|
||||||
printf("PASS\n");
|
printf("PASS\n");
|
||||||
} else {
|
} else {
|
||||||
printf("FAIL\n");
|
printf("FAIL\n");
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <espressif/spi_flash.h>
|
#include <espressif/spi_flash.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <esp/uart.h>
|
#include <esp/uart.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
spiffs fs;
|
spiffs fs;
|
||||||
|
|
||||||
|
@ -187,11 +188,15 @@ void esp_spiffs_unmount()
|
||||||
cache_buf = 0;
|
cache_buf = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* syscall implementation for stdio write to UART */
|
#define FD_OFFSET 3
|
||||||
|
|
||||||
|
// This implementation replaces implementation in core/newlib_syscals.c
|
||||||
long _write_r(struct _reent *r, int fd, const char *ptr, int len )
|
long _write_r(struct _reent *r, int fd, const char *ptr, int len )
|
||||||
{
|
{
|
||||||
if(fd != r->_stdout->_file) {
|
if(fd != r->_stdout->_file) {
|
||||||
return SPIFFS_write(&fs, (spiffs_file)fd, (char*)ptr, len);
|
long ret = SPIFFS_write(&fs, (spiffs_file)(fd - FD_OFFSET),
|
||||||
|
(char*)ptr, len);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
for(int i = 0; i < len; i++) {
|
for(int i = 0; i < len; i++) {
|
||||||
/* Auto convert CR to CRLF, ignore other LFs (compatible with Espressif SDK behaviour) */
|
/* Auto convert CR to CRLF, ignore other LFs (compatible with Espressif SDK behaviour) */
|
||||||
|
@ -204,13 +209,14 @@ long _write_r(struct _reent *r, int fd, const char *ptr, int len )
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* syscall implementation for stdio read from UART */
|
// This implementation replaces implementation in core/newlib_syscals.c
|
||||||
long _read_r( struct _reent *r, int fd, char *ptr, int len )
|
long _read_r( struct _reent *r, int fd, char *ptr, int len )
|
||||||
{
|
{
|
||||||
int ch, i;
|
int ch, i;
|
||||||
|
|
||||||
if(fd != r->_stdin->_file) {
|
if(fd != r->_stdin->_file) {
|
||||||
return SPIFFS_read(&fs, (spiffs_file)fd, ptr, len);
|
long ret = SPIFFS_read(&fs, (spiffs_file)(fd - FD_OFFSET), ptr, len);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
uart_rxfifo_wait(0, 1);
|
uart_rxfifo_wait(0, 1);
|
||||||
for(i = 0; i < len; i++) {
|
for(i = 0; i < len; i++) {
|
||||||
|
@ -221,15 +227,26 @@ long _read_r( struct _reent *r, int fd, char *ptr, int len )
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* syscall implementation for stdio write to UART */
|
|
||||||
int _open_r(struct _reent *r, const char *pathname, int flags, int mode)
|
int _open_r(struct _reent *r, const char *pathname, int flags, int mode)
|
||||||
{
|
{
|
||||||
return SPIFFS_open(&fs, pathname, flags, mode);
|
uint32_t spiffs_flags = SPIFFS_RDONLY;
|
||||||
|
|
||||||
|
if (flags & O_CREAT) spiffs_flags |= SPIFFS_CREAT;
|
||||||
|
if (flags & O_APPEND) spiffs_flags |= SPIFFS_APPEND;
|
||||||
|
if (flags & O_TRUNC) spiffs_flags |= SPIFFS_TRUNC;
|
||||||
|
if (flags & O_RDONLY) spiffs_flags |= SPIFFS_RDONLY;
|
||||||
|
if (flags & O_WRONLY) spiffs_flags |= SPIFFS_WRONLY;
|
||||||
|
|
||||||
|
int ret = SPIFFS_open(&fs, pathname, spiffs_flags, mode);
|
||||||
|
if (ret > 0) {
|
||||||
|
return ret + FD_OFFSET;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _close_r(struct _reent *r, int fd)
|
int _close_r(struct _reent *r, int fd)
|
||||||
{
|
{
|
||||||
return SPIFFS_close(&fs, (spiffs_file)fd);
|
return SPIFFS_close(&fs, (spiffs_file)(fd - FD_OFFSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
int _unlink_r(struct _reent *r, const char *path)
|
int _unlink_r(struct _reent *r, const char *path)
|
||||||
|
|
Loading…
Reference in a new issue