summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--ports/zephyr/Makefile1
-rw-r--r--ports/zephyr/main.c14
-rw-r--r--ports/zephyr/moduos.c58
-rw-r--r--ports/zephyr/mpconfigport.h13
4 files changed, 85 insertions, 1 deletions
diff --git a/ports/zephyr/Makefile b/ports/zephyr/Makefile
index b1c1866788..612548dbd0 100644
--- a/ports/zephyr/Makefile
+++ b/ports/zephyr/Makefile
@@ -38,6 +38,7 @@ INC += -I$(ZEPHYR_BASE)/net/ip/contiki/os
SRC_C = main.c \
help.c \
+ moduos.c \
modusocket.c \
modutime.c \
modzephyr.c \
diff --git a/ports/zephyr/main.c b/ports/zephyr/main.c
index 00dc71e28b..7c6458900c 100644
--- a/ports/zephyr/main.c
+++ b/ports/zephyr/main.c
@@ -41,6 +41,10 @@
#include "lib/utils/pyexec.h"
#include "lib/mp-readline/readline.h"
+#if MICROPY_VFS
+#include "extmod/vfs.h"
+#endif
+
#ifdef TEST
#include "lib/upytesthelper/upytesthelper.h"
#include "lib/tinytest/tinytest.c"
@@ -132,16 +136,26 @@ void gc_collect(void) {
//gc_dump_info();
}
+#if !MICROPY_READER_VFS
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
mp_raise_OSError(ENOENT);
}
+#endif
mp_import_stat_t mp_import_stat(const char *path) {
+ #if MICROPY_VFS
+ return mp_vfs_import_stat(path);
+ #else
return MP_IMPORT_STAT_NO_EXIST;
+ #endif
}
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
+ #if MICROPY_VFS
+ return mp_vfs_open(n_args, args, kwargs);
+ #else
return mp_const_none;
+ #endif
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
diff --git a/ports/zephyr/moduos.c b/ports/zephyr/moduos.c
new file mode 100644
index 0000000000..8bda39b562
--- /dev/null
+++ b/ports/zephyr/moduos.c
@@ -0,0 +1,58 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 NXP
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "py/obj.h"
+
+#include "extmod/vfs.h"
+
+#if MICROPY_PY_UOS
+
+STATIC const mp_rom_map_elem_t uos_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) },
+ #if MICROPY_VFS
+ { MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&mp_vfs_chdir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&mp_vfs_getcwd_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mp_vfs_ilistdir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&mp_vfs_listdir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mp_vfs_mkdir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&mp_vfs_remove_obj) },
+ { MP_ROM_QSTR(MP_QSTR_rename),MP_ROM_PTR(&mp_vfs_rename_obj)},
+ { MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&mp_vfs_rmdir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&mp_vfs_stat_obj) },
+ { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&mp_vfs_statvfs_obj) },
+ { MP_ROM_QSTR(MP_QSTR_unlink), MP_ROM_PTR(&mp_vfs_remove_obj) },
+ { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
+ { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
+ #endif
+};
+STATIC MP_DEFINE_CONST_DICT(uos_module_globals, uos_module_globals_table);
+
+const mp_obj_module_t mp_module_uos = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&uos_module_globals,
+};
+
+#endif // MICROPY_PY_UOS
diff --git a/ports/zephyr/mpconfigport.h b/ports/zephyr/mpconfigport.h
index 1ca357756c..73362f7e9d 100644
--- a/ports/zephyr/mpconfigport.h
+++ b/ports/zephyr/mpconfigport.h
@@ -72,6 +72,7 @@
#endif
#define MICROPY_PY_UBINASCII (1)
#define MICROPY_PY_UHASHLIB (1)
+#define MICROPY_PY_UOS (1)
#define MICROPY_PY_UTIME (1)
#define MICROPY_PY_UTIME_MP_HAL (1)
#define MICROPY_PY_ZEPHYR (1)
@@ -80,6 +81,8 @@
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_PY_BUILTINS_COMPLEX (0)
+#define MICROPY_VFS (1)
+#define MICROPY_READER_VFS (MICROPY_VFS)
// Saving extra crumbs to make sure binary fits in 128K
#define MICROPY_COMP_CONST_FOLDING (0)
@@ -113,10 +116,17 @@ typedef long mp_off_t;
extern const struct _mp_obj_module_t mp_module_machine;
extern const struct _mp_obj_module_t mp_module_time;
+extern const struct _mp_obj_module_t mp_module_uos;
extern const struct _mp_obj_module_t mp_module_usocket;
extern const struct _mp_obj_module_t mp_module_zephyr;
extern const struct _mp_obj_module_t mp_module_zsensor;
+#if MICROPY_PY_UOS
+#define MICROPY_PY_UOS_DEF { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) },
+#else
+#define MICROPY_PY_UOS_DEF
+#endif
+
#if MICROPY_PY_USOCKET
#define MICROPY_PY_USOCKET_DEF { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_usocket) },
#else
@@ -143,6 +153,7 @@ extern const struct _mp_obj_module_t mp_module_zsensor;
#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \
+ MICROPY_PY_UOS_DEF \
MICROPY_PY_USOCKET_DEF \
MICROPY_PY_UTIME_DEF \
MICROPY_PY_ZEPHYR_DEF \
@@ -150,4 +161,4 @@ extern const struct _mp_obj_module_t mp_module_zsensor;
// extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
-
+ { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },