Skip to content

Commit d20cf8f

Browse files
committed
Merge branch 'feature/update_vfs_for_fatfs' into 'master'
feat(vfs): update vfs for ESP8266 See merge request sdk/ESP8266_RTOS_SDK!1317
2 parents 02c5155 + 5ddea6d commit d20cf8f

File tree

32 files changed

+2885
-549
lines changed

32 files changed

+2885
-549
lines changed

components/esp8266/driver/uart.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,16 +667,12 @@ static void uart_rx_intr_handler_default(void *param)
667667
notify = UART_SELECT_ERROR_NOTIF;
668668
}
669669

670-
#ifdef CONFIG_USING_ESP_VFS
671670
if (uart_event.type != UART_EVENT_MAX && p_uart->uart_select_notif_callback) {
672671
p_uart->uart_select_notif_callback(uart_num, notify, &task_woken);
673672
if (task_woken == pdTRUE) {
674673
portYIELD_FROM_ISR();
675674
}
676675
}
677-
#else
678-
(void)notify;
679-
#endif
680676

681677
if (uart_event.type != UART_EVENT_MAX && p_uart->xQueueUart) {
682678
if (pdFALSE == xQueueSendFromISR(p_uart->xQueueUart, (void *)&uart_event, &task_woken)) {
@@ -1094,3 +1090,8 @@ esp_err_t uart_set_rx_timeout(uart_port_t uart_num, const uint8_t tout_thresh)
10941090
UART_EXIT_CRITICAL();
10951091
return ESP_OK;
10961092
}
1093+
1094+
bool uart_is_driver_installed(uart_port_t uart_num)
1095+
{
1096+
return uart_num < UART_NUM_MAX && (p_uart_obj[uart_num] != NULL);
1097+
}

components/esp8266/include/driver/uart.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
extern "C" {
2121
#endif
2222

23+
#include <stdbool.h>
2324
#include "esp_err.h"
2425
#include "esp_log.h"
2526
#include "freertos/queue.h"
@@ -553,6 +554,17 @@ esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t *size);
553554
*/
554555
esp_err_t uart_set_rx_timeout(uart_port_t uart_num, const uint8_t tout_thresh);
555556

557+
/**
558+
* @brief Checks whether the driver is installed or not
559+
*
560+
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
561+
*
562+
* @return
563+
* - true driver is installed
564+
* - false driver is not installed
565+
*/
566+
bool uart_is_driver_installed(uart_port_t uart_num);
567+
556568
#ifdef __cplusplus
557569
}
558570
#endif

components/lwip/port/esp8266/vfs_lwip.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,35 @@
2121
#include "esp_vfs.h"
2222
#include "esp_vfs_dev.h"
2323
#include "esp_attr.h"
24-
#include "esp8266/uart_struct.h"
2524
#include "lwip/sockets.h"
2625
#include "sdkconfig.h"
2726
#include "lwip/sys.h"
2827

2928
_Static_assert(MAX_FDS >= CONFIG_LWIP_MAX_SOCKETS, "MAX_FDS < CONFIG_LWIP_MAX_SOCKETS");
3029

31-
static void lwip_stop_socket_select()
30+
static void lwip_stop_socket_select(void *sem)
3231
{
33-
sys_sem_signal(sys_thread_sem_get()); //socket_select will return
32+
sys_sem_signal(sem); //socket_select will return
3433
}
3534

36-
static void lwip_stop_socket_select_isr(BaseType_t *woken)
35+
static void lwip_stop_socket_select_isr(void *sem, BaseType_t *woken)
3736
{
38-
if (sys_sem_signal_isr(sys_thread_sem_get()) && woken) {
37+
if (sys_sem_signal_isr(sem) && woken) {
3938
*woken = pdTRUE;
4039
}
4140
}
4241

43-
static int lwip_fcntl_r_wrapper(int fd, int cmd, va_list args)
42+
static void *lwip_get_socket_select_semaphore(void)
4443
{
45-
return lwip_fcntl(fd, cmd, va_arg(args, int));
44+
/* Calling this from the same process as select() will ensure that the semaphore won't be allocated from
45+
* ISR (lwip_stop_socket_select_isr).
46+
*/
47+
return (void *) sys_thread_sem_get();
48+
}
49+
50+
static int lwip_fcntl_r_wrapper(int fd, int cmd, int arg)
51+
{
52+
return lwip_fcntl(fd, cmd, arg);
4653
}
4754

4855
static int lwip_ioctl_r_wrapper(int fd, int cmd, va_list args)
@@ -62,6 +69,7 @@ void esp_vfs_lwip_sockets_register(void)
6269
.fcntl = &lwip_fcntl_r_wrapper,
6370
.ioctl = &lwip_ioctl_r_wrapper,
6471
.socket_select = &lwip_select,
72+
.get_socket_select_semaphore = &lwip_get_socket_select_semaphore,
6573
.stop_socket_select = &lwip_stop_socket_select,
6674
.stop_socket_select_isr = &lwip_stop_socket_select_isr,
6775
};

