8000 zephyr: Enable virtual file system and uos module. · boris93/micropython@a0440b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit a0440b0

Browse files
MaureenHelmdpgeorge
authored andcommitted
zephyr: Enable virtual file system and uos module.
Enables the virtual file system and uos module in the zephyr port. No concrete file system implementations are enabled yet.
1 parent cc19cf2 commit a0440b0

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

ports/zephyr/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ INC += -I$(ZEPHYR_BASE)/net/ip/contiki/os
3838

3939
SRC_C = main.c \
4040
help.c \
41+
moduos.c \
4142
modusocket.c \
4243
modutime.c \
4344
modzephyr.c \

ports/zephyr/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
#include "lib/utils/pyexec.h"
4242
#include "lib/mp-readline/readline.h"
4343

44+
#if MICROPY_VFS
45+
#include "extmod/vfs.h"
46+
#endif
47+
4448
#ifdef TEST
4549
#include "lib/upytesthelper/upytesthelper.h"
4650
#include "lib/tinytest/tinytest.c"
@@ -132,16 +136,26 @@ void gc_collect(void) {
132136
//gc_dump_info();
133137
}
134138

139+
#if !MICROPY_READER_VFS
135140
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
136141
mp_raise_OSError(ENOENT);
137142
}
143+
#endif
138144

139145
mp_import_stat_t mp_import_stat(const char *path) {
146+
#if MICROPY_VFS
147+
return mp_vfs_import_stat(path);
148+
#else
140149
return MP_IMPORT_STAT_NO_EXIST;
150+
#endif
141151
}
142152

143153
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
154+
#if MICROPY_VFS
155+
return mp_vfs_open(n_args, args, kwargs);
156+
#else
144157
return mp_const_none;
158+
#endif
145159
}
146160
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
147161

ports/zephyr/moduos.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 NXP
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/obj.h"
28+
29+
#include "extmod/vfs.h"
30+
31+
#if MICROPY_PY_UOS
32+
33+
STATIC const mp_rom_map_elem_t uos_module_globals_table[] = {
34+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) },
35+
#if MICROPY_VFS
36+
{ MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&mp_vfs_chdir_obj) },
37+
{ MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&mp_vfs_getcwd_obj) },
38+
{ MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mp_vfs_ilistdir_obj) },
39+
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&mp_vfs_listdir_obj) },
40+
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mp_vfs_mkdir_obj) },
41+
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&mp_vfs_remove_obj) },
42+
{ MP_ROM_QSTR(MP_QSTR_rename),MP_ROM_PTR(&mp_vfs_rename_obj)},
43+
{ MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&mp_vfs_rmdir_obj) },
44+
{ MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&mp_vfs_stat_obj) },
45+
{ MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&mp_vfs_statvfs_obj) },
46+
{ MP_ROM_QSTR(MP_QSTR_unlink), MP_ROM_PTR(&mp_vfs_remove_obj) },
47+
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
48+
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
49+
#endif
50+
};
51+
STATIC MP_DEFINE_CONST_DICT(uos_module_globals, uos_module_globals_table);
52+
53+
const mp_obj_module_t mp_module_uos = {
54+
.base = { &mp_type_module },
55+
.globals = (mp_obj_dict_t*)&uos_module_globals,
56+
};
57+
58+
#endif // MICROPY_PY_UOS

ports/zephyr/mpconfigport.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#endif
7373
#define MICROPY_PY_UBINASCII (1)
7474
#define MICROPY_PY_UHASHLIB (1)
75+
#define MICROPY_PY_UOS (1)
7576
#define MICROPY_PY_UTIME (1)
7677
#define MICROPY_PY_UTIME_MP_HAL (1)
7778
#define MICROPY_PY_ZEPHYR (1)
@@ -80,6 +81,8 @@
8081
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG)
8182
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
8283
#define MICROPY_PY_BUILTINS_COMPLEX (0)
84+
#define MICROPY_VFS (1)
85+
#define MICROPY_READER_VFS (MICROPY_VFS)
8386

8487
// Saving extra crumbs to make sure binary fits in 128K
8588
#define MICROPY_COMP_CONST_FOLDING (0)
@@ -113,10 +116,17 @@ typedef long mp_off_t;
113116

114117
extern const struct _mp_obj_module_t mp_module_machine;
115118
extern const struct _mp_obj_module_t mp_module_time;
119+
extern const struct _mp_obj_module_t mp_module_uos;
116120
extern const struct _mp_obj_module_t mp_module_usocket;
117121
extern const struct _mp_obj_module_t mp_module_zephyr;
118122
extern const struct _mp_obj_module_t mp_module_zsensor;
119123

124+
#if MICROPY_PY_UOS
125+
#define MICROPY_PY_UOS_DEF { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) },
126+
#else
127+
#define MICROPY_PY_UOS_DEF
128+
#endif
129+
120130
#if MICROPY_PY_USOCKET
121131
#define MICROPY_PY_USOCKET_DEF { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_usocket) },
122132
#else
@@ -143,11 +153,12 @@ extern const struct _mp_obj_module_t mp_module_zsensor;
143153

144154
#define MICROPY_PORT_BUILTIN_MODULES \
145155
{ MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \
156+
MICROPY_PY_UOS_DEF \
146157
MICROPY_PY_USOCKET_DEF \
147158
MICROPY_PY_UTIME_DEF \
148159
MICROPY_PY_ZEPHYR_DEF \
149160
MICROPY_PY_ZSENSOR_DEF \
150161

151162
// extra built in names to add to the global namespace
152163
#define MICROPY_PORT_BUILTINS \
153-
164+
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },

0 commit comments

Comments
 (0)
0