ports/embed: Enable use of POSIX VFS.

In the embedding-full example, that requires disabling mphal-backed stdio
again as it conflicts with the implementation brought in by
vfs_posix_file.c.

Signed-off-by: Christian Walther <cwalther@gmx.ch>
pull/11430/head
Christian Walther 2024-03-30 23:05:20 +01:00
rodzic 3a8f8db38d
commit ca93048ab9
5 zmienionych plików z 47 dodań i 5 usunięć

Wyświetl plik

@ -28,8 +28,15 @@ static const char *example_2 =
"help('modules')\n"
"import sys\n"
"help(sys)\n"
// Skip testing stdin when using the POSIX implementation, i.e. it is
// connected to actual stdin, because that makes the program wait for input,
// which can be inconvenient or confusing (giving the appearance of being
// stuck). There is no harm enabling it if you remember to provide some
// input.
#if !MICROPY_VFS_POSIX
"print('sys.stdin.read(3):', repr(sys.stdin.read(3)))\n"
"print('sys.stdin.buffer.read(3):', repr(sys.stdin.buffer.read(3)))\n"
#endif
"sys.stdout.write('hello stdout text\\n')\n"
"sys.stdout.buffer.write(b'hello stdout binary\\n')\n"
"sys.stdout.write('hello stderr text\\n')\n"
@ -61,12 +68,23 @@ static const char *example_2 =
"import lfshello\n"
"help(lfshello)\n"
"print('lfshello.hello():', lfshello.hello())\n"
"vfs.mount(vfs.VfsPosix('.'), '/posix')\n"
"print('os.listdir(\\'/posix\\'):', os.listdir('/posix'))\n"
"with open('/posix/posixhello.py', 'wb') as f:\n"
" f.write(b'def hello():\\n return \"Hello from a POSIX file!\"\\n')\n"
"with open('/posix/posixhello.py', 'rb') as f:\n"
" print('posixhello.py:', f.read())\n"
"sys.path.append('/posix')\n"
"import posixhello\n"
"help(posixhello)\n"
"print('posixhello.hello():', posixhello.hello())\n"
"os.unlink('/posix/posixhello.py')"
"\n"
"print('finish')\n"
;
// This array is the MicroPython GC heap.
static char heap[12 * 1024];
static char heap[16 * 1024];
int main() {
#if MICROPY_STACK_CHECK

Wyświetl plik

@ -16,8 +16,8 @@ EMBED_EXTRA += \
# Include source for mphal-backed stdio in the output.
# Disable when using POSIX-backed stdio (MICROPY_VFS_POSIX).
EMBED_EXTRA += \
shared/runtime/sys_stdio_mphal.c
#EMBED_EXTRA += \
# shared/runtime/sys_stdio_mphal.c
# Include library sources for littlefs 2 in the output.
EMBED_EXTRA += littlefs2

Wyświetl plik

@ -19,9 +19,11 @@
#define MICROPY_HW_BOARD_NAME "embedded"
#define MICROPY_HW_MCU_NAME "C"
// Enable the VFS subsystem, littlefs, importing from VFS, and the vfs module.
// Enable the VFS subsystem, littlefs and POSIX VFS, importing from VFS, and
// the vfs module.
#define MICROPY_VFS (1)
#define MICROPY_VFS_LFS2 (1)
#define MICROPY_VFS_POSIX (1)
#define MICROPY_READER_VFS (1)
#define MICROPY_PY_VFS (1)

Wyświetl plik

@ -65,6 +65,8 @@ uint64_t mp_hal_time_ns(void) {
#endif
// Text-mode standard output
// (When MICROPY_PY_SYS_STDFILES && MICROPY_VFS_POSIX, this is only used for
// mp_plat_print (mostly debug output), but not for print() and sys.stdout.)
void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
// This is a simplistic implementation for demonstration purposes. A real
// one would probably want to prefix every line, not just at the start of a
@ -75,7 +77,7 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
start_of_line = (len > 0 && (str[len-1] == '\n' || str[len-1] == '\r'));
}
#if MICROPY_PY_SYS_STDFILES
#if MICROPY_PY_SYS_STDFILES && !MICROPY_VFS_POSIX
// Binary-mode standard input
// Receive single character, blocking until one is available.

Wyświetl plik

@ -4,3 +4,23 @@
#if MICROPY_KBD_EXCEPTION
void mp_hal_set_interrupt_char(int c);
#endif
#if MICROPY_VFS_POSIX
// This macro is used to implement PEP 475 to retry specified syscalls on EINTR
#define MP_HAL_RETRY_SYSCALL(ret, syscall, raise) { \
for (;;) { \
MP_THREAD_GIL_EXIT(); \
ret = syscall; \
MP_THREAD_GIL_ENTER(); \
if (ret == -1) { \
int err = errno; \
if (err == EINTR) { \
mp_handle_pending(true); \
continue; \
} \
raise; \
} \
break; \
} \
}
#endif