components/newlib/newlib/port/esp_newlib.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
#include <stdlib.h>
1919
#include <string.h>
2020
#include <unistd.h>
21-
#ifdef CONFIG_USING_ESP_VFS
2221
#include "esp_vfs_dev.h"
23-
#endif
2422

2523
#define _STR(_s) #_s
2624
#define STR(_s) _STR(_s)
@@ -56,9 +54,7 @@ int esp_newlib_init(void)
5654

5755
esp_reent_init(_global_impure_ptr);
5856

59-
#ifdef CONFIG_USING_ESP_VFS
6057
esp_vfs_dev_uart_register();
61-
#endif
6258

6359
_GLOBAL_REENT->_stdout = fopen(default_uart_dev, "w");
6460
if (!_GLOBAL_REENT->_stdout)

components/newlib/newlib/port/select.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <sys/select.h>
1616
#include "sdkconfig.h"
1717

18-
#ifdef CONFIG_USING_ESP_VFS
1918
#include "esp_vfs.h"
2019

2120
#ifdef CONFIG_USE_ONLY_LWIP_SELECT
@@ -64,4 +63,3 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct
6463
return esp_vfs_select(nfds, readfds, writefds, errorfds, timeout);
6564
#endif
6665
}
67-
#endif /* CONFIG_USING_ESP_VFS */

components/newlib/newlib/port/syscall.c

Lines changed: 13 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -16,119 +16,17 @@
1616

1717
#include <stdio.h>
1818
#include <string.h>
19+
#include <reent.h>
1920
#include <sys/stat.h>
2021
#include <sys/errno.h>
22+
#include <sys/fcntl.h>
2123

2224
#include "esp_libc.h"
2325
#include "FreeRTOS.h"
2426
#include "esp_log.h"
2527

26-
#ifdef CONFIG_USING_ESP_VFS
27-
2828
#include "esp_vfs.h"
2929

30-
int _open_r(struct _reent *r, const char *filename, int flags, int mode)
31-
{
32-
return esp_vfs_open(r, filename, flags, mode);
33-
}
34-
35-
_ssize_t _read_r(struct _reent *r, int fd, void *buf, size_t len)
36-
{
37-
return esp_vfs_read(r, fd, buf, len);
38-
}
39-
40-
_ssize_t _write_r(struct _reent *r, int fd, const void *buf, size_t len)
41-
{
42-
return esp_vfs_write(r, fd, buf, len);
43-
}
44-
45-
_off_t _lseek_r(struct _reent *r, int fd, _off_t where, int whence)
46-
{
47-
return esp_vfs_lseek(r, fd, where, whence);
48-
}
49-
50-
int _close_r(struct _reent *r, int fd)
51-
{
52-
return esp_vfs_close(r, fd);
53-
}
54-
55-
int _rename_r(struct _reent *r, const char *from, const char *to)
56-
{
57-
return esp_vfs_rename(r, from, to);
58-
}
59-
60-
int _unlink_r(struct _reent *r, const char *filename)
61-
{
62-
return esp_vfs_unlink(r, filename);
63-
}
64-
65-
int _fstat_r(struct _reent *r, int fd, struct stat *s)
66-
{
67-
return esp_vfs_fstat(r, fd, s);
68-
}
69-
70-
int _stat_r(struct _reent *r, const char *path, struct stat *st)
71-
{
72-
return esp_vfs_stat(r, path, st);
73-
}
74-
75-
#else
76-
77-
int _open_r(struct _reent *r, const char *filename, int flags, int mode)
78-
{
79-
return 0;
80-
}
81-
82-
_ssize_t _read_r(struct _reent *r, int fd, void *buf, size_t len)
83-
{
84-
return 0;
85-
}
86-
87-
_ssize_t _write_r(struct _reent *r, int fd, const void *buf, size_t len)
88-
{
89-
int i;
90-
const char *cbuf = buf;
91-
92-
for (i = 0; i < len; i++)
93-
ets_putc(cbuf[i]);
94-
95-
return len;
96-
}
97-
98-
_off_t _lseek_r(struct _reent *r, int fd, _off_t where, int whence)
99-
{
100-
return 0;
101-
}
102-
103-
int _close_r(struct _reent *r, int fd)
104-
{
105-
return 0;
106-
}
107-
108-
int _rename_r(struct _reent *r, const char *from, const char *to)
109-
{
110-
return 0;
111-
}
112-
113-
int _unlink_r(struct _reent *r, const char *filename)
114-
{
115-
return 0;
116-
}
117-
118-
int _fstat_r(struct _reent *r, int fd, struct stat *s)
119-
{
120-
s->st_mode = S_IFCHR;
121-
122-
return 0;
123-
}
124-
125-
int _stat_r(struct _reent *r, const char *path, struct stat *st)
126-
{
127-
return 0;
128-
}
129-
130-
#endif /* CONFIG_USING_ESP_VFS */
131-
13230
void *_malloc_r(struct _reent *r, size_t n)
13331
{
13432
void *return_addr = (void *)__builtin_return_address(0);
@@ -184,3 +82,14 @@ int _getpid_r(struct _reent *r)
18482
__errno_r(r) = ENOSYS;
18583
return -1;
18684
}
85+
86+
/* Replaces newlib fcntl, which has been compiled without HAVE_FCNTL */
87+
int fcntl(int fd, int cmd, ...)
88+
{
89+
va_list args;
90+
va_start(args, cmd);
91+
int arg = va_arg(args, int);
92+
va_end(args);
93+
struct _reent* r = __getreent();
94+
return _fcntl_r(r, fd, cmd, arg);
95+
}

components/vfs/CMakeLists.txt

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
2-
if(CONFIG_USING_ESP_VFS)
3-
set(COMPONENT_SRCS "vfs.c"
4-
"vfs_uart.c")
5-
else()
6-
set(COMPONENT_SRCDIRS "port")
7-
endif()
8-
9-
set(COMPONENT_ADD_INCLUDEDIRS "include")
10-
11-
set(COMPONENT_REQUIRES "lwip")
12-
13-
register_component()
1+
idf_component_register(SRCS "vfs.c"
2+
"vfs_uart.c"
3+
"vfs_semihost.c"
4+
INCLUDE_DIRS include)
5+
6+
# Some newlib syscalls are implemented in vfs.c, make sure these are always
7+
# seen by the linker
8+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u vfs_include_syscalls_impl")

components/vfs/Kconfig

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
menu "Virtual file system"
22

3-
config USING_ESP_VFS
4-
bool "Using espressif VFS"
5-
default y
6-
help
7-
Enable this option, espressif VFS can be used. Users can use APIs like "open", "read", "write"
8-
and so on to operate I/O device which is registered.
3+
config VFS_SUPPRESS_SELECT_DEBUG_OUTPUT
4+
bool "Suppress select() related debug outputs"
5+
default y
6+
help
7+
Select() related functions might produce an unconveniently lot of
8+
debug outputs when one sets the default log level to DEBUG or higher.
9+
It is possible to suppress these debug outputs by enabling this
10+
option.
911

10-
config SUPPRESS_SELECT_DEBUG_OUTPUT
11-
bool "Suppress select() related debug outputs"
12-
default n
13-
depends on USING_ESP_VFS
14-
help
15-
Select() related functions might produce an unconveniently lot of
16-
debug outputs when one sets the default log level to DEBUG or higher.
17-
It is possible to suppress these debug outputs by enabling this
18-
option.
12+
config VFS_SUPPORT_TERMIOS
13+
bool "Add support for termios.h"
14+
default y
15+
help
16+
Disabling this option can save memory when the support for termios.h is not required.
1917

20-
config SUPPORT_TERMIOS
21-
bool "Add support for termios.h"
22-
default n
23-
depends on USING_ESP_VFS
24-
help
25-
Disabling this option can save memory when the support for termios.h is not required.
18+
menu "Host File System I/O (Semihosting)"
19+
config SEMIHOSTFS_MAX_MOUNT_POINTS
20+
int "Maximum number of the host filesystem mount points"
21+
default 1
22+
help
23+
Define maximum number of host filesystem mount points.
24+
25+
config SEMIHOSTFS_HOST_PATH_MAX_LEN
26+
int "Maximum path length for the host base directory"
27+
default 128
28+
help
29+
Define maximum path length for the host base directory which is to be mounted.
30+
If host path passed to esp_vfs_semihost_register() is longer than this value
31+
it will be truncated.
32+
endmenu
2633

2734
endmenu

0 commit comments

Comments
 (0)