From 4d7fba83a6192df95f8728e87d5923b11c29ece6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 22 Jan 2017 10:18:25 +1100 Subject: cc3200: Convert to use builtin help function. --- cc3200/application.mk | 1 - cc3200/misc/help.c | 19 ++----------------- cc3200/mpconfigport.h | 3 ++- 3 files changed, 4 insertions(+), 19 deletions(-) (limited to 'cc3200') diff --git a/cc3200/application.mk b/cc3200/application.mk index f2801c337..b4d659fa1 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -153,7 +153,6 @@ APP_LIB_SRC_C = $(addprefix lib/,\ netutils/netutils.c \ timeutils/timeutils.c \ utils/pyexec.c \ - utils/pyhelp.c \ ) APP_STM_SRC_C = $(addprefix stmhal/,\ diff --git a/cc3200/misc/help.c b/cc3200/misc/help.c index 4601818bd..cce515898 100644 --- a/cc3200/misc/help.c +++ b/cc3200/misc/help.c @@ -25,23 +25,8 @@ * THE SOFTWARE. */ -#include +#include "py/builtin.h" -#include "lib/utils/pyhelp.h" - -STATIC const char help_text[] = "Welcome to MicroPython!\n" +const char *cc3200_help_text = "Welcome to MicroPython!\n" "For online help please visit http://micropython.org/help/.\n" "For further help on a specific object, type help(obj)\n"; - -STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) { - if (n_args == 0) { - // print a general help message - printf("%s", help_text); - } - else { - // try to print something sensible about the given object - pyhelp_print_obj(args[0]); - } - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj, 0, 1, pyb_help); diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 5b6a035d5..4bf0b1061 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -80,6 +80,8 @@ #define MICROPY_PY_ASYNC_AWAIT (0) #define MICROPY_PY_BUILTINS_TIMEOUTERROR (1) #define MICROPY_PY_ALL_SPECIAL_METHODS (1) +#define MICROPY_PY_BUILTINS_HELP (1) +#define MICROPY_PY_BUILTINS_HELP_TEXT cc3200_help_text #ifndef DEBUG #define MICROPY_PY_BUILTINS_STR_UNICODE (1) #define MICROPY_PY_BUILTINS_STR_SPLITLINES (1) @@ -120,7 +122,6 @@ // extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_help), (mp_obj_t)&mp_builtin_help_obj }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, \ -- cgit v1.2.3 From 32a1138b9f66b76808906064a76c5f9533cc825c Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 27 Jan 2017 15:04:17 +1100 Subject: extmod: Rename vfs_fat_file.h to vfs_fat.h. And move declaration of mp_fat_vfs_type to this file. --- cc3200/mods/moduos.c | 2 +- esp8266/moduos.c | 3 +-- extmod/vfs_fat.c | 2 +- extmod/vfs_fat.h | 39 +++++++++++++++++++++++++++++++++++++++ extmod/vfs_fat_ffconf.c | 2 +- extmod/vfs_fat_file.c | 2 +- extmod/vfs_fat_file.h | 38 -------------------------------------- extmod/vfs_fat_misc.c | 2 +- extmod/vfs_fat_reader.c | 2 +- stmhal/builtin_open.c | 2 +- stmhal/moduos.c | 2 +- unix/modos.c | 2 +- 12 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 extmod/vfs_fat.h delete mode 100644 extmod/vfs_fat_file.h (limited to 'cc3200') diff --git a/cc3200/mods/moduos.c b/cc3200/mods/moduos.c index d5b29336a..1c9932b8e 100644 --- a/cc3200/mods/moduos.c +++ b/cc3200/mods/moduos.c @@ -37,7 +37,7 @@ #include "moduos.h" #include "diskio.h" #include "sflash_diskio.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "random.h" #include "mpexception.h" #include "version.h" diff --git a/esp8266/moduos.c b/esp8266/moduos.c index e9c4c3e8c..5f5aab166 100644 --- a/esp8266/moduos.c +++ b/esp8266/moduos.c @@ -34,12 +34,11 @@ #include "py/runtime.h" #include "py/mperrno.h" #include "extmod/misc.h" +#include "extmod/vfs_fat.h" #include "genhdr/mpversion.h" #include "esp_mphal.h" #include "user_interface.h" -extern const mp_obj_type_t mp_fat_vfs_type; - STATIC const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 36bdb5dbd..36e5031a8 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -37,7 +37,7 @@ #include "py/runtime.h" #include "py/mperrno.h" #include "lib/oofatfs/ff.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "extmod/fsusermount.h" #include "timeutils.h" diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h new file mode 100644 index 000000000..441b35c04 --- /dev/null +++ b/extmod/vfs_fat.h @@ -0,0 +1,39 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013, 2014 Damien P. George + * + * 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. + */ + +struct _fs_user_mount_t; + +extern const byte fresult_to_errno_table[20]; +extern const mp_obj_type_t mp_fat_vfs_type; + +struct _fs_user_mount_t *ff_get_vfs(const char **path); + +mp_obj_t fatfs_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs); +mp_obj_t fatfs_builtin_open_self(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); +MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj); + +mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type); +mp_obj_t fat_vfs_listdir2(struct _fs_user_mount_t *vfs, const char *path, bool is_str_type); diff --git a/extmod/vfs_fat_ffconf.c b/extmod/vfs_fat_ffconf.c index ddcdd8844..89081380e 100644 --- a/extmod/vfs_fat_ffconf.c +++ b/extmod/vfs_fat_ffconf.c @@ -36,7 +36,7 @@ #include "lib/fatfs/ff.h" #endif #include "extmod/fsusermount.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" STATIC bool check_path(const TCHAR **path, const char *mount_point_str, mp_uint_t mount_point_len) { if (strncmp(*path, mount_point_str, mount_point_len) == 0) { diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index 6651d70d0..ea332709e 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -42,7 +42,7 @@ #include "lib/fatfs/ff.h" #endif #include "extmod/fsusermount.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #if MICROPY_VFS_FAT #define mp_type_fileio fatfs_type_fileio diff --git a/extmod/vfs_fat_file.h b/extmod/vfs_fat_file.h deleted file mode 100644 index 9693aa04a..000000000 --- a/extmod/vfs_fat_file.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * 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. - */ - -struct _fs_user_mount_t; - -extern const byte fresult_to_errno_table[20]; - -struct _fs_user_mount_t *ff_get_vfs(const char **path); - -mp_obj_t fatfs_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs); -mp_obj_t fatfs_builtin_open_self(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); -MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj); - -mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type); -mp_obj_t fat_vfs_listdir2(struct _fs_user_mount_t *vfs, const char *path, bool is_str_type); diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index 5e89009cd..ea267a15f 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -37,7 +37,7 @@ #else #include "lib/fatfs/ff.h" #endif -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "extmod/fsusermount.h" #include "py/lexer.h" diff --git a/extmod/vfs_fat_reader.c b/extmod/vfs_fat_reader.c index efd2de0c1..b9abf3ad7 100644 --- a/extmod/vfs_fat_reader.c +++ b/extmod/vfs_fat_reader.c @@ -38,7 +38,7 @@ #include "lib/fatfs/ff.h" #endif #include "extmod/fsusermount.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" typedef struct _mp_reader_fatfs_t { FIL fp; diff --git a/stmhal/builtin_open.c b/stmhal/builtin_open.c index 697eec8ea..56b98ea61 100644 --- a/stmhal/builtin_open.c +++ b/stmhal/builtin_open.c @@ -25,6 +25,6 @@ */ #include "py/runtime.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, fatfs_builtin_open); diff --git a/stmhal/moduos.c b/stmhal/moduos.c index b3c6570a5..158e530ff 100644 --- a/stmhal/moduos.c +++ b/stmhal/moduos.c @@ -37,7 +37,7 @@ #include "timeutils.h" #include "rng.h" #include "uart.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "sdcard.h" #include "extmod/fsusermount.h" #include "portmodules.h" diff --git a/unix/modos.c b/unix/modos.c index 72f5d872e..c35b246dd 100644 --- a/unix/modos.c +++ b/unix/modos.c @@ -39,6 +39,7 @@ #include "py/objtuple.h" #include "py/mphal.h" #include "extmod/misc.h" +#include "extmod/vfs_fat.h" // Can't include this, as FATFS structure definition is required, // and FatFs header defining it conflicts with POSIX. @@ -46,7 +47,6 @@ MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mount_obj); MP_DECLARE_CONST_FUN_OBJ_1(fsuser_umount_obj); MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj); -extern const mp_obj_type_t mp_fat_vfs_type; #ifdef __ANDROID__ #define USE_STATFS 1 -- cgit v1.2.3 From bfa948c0a50c8f543c9b0751eb42cffac09656ec Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 27 Jan 2017 23:14:11 +1100 Subject: cc3200: Add implementations of mp_import_stat and builtin_open. They disappeared when stmhal changed to use new MICROPY_VFS code. --- cc3200/application.mk | 2 -- cc3200/main.c | 11 +++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'cc3200') diff --git a/cc3200/application.mk b/cc3200/application.mk index b4d659fa1..a4d496649 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -157,8 +157,6 @@ APP_LIB_SRC_C = $(addprefix lib/,\ APP_STM_SRC_C = $(addprefix stmhal/,\ bufhelper.c \ - builtin_open.c \ - import.c \ input.c \ irq.c \ pybstdio.c \ diff --git a/cc3200/main.c b/cc3200/main.c index 06b3604b6..fd263442c 100644 --- a/cc3200/main.c +++ b/cc3200/main.c @@ -113,3 +113,14 @@ void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, *ppxIdleTaskStackBuffer = uxIdleTaskStack; *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; } + +// the following is temporay, until cc3200 converts to oofatfs + +#include "py/lexer.h" +#include "extmod/vfs_fat.h" + +mp_import_stat_t mp_import_stat(const char *path) { + return fat_vfs_import_stat(NULL, path); +} + +MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, fatfs_builtin_open); -- cgit v1.2.3 From 3a3543251fee73597c2cebefea94da78c4fc8b89 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 29 Jan 2017 02:47:26 +0300 Subject: cc3200/modusocket: Remove deprecated socket.error. socket.error is deprecated even in upstream: https://docs.python.org/3/library/socket.html#socket.error, and never was a part of MicroPython socket API. --- cc3200/mods/modusocket.c | 1 - 1 file changed, 1 deletion(-) (limited to 'cc3200') diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index 9554c2608..45f1f2d47 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -522,7 +522,6 @@ STATIC const mp_map_elem_t mp_module_usocket_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&mod_usocket_getaddrinfo_obj }, // class exceptions - { MP_OBJ_NEW_QSTR(MP_QSTR_error), (mp_obj_t)&mp_type_OSError }, { MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&mp_type_TimeoutError }, // class constants -- cgit v1.2.3 From 56506fd64a40f9c5ea97888245df6f2cb8b20744 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 29 Jan 2017 15:15:16 +1100 Subject: cc3200: Convert to use new VFS sub-system and new ooFatFs library. --- cc3200/Makefile | 1 + cc3200/application.mk | 12 +- cc3200/fatfs/src/diskio.c | 209 -------------- cc3200/fatfs/src/drivers/sd_diskio.c | 3 +- cc3200/fatfs/src/drivers/sflash_diskio.c | 3 +- cc3200/fatfs/src/ffconf.c | 93 ------- cc3200/fatfs/src/option/syscall.c | 150 ---------- cc3200/fatfs_port.c | 74 +++++ cc3200/ftp/ftp.c | 135 ++++++--- cc3200/main.c | 11 - cc3200/mods/moduos.c | 464 ++----------------------------- cc3200/mods/moduos.h | 16 +- cc3200/mods/pybflash.c | 110 ++++++++ cc3200/mods/pybflash.h | 35 +++ cc3200/mods/pybsd.c | 46 ++- cc3200/mpconfigport.h | 17 +- cc3200/mptask.c | 62 +++-- 17 files changed, 445 insertions(+), 996 deletions(-) delete mode 100644 cc3200/fatfs/src/diskio.c delete mode 100644 cc3200/fatfs/src/ffconf.c delete mode 100644 cc3200/fatfs/src/option/syscall.c create mode 100644 cc3200/fatfs_port.c create mode 100644 cc3200/mods/pybflash.c create mode 100644 cc3200/mods/pybflash.h (limited to 'cc3200') diff --git a/cc3200/Makefile b/cc3200/Makefile index 1798ac927..4db3b9e8d 100644 --- a/cc3200/Makefile +++ b/cc3200/Makefile @@ -23,6 +23,7 @@ CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -march=armv7e-m -mabi=aapcs -mcpu=co CFLAGS = -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) -Os CFLAGS += -g -ffunction-sections -fdata-sections -fno-common -fsigned-char -mno-unaligned-access CFLAGS += -Iboards/$(BOARD) +CFLAGS += $(CFLAGS_MOD) LDFLAGS = -Wl,-nostdlib -Wl,--gc-sections -Wl,-Map=$@.map diff --git a/cc3200/application.mk b/cc3200/application.mk index a4d496649..5ee909144 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -18,7 +18,6 @@ APP_INC += -Iutil APP_INC += -Ibootmgr APP_INC += -I$(BUILD) APP_INC += -I$(BUILD)/genhdr -APP_INC += -I../lib/fatfs APP_INC += -I../lib/mp-readline APP_INC += -I../lib/netutils APP_INC += -I../lib/timeutils @@ -29,9 +28,6 @@ APP_CPPDEFINES = -Dgcc -DTARGET_IS_CC3200 -DSL_FULL -DUSE_FREERTOS APP_FATFS_SRC_C = $(addprefix fatfs/src/,\ drivers/sflash_diskio.c \ drivers/sd_diskio.c \ - option/syscall.c \ - diskio.c \ - ffconf.c \ ) APP_RTOS_SRC_C = $(addprefix FreeRTOS/Source/,\ @@ -98,6 +94,7 @@ APP_MODS_SRC_C = $(addprefix mods/,\ pybpin.c \ pybi2c.c \ pybrtc.c \ + pybflash.c \ pybsd.c \ pybsleep.c \ pybspi.c \ @@ -143,11 +140,12 @@ APP_MAIN_SRC_C = \ main.c \ mptask.c \ mpthreadport.c \ - serverstask.c + serverstask.c \ + fatfs_port.c \ APP_LIB_SRC_C = $(addprefix lib/,\ - fatfs/ff.c \ - fatfs/option/ccsbcs.c \ + oofatfs/ff.c \ + oofatfs/option/unicode.c \ libc/string0.c \ mp-readline/readline.c \ netutils/netutils.c \ diff --git a/cc3200/fatfs/src/diskio.c b/cc3200/fatfs/src/diskio.c deleted file mode 100644 index 74bc6a0d5..000000000 --- a/cc3200/fatfs/src/diskio.c +++ /dev/null @@ -1,209 +0,0 @@ -/*-----------------------------------------------------------------------*/ -/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */ -/*-----------------------------------------------------------------------*/ -/* If a working storage control module is available, it should be */ -/* attached to the FatFs via a glue function rather than modifying it. */ -/* This is an example of glue functions to attach various exsisting */ -/* storage control modules to the FatFs module with a defined API. */ -/*-----------------------------------------------------------------------*/ -#include -#include - -#include "py/mpconfig.h" -#include "py/runtime.h" -#include "py/obj.h" -#include "lib/fatfs/ff.h" -#include "lib/fatfs/diskio.h" /* FatFs lower layer API */ -#include "sflash_diskio.h" /* Serial flash disk IO API */ -#include "sd_diskio.h" /* SDCARD disk IO API */ -#include "inc/hw_types.h" -#include "inc/hw_ints.h" -#include "inc/hw_memmap.h" -#include "rom_map.h" -#include "prcm.h" -#include "pybrtc.h" -#include "timeutils.h" -#include "pybsd.h" -#include "moduos.h" - - -/*-----------------------------------------------------------------------*/ -/* Get Drive Status */ -/*-----------------------------------------------------------------------*/ - -DSTATUS disk_status ( - BYTE pdrv /* Physical drive nmuber to identify the drive */ -) -{ - if (pdrv == PD_FLASH) { - return sflash_disk_status(); - } else { - os_fs_mount_t *mount_obj; - if ((mount_obj = osmount_find_by_volume(pdrv))) { - if (mount_obj->writeblocks[0] == MP_OBJ_NULL) { - return STA_PROTECT; - } - return 0; - } - } - return STA_NODISK; -} - -/*-----------------------------------------------------------------------*/ -/* Inidialize a Drive */ -/*-----------------------------------------------------------------------*/ - -DSTATUS disk_initialize ( - BYTE pdrv /* Physical drive nmuber to identify the drive */ -) -{ - if (pdrv == PD_FLASH) { - if (RES_OK != sflash_disk_init()) { - return STA_NOINIT; - } - } else { - os_fs_mount_t *mount_obj; - if ((mount_obj = osmount_find_by_volume(pdrv))) { - if (mount_obj->writeblocks[0] == MP_OBJ_NULL) { - return STA_PROTECT; - } - return 0; - } - } - return STA_NODISK; -} - -/*-----------------------------------------------------------------------*/ -/* Read Sector(s) */ -/*-----------------------------------------------------------------------*/ - -DRESULT disk_read ( - BYTE pdrv, /* Physical drive nmuber to identify the drive */ - BYTE *buff, /* Data buffer to store read data */ - DWORD sector, /* Sector address in LBA */ - UINT count /* Number of sectors to read */ -) -{ - if (pdrv == PD_FLASH) { - return sflash_disk_read(buff, sector, count); - } else { - os_fs_mount_t *mount_obj; - if ((mount_obj = osmount_find_by_volume(pdrv))) { - // optimization for the built-in sd card device - if (mount_obj->device == (mp_obj_t)&pybsd_obj) { - return sd_disk_read(buff, sector, count); - } - mount_obj->readblocks[2] = MP_OBJ_NEW_SMALL_INT(sector); - mount_obj->readblocks[3] = mp_obj_new_bytearray_by_ref(count * 512, buff); - return mp_obj_get_int(mp_call_method_n_kw(2, 0, mount_obj->readblocks)); - } - // nothing mounted - return RES_ERROR; - } - return RES_PARERR; -} - -/*-----------------------------------------------------------------------*/ -/* Write Sector(s) */ -/*-----------------------------------------------------------------------*/ - -#if _USE_WRITE -DRESULT disk_write ( - BYTE pdrv, /* Physical drive nmuber to identify the drive */ - const BYTE *buff, /* Data to be written */ - DWORD sector, /* Sector address in LBA */ - UINT count /* Number of sectors to write */ -) -{ - if (pdrv == PD_FLASH) { - return sflash_disk_write(buff, sector, count); - } else { - os_fs_mount_t *mount_obj; - if ((mount_obj = osmount_find_by_volume(pdrv))) { - // optimization for the built-in sd card device - if (mount_obj->device == (mp_obj_t)&pybsd_obj) { - return sd_disk_write(buff, sector, count); - } - mount_obj->writeblocks[2] = MP_OBJ_NEW_SMALL_INT(sector); - mount_obj->writeblocks[3] = mp_obj_new_bytearray_by_ref(count * 512, (void *)buff); - return mp_obj_get_int(mp_call_method_n_kw(2, 0, mount_obj->writeblocks)); - } - // nothing mounted - return RES_ERROR; - } - return RES_PARERR; -} -#endif - - -/*-----------------------------------------------------------------------*/ -/* Miscellaneous Functions */ -/*-----------------------------------------------------------------------*/ - -#if _USE_IOCTL -DRESULT disk_ioctl ( - BYTE pdrv, /* Physical drive nmuber (0..) */ - BYTE cmd, /* Control code */ - void *buff /* Buffer to send/receive control data */ -) -{ - if (pdrv == PD_FLASH) { - switch (cmd) { - case CTRL_SYNC: - return sflash_disk_flush(); - case GET_SECTOR_COUNT: - *((DWORD*)buff) = SFLASH_SECTOR_COUNT; - return RES_OK; - case GET_SECTOR_SIZE: - *((DWORD*)buff) = SFLASH_SECTOR_SIZE; - return RES_OK; - case GET_BLOCK_SIZE: - *((DWORD*)buff) = 1; // high-level sector erase size in units of the block size - return RES_OK; - } - } else { - os_fs_mount_t *mount_obj; - if ((mount_obj = osmount_find_by_volume(pdrv))) { - switch (cmd) { - case CTRL_SYNC: - if (mount_obj->sync[0] != MP_OBJ_NULL) { - mp_call_method_n_kw(0, 0, mount_obj->sync); - } - return RES_OK; - case GET_SECTOR_COUNT: - // optimization for the built-in sd card device - if (mount_obj->device == (mp_obj_t)&pybsd_obj) { - *((DWORD*)buff) = sd_disk_info.ulNofBlock * (sd_disk_info.ulBlockSize / 512); - } else { - *((DWORD*)buff) = mp_obj_get_int(mp_call_method_n_kw(0, 0, mount_obj->count)); - } - return RES_OK; - case GET_SECTOR_SIZE: - *((DWORD*)buff) = SD_SECTOR_SIZE; // Sector size is fixed to 512 bytes, as with SD cards - return RES_OK; - case GET_BLOCK_SIZE: - *((DWORD*)buff) = 1; // high-level sector erase size in units of the block size - return RES_OK; - } - } - // nothing mounted - return RES_ERROR; - } - return RES_PARERR; -} -#endif - -#if !_FS_READONLY && !_FS_NORTC -DWORD get_fattime ( - void -) -{ - timeutils_struct_time_t tm; - timeutils_seconds_since_2000_to_struct_time(pyb_rtc_get_seconds(), &tm); - - return ((tm.tm_year - 1980) << 25) | ((tm.tm_mon) << 21) | - ((tm.tm_mday) << 16) | ((tm.tm_hour) << 11) | - ((tm.tm_min) << 5) | (tm.tm_sec >> 1); -} -#endif - diff --git a/cc3200/fatfs/src/drivers/sd_diskio.c b/cc3200/fatfs/src/drivers/sd_diskio.c index c20969bfb..0a1379181 100644 --- a/cc3200/fatfs/src/drivers/sd_diskio.c +++ b/cc3200/fatfs/src/drivers/sd_diskio.c @@ -39,11 +39,12 @@ #include "py/mpconfig.h" #include "py/mphal.h" +#include "lib/oofatfs/ff.h" +#include "lib/oofatfs/diskio.h" #include "hw_types.h" #include "hw_memmap.h" #include "hw_ints.h" #include "rom_map.h" -#include "diskio.h" #include "sd_diskio.h" #include "sdhost.h" #include "pin.h" diff --git a/cc3200/fatfs/src/drivers/sflash_diskio.c b/cc3200/fatfs/src/drivers/sflash_diskio.c index 7fb2c97a7..1cfd41fb7 100644 --- a/cc3200/fatfs/src/drivers/sflash_diskio.c +++ b/cc3200/fatfs/src/drivers/sflash_diskio.c @@ -4,8 +4,9 @@ #include "py/mpconfig.h" #include "py/obj.h" +#include "lib/oofatfs/ff.h" +#include "lib/oofatfs/diskio.h" #include "simplelink.h" -#include "diskio.h" #include "sflash_diskio.h" #include "debug.h" #include "modnetwork.h" diff --git a/cc3200/fatfs/src/ffconf.c b/cc3200/fatfs/src/ffconf.c deleted file mode 100644 index 71ef6a40b..000000000 --- a/cc3200/fatfs/src/ffconf.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * 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 - -#include "py/mpstate.h" -#include "lib/fatfs/ff.h" -#include "lib/fatfs/ffconf.h" -#include "lib/fatfs/diskio.h" -#include "moduos.h" - -#if _FS_RPATH -extern BYTE ff_CurrVol; -#endif - -STATIC bool check_path(const TCHAR **path, const char *mount_point_str, mp_uint_t mount_point_len) { - if (strncmp(*path, mount_point_str, mount_point_len) == 0) { - if ((*path)[mount_point_len] == '/') { - *path += mount_point_len; - return true; - } else if ((*path)[mount_point_len] == '\0') { - *path = "/"; - return true; - } - } - return false; -} - -// "path" is the path to lookup; will advance this pointer beyond the volume name. -// Returns logical drive number (-1 means invalid path). -int ff_get_ldnumber (const TCHAR **path) { - if (!(*path)) { - return -1; - } - - if (**path != '/') { - #if _FS_RPATH - return ff_CurrVol; - #else - return -1; - #endif - } - - if (check_path(path, "/flash", 6)) { - return PD_FLASH; - } - else { - for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) { - os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i])); - if (check_path(path, mount_obj->path, mount_obj->pathlen)) { - return mount_obj->vol; - } - } - } - - return -1; -} - -void ff_get_volname(BYTE vol, TCHAR **dest) { - if (vol == PD_FLASH) { - memcpy(*dest, "/flash", 6); - *dest += 6; - } else { - os_fs_mount_t *mount_obj; - if ((mount_obj = osmount_find_by_volume(vol))) { - memcpy(*dest, mount_obj->path, mount_obj->pathlen); - *dest += mount_obj->pathlen; - } - } -} diff --git a/cc3200/fatfs/src/option/syscall.c b/cc3200/fatfs/src/option/syscall.c deleted file mode 100644 index 1ada97bd4..000000000 --- a/cc3200/fatfs/src/option/syscall.c +++ /dev/null @@ -1,150 +0,0 @@ -/*------------------------------------------------------------------------*/ -/* Sample code of OS dependent controls for FatFs */ -/* (C)ChaN, 2014 */ -/*------------------------------------------------------------------------*/ - -#include "ff.h" - - -#if _FS_REENTRANT -/*------------------------------------------------------------------------*/ -/* Create a Synchronization Object */ -/*------------------------------------------------------------------------*/ -/* This function is called in f_mount() function to create a new -/ synchronization object, such as semaphore and mutex. When a 0 is returned, -/ the f_mount() function fails with FR_INT_ERR. -*/ - -int ff_cre_syncobj ( /* !=0:Function succeeded, ==0:Could not create due to any error */ - BYTE vol, /* Corresponding logical drive being processed */ - _SYNC_t *sobj /* Pointer to return the created sync object */ -) -{ - int ret; - -// -// *sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */ -// ret = (int)(*sobj != INVALID_HANDLE_VALUE); - -// *sobj = SyncObjects[vol]; /* uITRON (give a static created sync object) */ -// ret = 1; /* The initial value of the semaphore must be 1. */ - -// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */ -// ret = (int)(err == OS_NO_ERR); - - vSemaphoreCreateBinary( (*sobj) ); /* FreeRTOS */ - ret = (int)(*sobj != NULL); - - return ret; -} - - - -/*------------------------------------------------------------------------*/ -/* Delete a Synchronization Object */ -/*------------------------------------------------------------------------*/ -/* This function is called in f_mount() function to delete a synchronization -/ object that created with ff_cre_syncobj function. When a 0 is returned, -/ the f_mount() function fails with FR_INT_ERR. -*/ - -int ff_del_syncobj ( /* !=0:Function succeeded, ==0:Could not delete due to any error */ - _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ -) -{ - int ret; - - -// ret = CloseHandle(sobj); /* Win32 */ - -// ret = 1; /* uITRON (nothing to do) */ - -// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */ -// ret = (int)(err == OS_NO_ERR); - - vSemaphoreDelete(sobj); /* FreeRTOS */ - ret = 1; - - return ret; -} - - - -/*------------------------------------------------------------------------*/ -/* Request Grant to Access the Volume */ -/*------------------------------------------------------------------------*/ -/* This function is called on entering file functions to lock the volume. -/ When a 0 is returned, the file function fails with FR_TIMEOUT. -*/ - -int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */ - _SYNC_t sobj /* Sync object to wait */ -) -{ - int ret; - -// ret = (int)(WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */ - -// ret = (int)(wai_sem(sobj) == E_OK); /* uITRON */ - -// OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */ -// ret = (int)(err == OS_NO_ERR); - - ret = (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */ - - return ret; -} - - - -/*------------------------------------------------------------------------*/ -/* Release Grant to Access the Volume */ -/*------------------------------------------------------------------------*/ -/* This function is called on leaving file functions to unlock the volume. -*/ - -void ff_rel_grant ( - _SYNC_t sobj /* Sync object to be signaled */ -) -{ -// ReleaseMutex(sobj); /* Win32 */ - -// sig_sem(sobj); /* uITRON */ - -// OSMutexPost(sobj); /* uC/OS-II */ - - xSemaphoreGive(sobj); /* FreeRTOS */ -} - -#endif - - - - -#if _USE_LFN == 3 /* LFN with a working buffer on the heap */ -/*------------------------------------------------------------------------*/ -/* Allocate a memory block */ -/*------------------------------------------------------------------------*/ -/* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE. -*/ - -void* ff_memalloc ( /* Returns pointer to the allocated memory block */ - UINT msize /* Number of bytes to allocate */ -) -{ - return pvPortMalloc(msize); /* Allocate a new memory block with POSIX API */ -} - - -/*------------------------------------------------------------------------*/ -/* Free a memory block */ -/*------------------------------------------------------------------------*/ - -void ff_memfree ( - void* mblock /* Pointer to the memory block to free */ -) -{ - vPortFree(mblock); /* Discard the memory block with POSIX API */ -} - -#endif diff --git a/cc3200/fatfs_port.c b/cc3200/fatfs_port.c new file mode 100644 index 000000000..658c94e88 --- /dev/null +++ b/cc3200/fatfs_port.c @@ -0,0 +1,74 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2017 Damien P. George + * Parts of this file are (C)ChaN, 2014, from FatFs option/syscall.c + * + * 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/runtime.h" +#include "lib/oofatfs/ff.h" +#include "lib/timeutils/timeutils.h" +#include "mods/pybrtc.h" + +#if _FS_REENTRANT +// Create a Synchronization Object +// This function is called in f_mount() function to create a new +// synchronization object, such as semaphore and mutex. +// A return of 0 indicates failure, and then f_mount() fails with FR_INT_ERR. +int ff_cre_syncobj(FATFS *fatfs, _SYNC_t *sobj) { + vSemaphoreCreateBinary((*sobj)); + return (int)(*sobj != NULL); +} + +// Delete a Synchronization Object +// This function is called in f_mount() function to delete a synchronization +// object that created with ff_cre_syncobj function. +// A return of 0 indicates failure, and then f_mount() fails with FR_INT_ERR. +int ff_del_syncobj(_SYNC_t sobj) { + vSemaphoreDelete(sobj); + return 1; +} + +// Request Grant to Access the Volume +// This function is called on entering file functions to lock the volume. +// When a 0 is returned, the file function fails with FR_TIMEOUT. +int ff_req_grant(_SYNC_t sobj) { + return (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); +} + +// Release Grant to Access the Volume +// This function is called on leaving file functions to unlock the volume. +void ff_rel_grant(_SYNC_t sobj) { + xSemaphoreGive(sobj); +} + +#endif + +DWORD get_fattime(void) { + timeutils_struct_time_t tm; + timeutils_seconds_since_2000_to_struct_time(pyb_rtc_get_seconds(), &tm); + + return ((tm.tm_year - 1980) << 25) | ((tm.tm_mon) << 21) | + ((tm.tm_mday) << 16) | ((tm.tm_hour) << 11) | + ((tm.tm_min) << 5) | (tm.tm_sec >> 1); +} diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c index 252a3d756..c8a52149c 100644 --- a/cc3200/ftp/ftp.c +++ b/cc3200/ftp/ftp.c @@ -30,6 +30,9 @@ #include "py/mpstate.h" #include "py/obj.h" +#include "lib/oofatfs/ff.h" +#include "extmod/vfs.h" +#include "extmod/fsusermount.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" @@ -43,7 +46,6 @@ #include "modusocket.h" #include "debug.h" #include "serverstask.h" -#include "ff.h" #include "fifo.h" #include "socketfifo.h" #include "updater.h" @@ -115,7 +117,7 @@ typedef struct { uint8_t *dBuffer; uint32_t ctimeout; union { - DIR dp; + FF_DIR dp; FIL fp; }; int16_t lc_sd; @@ -192,6 +194,80 @@ static const ftp_month_t ftp_month[] = { { "Jan" }, { "Feb" }, { "Mar" }, { "Apr static SocketFifoElement_t ftp_fifoelements[FTP_SOCKETFIFO_ELEMENTS_MAX]; static FIFO_t ftp_socketfifo; +/****************************************************************************** + DEFINE VFS WRAPPER FUNCTIONS + ******************************************************************************/ + +// These wrapper functions are used so that the FTP server can access the +// mounted FATFS devices directly without going through the costly mp_vfs_XXX +// functions. The latter may raise exceptions and we would then need to wrap +// all calls in an nlr handler. The wrapper functions below assume that there +// are only FATFS filesystems mounted. + +STATIC FATFS *lookup_path(const TCHAR **path) { + mp_vfs_mount_t *fs = mp_vfs_lookup_path(*path, path); + if (fs == MP_VFS_NONE || fs == MP_VFS_ROOT) { + return NULL; + } + // here we assume that the mounted device is FATFS + return &((fs_user_mount_t*)MP_OBJ_TO_PTR(fs->obj))->fatfs; +} + +STATIC FRESULT f_open_helper(FIL *fp, const TCHAR *path, BYTE mode) { + FATFS *fs = lookup_path(&path); + if (fs == NULL) { + return FR_NO_PATH; + } + return f_open(fs, fp, path, mode); +} + +STATIC FRESULT f_opendir_helper(FF_DIR *dp, const TCHAR *path) { + FATFS *fs = lookup_path(&path); + if (fs == NULL) { + return FR_NO_PATH; + } + return f_opendir(fs, dp, path); +} + +STATIC FRESULT f_stat_helper(const TCHAR *path, FILINFO *fno) { + FATFS *fs = lookup_path(&path); + if (fs == NULL) { + return FR_NO_PATH; + } + return f_stat(fs, path, fno); +} + +STATIC FRESULT f_mkdir_helper(const TCHAR *path) { + FATFS *fs = lookup_path(&path); + if (fs == NULL) { + return FR_NO_PATH; + } + return f_mkdir(fs, path); +} + +STATIC FRESULT f_unlink_helper(const TCHAR *path) { + FATFS *fs = lookup_path(&path); + if (fs == NULL) { + return FR_NO_PATH; + } + return f_unlink(fs, path); +} + +STATIC FRESULT f_rename_helper(const TCHAR *path_old, const TCHAR *path_new) { + FATFS *fs_old = lookup_path(&path_old); + if (fs_old == NULL) { + return FR_NO_PATH; + } + FATFS *fs_new = lookup_path(&path_new); + if (fs_new == NULL) { + return FR_NO_PATH; + } + if (fs_old != fs_new) { + return FR_NO_PATH; + } + return f_rename(fs_new, path_old, path_new); +} + /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ @@ -210,7 +286,7 @@ static void ftp_close_cmd_data (void); static ftp_cmd_index_t ftp_pop_command (char **str); static void ftp_pop_param (char **str, char *param); static int ftp_print_eplf_item (char *dest, uint32_t destsize, FILINFO *fno); -static int ftp_print_eplf_drive (char *dest, uint32_t destsize, char *name); +static int ftp_print_eplf_drive (char *dest, uint32_t destsize, const char *name); static bool ftp_open_file (const char *path, int mode); static ftp_result_t ftp_read_file (char *filebuf, uint32_t desiredsize, uint32_t *actualsize); static ftp_result_t ftp_write_file (char *filebuf, uint32_t size); @@ -604,10 +680,6 @@ static void ftp_process_cmd (void) { ftp_result_t result; FRESULT fres; FILINFO fno; -#if _USE_LFN - fno.lfname = NULL; - fno.lfsize = 0; -#endif ftp_data.closechild = false; // also use the reply buffer to receive new commands @@ -634,7 +706,7 @@ static void ftp_process_cmd (void) { fres = FR_NO_PATH; ftp_pop_param (&bufptr, ftp_scratch_buffer); ftp_open_child (ftp_path, ftp_scratch_buffer); - if ((ftp_path[0] == '/' && ftp_path[1] == '\0') || ((fres = f_opendir (&ftp_data.dp, ftp_path)) == FR_OK)) { + if ((ftp_path[0] == '/' && ftp_path[1] == '\0') || ((fres = f_opendir_helper (&ftp_data.dp, ftp_path)) == FR_OK)) { if (fres == FR_OK) { f_closedir(&ftp_data.dp); } @@ -653,7 +725,7 @@ static void ftp_process_cmd (void) { case E_FTP_CMD_SIZE: { ftp_get_param_and_open_child (&bufptr); - if (FR_OK == f_stat (ftp_path, &fno)) { + if (FR_OK == f_stat_helper(ftp_path, &fno)) { // send the size snprintf((char *)ftp_data.dBuffer, FTP_BUFFER_SIZE, "%u", (_u32)fno.fsize); ftp_send_reply(213, (char *)ftp_data.dBuffer); @@ -665,7 +737,7 @@ static void ftp_process_cmd (void) { break; case E_FTP_CMD_MDTM: ftp_get_param_and_open_child (&bufptr); - if (FR_OK == f_stat (ftp_path, &fno)) { + if (FR_OK == f_stat_helper(ftp_path, &fno)) { // send the last modified time snprintf((char *)ftp_data.dBuffer, FTP_BUFFER_SIZE, "%u%02u%02u%02u%02u%02u", 1980 + ((fno.fdate >> 9) & 0x7f), (fno.fdate >> 5) & 0x0f, @@ -773,7 +845,7 @@ static void ftp_process_cmd (void) { case E_FTP_CMD_DELE: case E_FTP_CMD_RMD: ftp_get_param_and_open_child (&bufptr); - if (FR_OK == f_unlink(ftp_path)) { + if (FR_OK == f_unlink_helper(ftp_path)) { ftp_send_reply(250, NULL); } else { @@ -782,7 +854,7 @@ static void ftp_process_cmd (void) { break; case E_FTP_CMD_MKD: ftp_get_param_and_open_child (&bufptr); - if (FR_OK == f_mkdir(ftp_path)) { + if (FR_OK == f_mkdir_helper(ftp_path)) { ftp_send_reply(250, NULL); } else { @@ -791,7 +863,7 @@ static void ftp_process_cmd (void) { break; case E_FTP_CMD_RNFR: ftp_get_param_and_open_child (&bufptr); - if (FR_OK == f_stat (ftp_path, &fno)) { + if (FR_OK == f_stat_helper(ftp_path, &fno)) { ftp_send_reply(350, NULL); // save the current path strcpy ((char *)ftp_data.dBuffer, ftp_path); @@ -803,7 +875,7 @@ static void ftp_process_cmd (void) { case E_FTP_CMD_RNTO: ftp_get_param_and_open_child (&bufptr); // old path was saved in the data buffer - if (FR_OK == (fres = f_rename ((char *)ftp_data.dBuffer, ftp_path))) { + if (FR_OK == (fres = f_rename_helper((char *)ftp_data.dBuffer, ftp_path))) { ftp_send_reply(250, NULL); } else { @@ -898,24 +970,16 @@ static int ftp_print_eplf_item (char *dest, uint32_t destsize, FILINFO *fno) { if (FTP_UNIX_SECONDS_180_DAYS < tseconds - fseconds) { return snprintf(dest, destsize, "%srw-rw-r-- 1 root root %9u %s %2u %5u %s\r\n", type, (_u32)fno->fsize, ftp_month[mindex].month, day, - #if _USE_LFN - 1980 + ((fno->fdate >> 9) & 0x7f), *fno->lfname ? fno->lfname : fno->fname); - #else 1980 + ((fno->fdate >> 9) & 0x7f), fno->fname); - #endif } else { return snprintf(dest, destsize, "%srw-rw-r-- 1 root root %9u %s %2u %02u:%02u %s\r\n", type, (_u32)fno->fsize, ftp_month[mindex].month, day, - #if _USE_LFN - (fno->ftime >> 11) & 0x1f, (fno->ftime >> 5) & 0x3f, *fno->lfname ? fno->lfname : fno->fname); - #else (fno->ftime >> 11) & 0x1f, (fno->ftime >> 5) & 0x3f, fno->fname); - #endif } } -static int ftp_print_eplf_drive (char *dest, uint32_t destsize, char *name) { +static int ftp_print_eplf_drive (char *dest, uint32_t destsize, const char *name) { timeutils_struct_time_t tm; uint32_t tseconds; char *type = "d"; @@ -934,7 +998,7 @@ static int ftp_print_eplf_drive (char *dest, uint32_t destsize, char *name) { } static bool ftp_open_file (const char *path, int mode) { - FRESULT res = f_open(&ftp_data.fp, path, mode); + FRESULT res = f_open_helper(&ftp_data.fp, path, mode); if (res != FR_OK) { return false; } @@ -976,7 +1040,7 @@ static ftp_result_t ftp_open_dir_for_listing (const char *path) { ftp_data.listroot = true; } else { FRESULT res; - res = f_opendir(&ftp_data.dp, path); /* Open the directory */ + res = f_opendir_helper(&ftp_data.dp, path); /* Open the directory */ if (res != FR_OK) { return E_FTP_RESULT_FAILED; } @@ -993,9 +1057,6 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li ftp_result_t result = E_FTP_RESULT_CONTINUE; FILINFO fno; #if _USE_LFN - fno.lfname = mem_Malloc(_MAX_LFN); - fno.lfsize = _MAX_LFN; - // read up to 2 directory items while (listcount < 2) { #else @@ -1004,17 +1065,20 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li #endif if (ftp_data.listroot) { // root directory "hack" - if (0 == ftp_data.volcount) { - next += ftp_print_eplf_drive((list + next), (maxlistsize - next), "flash"); - } else if (ftp_data.volcount <= MP_STATE_PORT(mount_obj_list).len) { - os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[(ftp_data.volcount - 1)])); - next += ftp_print_eplf_drive((list + next), (maxlistsize - next), (char *)&mount_obj->path[1]); - } else { + mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); + int i = ftp_data.volcount; + while (vfs != NULL && i != 0) { + vfs = vfs->next; + i -= 1; + } + if (vfs == NULL) { if (!next) { // no volume found this time, we are done ftp_data.volcount = 0; } break; + } else { + next += ftp_print_eplf_drive((list + next), (maxlistsize - next), vfs->str + 1); } ftp_data.volcount++; } else { @@ -1036,9 +1100,6 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li ftp_close_files(); } *listsize = next; -#if _USE_LFN - mem_Free(fno.lfname); -#endif return result; } diff --git a/cc3200/main.c b/cc3200/main.c index fd263442c..06b3604b6 100644 --- a/cc3200/main.c +++ b/cc3200/main.c @@ -113,14 +113,3 @@ void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, *ppxIdleTaskStackBuffer = uxIdleTaskStack; *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; } - -// the following is temporay, until cc3200 converts to oofatfs - -#include "py/lexer.h" -#include "extmod/vfs_fat.h" - -mp_import_stat_t mp_import_stat(const char *path) { - return fat_vfs_import_stat(NULL, path); -} - -MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, fatfs_builtin_open); diff --git a/cc3200/mods/moduos.c b/cc3200/mods/moduos.c index 1c9932b8e..0adc75503 100644 --- a/cc3200/mods/moduos.c +++ b/cc3200/mods/moduos.c @@ -33,10 +33,12 @@ #include "py/objtuple.h" #include "py/objstr.h" #include "py/runtime.h" +#include "lib/oofatfs/ff.h" +#include "lib/oofatfs/diskio.h" #include "genhdr/mpversion.h" #include "moduos.h" -#include "diskio.h" #include "sflash_diskio.h" +#include "extmod/vfs.h" #include "extmod/vfs_fat.h" #include "random.h" #include "mpexception.h" @@ -59,155 +61,20 @@ /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC uint32_t os_num_mounted_devices; STATIC os_term_dup_obj_t os_term_dup_obj; -/****************************************************************************** - DECLARE PRIVATE FUNCTIONS - ******************************************************************************/ -STATIC void unmount (os_fs_mount_t *mount_obj); -STATIC bool path_equal(const char *path, const char *path_canonical); -STATIC void append_dir_item (mp_obj_t dirlist, const char *item, bool string); -STATIC void mount (mp_obj_t device, const char *path, uint pathlen, bool readonly); - /****************************************************************************** DEFINE PUBLIC FUNCTIONS ******************************************************************************/ -void moduos_init0 (void) { - // initialize the mount objects list - mp_obj_list_init(&MP_STATE_PORT(mount_obj_list), 0); - os_num_mounted_devices = 0; -} - -os_fs_mount_t *osmount_find_by_path (const char *path) { - for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) { - os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i])); - if (!strcmp(path, mount_obj->path)) { - return mount_obj; - } - } - return NULL; -} - -os_fs_mount_t *osmount_find_by_volume (uint8_t vol) { - for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) { - os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i])); - if (vol == mount_obj->vol) { - return mount_obj; - } - } - return NULL; -} - -os_fs_mount_t *osmount_find_by_device (mp_obj_t device) { - for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) { - os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i])); - if (device == mount_obj->device) { - return mount_obj; - } - } - return NULL; -} - void osmount_unmount_all (void) { + //TODO + /* for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) { os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i])); unmount(mount_obj); } -} - -/****************************************************************************** - DEFINE PRIVATE FUNCTIONS - ******************************************************************************/ - -// Checks for path equality, ignoring trailing slashes: -// path_equal(/, /) -> true -// path_equal(/flash//, /flash) -> true -// second argument must be in canonical form (meaning no trailing slash, unless it's just /) -STATIC bool path_equal(const char *path, const char *path_canonical) { - for (; *path_canonical != '\0' && *path == *path_canonical; ++path, ++path_canonical) { - } - if (*path_canonical != '\0') { - return false; - } - for (; *path == '/'; ++path) { - } - return *path == '\0'; -} - -STATIC void append_dir_item (mp_obj_t dirlist, const char *item, bool string) { - // make a string object for this entry - mp_obj_t entry_o; - if (string) { - entry_o = mp_obj_new_str(item, strlen(item), false); - } else { - entry_o = mp_obj_new_bytes((const byte*)item, strlen(item)); - } - - // add the entry to the list - mp_obj_list_append(dirlist, entry_o); -} - -STATIC void mount (mp_obj_t device, const char *path, uint pathlen, bool readonly) { - // is the mount point already in use? - FILINFO fno; -#if _USE_LFN - fno.lfname = NULL; - fno.lfsize = 0; -#endif - // cannot mount twice or on existing paths - if (f_stat(path, &fno) == FR_OK || osmount_find_by_device(device)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); - } - - // create a new object - os_fs_mount_t *self = m_new_obj(os_fs_mount_t); - self->device = device; - self->path = path; - self->pathlen = pathlen; - self->vol = os_num_mounted_devices + 1; // '/flash' is volume 0 - - if (device == (mp_obj_t)&pybsd_obj) { - // need to make it different to NULL, otherwise it's read only by default - self->writeblocks[0] = mp_const_none; - self->sync[0] = MP_OBJ_NULL; // no need to sync the SD card - self->count[0] = MP_OBJ_NULL; - } else { - // load block protocol methods - mp_load_method(device, MP_QSTR_readblocks, self->readblocks); - mp_load_method_maybe(device, MP_QSTR_writeblocks, self->writeblocks); - mp_load_method_maybe(device, MP_QSTR_sync, self->sync); - mp_load_method(device, MP_QSTR_count, self->count); - } - - // Read-only device indicated by writeblocks[0] == MP_OBJ_NULL. - // User can specify read-only device by: - // 1. readonly=True keyword argument - // 2. nonexistent writeblocks method (then writeblocks[0] == MP_OBJ_NULL already) - if (readonly) { - self->writeblocks[0] = MP_OBJ_NULL; - } - - // we need to add it before doing the actual mount, so that the volume can be found - mp_obj_list_append(&MP_STATE_PORT(mount_obj_list), self); - - // actually mount it - if (f_mount(&self->fatfs, self->path, 1) != FR_OK) { - // remove it and raise - mp_obj_list_remove(&MP_STATE_PORT(mount_obj_list), self); - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); - } - - // mount succeeded, increment the count - os_num_mounted_devices++; -} - -STATIC void unmount (os_fs_mount_t *mount_obj) { - // remove it from the list and then call FatFs - f_mount (NULL, mount_obj->path, 1); - mp_obj_list_remove(&MP_STATE_PORT(mount_obj_list), mount_obj); - os_num_mounted_devices--; + */ } /******************************************************************************/ @@ -239,193 +106,6 @@ STATIC mp_obj_t os_uname(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname); -/// \function chdir(path) -/// Change current directory. -STATIC mp_obj_t os_chdir(mp_obj_t path_in) { - const char *path; - path = mp_obj_str_get_str(path_in); - - FRESULT res = f_chdrive(path); - - if (res == FR_OK) { - res = f_chdir(path); - } - - if (res != FR_OK) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); - } - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_chdir_obj, os_chdir); - -STATIC mp_obj_t os_getcwd(void) { - char buf[MICROPY_ALLOC_PATH_MAX + 1]; - FRESULT res = f_getcwd(buf, sizeof buf); - if (res != FR_OK) { - mp_raise_OSError(fresult_to_errno_table[res]); - } - return mp_obj_new_str(buf, strlen(buf), false); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_getcwd_obj, os_getcwd); - -STATIC mp_obj_t os_listdir(mp_uint_t n_args, const mp_obj_t *args) { - bool is_str_type = true; - const char *path; - mp_obj_t dir_list = mp_obj_new_list(0, NULL); - - if (n_args == 1) { - if (mp_obj_get_type(args[0]) == &mp_type_bytes) { - is_str_type = false; - } - path = mp_obj_str_get_str(args[0]); - } else { - path = ""; - } - - // "hack" to list the root directory - if (path[0] == '/' && path[1] == '\0') { - // add 'flash' to the list - append_dir_item (dir_list, "flash", is_str_type); - for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) { - os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i])); - append_dir_item (dir_list, &mount_obj->path[1], is_str_type); - } - } else { - FRESULT res; - DIR dir; - FILINFO fno; - #if _USE_LFN - char lfn_buf[_MAX_LFN + 1]; - fno.lfname = lfn_buf; - fno.lfsize = sizeof(lfn_buf); - #endif - - res = f_opendir(&dir, path); /* Open the directory */ - if (res != FR_OK) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); - } - - for ( ; ; ) { - res = f_readdir(&dir, &fno); /* Read a directory item */ - if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ - if (fno.fname[0] == '.' && fno.fname[1] == 0) continue; /* Ignore . entry */ - if (fno.fname[0] == '.' && fno.fname[1] == '.' && fno.fname[2] == 0) continue; /* Ignore .. entry */ - - #if _USE_LFN - char *fn = *fno.lfname ? fno.lfname : fno.fname; - #else - char *fn = fno.fname; - #endif - - // add the entry to the list - append_dir_item (dir_list, fn, is_str_type); - } - f_closedir(&dir); - } - - return dir_list; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_listdir_obj, 0, 1, os_listdir); - -STATIC mp_obj_t os_mkdir(mp_obj_t path_o) { - const char *path = mp_obj_str_get_str(path_o); - FRESULT res = f_mkdir(path); - switch (res) { - case FR_OK: - return mp_const_none; - case FR_EXIST: - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); - break; - default: - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); - } -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mkdir_obj, os_mkdir); - -STATIC mp_obj_t os_rename(mp_obj_t path_in, mp_obj_t path_out) { - const char *old_path = mp_obj_str_get_str(path_in); - const char *new_path = mp_obj_str_get_str(path_out); - FRESULT res = f_rename(old_path, new_path); - switch (res) { - case FR_OK: - return mp_const_none; - default: - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); - } -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(os_rename_obj, os_rename); - -STATIC mp_obj_t os_remove(mp_obj_t path_o) { - const char *path = mp_obj_str_get_str(path_o); - FRESULT res = f_unlink(path); - switch (res) { - case FR_OK: - return mp_const_none; - default: - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); - } -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_remove_obj, os_remove); - -STATIC mp_obj_t os_stat(mp_obj_t path_in) { - const char *path = mp_obj_str_get_str(path_in); - bool isbuilt_in = false; - FILINFO fno; - FRESULT res; -#if _USE_LFN - fno.lfname = NULL; - fno.lfsize = 0; -#endif - - // check on the user mounted devices - for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) { - os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i])); - if (path_equal(path, mount_obj->path)) { - isbuilt_in = true; - break; - } - } - - if (path_equal(path, "/") || path_equal(path, "/flash") || isbuilt_in) { - // stat built-in directory - fno.fsize = 0; - fno.fdate = 0; - fno.ftime = 0; - fno.fattrib = AM_DIR; - } else if ((res = f_stat(path, &fno)) != FR_OK) { - mp_raise_OSError(fresult_to_errno_table[res]); - } - - mp_obj_tuple_t *t = mp_obj_new_tuple(10, NULL); - mp_int_t mode = 0; - if (fno.fattrib & AM_DIR) { - mode |= 0x4000; // stat.S_IFDIR - } else { - mode |= 0x8000; // stat.S_IFREG - } - mp_int_t seconds = timeutils_seconds_since_2000( - 1980 + ((fno.fdate >> 9) & 0x7f), - (fno.fdate >> 5) & 0x0f, - fno.fdate & 0x1f, - (fno.ftime >> 11) & 0x1f, - (fno.ftime >> 5) & 0x3f, - 2 * (fno.ftime & 0x1f) - ); - t->items[0] = mp_obj_new_int(mode); // st_mode - t->items[1] = MP_OBJ_NEW_SMALL_INT(0); // st_ino - t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // st_dev - t->items[3] = MP_OBJ_NEW_SMALL_INT(0); // st_nlink - t->items[4] = MP_OBJ_NEW_SMALL_INT(0); // st_uid - t->items[5] = MP_OBJ_NEW_SMALL_INT(0); // st_gid - t->items[6] = mp_obj_new_int(fno.fsize); // st_size - t->items[7] = mp_obj_new_int(seconds); // st_atime - t->items[8] = t->items[7]; // st_mtime - t->items[9] = t->items[7]; // st_ctime - return t; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_stat_obj, os_stat); - STATIC mp_obj_t os_sync(void) { sflash_disk_flush(); return mp_const_none; @@ -443,110 +123,6 @@ STATIC mp_obj_t os_urandom(mp_obj_t num) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom); -STATIC mp_obj_t os_mount(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - static const mp_arg_t mount_args[] = { - { MP_QSTR_readonly, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, - }; - - // parse args - mp_obj_t device = pos_args[0]; - mp_obj_t mount_point = pos_args[1]; - mp_arg_val_t args[MP_ARRAY_SIZE(mount_args)]; - mp_arg_parse_all(n_args - 2, pos_args + 2, kw_args, MP_ARRAY_SIZE(mount_args), mount_args, args); - - // get the mount point - mp_uint_t pathlen; - const char *path_in = mp_obj_str_get_data(mount_point, &pathlen); - if (pathlen == 0) { - goto invalid_args; - } - - char *path = m_new(char, pathlen + 1); - memcpy(path, path_in, pathlen); - path[pathlen] = '\0'; - - // "remove" any extra slahes at the end - while (path[(pathlen - 1)] == '/') { - path[--pathlen] = '\0'; - } - - // is the mount point valid? - if (pathlen < 2 || path[0] !='/' || strchr(&path[1], '/')) { - goto invalid_args; - } - - // now mount it - mount(device, path, pathlen, args[0].u_bool); - - return mp_const_none; - -invalid_args: - mp_raise_msg(&mp_type_OSError, mpexception_value_invalid_arguments); -} -MP_DEFINE_CONST_FUN_OBJ_KW(os_mount_obj, 2, os_mount); - -STATIC mp_obj_t os_unmount(mp_obj_t path_o) { - const char *path = mp_obj_str_get_str(path_o); - - // '/flash' cannot be unmounted, also not the current working directory - if (path_equal(path, "/flash")) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); - } - - // now unmount it - os_fs_mount_t *mount_obj; - if ((mount_obj = osmount_find_by_path(path))) { - unmount (mount_obj); - } else { - mp_raise_msg(&mp_type_ValueError, mpexception_value_invalid_arguments); - } - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_unmount_obj, os_unmount); - -STATIC mp_obj_t os_mkfs(mp_obj_t device) { - const char *path = "/__mkfs__mnt__"; - os_fs_mount_t *mount_obj = NULL; - bool unmt = false; - FRESULT res; - - if (MP_OBJ_IS_STR_OR_BYTES(device)) { - path = mp_obj_str_get_str(device); - // otherwise the relative path check will pass... - if (path[0] != '/') { - mp_raise_msg(&mp_type_OSError, mpexception_value_invalid_arguments); - } - } else { - // mount it briefly - mount(device, path, strlen(path), false); - unmt = true; - } - - byte sfd = 0; - if (!memcmp(path, "/flash", strlen("/flash"))) { - sfd = 1; - } else if ((mount_obj = osmount_find_by_path(path))) { - if (mount_obj->device != (mp_obj_t)&pybsd_obj && - mp_obj_get_int(mp_call_method_n_kw(0, 0, mount_obj->count)) < 2048) { - sfd = 1; - } - } - - // now format the device - res = f_mkfs(path, sfd, 0); - - if (unmt && mount_obj) { - unmount (mount_obj); - } - - if (res != FR_OK) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); - } - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mkfs_obj, os_mkfs); - STATIC mp_obj_t os_dupterm(uint n_args, const mp_obj_t *args) { if (n_args == 0) { if (MP_STATE_PORT(os_term_dup_obj) == MP_OBJ_NULL) { @@ -576,22 +152,26 @@ STATIC const mp_map_elem_t os_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_uos) }, { MP_OBJ_NEW_QSTR(MP_QSTR_uname), (mp_obj_t)&os_uname_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_chdir), (mp_obj_t)&os_chdir_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_getcwd), (mp_obj_t)&os_getcwd_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_listdir), (mp_obj_t)&os_listdir_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_mkdir), (mp_obj_t)&os_mkdir_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_rename), (mp_obj_t)&os_rename_obj}, - { MP_OBJ_NEW_QSTR(MP_QSTR_remove), (mp_obj_t)&os_remove_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_rmdir), (mp_obj_t)&os_remove_obj }, // rmdir aliases to remove - { MP_OBJ_NEW_QSTR(MP_QSTR_stat), (mp_obj_t)&os_stat_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_unlink), (mp_obj_t)&os_remove_obj }, // unlink aliases to remove + + { MP_OBJ_NEW_QSTR(MP_QSTR_chdir), (mp_obj_t)&mp_vfs_chdir_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_getcwd), (mp_obj_t)&mp_vfs_getcwd_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_listdir), (mp_obj_t)&mp_vfs_listdir_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_mkdir), (mp_obj_t)&mp_vfs_mkdir_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_rename), (mp_obj_t)&mp_vfs_rename_obj}, + { MP_OBJ_NEW_QSTR(MP_QSTR_remove), (mp_obj_t)&mp_vfs_remove_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_rmdir), (mp_obj_t)&mp_vfs_rmdir_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_stat), (mp_obj_t)&mp_vfs_stat_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_unlink), (mp_obj_t)&mp_vfs_remove_obj }, // unlink aliases to remove + { MP_OBJ_NEW_QSTR(MP_QSTR_sync), (mp_obj_t)&os_sync_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_urandom), (mp_obj_t)&os_urandom_obj }, // MicroPython additions - { MP_OBJ_NEW_QSTR(MP_QSTR_mount), (mp_obj_t)&os_mount_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_unmount), (mp_obj_t)&os_unmount_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_mkfs), (mp_obj_t)&os_mkfs_obj }, + // removed: mkfs + // renamed: unmount -> umount + { MP_OBJ_NEW_QSTR(MP_QSTR_mount), (mp_obj_t)&mp_vfs_mount_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_umount), (mp_obj_t)&mp_vfs_umount_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_VfsFat), (mp_obj_t)&mp_fat_vfs_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_dupterm), (mp_obj_t)&os_dupterm_obj }, /// \constant sep - separation character used in paths diff --git a/cc3200/mods/moduos.h b/cc3200/mods/moduos.h index 1ebf16cdf..4c8bc9659 100644 --- a/cc3200/mods/moduos.h +++ b/cc3200/mods/moduos.h @@ -28,22 +28,11 @@ #ifndef MODUOS_H_ #define MODUOS_H_ -#include "ff.h" +#include "py/obj.h" /****************************************************************************** DEFINE PUBLIC TYPES ******************************************************************************/ -typedef struct _os_fs_mount_t { - mp_obj_t device; - const char *path; - mp_uint_t pathlen; - mp_obj_t readblocks[4]; - mp_obj_t writeblocks[4]; - mp_obj_t sync[2]; - mp_obj_t count[2]; - FATFS fatfs; - uint8_t vol; -} os_fs_mount_t; typedef struct _os_term_dup_obj_t { mp_obj_t stream_o; @@ -54,9 +43,6 @@ typedef struct _os_term_dup_obj_t { /****************************************************************************** DECLARE PUBLIC FUNCTIONS ******************************************************************************/ -void moduos_init0 (void); -os_fs_mount_t *osmount_find_by_path (const char *path); -os_fs_mount_t *osmount_find_by_volume (uint8_t vol); void osmount_unmount_all (void); #endif // MODUOS_H_ diff --git a/cc3200/mods/pybflash.c b/cc3200/mods/pybflash.c new file mode 100644 index 000000000..0779f4a05 --- /dev/null +++ b/cc3200/mods/pybflash.c @@ -0,0 +1,110 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2017 Damien P. George + * + * 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 +//#include + +#include "py/runtime.h" +#include "lib/oofatfs/ff.h" +#include "lib/oofatfs/diskio.h" +#include "extmod/vfs_fat.h" +#include "extmod/fsusermount.h" + +#include "fatfs/src/drivers/sflash_diskio.h" +#include "mods/pybflash.h" + +/******************************************************************************/ +// MicroPython bindings to expose the internal flash as an object with the +// block protocol. + +// there is a singleton Flash object +STATIC const mp_obj_base_t pyb_flash_obj = {&pyb_flash_type}; + +STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + // check arguments + mp_arg_check_num(n_args, n_kw, 0, 0, false); + + // return singleton object + return (mp_obj_t)&pyb_flash_obj; +} + +STATIC mp_obj_t pyb_flash_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); + DRESULT res = sflash_disk_read(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SFLASH_SECTOR_SIZE); + return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_readblocks_obj, pyb_flash_readblocks); + +STATIC mp_obj_t pyb_flash_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); + DRESULT res = sflash_disk_write(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SFLASH_SECTOR_SIZE); + return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_writeblocks_obj, pyb_flash_writeblocks); + +STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) { + mp_int_t cmd = mp_obj_get_int(cmd_in); + switch (cmd) { + case BP_IOCTL_INIT: return MP_OBJ_NEW_SMALL_INT(sflash_disk_init() != RES_OK); + case BP_IOCTL_DEINIT: sflash_disk_flush(); return MP_OBJ_NEW_SMALL_INT(0); + case BP_IOCTL_SYNC: sflash_disk_flush(); return MP_OBJ_NEW_SMALL_INT(0); + case BP_IOCTL_SEC_COUNT: return MP_OBJ_NEW_SMALL_INT(SFLASH_SECTOR_COUNT); + case BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(SFLASH_SECTOR_SIZE); + default: return mp_const_none; + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl); + +STATIC const mp_map_elem_t pyb_flash_locals_dict_table[] = { + { MP_OBJ_NEW_QSTR(MP_QSTR_readblocks), (mp_obj_t)&pyb_flash_readblocks_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_writeblocks), (mp_obj_t)&pyb_flash_writeblocks_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ioctl), (mp_obj_t)&pyb_flash_ioctl_obj }, +}; + +STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table); + +const mp_obj_type_t pyb_flash_type = { + { &mp_type_type }, + .name = MP_QSTR_Flash, + .make_new = pyb_flash_make_new, + .locals_dict = (mp_obj_t)&pyb_flash_locals_dict, +}; + +void pyb_flash_init_vfs(fs_user_mount_t *vfs) { + vfs->base.type = &mp_fat_vfs_type; + vfs->flags |= FSUSER_NATIVE | FSUSER_HAVE_IOCTL; + vfs->fatfs.drv = vfs; + vfs->readblocks[0] = (mp_obj_t)&pyb_flash_readblocks_obj; + vfs->readblocks[1] = (mp_obj_t)&pyb_flash_obj; + vfs->readblocks[2] = (mp_obj_t)sflash_disk_read; // native version + vfs->writeblocks[0] = (mp_obj_t)&pyb_flash_writeblocks_obj; + vfs->writeblocks[1] = (mp_obj_t)&pyb_flash_obj; + vfs->writeblocks[2] = (mp_obj_t)sflash_disk_write; // native version + vfs->u.ioctl[0] = (mp_obj_t)&pyb_flash_ioctl_obj; + vfs->u.ioctl[1] = (mp_obj_t)&pyb_flash_obj; +} diff --git a/cc3200/mods/pybflash.h b/cc3200/mods/pybflash.h new file mode 100644 index 000000000..6f8ddf291 --- /dev/null +++ b/cc3200/mods/pybflash.h @@ -0,0 +1,35 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Damien P. George + * + * 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. + */ +#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBFLASH_H +#define MICROPY_INCLUDED_CC3200_MODS_PYBFLASH_H + +#include "py/obj.h" + +extern const mp_obj_type_t pyb_flash_type; + +void pyb_flash_init_vfs(fs_user_mount_t *vfs); + +#endif // MICROPY_INCLUDED_CC3200_MODS_PYBFLASH_H diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c index b8d5b4cc1..bac5a270c 100644 --- a/cc3200/mods/pybsd.c +++ b/cc3200/mods/pybsd.c @@ -27,6 +27,9 @@ #include "py/mpconfig.h" #include "py/obj.h" #include "py/runtime.h" +#include "lib/oofatfs/ff.h" +#include "lib/oofatfs/diskio.h" +#include "extmod/fsusermount.h" #include "inc/hw_types.h" #include "inc/hw_gpio.h" #include "inc/hw_ints.h" @@ -36,8 +39,6 @@ #include "prcm.h" #include "gpio.h" #include "sdhost.h" -#include "ff.h" -#include "diskio.h" #include "sd_diskio.h" #include "pybsd.h" #include "mpexception.h" @@ -163,9 +164,50 @@ STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sd_deinit_obj, pyb_sd_deinit); +STATIC mp_obj_t pyb_sd_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); + DRESULT res = sd_disk_read(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SD_SECTOR_SIZE); + return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_readblocks_obj, pyb_sd_readblocks); + +STATIC mp_obj_t pyb_sd_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); + DRESULT res = sd_disk_write(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SD_SECTOR_SIZE); + return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_writeblocks_obj, pyb_sd_writeblocks); + +STATIC mp_obj_t pyb_sd_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) { + mp_int_t cmd = mp_obj_get_int(cmd_in); + switch (cmd) { + case BP_IOCTL_INIT: + case BP_IOCTL_DEINIT: + case BP_IOCTL_SYNC: + // nothing to do + return MP_OBJ_NEW_SMALL_INT(0); // success + + case BP_IOCTL_SEC_COUNT: + return MP_OBJ_NEW_SMALL_INT(sd_disk_info.ulNofBlock * (sd_disk_info.ulBlockSize / 512)); + + case BP_IOCTL_SEC_SIZE: + return MP_OBJ_NEW_SMALL_INT(SD_SECTOR_SIZE); + + default: // unknown command + return MP_OBJ_NEW_SMALL_INT(-1); // error + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_ioctl_obj, pyb_sd_ioctl); + STATIC const mp_map_elem_t pyb_sd_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_sd_init_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_sd_deinit_obj }, + // block device protocol + { MP_OBJ_NEW_QSTR(MP_QSTR_readblocks), (mp_obj_t)&pyb_sd_readblocks_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_writeblocks), (mp_obj_t)&pyb_sd_writeblocks_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ioctl), (mp_obj_t)&pyb_sd_ioctl_obj }, }; STATIC MP_DEFINE_CONST_DICT(pyb_sd_locals_dict, pyb_sd_locals_dict_table); diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 4bf0b1061..939d9f62b 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -55,7 +55,7 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE) #define MICROPY_OPT_COMPUTED_GOTO (0) #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0) -#define MICROPY_READER_FATFS (1) +#define MICROPY_READER_VFS (1) #ifndef DEBUG // we need ram on the launchxl while debugging #define MICROPY_CPYTHON_COMPAT (1) #else @@ -64,19 +64,20 @@ #define MICROPY_QSTR_BYTES_IN_HASH (1) // fatfs configuration used in ffconf.h +#define MICROPY_FATFS_OO (1) #define MICROPY_FATFS_ENABLE_LFN (2) #define MICROPY_FATFS_MAX_LFN (MICROPY_ALLOC_PATH_MAX) #define MICROPY_FATFS_LFN_CODE_PAGE (437) // 1=SFN/ANSI 437=LFN/U.S.(OEM) #define MICROPY_FATFS_RPATH (2) -#define MICROPY_FATFS_VOLUMES (2) #define MICROPY_FATFS_REENTRANT (1) #define MICROPY_FATFS_TIMEOUT (2500) #define MICROPY_FATFS_SYNC_T SemaphoreHandle_t -#define MICROPY_FSUSERMOUNT_ADHOC (1) #define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_MODULE_WEAK_LINKS (1) #define MICROPY_CAN_OVERRIDE_BUILTINS (1) +#define MICROPY_VFS (1) +#define MICROPY_VFS_FAT (1) #define MICROPY_PY_ASYNC_AWAIT (0) #define MICROPY_PY_BUILTINS_TIMEOUTERROR (1) #define MICROPY_PY_ALL_SPECIAL_METHODS (1) @@ -120,6 +121,15 @@ #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) +// TODO these should be generic, not bound to fatfs +#define mp_type_fileio fatfs_type_fileio +#define mp_type_textio fatfs_type_textio + +// use vfs's functions for import stat and builtin open +#define mp_import_stat mp_vfs_import_stat +#define mp_builtin_open mp_vfs_open +#define mp_builtin_open_obj mp_vfs_open_obj + // extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ @@ -174,7 +184,6 @@ extern const struct _mp_obj_module_t mp_module_ussl; mp_obj_list_t pyb_sleep_obj_list; \ mp_obj_list_t mp_irq_obj_list; \ mp_obj_list_t pyb_timer_channel_obj_list; \ - mp_obj_list_t mount_obj_list; \ struct _pyb_uart_obj_t *pyb_uart_objs[2]; \ struct _os_term_dup_obj_t *os_term_dup_obj; \ diff --git a/cc3200/mptask.c b/cc3200/mptask.c index 3c34ceeca..476561c6d 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -33,6 +33,10 @@ #include "py/runtime.h" #include "py/gc.h" #include "py/mphal.h" +#include "lib/oofatfs/ff.h" +#include "lib/oofatfs/diskio.h" +#include "extmod/vfs.h" +#include "extmod/fsusermount.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" @@ -56,13 +60,12 @@ #include "serverstask.h" #include "telnet.h" #include "debug.h" -#include "ff.h" -#include "diskio.h" #include "sflash_diskio.h" #include "mpexception.h" #include "random.h" #include "pybi2c.h" #include "pins.h" +#include "mods/pybflash.h" #include "pybsleep.h" #include "pybtimer.h" #include "cryptohash.h" @@ -94,7 +97,8 @@ OsiTaskHandle svTaskHandle; /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -static FATFS *sflash_fatfs; +static fs_user_mount_t *sflash_vfs_fat; +static mp_vfs_mount_t sflash_vfs_mount; static const char fresh_main_py[] = "# main.py -- put your code here!\r\n"; static const char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n" @@ -149,7 +153,6 @@ soft_reset: timer_init0(); readline_init0(); mod_network_init0(); - moduos_init0(); rng_init0(); pybsleep_reset_cause_t rstcause = pyb_sleep_get_reset_cause(); @@ -270,7 +273,7 @@ STATIC void mptask_pre_init (void) { ASSERT (OSI_OK == VStartSimpleLinkSpawnTask(SIMPLELINK_SPAWN_TASK_PRIORITY)); // Allocate memory for the flash file system - ASSERT ((sflash_fatfs = mem_Malloc(sizeof(FATFS))) != NULL); + ASSERT ((sflash_vfs_fat = mem_Malloc(sizeof(*sflash_vfs_fat))) != NULL); // this one allocates memory for the nvic vault pyb_sleep_pre_init(); @@ -296,17 +299,21 @@ STATIC void mptask_pre_init (void) { STATIC void mptask_init_sflash_filesystem (void) { FILINFO fno; -#if _USE_LFN - fno.lfname = NULL; - fno.lfsize = 0; -#endif // Initialise the local flash filesystem. + // init the vfs object + fs_user_mount_t *vfs_fat = sflash_vfs_fat; + vfs_fat->str = NULL; + vfs_fat->len = 0; + vfs_fat->flags = 0; + pyb_flash_init_vfs(vfs_fat); + // Create it if needed, and mount in on /flash. - FRESULT res = f_mount(sflash_fatfs, "/flash", 1); + FRESULT res = f_mount(&vfs_fat->fatfs); if (res == FR_NO_FILESYSTEM) { // no filesystem, so create a fresh one - res = f_mkfs("/flash", 1, 0); + uint8_t working_buf[_MAX_SS]; + res = f_mkfs(&vfs_fat->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf)); if (res == FR_OK) { // success creating fresh LFS } else { @@ -316,7 +323,7 @@ STATIC void mptask_init_sflash_filesystem (void) { mptask_create_main_py(); } else if (res == FR_OK) { // mount sucessful - if (FR_OK != f_stat("/flash/main.py", &fno)) { + if (FR_OK != f_stat(&vfs_fat->fatfs, "/main.py", &fno)) { // create empty main.py mptask_create_main_py(); } @@ -324,25 +331,33 @@ STATIC void mptask_init_sflash_filesystem (void) { __fatal_error("failed to create /flash"); } + // mount the flash device (there should be no other devices mounted at this point) + mp_vfs_mount_t *vfs = &sflash_vfs_mount; + vfs->str = "/flash"; + vfs->len = 6; + vfs->obj = MP_OBJ_FROM_PTR(vfs_fat); + vfs->next = NULL; + MP_STATE_VM(vfs_mount_table) = vfs; + // The current directory is used as the boot up directory. // It is set to the internal flash filesystem by default. - f_chdrive("/flash"); + MP_STATE_PORT(vfs_cur) = vfs; // create /flash/sys, /flash/lib and /flash/cert if they don't exist - if (FR_OK != f_chdir ("/flash/sys")) { - f_mkdir("/flash/sys"); + if (FR_OK != f_chdir(&vfs_fat->fatfs, "/sys")) { + f_mkdir(&vfs_fat->fatfs, "/sys"); } - if (FR_OK != f_chdir ("/flash/lib")) { - f_mkdir("/flash/lib"); + if (FR_OK != f_chdir(&vfs_fat->fatfs, "/lib")) { + f_mkdir(&vfs_fat->fatfs, "/lib"); } - if (FR_OK != f_chdir ("/flash/cert")) { - f_mkdir("/flash/cert"); + if (FR_OK != f_chdir(&vfs_fat->fatfs, "/cert")) { + f_mkdir(&vfs_fat->fatfs, "/cert"); } - f_chdir ("/flash"); + f_chdir(&vfs_fat->fatfs, "/"); // make sure we have a /flash/boot.py. Create it if needed. - res = f_stat("/flash/boot.py", &fno); + res = f_stat(&vfs_fat->fatfs, "/boot.py", &fno); if (res == FR_OK) { if (fno.fattrib & AM_DIR) { // exists as a directory @@ -354,7 +369,7 @@ STATIC void mptask_init_sflash_filesystem (void) { } else { // doesn't exist, create fresh file FIL fp; - f_open(&fp, "/flash/boot.py", FA_WRITE | FA_CREATE_ALWAYS); + f_open(&vfs_fat->fatfs, &fp, "/boot.py", FA_WRITE | FA_CREATE_ALWAYS); UINT n; f_write(&fp, fresh_boot_py, sizeof(fresh_boot_py) - 1 /* don't count null terminator */, &n); // TODO check we could write n bytes @@ -374,9 +389,8 @@ STATIC void mptask_enter_ap_mode (void) { STATIC void mptask_create_main_py (void) { // create empty main.py FIL fp; - f_open(&fp, "/flash/main.py", FA_WRITE | FA_CREATE_ALWAYS); + f_open(&sflash_vfs_fat->fatfs, &fp, "/main.py", FA_WRITE | FA_CREATE_ALWAYS); UINT n; f_write(&fp, fresh_main_py, sizeof(fresh_main_py) - 1 /* don't count null terminator */, &n); f_close(&fp); } - -- cgit v1.2.3 From 0bd61d23b9b21819da9d10290dfccd4ae4a69e1a Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 29 Jan 2017 15:26:24 +1100 Subject: extmod/vfs_fat: Remove MICROPY_FATFS_OO config option. Everyone should now be using the new ooFatFs library. The old one is no longer supported and will be removed. --- cc3200/mpconfigport.h | 1 - esp8266/mpconfigport.h | 1 - extmod/vfs_fat.c | 4 ---- extmod/vfs_fat_diskio.c | 32 ++------------------------------ extmod/vfs_fat_file.c | 13 ------------- extmod/vfs_fat_misc.c | 29 ----------------------------- stmhal/mpconfigport.h | 1 - unix/mpconfigport.h | 1 - 8 files changed, 2 insertions(+), 80 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 939d9f62b..49ea64403 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -64,7 +64,6 @@ #define MICROPY_QSTR_BYTES_IN_HASH (1) // fatfs configuration used in ffconf.h -#define MICROPY_FATFS_OO (1) #define MICROPY_FATFS_ENABLE_LFN (2) #define MICROPY_FATFS_MAX_LFN (MICROPY_ALLOC_PATH_MAX) #define MICROPY_FATFS_LFN_CODE_PAGE (437) // 1=SFN/ANSI 437=LFN/U.S.(OEM) diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index 89d9dae76..04b9792eb 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -95,7 +95,6 @@ #define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool #define MICROPY_VFS (1) -#define MICROPY_FATFS_OO (1) #define MICROPY_FATFS_ENABLE_LFN (1) #define MICROPY_FATFS_RPATH (2) #define MICROPY_FATFS_MAX_SS (4096) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index a6f2ae806..ecbbdb59a 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -32,10 +32,6 @@ #error "with MICROPY_VFS_FAT enabled, must also enable MICROPY_VFS" #endif -#if !MICROPY_FATFS_OO -#error "with MICROPY_VFS_FAT enabled, must also enable MICROPY_FATFS_OO" -#endif - #include #include "py/nlr.h" #include "py/runtime.h" diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index c8a6e1533..e12c4597e 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -36,13 +36,8 @@ #include "py/mphal.h" #include "py/runtime.h" -#if MICROPY_FATFS_OO #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" -#else -#include "lib/fatfs/ff.h" /* FatFs lower layer API */ -#include "lib/fatfs/diskio.h" /* FatFs lower layer API */ -#endif #include "extmod/fsusermount.h" #if _MAX_SS == _MIN_SS @@ -51,29 +46,16 @@ #define SECSIZE(fs) ((fs)->ssize) #endif -#if MICROPY_FATFS_OO typedef void *bdev_t; STATIC fs_user_mount_t *disk_get_device(void *bdev) { return (fs_user_mount_t*)bdev; } -#else -typedef BYTE bdev_t; -STATIC fs_user_mount_t *disk_get_device(uint id) { - if (id < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount))) { - return MP_STATE_PORT(fs_user_mount)[id]; - } else { - return NULL; - } -} -#endif /*-----------------------------------------------------------------------*/ /* Initialize a Drive */ /*-----------------------------------------------------------------------*/ -#if MICROPY_FATFS_OO STATIC -#endif DSTATUS disk_initialize ( bdev_t pdrv /* Physical drive nmuber (0..) */ ) @@ -105,9 +87,7 @@ DSTATUS disk_initialize ( /* Get Disk Status */ /*-----------------------------------------------------------------------*/ -#if MICROPY_FATFS_OO STATIC -#endif DSTATUS disk_status ( bdev_t pdrv /* Physical drive nmuber (0..) */ ) @@ -159,7 +139,6 @@ DRESULT disk_read ( /* Write Sector(s) */ /*-----------------------------------------------------------------------*/ -#if MICROPY_FATFS_OO || _USE_WRITE DRESULT disk_write ( bdev_t pdrv, /* Physical drive nmuber (0..) */ const BYTE *buff, /* Data to be written */ @@ -191,14 +170,12 @@ DRESULT disk_write ( return RES_OK; } -#endif /*-----------------------------------------------------------------------*/ /* Miscellaneous Functions */ /*-----------------------------------------------------------------------*/ -#if MICROPY_FATFS_OO || _USE_IOCTL DRESULT disk_ioctl ( bdev_t pdrv, /* Physical drive nmuber (0..) */ BYTE cmd, /* Control code */ @@ -237,7 +214,7 @@ DRESULT disk_ioctl ( } else { *((WORD*)buff) = mp_obj_get_int(ret); } - #if MICROPY_FATFS_OO && _MAX_SS != _MIN_SS + #if _MAX_SS != _MIN_SS // need to store ssize because we use it in disk_read/disk_write vfs->fatfs.ssize = *((WORD*)buff); #endif @@ -248,7 +225,6 @@ DRESULT disk_ioctl ( *((DWORD*)buff) = 1; // erase block size in units of sector size return RES_OK; - #if MICROPY_FATFS_OO case IOCTL_INIT: *((DSTATUS*)buff) = disk_initialize(pdrv); return RES_OK; @@ -256,7 +232,6 @@ DRESULT disk_ioctl ( case IOCTL_STATUS: *((DSTATUS*)buff) = disk_status(pdrv); return RES_OK; - #endif default: return RES_PARERR; @@ -278,7 +253,7 @@ DRESULT disk_ioctl ( case GET_SECTOR_SIZE: *((WORD*)buff) = 512; // old protocol had fixed sector size - #if MICROPY_FATFS_OO && _MAX_SS != _MIN_SS + #if _MAX_SS != _MIN_SS // need to store ssize because we use it in disk_read/disk_write vfs->fatfs.ssize = 512; #endif @@ -288,7 +263,6 @@ DRESULT disk_ioctl ( *((DWORD*)buff) = 1; // erase block size in units of sector size return RES_OK; - #if MICROPY_FATFS_OO case IOCTL_INIT: *((DSTATUS*)buff) = disk_initialize(pdrv); return RES_OK; @@ -296,13 +270,11 @@ DRESULT disk_ioctl ( case IOCTL_STATUS: *((DSTATUS*)buff) = disk_status(pdrv); return RES_OK; - #endif default: return RES_PARERR; } } } -#endif #endif // MICROPY_VFS diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index dccd12035..bb5903575 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -34,11 +34,7 @@ #include "py/runtime.h" #include "py/stream.h" #include "py/mperrno.h" -#if MICROPY_FATFS_OO #include "lib/oofatfs/ff.h" -#else -#include "lib/fatfs/ff.h" -#endif #include "extmod/fsusermount.h" #include "extmod/vfs_fat.h" @@ -115,11 +111,7 @@ STATIC mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t siz STATIC mp_obj_t file_obj_close(mp_obj_t self_in) { pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in); // if fs==NULL then the file is closed and in that case this method is a no-op - #if MICROPY_FATFS_OO if (self->fp.obj.fs != NULL) { - #else - if (self->fp.fs != NULL) { - #endif FRESULT res = f_close(&self->fp); if (res != FR_OK) { mp_raise_OSError(fresult_to_errno_table[res]); @@ -221,13 +213,8 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar o->base.type = type; const char *fname = mp_obj_str_get_str(args[0].u_obj); - #if MICROPY_FATFS_OO assert(vfs != NULL); FRESULT res = f_open(&vfs->fatfs, &o->fp, fname, mode); - #else - (void)vfs; - FRESULT res = f_open(&o->fp, fname, mode); - #endif if (res != FR_OK) { m_del_obj(pyb_file_obj_t, o); mp_raise_OSError(fresult_to_errno_table[res]); diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index 82ef91a1f..ba513ef92 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -30,19 +30,11 @@ #include #include "py/nlr.h" #include "py/runtime.h" -#if MICROPY_FATFS_OO #include "lib/oofatfs/ff.h" -#else -#include "lib/fatfs/ff.h" -#endif #include "extmod/vfs_fat.h" #include "extmod/fsusermount.h" #include "py/lexer.h" -#if !MICROPY_FATFS_OO && _USE_LFN -STATIC char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */ -#endif - // TODO: actually, the core function should be ilistdir() mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type) { @@ -53,16 +45,8 @@ mp_obj_t fat_vfs_listdir2(fs_user_mount_t *vfs, const char *path, bool is_str_ty FRESULT res; FILINFO fno; FF_DIR dir; -#if !MICROPY_FATFS_OO && _USE_LFN - fno.lfname = lfn; - fno.lfsize = sizeof lfn; -#endif - #if MICROPY_FATFS_OO res = f_opendir(&vfs->fatfs, &dir, path); - #else - res = f_opendir(&dir, path); /* Open the directory */ - #endif if (res != FR_OK) { mp_raise_OSError(fresult_to_errno_table[res]); } @@ -75,11 +59,7 @@ mp_obj_t fat_vfs_listdir2(fs_user_mount_t *vfs, const char *path, bool is_str_ty if (fno.fname[0] == '.' && fno.fname[1] == 0) continue; /* Ignore . entry */ if (fno.fname[0] == '.' && fno.fname[1] == '.' && fno.fname[2] == 0) continue; /* Ignore .. entry */ -#if !MICROPY_FATFS_OO && _USE_LFN - char *fn = *fno.lfname ? fno.lfname : fno.fname; -#else char *fn = fno.fname; -#endif /* if (fno.fattrib & AM_DIR) { @@ -108,17 +88,8 @@ mp_obj_t fat_vfs_listdir2(fs_user_mount_t *vfs, const char *path, bool is_str_ty mp_import_stat_t fat_vfs_import_stat(fs_user_mount_t *vfs, const char *path) { FILINFO fno; -#if !MICROPY_FATFS_OO && _USE_LFN - fno.lfname = NULL; - fno.lfsize = 0; -#endif - #if MICROPY_FATFS_OO assert(vfs != NULL); FRESULT res = f_stat(&vfs->fatfs, path, &fno); - #else - (void)vfs; - FRESULT res = f_stat(path, &fno); - #endif if (res == FR_OK) { if ((fno.fattrib & AM_DIR) != 0) { return MP_IMPORT_STAT_DIR; diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 53369a182..873215458 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -135,7 +135,6 @@ #endif // fatfs configuration used in ffconf.h -#define MICROPY_FATFS_OO (1) #define MICROPY_FATFS_ENABLE_LFN (1) #define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ #define MICROPY_FATFS_USE_LABEL (1) diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index 9e418fe0a..ba2b5ce98 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -131,7 +131,6 @@ #define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr #define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr -#define MICROPY_FATFS_OO (1) #define MICROPY_FATFS_ENABLE_LFN (1) #define MICROPY_FATFS_RPATH (2) #define MICROPY_FATFS_MAX_SS (4096) -- cgit v1.2.3 From b697c890096805d9ccaf7553dbff5b82f5332609 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 29 Jan 2017 19:20:27 +1100 Subject: extmod: Merge old fsusermount.h header into vfs.h and vfs_fat.h. vfs.h is for generic VFS declarations, and vfs_fat.h is for VfsFat specific things. --- cc3200/ftp/ftp.c | 2 +- cc3200/mods/pybflash.c | 1 - cc3200/mods/pybsd.c | 2 +- cc3200/mptask.c | 2 +- extmod/fsusermount.h | 62 ------------------------------------------------- extmod/vfs.c | 5 +++- extmod/vfs.h | 7 ++++++ extmod/vfs_fat.c | 1 - extmod/vfs_fat.h | 26 ++++++++++++++++++++- extmod/vfs_fat_diskio.c | 2 +- extmod/vfs_fat_file.c | 1 - extmod/vfs_fat_misc.c | 1 - stmhal/main.c | 2 +- stmhal/modmachine.c | 2 +- stmhal/sdcard.c | 1 - stmhal/storage.c | 1 - 16 files changed, 42 insertions(+), 76 deletions(-) delete mode 100644 extmod/fsusermount.h (limited to 'cc3200') diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c index c8a52149c..679c32561 100644 --- a/cc3200/ftp/ftp.c +++ b/cc3200/ftp/ftp.c @@ -32,7 +32,7 @@ #include "py/obj.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" diff --git a/cc3200/mods/pybflash.c b/cc3200/mods/pybflash.c index 0779f4a05..f5af79dbf 100644 --- a/cc3200/mods/pybflash.c +++ b/cc3200/mods/pybflash.c @@ -31,7 +31,6 @@ #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" #include "extmod/vfs_fat.h" -#include "extmod/fsusermount.h" #include "fatfs/src/drivers/sflash_diskio.h" #include "mods/pybflash.h" diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c index bac5a270c..937b8599d 100644 --- a/cc3200/mods/pybsd.c +++ b/cc3200/mods/pybsd.c @@ -29,7 +29,7 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #include "inc/hw_types.h" #include "inc/hw_gpio.h" #include "inc/hw_ints.h" diff --git a/cc3200/mptask.c b/cc3200/mptask.c index 476561c6d..c7c1832ed 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -36,7 +36,7 @@ #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" #include "extmod/vfs.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" diff --git a/extmod/fsusermount.h b/extmod/fsusermount.h deleted file mode 100644 index af6867d23..000000000 --- a/extmod/fsusermount.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2014 Damien P. George - * - * 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. - */ - -// these are the values for fs_user_mount_t.flags -#define FSUSER_NATIVE (0x0001) // readblocks[2]/writeblocks[2] contain native func -#define FSUSER_FREE_OBJ (0x0002) // fs_user_mount_t obj should be freed on umount -#define FSUSER_HAVE_IOCTL (0x0004) // new protocol with ioctl - -// constants for block protocol ioctl -#define BP_IOCTL_INIT (1) -#define BP_IOCTL_DEINIT (2) -#define BP_IOCTL_SYNC (3) -#define BP_IOCTL_SEC_COUNT (4) -#define BP_IOCTL_SEC_SIZE (5) - -typedef struct _fs_user_mount_t { - mp_obj_base_t base; - const char *str; - uint16_t len; // length of str - uint16_t flags; - mp_obj_t readblocks[4]; - mp_obj_t writeblocks[4]; - // new protocol uses just ioctl, old uses sync (optional) and count - union { - mp_obj_t ioctl[4]; - struct { - mp_obj_t sync[2]; - mp_obj_t count[2]; - } old; - } u; - FATFS fatfs; -} fs_user_mount_t; - -fs_user_mount_t *fatfs_mount_mkfs(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, bool mkfs); -mp_obj_t fatfs_umount(mp_obj_t bdev_or_path_in); - -MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mount_obj); -MP_DECLARE_CONST_FUN_OBJ_1(fsuser_umount_obj); -MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj); diff --git a/extmod/vfs.c b/extmod/vfs.c index 97c9077a2..1eb26acf1 100644 --- a/extmod/vfs.c +++ b/extmod/vfs.c @@ -31,10 +31,13 @@ #include "py/objstr.h" #include "py/mperrno.h" #include "extmod/vfs.h" -#include "extmod/vfs_fat.h" #if MICROPY_VFS +#if MICROPY_VFS_FAT +#include "extmod/vfs_fat.h" +#endif + // path is the path to lookup and *path_out holds the path within the VFS // object (starts with / if an absolute path). // Returns MP_VFS_ROOT for root dir (and then path_out is undefined) and diff --git a/extmod/vfs.h b/extmod/vfs.h index 92e53b305..4a1c225a0 100644 --- a/extmod/vfs.h +++ b/extmod/vfs.h @@ -35,6 +35,13 @@ #define MP_VFS_NONE ((mp_vfs_mount_t*)1) #define MP_VFS_ROOT ((mp_vfs_mount_t*)0) +// constants for block protocol ioctl +#define BP_IOCTL_INIT (1) +#define BP_IOCTL_DEINIT (2) +#define BP_IOCTL_SYNC (3) +#define BP_IOCTL_SEC_COUNT (4) +#define BP_IOCTL_SEC_SIZE (5) + typedef struct _mp_vfs_mount_t { const char *str; // mount point with leading / size_t len; diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index ecbbdb59a..b32bf7ad9 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -38,7 +38,6 @@ #include "py/mperrno.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs_fat.h" -#include "extmod/fsusermount.h" #include "timeutils.h" #if _MAX_SS == _MIN_SS diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index bc5be0c67..fefae776c 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -25,8 +25,32 @@ */ #include "py/lexer.h" +#include "py/obj.h" +#include "lib/oofatfs/ff.h" +#include "extmod/vfs.h" -struct _fs_user_mount_t; +// these are the values for fs_user_mount_t.flags +#define FSUSER_NATIVE (0x0001) // readblocks[2]/writeblocks[2] contain native func +#define FSUSER_FREE_OBJ (0x0002) // fs_user_mount_t obj should be freed on umount +#define FSUSER_HAVE_IOCTL (0x0004) // new protocol with ioctl + +typedef struct _fs_user_mount_t { + mp_obj_base_t base; + const char *str; + uint16_t len; // length of str + uint16_t flags; + mp_obj_t readblocks[4]; + mp_obj_t writeblocks[4]; + // new protocol uses just ioctl, old uses sync (optional) and count + union { + mp_obj_t ioctl[4]; + struct { + mp_obj_t sync[2]; + mp_obj_t count[2]; + } old; + } u; + FATFS fatfs; +} fs_user_mount_t; extern const byte fresult_to_errno_table[20]; extern const mp_obj_type_t mp_fat_vfs_type; diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index e12c4597e..7efcc22f2 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -38,7 +38,7 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #if _MAX_SS == _MIN_SS #define SECSIZE(fs) (_MIN_SS) diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index bb5903575..0f2a7a1aa 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -35,7 +35,6 @@ #include "py/stream.h" #include "py/mperrno.h" #include "lib/oofatfs/ff.h" -#include "extmod/fsusermount.h" #include "extmod/vfs_fat.h" #if MICROPY_VFS_FAT diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index ba513ef92..97d2675cd 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -32,7 +32,6 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs_fat.h" -#include "extmod/fsusermount.h" #include "py/lexer.h" // TODO: actually, the core function should be ilistdir() diff --git a/stmhal/main.c b/stmhal/main.c index 9eab50061..3a0bd7a6b 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -39,7 +39,7 @@ #include "lib/utils/pyexec.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #include "systick.h" #include "pendsv.h" diff --git a/stmhal/modmachine.c b/stmhal/modmachine.c index aec8e29c5..b10bca819 100644 --- a/stmhal/modmachine.c +++ b/stmhal/modmachine.c @@ -37,7 +37,7 @@ #include "lib/utils/pyexec.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #include "gccollect.h" #include "irq.h" #include "rng.h" diff --git a/stmhal/sdcard.c b/stmhal/sdcard.c index 52ede492b..b1d67f62a 100644 --- a/stmhal/sdcard.c +++ b/stmhal/sdcard.c @@ -30,7 +30,6 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs_fat.h" -#include "extmod/fsusermount.h" #include "mphalport.h" #include "sdcard.h" diff --git a/stmhal/storage.c b/stmhal/storage.c index 6130d6fb8..c1daad4c2 100644 --- a/stmhal/storage.c +++ b/stmhal/storage.c @@ -31,7 +31,6 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs_fat.h" -#include "extmod/fsusermount.h" #include "systick.h" #include "led.h" -- cgit v1.2.3 From b7d27e31e8c5d34aaba7e2a7070bb3b6fb082d28 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 6 Feb 2017 11:14:16 +1100 Subject: cc3200: Refactor "ticks" functions to use common extmod implementation. The port now uses the common mp_utime_ticks_{ms,us,cpu,add,diff} functions from extmod/utime_mphal.c. The mp_utime_sleep_XXX functions are still cc3200-specific because they handle the GIL differently to the ones in extmod. The files misc/mpsystick.[ch] have been removed because they contain 2 unused functions, and the other remaining function is renamed to mp_hal_ticks_us and moved to hal/cc3200_hal.c. --- cc3200/application.mk | 1 - cc3200/hal/cc3200_hal.c | 14 +++++++++- cc3200/hal/cc3200_hal.h | 6 +++++ cc3200/misc/mpsystick.c | 71 ------------------------------------------------- cc3200/misc/mpsystick.h | 35 ------------------------ cc3200/mods/modutime.c | 39 +++++---------------------- cc3200/mpconfigport.h | 1 + 7 files changed, 27 insertions(+), 140 deletions(-) delete mode 100644 cc3200/misc/mpsystick.c delete mode 100644 cc3200/misc/mpsystick.h (limited to 'cc3200') diff --git a/cc3200/application.mk b/cc3200/application.mk index 5ee909144..b15dbde7f 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -77,7 +77,6 @@ APP_MISC_SRC_C = $(addprefix misc/,\ mpirq.c \ mperror.c \ mpexception.c \ - mpsystick.c \ ) APP_MODS_SRC_C = $(addprefix mods/,\ diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c index 37026db14..5c0e9c30f 100644 --- a/cc3200/hal/cc3200_hal.c +++ b/cc3200/hal/cc3200_hal.c @@ -108,6 +108,19 @@ mp_uint_t mp_hal_ticks_ms(void) { return HAL_tickCount; } +// The SysTick timer counts down at HAL_FCPU_HZ, so we can use that knowledge +// to grab a microsecond counter. +mp_uint_t mp_hal_ticks_us(void) { + mp_uint_t irq_state = disable_irq(); + uint32_t counter = SysTickValueGet(); + uint32_t milliseconds = mp_hal_ticks_ms(); + enable_irq(irq_state); + + uint32_t load = SysTickPeriodGet(); + counter = load - counter; // Convert from decrementing to incrementing + return (milliseconds * 1000) + ((counter * 1000) / load); +} + void mp_hal_delay_ms(mp_uint_t delay) { // only if we are not within interrupt context and interrupts are enabled if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0 && query_irq() == IRQ_STATE_ENABLED) { @@ -211,4 +224,3 @@ static void hal_TickInit (void) { MAP_SysTickEnable(); } #endif - diff --git a/cc3200/hal/cc3200_hal.h b/cc3200/hal/cc3200_hal.h index 9715096b6..fcb85b292 100644 --- a/cc3200/hal/cc3200_hal.h +++ b/cc3200/hal/cc3200_hal.h @@ -30,6 +30,9 @@ #include #include +#include "hal/utils.h" +#include "hal/systick.h" + /****************************************************************************** DEFINE CONSTANTS ******************************************************************************/ @@ -64,4 +67,7 @@ extern void HAL_SystemDeInit (void); extern void HAL_IncrementTick(void); extern void mp_hal_set_interrupt_char (int c); +#define mp_hal_delay_us(usec) UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec)) +#define mp_hal_ticks_cpu() (SysTickPeriodGet() - SysTickValueGet()) + #endif /* CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ */ diff --git a/cc3200/misc/mpsystick.c b/cc3200/misc/mpsystick.c deleted file mode 100644 index 7c35354e1..000000000 --- a/cc3200/misc/mpsystick.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * Copyright (c) 2015 Daniel Campora - * - * 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/mpconfig.h" -#include "py/obj.h" -#include "py/mphal.h" -#include "mpsystick.h" -#include "systick.h" -#include "inc/hw_types.h" -#include "inc/hw_nvic.h" - -#ifdef USE_FREERTOS -#include "FreeRTOS.h" -#include "task.h" -#endif - - -bool sys_tick_has_passed(uint32_t start_tick, uint32_t delay_ms) { - return mp_hal_ticks_ms() - start_tick >= delay_ms; -} - -// waits until at least delay_ms milliseconds have passed from the sampling of -// startTick. Handles overflow properly. Assumes stc was taken from -// mp_hal_ticks_ms() some time before calling this function. -void sys_tick_wait_at_least(uint32_t start_tick, uint32_t delay_ms) { -#ifdef USE_FREERTOS - vTaskDelay (delay_ms / portTICK_PERIOD_MS); -#else - while (!sys_tick_has_passed(start_tick, delay_ms)) { - __WFI(); // enter sleep mode, waiting for interrupt - } -#endif -} - -// The SysTick timer counts down at HAL_FCPU_HZ, so we can use that knowledge -// to grab a microsecond counter. -// We assume that mp_hal_ticks_ms returns milliseconds. -uint32_t sys_tick_get_microseconds(void) { - mp_uint_t irq_state = disable_irq(); - uint32_t counter = SysTickValueGet(); - uint32_t milliseconds = mp_hal_ticks_ms(); - enable_irq(irq_state); - - uint32_t load = SysTickPeriodGet(); - counter = load - counter; // Convert from decrementing to incrementing - return (milliseconds * 1000) + ((counter * 1000) / load); -} diff --git a/cc3200/misc/mpsystick.h b/cc3200/misc/mpsystick.h deleted file mode 100644 index d7ad59461..000000000 --- a/cc3200/misc/mpsystick.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * Copyright (c) 2015 Daniel Campora - * - * 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. - */ - -#ifndef MPSYSTICK_H -#define MPSYSTICK_H - -void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms); -bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms); -uint32_t sys_tick_get_microseconds(void); - -#endif // MPSYSTICK_H diff --git a/cc3200/mods/modutime.c b/cc3200/mods/modutime.c index 7ea8df1ef..de1f75012 100644 --- a/cc3200/mods/modutime.c +++ b/cc3200/mods/modutime.c @@ -33,6 +33,7 @@ #include "py/obj.h" #include "py/smallint.h" #include "py/mphal.h" +#include "extmod/utime_mphal.h" #include "timeutils.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" @@ -41,7 +42,6 @@ #include "prcm.h" #include "systick.h" #include "pybrtc.h" -#include "mpsystick.h" #include "mpexception.h" #include "utils.h" @@ -143,38 +143,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_ms_obj, time_sleep_ms); STATIC mp_obj_t time_sleep_us (mp_obj_t usec_in) { mp_int_t usec = mp_obj_get_int(usec_in); if (usec > 0) { - UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec)); + mp_hal_delay_us(usec); } return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_us_obj, time_sleep_us); -STATIC mp_obj_t time_ticks_ms(void) { - // We want to "cast" the 32 bit unsigned into a 30-bit small-int - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_ms_obj, time_ticks_ms); - -STATIC mp_obj_t time_ticks_us(void) { - // We want to "cast" the 32 bit unsigned into a 30-bit small-int - return MP_OBJ_NEW_SMALL_INT(sys_tick_get_microseconds() & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_us_obj, time_ticks_us); - -STATIC mp_obj_t time_ticks_cpu(void) { - // We want to "cast" the 32 bit unsigned into a 30-bit small-int - return MP_OBJ_NEW_SMALL_INT((SysTickPeriodGet() - SysTickValueGet()) & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_cpu_obj, time_ticks_cpu); - -STATIC mp_obj_t time_ticks_diff(mp_obj_t t0, mp_obj_t t1) { - // We want to "cast" the 32 bit unsigned into a 30-bit small-int - uint32_t start = mp_obj_get_int(t0); - uint32_t end = mp_obj_get_int(t1); - return MP_OBJ_NEW_SMALL_INT((end - start) & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(time_ticks_diff_obj, time_ticks_diff); - STATIC const mp_map_elem_t time_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_utime) }, @@ -186,10 +160,11 @@ STATIC const mp_map_elem_t time_module_globals_table[] = { // MicroPython additions { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_ms), (mp_obj_t)&time_sleep_ms_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_us), (mp_obj_t)&time_sleep_us_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&time_ticks_ms_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&time_ticks_us_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&time_ticks_cpu_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_diff), (mp_obj_t)&time_ticks_diff_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&mp_utime_ticks_ms_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&mp_utime_ticks_us_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&mp_utime_ticks_cpu_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_add), (mp_obj_t)&mp_utime_ticks_add_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_diff), (mp_obj_t)&mp_utime_ticks_diff_obj }, }; STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 49ea64403..944a6c071 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -116,6 +116,7 @@ #define MICROPY_PY_UHEAPQ (0) #define MICROPY_PY_UHASHLIB (0) #define MICROPY_PY_USELECT (1) +#define MICROPY_PY_UTIME_MP_HAL (1) #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) -- cgit v1.2.3 From ae8d86758631e62466a55d179897d2111c3cb1c1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 9 Jan 2016 23:14:54 +0000 Subject: py: Add iter_buf to getiter type method. Allows to iterate over the following without allocating on the heap: - tuple - list - string, bytes - bytearray, array - dict (not dict.keys, dict.values, dict.items) - set, frozenset Allows to call the following without heap memory: - all, any, min, max, sum TODO: still need to allocate stack memory in bytecode for iter_buf. --- cc3200/mods/pybuart.c | 2 +- esp8266/machine_uart.c | 2 +- extmod/modbtree.c | 3 ++- extmod/vfs_fat_file.c | 4 ++-- py/emitnative.c | 1 + py/modbuiltins.c | 14 +++++++++----- py/obj.c | 5 +++++ py/obj.h | 15 +++++++++++++-- py/objarray.c | 14 +++++++++----- py/objdict.c | 24 +++++++++++++++--------- py/objenumerate.c | 6 +++--- py/objfilter.c | 4 ++-- py/objgenerator.c | 2 +- py/objgetitemiter.c | 7 ++++--- py/objlist.c | 14 ++++++++------ py/objmap.c | 4 ++-- py/objpolyiter.c | 2 +- py/objrange.c | 11 ++++++----- py/objreversed.c | 2 +- py/objset.c | 26 +++++++++++++++++--------- py/objstr.c | 17 ++++++++++------- py/objstringio.c | 4 ++-- py/objstrunicode.c | 7 ++++--- py/objtuple.c | 18 +++++++----------- py/objtuple.h | 2 +- py/objtype.c | 4 ++-- py/objzip.c | 4 ++-- py/runtime.c | 26 ++++++++++++++++++-------- py/runtime.h | 2 +- py/vm.c | 2 +- stmhal/pybstdio.c | 4 ++-- stmhal/uart.c | 2 +- stmhal/usb.c | 2 +- unix/file.c | 4 ++-- unix/modffi.c | 6 ++++-- unix/moduselect.c | 2 +- 36 files changed, 162 insertions(+), 106 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index fe710be92..dceb842d5 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -664,7 +664,7 @@ const mp_obj_type_t pyb_uart_type = { .name = MP_QSTR_UART, .print = pyb_uart_print, .make_new = pyb_uart_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &uart_stream_p, .locals_dict = (mp_obj_t)&pyb_uart_locals_dict, diff --git a/esp8266/machine_uart.c b/esp8266/machine_uart.c index efdfafd1a..ef52e8c9a 100644 --- a/esp8266/machine_uart.c +++ b/esp8266/machine_uart.c @@ -285,7 +285,7 @@ const mp_obj_type_t pyb_uart_type = { .name = MP_QSTR_UART, .print = pyb_uart_print, .make_new = pyb_uart_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &uart_stream_p, .locals_dict = (mp_obj_dict_t*)&pyb_uart_locals_dict, diff --git a/extmod/modbtree.c b/extmod/modbtree.c index bb75845b1..27f700eea 100644 --- a/extmod/modbtree.c +++ b/extmod/modbtree.c @@ -184,7 +184,8 @@ STATIC mp_obj_t btree_items(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_items_obj, 1, 4, btree_items); -STATIC mp_obj_t btree_getiter(mp_obj_t self_in) { +STATIC mp_obj_t btree_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { + (void)iter_buf; mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in); if (self->next_flags != 0) { // If we're called immediately after keys(), values(), or items(), diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index 62da23f94..6263492cb 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -264,7 +264,7 @@ const mp_obj_type_t mp_type_fileio = { .name = MP_QSTR_FileIO, .print = file_obj_print, .make_new = file_obj_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &fileio_stream_p, .locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict, @@ -283,7 +283,7 @@ const mp_obj_type_t mp_type_textio = { .name = MP_QSTR_TextIOWrapper, .print = file_obj_print, .make_new = file_obj_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &textio_stream_p, .locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict, diff --git a/py/emitnative.c b/py/emitnative.c index bdb590e77..e8e3754e1 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -1806,6 +1806,7 @@ STATIC void emit_native_get_iter(emit_t *emit) { vtype_kind_t vtype; emit_pre_pop_reg(emit, &vtype, REG_ARG_1); assert(vtype == VTYPE_PYOBJ); + assert(0); // TODO allocate memory for iter_buf emit_call(emit, MP_F_GETITER); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } diff --git a/py/modbuiltins.c b/py/modbuiltins.c index a0c68930d..13312d229 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -117,7 +117,8 @@ STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) { MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs); STATIC mp_obj_t mp_builtin_all(mp_obj_t o_in) { - mp_obj_t iterable = mp_getiter(o_in); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(o_in, &iter_buf); mp_obj_t item; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (!mp_obj_is_true(item)) { @@ -129,7 +130,8 @@ STATIC mp_obj_t mp_builtin_all(mp_obj_t o_in) { MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_all_obj, mp_builtin_all); STATIC mp_obj_t mp_builtin_any(mp_obj_t o_in) { - mp_obj_t iterable = mp_getiter(o_in); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(o_in, &iter_buf); mp_obj_t item; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (mp_obj_is_true(item)) { @@ -258,7 +260,7 @@ STATIC mp_obj_t mp_builtin_hex(mp_obj_t o_in) { MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hex_obj, mp_builtin_hex); STATIC mp_obj_t mp_builtin_iter(mp_obj_t o_in) { - return mp_getiter(o_in); + return mp_getiter(o_in, NULL); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_iter_obj, mp_builtin_iter); @@ -270,7 +272,8 @@ STATIC mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t mp_obj_t key_fn = key_elem == NULL ? MP_OBJ_NULL : key_elem->value; if (n_args == 1) { // given an iterable - mp_obj_t iterable = mp_getiter(args[0]); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(args[0], &iter_buf); mp_obj_t best_key = MP_OBJ_NULL; mp_obj_t best_obj = MP_OBJ_NULL; mp_obj_t item; @@ -495,7 +498,8 @@ STATIC mp_obj_t mp_builtin_sum(size_t n_args, const mp_obj_t *args) { case 1: value = MP_OBJ_NEW_SMALL_INT(0); break; default: value = args[1]; break; } - mp_obj_t iterable = mp_getiter(args[0]); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(args[0], &iter_buf); mp_obj_t item; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { value = mp_binary_op(MP_BINARY_OP_ADD, value, item); diff --git a/py/obj.c b/py/obj.c index 1d0c80ab9..4534ef1b2 100644 --- a/py/obj.c +++ b/py/obj.c @@ -481,6 +481,11 @@ mp_obj_t mp_identity(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_identity_obj, mp_identity); +mp_obj_t mp_identity_getiter(mp_obj_t self, mp_obj_iter_buf_t *iter_buf) { + (void)iter_buf; + return self; +} + bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) { mp_obj_type_t *type = mp_obj_get_type(obj); if (type->buffer_p.get_buffer == NULL) { diff --git a/py/obj.h b/py/obj.h index 1169a9095..79a6d56fa 100644 --- a/py/obj.h +++ b/py/obj.h @@ -417,6 +417,11 @@ typedef enum { PRINT_EXC_SUBCLASS = 0x80, // Internal flag for printing exception subclasses } mp_print_kind_t; +typedef struct _mp_obj_iter_buf_t { + mp_obj_base_t base; + mp_obj_t buf[3]; +} mp_obj_iter_buf_t; + typedef void (*mp_print_fun_t)(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind); typedef mp_obj_t (*mp_make_new_fun_t)(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); typedef mp_obj_t (*mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args); @@ -424,6 +429,7 @@ typedef mp_obj_t (*mp_unary_op_fun_t)(mp_uint_t op, mp_obj_t); typedef mp_obj_t (*mp_binary_op_fun_t)(mp_uint_t op, mp_obj_t, mp_obj_t); typedef void (*mp_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t *dest); typedef mp_obj_t (*mp_subscr_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value); +typedef mp_obj_t (*mp_getiter_fun_t)(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf); // Buffer protocol typedef struct _mp_buffer_info_t { @@ -486,7 +492,11 @@ struct _mp_obj_type_t { // value=MP_OBJ_NULL means delete, value=MP_OBJ_SENTINEL means load, else store // can return MP_OBJ_NULL if op not supported - mp_fun_1_t getiter; // corresponds to __iter__ special method + // corresponds to __iter__ special method + // can use given mp_obj_iter_buf_t to store iterator + // otherwise can return a pointer to an object on the heap + mp_getiter_fun_t getiter; + mp_fun_1_t iternext; // may return MP_OBJ_STOP_ITERATION as an optimisation instead of raising StopIteration() (with no args) mp_buffer_p_t buffer_p; @@ -637,7 +647,7 @@ mp_obj_t mp_obj_new_set(size_t n_args, mp_obj_t *items); mp_obj_t mp_obj_new_slice(mp_obj_t start, mp_obj_t stop, mp_obj_t step); mp_obj_t mp_obj_new_super(mp_obj_t type, mp_obj_t obj); mp_obj_t mp_obj_new_bound_meth(mp_obj_t meth, mp_obj_t self); -mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args); +mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args, mp_obj_iter_buf_t *iter_buf); mp_obj_t mp_obj_new_module(qstr module_name); mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items); @@ -775,6 +785,7 @@ qstr mp_obj_code_get_name(const byte *code_info); mp_obj_t mp_identity(mp_obj_t self); MP_DECLARE_CONST_FUN_OBJ_1(mp_identity_obj); +mp_obj_t mp_identity_getiter(mp_obj_t self, mp_obj_iter_buf_t *iter_buf); // module typedef struct _mp_obj_module_t { diff --git a/py/objarray.c b/py/objarray.c index f23791857..c81aebb50 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -59,7 +59,7 @@ #define TYPECODE_MASK (~(size_t)0) #endif -STATIC mp_obj_t array_iterator_new(mp_obj_t array_in); +STATIC mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf); STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg); STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in); STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags); @@ -141,7 +141,8 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) { mp_obj_array_t *array = array_new(typecode, len); - mp_obj_t iterable = mp_getiter(initializer); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(initializer, &iter_buf); mp_obj_t item; size_t i = 0; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { @@ -608,15 +609,18 @@ STATIC mp_obj_t array_it_iternext(mp_obj_t self_in) { STATIC const mp_obj_type_t array_it_type = { { &mp_type_type }, .name = MP_QSTR_iterator, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = array_it_iternext, }; -STATIC mp_obj_t array_iterator_new(mp_obj_t array_in) { +STATIC mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_array_t) <= sizeof(mp_obj_iter_buf_t)); mp_obj_array_t *array = MP_OBJ_TO_PTR(array_in); - mp_obj_array_it_t *o = m_new0(mp_obj_array_it_t, 1); + mp_obj_array_it_t *o = (mp_obj_array_it_t*)iter_buf; o->base.type = &array_it_type; o->array = array; + o->offset = 0; + o->cur = 0; #if MICROPY_PY_BUILTINS_MEMORYVIEW if (array->base.type == &mp_type_memoryview) { o->offset = array->free; diff --git a/py/objdict.c b/py/objdict.c index 640df7b62..c52403f71 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -210,8 +210,9 @@ STATIC mp_obj_t dict_it_iternext(mp_obj_t self_in) { } } -STATIC mp_obj_t dict_getiter(mp_obj_t self_in) { - mp_obj_dict_it_t *o = m_new_obj(mp_obj_dict_it_t); +STATIC mp_obj_t dict_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_dict_it_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_dict_it_t *o = (mp_obj_dict_it_t*)iter_buf; o->base.type = &mp_type_polymorph_iter; o->iternext = dict_it_iternext; o->dict = self_in; @@ -249,7 +250,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_copy_obj, dict_copy); // this is a classmethod STATIC mp_obj_t dict_fromkeys(size_t n_args, const mp_obj_t *args) { - mp_obj_t iter = mp_getiter(args[1]); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iter = mp_getiter(args[1], &iter_buf); mp_obj_t value = mp_const_none; mp_obj_t next = MP_OBJ_NULL; @@ -375,10 +377,12 @@ STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwarg } } else { // update from a generic iterable of pairs - mp_obj_t iter = mp_getiter(args[1]); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iter = mp_getiter(args[1], &iter_buf); mp_obj_t next = MP_OBJ_NULL; while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { - mp_obj_t inneriter = mp_getiter(next); + mp_obj_iter_buf_t inner_iter_buf; + mp_obj_t inneriter = mp_getiter(next, &inner_iter_buf); mp_obj_t key = mp_iternext(inneriter); mp_obj_t value = mp_iternext(inneriter); mp_obj_t stop = mp_iternext(inneriter); @@ -457,14 +461,15 @@ STATIC mp_obj_t dict_view_it_iternext(mp_obj_t self_in) { STATIC const mp_obj_type_t dict_view_it_type = { { &mp_type_type }, .name = MP_QSTR_iterator, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = dict_view_it_iternext, }; -STATIC mp_obj_t dict_view_getiter(mp_obj_t view_in) { +STATIC mp_obj_t dict_view_getiter(mp_obj_t view_in, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_dict_view_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_check_self(MP_OBJ_IS_TYPE(view_in, &dict_view_type)); mp_obj_dict_view_t *view = MP_OBJ_TO_PTR(view_in); - mp_obj_dict_view_it_t *o = m_new_obj(mp_obj_dict_view_it_t); + mp_obj_dict_view_it_t *o = (mp_obj_dict_view_it_t*)iter_buf; o->base.type = &dict_view_it_type; o->kind = view->kind; o->dict = view->dict; @@ -479,7 +484,8 @@ STATIC void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ bool first = true; mp_print_str(print, mp_dict_view_names[self->kind]); mp_print_str(print, "(["); - mp_obj_t self_iter = dict_view_getiter(self_in); + mp_obj_iter_buf_t iter_buf; + mp_obj_t self_iter = dict_view_getiter(self_in, &iter_buf); mp_obj_t next = MP_OBJ_NULL; while ((next = dict_view_it_iternext(self_iter)) != MP_OBJ_STOP_ITERATION) { if (!first) { diff --git a/py/objenumerate.c b/py/objenumerate.c index 2b646ca45..faae6516c 100644 --- a/py/objenumerate.c +++ b/py/objenumerate.c @@ -56,13 +56,13 @@ STATIC mp_obj_t enumerate_make_new(const mp_obj_type_t *type, size_t n_args, siz // create enumerate object mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t); o->base.type = type; - o->iter = mp_getiter(arg_vals.iterable.u_obj); + o->iter = mp_getiter(arg_vals.iterable.u_obj, NULL); o->cur = arg_vals.start.u_int; #else (void)n_kw; mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t); o->base.type = type; - o->iter = mp_getiter(args[0]); + o->iter = mp_getiter(args[0], NULL); o->cur = n_args > 1 ? mp_obj_get_int(args[1]) : 0; #endif @@ -74,7 +74,7 @@ const mp_obj_type_t mp_type_enumerate = { .name = MP_QSTR_enumerate, .make_new = enumerate_make_new, .iternext = enumerate_iternext, - .getiter = mp_identity, + .getiter = mp_identity_getiter, }; STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in) { diff --git a/py/objfilter.c b/py/objfilter.c index a5c85b2ce..a655b8a78 100644 --- a/py/objfilter.c +++ b/py/objfilter.c @@ -39,7 +39,7 @@ STATIC mp_obj_t filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t mp_obj_filter_t *o = m_new_obj(mp_obj_filter_t); o->base.type = type; o->fun = args[0]; - o->iter = mp_getiter(args[1]); + o->iter = mp_getiter(args[1], NULL); return MP_OBJ_FROM_PTR(o); } @@ -65,7 +65,7 @@ const mp_obj_type_t mp_type_filter = { { &mp_type_type }, .name = MP_QSTR_filter, .make_new = filter_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = filter_iternext, }; diff --git a/py/objgenerator.c b/py/objgenerator.c index 0be9b8d59..654b18670 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -236,7 +236,7 @@ const mp_obj_type_t mp_type_gen_instance = { { &mp_type_type }, .name = MP_QSTR_generator, .print = gen_instance_print, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = gen_instance_iternext, .locals_dict = (mp_obj_dict_t*)&gen_instance_locals_dict, }; diff --git a/py/objgetitemiter.c b/py/objgetitemiter.c index 526180fdb..a3c754448 100644 --- a/py/objgetitemiter.c +++ b/py/objgetitemiter.c @@ -61,13 +61,14 @@ STATIC mp_obj_t it_iternext(mp_obj_t self_in) { STATIC const mp_obj_type_t it_type = { { &mp_type_type }, .name = MP_QSTR_iterator, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = it_iternext, }; // args are those returned from mp_load_method_maybe (ie either an attribute or a method) -mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args) { - mp_obj_getitem_iter_t *o = m_new_obj(mp_obj_getitem_iter_t); +mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_getitem_iter_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_getitem_iter_t *o = (mp_obj_getitem_iter_t*)iter_buf; o->base.type = &it_type; o->args[0] = args[0]; o->args[1] = args[1]; diff --git a/py/objlist.c b/py/objlist.c index 210140388..28da10991 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -33,7 +33,7 @@ #include "py/runtime.h" #include "py/stackctrl.h" -STATIC mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, size_t cur); +STATIC mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, size_t cur, mp_obj_iter_buf_t *iter_buf); STATIC mp_obj_list_t *list_new(size_t n); STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in); STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args); @@ -60,7 +60,8 @@ STATIC void list_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t k } STATIC mp_obj_t list_extend_from_iter(mp_obj_t list, mp_obj_t iterable) { - mp_obj_t iter = mp_getiter(iterable); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iter = mp_getiter(iterable, &iter_buf); mp_obj_t item; while ((item = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { mp_obj_list_append(list, item); @@ -225,8 +226,8 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -STATIC mp_obj_t list_getiter(mp_obj_t o_in) { - return mp_obj_new_list_iterator(o_in, 0); +STATIC mp_obj_t list_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { + return mp_obj_new_list_iterator(o_in, 0, iter_buf); } mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg) { @@ -516,8 +517,9 @@ STATIC mp_obj_t list_it_iternext(mp_obj_t self_in) { } } -mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, size_t cur) { - mp_obj_list_it_t *o = m_new_obj(mp_obj_list_it_t); +mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, size_t cur, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_list_it_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_list_it_t *o = (mp_obj_list_it_t*)iter_buf; o->base.type = &mp_type_polymorph_iter; o->iternext = list_it_iternext; o->list = list; diff --git a/py/objmap.c b/py/objmap.c index ed0291435..0b2189016 100644 --- a/py/objmap.c +++ b/py/objmap.c @@ -43,7 +43,7 @@ STATIC mp_obj_t map_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ o->n_iters = n_args - 1; o->fun = args[0]; for (mp_uint_t i = 0; i < n_args - 1; i++) { - o->iters[i] = mp_getiter(args[i + 1]); + o->iters[i] = mp_getiter(args[i + 1], NULL); } return MP_OBJ_FROM_PTR(o); } @@ -68,6 +68,6 @@ const mp_obj_type_t mp_type_map = { { &mp_type_type }, .name = MP_QSTR_map, .make_new = map_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = map_iternext, }; diff --git a/py/objpolyiter.c b/py/objpolyiter.c index 9bba538c5..61bd1e0ac 100644 --- a/py/objpolyiter.c +++ b/py/objpolyiter.c @@ -49,6 +49,6 @@ STATIC mp_obj_t polymorph_it_iternext(mp_obj_t self_in) { const mp_obj_type_t mp_type_polymorph_iter = { { &mp_type_type }, .name = MP_QSTR_iterator, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = polymorph_it_iternext, }; diff --git a/py/objrange.c b/py/objrange.c index 79459316b..dd074a98a 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -55,12 +55,13 @@ STATIC mp_obj_t range_it_iternext(mp_obj_t o_in) { STATIC const mp_obj_type_t range_it_type = { { &mp_type_type }, .name = MP_QSTR_iterator, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = range_it_iternext, }; -STATIC mp_obj_t mp_obj_new_range_iterator(mp_int_t cur, mp_int_t stop, mp_int_t step) { - mp_obj_range_it_t *o = m_new_obj(mp_obj_range_it_t); +STATIC mp_obj_t mp_obj_new_range_iterator(mp_int_t cur, mp_int_t stop, mp_int_t step, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_range_it_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_range_it_t *o = (mp_obj_range_it_t*)iter_buf; o->base.type = &range_it_type; o->cur = cur; o->stop = stop; @@ -161,9 +162,9 @@ STATIC mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -STATIC mp_obj_t range_getiter(mp_obj_t o_in) { +STATIC mp_obj_t range_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { mp_obj_range_t *o = MP_OBJ_TO_PTR(o_in); - return mp_obj_new_range_iterator(o->start, o->stop, o->step); + return mp_obj_new_range_iterator(o->start, o->stop, o->step, iter_buf); } diff --git a/py/objreversed.c b/py/objreversed.c index 4343c1978..fc85e72bf 100644 --- a/py/objreversed.c +++ b/py/objreversed.c @@ -74,7 +74,7 @@ const mp_obj_type_t mp_type_reversed = { { &mp_type_type }, .name = MP_QSTR_reversed, .make_new = reversed_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = reversed_iternext, }; diff --git a/py/objset.c b/py/objset.c index b9da44a44..99e1e8ca5 100644 --- a/py/objset.c +++ b/py/objset.c @@ -129,7 +129,8 @@ STATIC mp_obj_t set_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ default: { // can only be 0 or 1 arg // 1 argument, an iterable from which we make a new set mp_obj_t set = mp_obj_new_set(0, NULL); - mp_obj_t iterable = mp_getiter(args[0]); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(args[0], &iter_buf); mp_obj_t item; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { mp_obj_set_store(set, item); @@ -156,8 +157,9 @@ STATIC mp_obj_t set_it_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC mp_obj_t set_getiter(mp_obj_t set_in) { - mp_obj_set_it_t *o = m_new_obj(mp_obj_set_it_t); +STATIC mp_obj_t set_getiter(mp_obj_t set_in, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_set_it_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_set_it_t *o = (mp_obj_set_it_t*)iter_buf; o->base.type = &mp_type_polymorph_iter; o->iternext = set_it_iternext; o->set = (mp_obj_set_t *)MP_OBJ_TO_PTR(set_in); @@ -233,7 +235,8 @@ STATIC mp_obj_t set_diff_int(size_t n_args, const mp_obj_t *args, bool update) { if (self == other) { set_clear(self); } else { - mp_obj_t iter = mp_getiter(other); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iter = mp_getiter(other, &iter_buf); mp_obj_t next; while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { set_discard(self, next); @@ -270,7 +273,8 @@ STATIC mp_obj_t set_intersect_int(mp_obj_t self_in, mp_obj_t other, bool update) mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_set_t *out = MP_OBJ_TO_PTR(mp_obj_new_set(0, NULL)); - mp_obj_t iter = mp_getiter(other); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iter = mp_getiter(other, &iter_buf); mp_obj_t next; while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { if (mp_set_lookup(&self->set, next, MP_MAP_LOOKUP)) { @@ -302,7 +306,8 @@ STATIC mp_obj_t set_isdisjoint(mp_obj_t self_in, mp_obj_t other) { check_set_or_frozenset(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); - mp_obj_t iter = mp_getiter(other); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iter = mp_getiter(other, &iter_buf); mp_obj_t next; while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { if (mp_set_lookup(&self->set, next, MP_MAP_LOOKUP)) { @@ -335,7 +340,8 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool if (proper && self->set.used == other->set.used) { out = false; } else { - mp_obj_t iter = set_getiter(MP_OBJ_FROM_PTR(self)); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iter = set_getiter(MP_OBJ_FROM_PTR(self), &iter_buf); mp_obj_t next; while ((next = set_it_iternext(iter)) != MP_OBJ_STOP_ITERATION) { if (!mp_set_lookup(&other->set, next, MP_MAP_LOOKUP)) { @@ -408,7 +414,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_remove_obj, set_remove); STATIC mp_obj_t set_symmetric_difference_update(mp_obj_t self_in, mp_obj_t other_in) { check_set(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); - mp_obj_t iter = mp_getiter(other_in); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iter = mp_getiter(other_in, &iter_buf); mp_obj_t next; while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { mp_set_lookup(&self->set, next, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND_OR_REMOVE_IF_FOUND); @@ -427,7 +434,8 @@ STATIC mp_obj_t set_symmetric_difference(mp_obj_t self_in, mp_obj_t other_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_obj, set_symmetric_difference); STATIC void set_update_int(mp_obj_set_t *self, mp_obj_t other_in) { - mp_obj_t iter = mp_getiter(other_in); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iter = mp_getiter(other_in, &iter_buf); mp_obj_t next; while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { mp_set_lookup(&self->set, next, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); diff --git a/py/objstr.c b/py/objstr.c index 262b89ddd..c137afe67 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -38,7 +38,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict); -STATIC mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str); +STATIC mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in); /******************************************************************************/ @@ -231,7 +231,8 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size vstr_init(&vstr, len); } - mp_obj_t iterable = mp_getiter(args[0]); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(args[0], &iter_buf); mp_obj_t item; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { mp_int_t val = mp_obj_get_int(item); @@ -1942,7 +1943,7 @@ STATIC const mp_rom_map_elem_t str8_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(str8_locals_dict, str8_locals_dict_table); #if !MICROPY_PY_BUILTINS_STR_UNICODE -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str); +STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); const mp_obj_type_t mp_type_str = { { &mp_type_type }, @@ -2142,8 +2143,9 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { } } -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str) { - mp_obj_str8_it_t *o = m_new_obj(mp_obj_str8_it_t); +STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_str8_it_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_str8_it_t *o = (mp_obj_str8_it_t*)iter_buf; o->base.type = &mp_type_polymorph_iter; o->iternext = str_it_iternext; o->str = str; @@ -2164,8 +2166,9 @@ STATIC mp_obj_t bytes_it_iternext(mp_obj_t self_in) { } } -mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str) { - mp_obj_str8_it_t *o = m_new_obj(mp_obj_str8_it_t); +mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_str8_it_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_str8_it_t *o = (mp_obj_str8_it_t*)iter_buf; o->base.type = &mp_type_polymorph_iter; o->iternext = bytes_it_iternext; o->str = str; diff --git a/py/objstringio.c b/py/objstringio.c index a77ffae24..61a30752e 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -215,7 +215,7 @@ const mp_obj_type_t mp_type_stringio = { .name = MP_QSTR_StringIO, .print = stringio_print, .make_new = stringio_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &stringio_stream_p, .locals_dict = (mp_obj_dict_t*)&stringio_locals_dict, @@ -227,7 +227,7 @@ const mp_obj_type_t mp_type_bytesio = { .name = MP_QSTR_BytesIO, .print = stringio_print, .make_new = stringio_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &bytesio_stream_p, .locals_dict = (mp_obj_dict_t*)&stringio_locals_dict, diff --git a/py/objstrunicode.c b/py/objstrunicode.c index 0091edd72..441ec293d 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -36,7 +36,7 @@ #if MICROPY_PY_BUILTINS_STR_UNICODE -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str); +STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); /******************************************************************************/ /* str */ @@ -301,8 +301,9 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { } } -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str) { - mp_obj_str_it_t *o = m_new_obj(mp_obj_str_it_t); +STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_str_it_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_str_it_t *o = (mp_obj_str_it_t*)iter_buf; o->base.type = &mp_type_polymorph_iter; o->iternext = str_it_iternext; o->str = str; diff --git a/py/objtuple.c b/py/objtuple.c index 1935a6709..ad45696ca 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -32,8 +32,6 @@ #include "py/runtime0.h" #include "py/runtime.h" -STATIC mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, size_t cur); - /******************************************************************************/ /* tuple */ @@ -84,7 +82,8 @@ STATIC mp_obj_t mp_obj_tuple_make_new(const mp_obj_type_t *type_in, size_t n_arg size_t len = 0; mp_obj_t *items = m_new(mp_obj_t, alloc); - mp_obj_t iterable = mp_getiter(args[0]); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(args[0], &iter_buf); mp_obj_t item; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (len >= alloc) { @@ -195,10 +194,6 @@ mp_obj_t mp_obj_tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -mp_obj_t mp_obj_tuple_getiter(mp_obj_t o_in) { - return mp_obj_new_tuple_iterator(MP_OBJ_TO_PTR(o_in), 0); -} - STATIC mp_obj_t tuple_count(mp_obj_t self_in, mp_obj_t value) { mp_check_self(MP_OBJ_IS_TYPE(self_in, &mp_type_tuple)); mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in); @@ -284,11 +279,12 @@ STATIC mp_obj_t tuple_it_iternext(mp_obj_t self_in) { } } -STATIC mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, size_t cur) { - mp_obj_tuple_it_t *o = m_new_obj(mp_obj_tuple_it_t); +mp_obj_t mp_obj_tuple_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_tuple_it_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_tuple_it_t *o = (mp_obj_tuple_it_t*)iter_buf; o->base.type = &mp_type_polymorph_iter; o->iternext = tuple_it_iternext; - o->tuple = tuple; - o->cur = cur; + o->tuple = MP_OBJ_TO_PTR(o_in); + o->cur = 0; return MP_OBJ_FROM_PTR(o); } diff --git a/py/objtuple.h b/py/objtuple.h index 760135f86..555c3b3c2 100644 --- a/py/objtuple.h +++ b/py/objtuple.h @@ -44,7 +44,7 @@ void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t mp_obj_t mp_obj_tuple_unary_op(mp_uint_t op, mp_obj_t self_in); mp_obj_t mp_obj_tuple_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs); mp_obj_t mp_obj_tuple_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value); -mp_obj_t mp_obj_tuple_getiter(mp_obj_t o_in); +mp_obj_t mp_obj_tuple_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf); extern const mp_obj_type_t mp_type_attrtuple; diff --git a/py/objtype.c b/py/objtype.c index 60f630c3d..a4c424929 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -758,7 +758,7 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons return mp_call_method_self_n_kw(member[0], member[1], n_args, n_kw, args); } -STATIC mp_obj_t instance_getiter(mp_obj_t self_in) { +STATIC mp_obj_t instance_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t member[2] = {MP_OBJ_NULL}; struct class_lookup_data lookup = { @@ -773,7 +773,7 @@ STATIC mp_obj_t instance_getiter(mp_obj_t self_in) { return MP_OBJ_NULL; } else if (member[0] == MP_OBJ_SENTINEL) { mp_obj_type_t *type = mp_obj_get_type(self->subobj[0]); - return type->getiter(self->subobj[0]); + return type->getiter(self->subobj[0], iter_buf); } else { return mp_call_method_n_kw(0, 0, member); } diff --git a/py/objzip.c b/py/objzip.c index 6edefc361..5d9ba48e7 100644 --- a/py/objzip.c +++ b/py/objzip.c @@ -43,7 +43,7 @@ STATIC mp_obj_t zip_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ o->base.type = type; o->n_iters = n_args; for (mp_uint_t i = 0; i < n_args; i++) { - o->iters[i] = mp_getiter(args[i]); + o->iters[i] = mp_getiter(args[i], NULL); } return MP_OBJ_FROM_PTR(o); } @@ -71,6 +71,6 @@ const mp_obj_type_t mp_type_zip = { { &mp_type_type }, .name = MP_QSTR_zip, .make_new = zip_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = zip_iternext, }; diff --git a/py/runtime.c b/py/runtime.c index 3ac30f58e..b9d7b72dc 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -520,7 +520,8 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { } if (type->getiter != NULL) { /* second attempt, walk the iterator */ - mp_obj_t iter = mp_getiter(rhs); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iter = mp_getiter(rhs, &iter_buf); mp_obj_t next; while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { if (mp_obj_equal(next, lhs)) { @@ -698,7 +699,8 @@ void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_ args2_len += n_args; // extract the variable position args from the iterator - mp_obj_t iterable = mp_getiter(pos_seq); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(pos_seq, &iter_buf); mp_obj_t item; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (args2_len >= args2_alloc) { @@ -743,7 +745,8 @@ void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_ // get the keys iterable mp_obj_t dest[3]; mp_load_method(kw_dict, MP_QSTR_keys, dest); - mp_obj_t iterable = mp_getiter(mp_call_method_n_kw(0, 0, dest)); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(mp_call_method_n_kw(0, 0, dest), &iter_buf); mp_obj_t key; while ((key = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { @@ -809,7 +812,8 @@ void mp_unpack_sequence(mp_obj_t seq_in, size_t num, mp_obj_t *items) { items[i] = seq_items[num - 1 - i]; } } else { - mp_obj_t iterable = mp_getiter(seq_in); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(seq_in, &iter_buf); for (seq_len = 0; seq_len < num; seq_len++) { mp_obj_t el = mp_iternext(iterable); @@ -873,7 +877,8 @@ void mp_unpack_ex(mp_obj_t seq_in, size_t num_in, mp_obj_t *items) { // items destination array, then the rest to a dynamically created list. Once the // iterable is exhausted, we take from this list for the right part of the items. // TODO Improve to waste less memory in the dynamically created list. - mp_obj_t iterable = mp_getiter(seq_in); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(seq_in, &iter_buf); mp_obj_t item; for (seq_len = 0; seq_len < num_left; seq_len++) { item = mp_iternext(iterable); @@ -1096,13 +1101,18 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) { } } -mp_obj_t mp_getiter(mp_obj_t o_in) { +mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { assert(o_in); + // if caller did not provide a buffer then allocate one on the heap + if (iter_buf == NULL) { + iter_buf = m_new_obj(mp_obj_iter_buf_t); + } + // check for native getiter (corresponds to __iter__) mp_obj_type_t *type = mp_obj_get_type(o_in); if (type->getiter != NULL) { - mp_obj_t iter = type->getiter(o_in); + mp_obj_t iter = type->getiter(o_in, iter_buf); if (iter != MP_OBJ_NULL) { return iter; } @@ -1113,7 +1123,7 @@ mp_obj_t mp_getiter(mp_obj_t o_in) { mp_load_method_maybe(o_in, MP_QSTR___getitem__, dest); if (dest[0] != MP_OBJ_NULL) { // __getitem__ exists, create and return an iterator - return mp_obj_new_getitem_iter(dest); + return mp_obj_new_getitem_iter(dest, iter_buf); } // object not iterable diff --git a/py/runtime.h b/py/runtime.h index e25f2a483..954833b67 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -123,7 +123,7 @@ void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest); void mp_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest); void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t val); -mp_obj_t mp_getiter(mp_obj_t o); +mp_obj_t mp_getiter(mp_obj_t o, mp_obj_iter_buf_t *iter_buf); mp_obj_t mp_iternext_allow_raise(mp_obj_t o); // may return MP_OBJ_STOP_ITERATION instead of raising StopIteration() mp_obj_t mp_iternext(mp_obj_t o); // will always return MP_OBJ_STOP_ITERATION instead of raising StopIteration(...) mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val); diff --git a/py/vm.c b/py/vm.c index 97f344b08..917d41a11 100644 --- a/py/vm.c +++ b/py/vm.c @@ -723,7 +723,7 @@ unwind_jump:; ENTRY(MP_BC_GET_ITER): MARK_EXC_IP_SELECTIVE(); - SET_TOP(mp_getiter(TOP())); + SET_TOP(mp_getiter(TOP(), NULL)); DISPATCH(); ENTRY(MP_BC_FOR_ITER): { diff --git a/stmhal/pybstdio.c b/stmhal/pybstdio.c index dec4f227a..9b1bfff90 100644 --- a/stmhal/pybstdio.c +++ b/stmhal/pybstdio.c @@ -120,7 +120,7 @@ STATIC const mp_obj_type_t stdio_obj_type = { .name = MP_QSTR_FileIO, // TODO .make_new? .print = stdio_obj_print, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &stdio_obj_stream_p, .locals_dict = (mp_obj_t)&stdio_locals_dict, @@ -153,7 +153,7 @@ STATIC const mp_obj_type_t stdio_buffer_obj_type = { { &mp_type_type }, .name = MP_QSTR_FileIO, .print = stdio_obj_print, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &stdio_buffer_obj_stream_p, .locals_dict = (mp_obj_t)&stdio_locals_dict, diff --git a/stmhal/uart.c b/stmhal/uart.c index d53ca5b80..4fae3a80c 100644 --- a/stmhal/uart.c +++ b/stmhal/uart.c @@ -1037,7 +1037,7 @@ const mp_obj_type_t pyb_uart_type = { .name = MP_QSTR_UART, .print = pyb_uart_print, .make_new = pyb_uart_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &uart_stream_p, .locals_dict = (mp_obj_t)&pyb_uart_locals_dict, diff --git a/stmhal/usb.c b/stmhal/usb.c index c413ce4ba..f71c70665 100644 --- a/stmhal/usb.c +++ b/stmhal/usb.c @@ -518,7 +518,7 @@ const mp_obj_type_t pyb_usb_vcp_type = { .name = MP_QSTR_USB_VCP, .print = pyb_usb_vcp_print, .make_new = pyb_usb_vcp_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &pyb_usb_vcp_stream_p, .locals_dict = (mp_obj_t)&pyb_usb_vcp_locals_dict, diff --git a/unix/file.c b/unix/file.c index 96fe78c49..a60840c81 100644 --- a/unix/file.c +++ b/unix/file.c @@ -244,7 +244,7 @@ const mp_obj_type_t mp_type_fileio = { .name = MP_QSTR_FileIO, .print = fdfile_print, .make_new = fdfile_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &fileio_stream_p, .locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict, @@ -263,7 +263,7 @@ const mp_obj_type_t mp_type_textio = { .name = MP_QSTR_TextIOWrapper, .print = fdfile_print, .make_new = fdfile_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &textio_stream_p, .locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict, diff --git a/unix/modffi.c b/unix/modffi.c index cae16c579..74194e2cc 100644 --- a/unix/modffi.c +++ b/unix/modffi.c @@ -194,7 +194,8 @@ STATIC mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in) o->rettype = *rettype; o->argtypes = argtypes; - mp_obj_t iterable = mp_getiter(argtypes_in); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(argtypes_in, &iter_buf); mp_obj_t item; int i = 0; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { @@ -251,7 +252,8 @@ STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t o->rettype = *rettype; - mp_obj_t iterable = mp_getiter(paramtypes_in); + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(paramtypes_in, &iter_buf); mp_obj_t item; int i = 0; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { diff --git a/unix/moduselect.c b/unix/moduselect.c index f966efa41..76938329f 100644 --- a/unix/moduselect.c +++ b/unix/moduselect.c @@ -288,7 +288,7 @@ STATIC MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table); STATIC const mp_obj_type_t mp_type_poll = { { &mp_type_type }, .name = MP_QSTR_poll, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = poll_iternext, .locals_dict = (void*)&poll_locals_dict, }; -- cgit v1.2.3 From 29551ba5666ba92c7577c554e2fb92d80651e505 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 21 Feb 2017 17:20:58 +1100 Subject: cc3200: Move stoupper to ftp.c and define in terms of unichar_toupper. ftp.c is the only user of this function so making it static in that file allows it to be inlined. Also, reusing unichar_toupper means we no longer depend on the C stdlib for toupper, saving about 300 bytes of code space. --- cc3200/ftp/ftp.c | 7 +++++++ cc3200/main.c | 7 ------- cc3200/util/std.h | 3 --- 3 files changed, 7 insertions(+), 10 deletions(-) (limited to 'cc3200') diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c index 679c32561..ebf7861a9 100644 --- a/cc3200/ftp/ftp.c +++ b/cc3200/ftp/ftp.c @@ -932,6 +932,13 @@ static void ftp_close_cmd_data (void) { ftp_close_filesystem_on_error (); } +static void stoupper (char *str) { + while (str && *str != '\0') { + *str = (char)unichar_toupper((int)(*str)); + str++; + } +} + static ftp_cmd_index_t ftp_pop_command (char **str) { char _cmd[FTP_CMD_SIZE_MAX]; ftp_pop_param (str, _cmd); diff --git a/cc3200/main.c b/cc3200/main.c index 06b3604b6..7c6c4b545 100644 --- a/cc3200/main.c +++ b/cc3200/main.c @@ -98,13 +98,6 @@ int main (void) { for ( ; ; ); } -void stoupper (char *str) { - while (str && *str != '\0') { - *str = (char)toupper((int)(*str)); - str++; - } -} - // We need this when configSUPPORT_STATIC_ALLOCATION is enabled void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, diff --git a/cc3200/util/std.h b/cc3200/util/std.h index a74c90e25..6adcb9463 100644 --- a/cc3200/util/std.h +++ b/cc3200/util/std.h @@ -31,6 +31,3 @@ typedef unsigned int size_t; int printf(const char *fmt, ...); int snprintf(char *str, size_t size, const char *fmt, ...); - -// Convenience function, defined in main.c. -void stoupper (char *str); -- cgit v1.2.3 From d9f7120af14508fa45cc911f4622914af567c81b Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 21 Feb 2017 17:24:12 +1100 Subject: cc3200: Use simplelink API instead of emulated BSD API. Most of cc3200 uses explicit simplelink calls anyway, and this means there are no longer any clashes with macros from the C stdlib. --- cc3200/ftp/ftp.c | 14 +++++++------- cc3200/mods/modusocket.c | 26 +++++++++++++------------- cc3200/mods/modwlan.c | 38 +++++++++++++++++++------------------- cc3200/simplelink/user.h | 2 +- cc3200/telnet/telnet.c | 14 +++++++------- 5 files changed, 47 insertions(+), 47 deletions(-) (limited to 'cc3200') diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c index ebf7861a9..9dbc7ca33 100644 --- a/cc3200/ftp/ftp.c +++ b/cc3200/ftp/ftp.c @@ -500,12 +500,12 @@ static void ftp_wait_for_enabled (void) { static bool ftp_create_listening_socket (_i16 *sd, _u16 port, _u8 backlog) { SlSockNonblocking_t nonBlockingOption; - sockaddr_in sServerAddress; + SlSockAddrIn_t sServerAddress; _i16 _sd; _i16 result; // Open a socket for ftp data listen - ASSERT ((*sd = sl_Socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) > 0); + ASSERT ((*sd = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, SL_IPPROTO_IP)) > 0); _sd = *sd; if (_sd > 0) { @@ -514,12 +514,12 @@ static bool ftp_create_listening_socket (_i16 *sd, _u16 port, _u8 backlog) { // Enable non-blocking mode nonBlockingOption.NonblockingEnabled = 1; - ASSERT ((result = sl_SetSockOpt(_sd, SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK); + ASSERT ((result = sl_SetSockOpt(_sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK); // Bind the socket to a port number - sServerAddress.sin_family = AF_INET; - sServerAddress.sin_addr.s_addr = INADDR_ANY; - sServerAddress.sin_port = htons(port); + sServerAddress.sin_family = SL_AF_INET; + sServerAddress.sin_addr.s_addr = SL_INADDR_ANY; + sServerAddress.sin_port = sl_Htons(port); ASSERT ((result |= sl_Bind(_sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress))) == SL_SOC_OK); @@ -535,7 +535,7 @@ static bool ftp_create_listening_socket (_i16 *sd, _u16 port, _u8 backlog) { } static ftp_result_t ftp_wait_for_connection (_i16 l_sd, _i16 *n_sd) { - sockaddr_in sClientAddress; + SlSockAddrIn_t sClientAddress; SlSocklen_t in_addrSize; // accepts a connection from a TCP client, if there is any, otherwise returns SL_EAGAIN diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index 45f1f2d47..d48c474ef 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -95,13 +95,13 @@ void modusocket_socket_delete (int16_t sd) { } void modusocket_enter_sleep (void) { - fd_set socketset; + SlFdSet_t socketset; int16_t maxfd = 0; for (int i = 0; i < MOD_NETWORK_MAX_SOCKETS; i++) { int16_t sd; if ((sd = modusocket_sockets[i].sd) >= 0) { - FD_SET(sd, &socketset); + SL_FD_SET(sd, &socketset); maxfd = (maxfd > sd) ? maxfd : sd; } } @@ -133,9 +133,9 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t // create socket object mod_network_socket_obj_t *s = m_new_obj_with_finaliser(mod_network_socket_obj_t); s->base.type = (mp_obj_t)&socket_type; - s->sock_base.u_param.domain = AF_INET; - s->sock_base.u_param.type = SOCK_STREAM; - s->sock_base.u_param.proto = IPPROTO_TCP; + s->sock_base.u_param.domain = SL_AF_INET; + s->sock_base.u_param.type = SL_SOCK_STREAM; + s->sock_base.u_param.proto = SL_IPPROTO_TCP; s->sock_base.u_param.fileno = -1; s->sock_base.has_timeout = false; s->sock_base.cert_req = false; @@ -501,13 +501,13 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) { // ipv4 only uint8_t out_ip[MOD_NETWORK_IPV4ADDR_BUF_SIZE]; - int32_t result = wlan_gethostbyname(host, hlen, out_ip, AF_INET); + int32_t result = wlan_gethostbyname(host, hlen, out_ip, SL_AF_INET); if (result < 0) { mp_raise_OSError(-result); } mp_obj_tuple_t *tuple = mp_obj_new_tuple(5, NULL); - tuple->items[0] = MP_OBJ_NEW_SMALL_INT(AF_INET); - tuple->items[1] = MP_OBJ_NEW_SMALL_INT(SOCK_STREAM); + tuple->items[0] = MP_OBJ_NEW_SMALL_INT(SL_AF_INET); + tuple->items[1] = MP_OBJ_NEW_SMALL_INT(SL_SOCK_STREAM); tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0); tuple->items[3] = MP_OBJ_NEW_QSTR(MP_QSTR_); tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_LITTLE); @@ -525,14 +525,14 @@ STATIC const mp_map_elem_t mp_module_usocket_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&mp_type_TimeoutError }, // class constants - { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(AF_INET) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(SL_AF_INET) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_STREAM), MP_OBJ_NEW_SMALL_INT(SOCK_STREAM) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_DGRAM), MP_OBJ_NEW_SMALL_INT(SOCK_DGRAM) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_STREAM), MP_OBJ_NEW_SMALL_INT(SL_SOCK_STREAM) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_DGRAM), MP_OBJ_NEW_SMALL_INT(SL_SOCK_DGRAM) }, { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_SEC), MP_OBJ_NEW_SMALL_INT(SL_SEC_SOCKET) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_TCP), MP_OBJ_NEW_SMALL_INT(IPPROTO_TCP) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_UDP), MP_OBJ_NEW_SMALL_INT(IPPROTO_UDP) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_TCP), MP_OBJ_NEW_SMALL_INT(SL_IPPROTO_TCP) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_UDP), MP_OBJ_NEW_SMALL_INT(SL_IPPROTO_UDP) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_usocket_globals, mp_module_usocket_globals_table); diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index d9b018350..3a2b869b1 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -122,8 +122,8 @@ typedef enum{ #define WLAN_MAX_RX_SIZE 16000 #define WLAN_MAX_TX_SIZE 1476 -#define MAKE_SOCKADDR(addr, ip, port) sockaddr addr; \ - addr.sa_family = AF_INET; \ +#define MAKE_SOCKADDR(addr, ip, port) SlSockAddr_t addr; \ + addr.sa_family = SL_AF_INET; \ addr.sa_data[0] = port >> 8; \ addr.sa_data[1] = port; \ addr.sa_data[2] = ip[3]; \ @@ -1364,8 +1364,8 @@ int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errn int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno) { // accept incoming connection int16_t sd; - sockaddr addr; - socklen_t addr_len = sizeof(addr); + SlSockAddr_t addr; + SlSocklen_t addr_len = sizeof(addr); sd = sl_Accept(s->sock_base.sd, &addr, &addr_len); // save the socket descriptor @@ -1413,7 +1413,7 @@ int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) { MAKE_SOCKADDR(addr, ip, port) - int ret = sl_SendTo(s->sock_base.sd, (byte*)buf, len, 0, (sockaddr*)&addr, sizeof(addr)); + int ret = sl_SendTo(s->sock_base.sd, (byte*)buf, len, 0, (SlSockAddr_t*)&addr, sizeof(addr)); if (ret < 0) { *_errno = ret; return -1; @@ -1422,8 +1422,8 @@ int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t } int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { - sockaddr addr; - socklen_t addr_len = sizeof(addr); + SlSockAddr_t addr; + SlSocklen_t addr_len = sizeof(addr); mp_int_t ret = sl_RecvFrom(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0, &addr, &addr_len); if (ret < 0) { *_errno = ret; @@ -1454,14 +1454,14 @@ int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int // set blocking mode option.NonblockingEnabled = 0; } - ret = sl_SetSockOpt(s->sock_base.sd, SOL_SOCKET, SO_NONBLOCKING, &option, sizeof(option)); + ret = sl_SetSockOpt(s->sock_base.sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &option, sizeof(option)); has_timeout = false; } else { // set timeout struct SlTimeval_t timeVal; timeVal.tv_sec = timeout_s; // seconds timeVal.tv_usec = 0; // microseconds. 10000 microseconds resolution - ret = sl_SetSockOpt(s->sock_base.sd, SOL_SOCKET, SO_RCVTIMEO, &timeVal, sizeof(timeVal)); + ret = sl_SetSockOpt(s->sock_base.sd, SL_SOL_SOCKET, SL_SO_RCVTIMEO, &timeVal, sizeof(timeVal)); has_timeout = true; } @@ -1482,20 +1482,20 @@ int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t int32_t sd = s->sock_base.sd; // init fds - fd_set rfds, wfds, xfds; - FD_ZERO(&rfds); - FD_ZERO(&wfds); - FD_ZERO(&xfds); + SlFdSet_t rfds, wfds, xfds; + SL_FD_ZERO(&rfds); + SL_FD_ZERO(&wfds); + SL_FD_ZERO(&xfds); // set fds if needed if (flags & MP_STREAM_POLL_RD) { - FD_SET(sd, &rfds); + SL_FD_SET(sd, &rfds); } if (flags & MP_STREAM_POLL_WR) { - FD_SET(sd, &wfds); + SL_FD_SET(sd, &wfds); } if (flags & MP_STREAM_POLL_HUP) { - FD_SET(sd, &xfds); + SL_FD_SET(sd, &xfds); } // call simplelink's select with minimum timeout @@ -1511,13 +1511,13 @@ int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t } // check return of select - if (FD_ISSET(sd, &rfds)) { + if (SL_FD_ISSET(sd, &rfds)) { ret |= MP_STREAM_POLL_RD; } - if (FD_ISSET(sd, &wfds)) { + if (SL_FD_ISSET(sd, &wfds)) { ret |= MP_STREAM_POLL_WR; } - if (FD_ISSET(sd, &xfds)) { + if (SL_FD_ISSET(sd, &xfds)) { ret |= MP_STREAM_POLL_HUP; } } else { diff --git a/cc3200/simplelink/user.h b/cc3200/simplelink/user.h index af3f14e34..d3f6d4adf 100644 --- a/cc3200/simplelink/user.h +++ b/cc3200/simplelink/user.h @@ -163,7 +163,7 @@ extern "C" { \warning */ -#define SL_INC_STD_BSD_API_NAMING +/* #define SL_INC_STD_BSD_API_NAMING */ /*! diff --git a/cc3200/telnet/telnet.c b/cc3200/telnet/telnet.c index e90bf928f..26e45a75f 100644 --- a/cc3200/telnet/telnet.c +++ b/cc3200/telnet/telnet.c @@ -296,23 +296,23 @@ static void telnet_wait_for_enabled (void) { static bool telnet_create_socket (void) { SlSockNonblocking_t nonBlockingOption; - sockaddr_in sServerAddress; + SlSockAddrIn_t sServerAddress; _i16 result; // Open a socket for telnet - ASSERT ((telnet_data.sd = sl_Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) > 0); + ASSERT ((telnet_data.sd = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, SL_IPPROTO_TCP)) > 0); if (telnet_data.sd > 0) { // add the socket to the network administration modusocket_socket_add(telnet_data.sd, false); // Enable non-blocking mode nonBlockingOption.NonblockingEnabled = 1; - ASSERT ((result = sl_SetSockOpt(telnet_data.sd, SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK); + ASSERT ((result = sl_SetSockOpt(telnet_data.sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK); // Bind the socket to a port number - sServerAddress.sin_family = AF_INET; - sServerAddress.sin_addr.s_addr = INADDR_ANY; - sServerAddress.sin_port = htons(TELNET_PORT); + sServerAddress.sin_family = SL_AF_INET; + sServerAddress.sin_addr.s_addr = SL_INADDR_ANY; + sServerAddress.sin_port = sl_Htons(TELNET_PORT); ASSERT ((result |= sl_Bind(telnet_data.sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress))) == SL_SOC_OK); @@ -330,7 +330,7 @@ static bool telnet_create_socket (void) { static void telnet_wait_for_connection (void) { SlSocklen_t in_addrSize; - sockaddr_in sClientAddress; + SlSockAddrIn_t sClientAddress; // accepts a connection from a TCP client, if there is any, otherwise returns SL_EAGAIN telnet_data.n_sd = sl_Accept(telnet_data.sd, (SlSockAddr_t *)&sClientAddress, (SlSocklen_t *)&in_addrSize); -- cgit v1.2.3 From 1c35270667dbdafa7a8e16a7b8546add07cc7e00 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 21 Feb 2017 17:26:21 +1100 Subject: cc3200: Remove util/std.h, can just use stdio.h instead. --- cc3200/fatfs/src/drivers/sflash_diskio.c | 2 +- cc3200/ftp/ftp.c | 3 +-- cc3200/misc/mpirq.c | 2 +- cc3200/mods/modwlan.c | 2 +- cc3200/util/std.h | 33 -------------------------------- 5 files changed, 4 insertions(+), 38 deletions(-) delete mode 100644 cc3200/util/std.h (limited to 'cc3200') diff --git a/cc3200/fatfs/src/drivers/sflash_diskio.c b/cc3200/fatfs/src/drivers/sflash_diskio.c index 1cfd41fb7..6a1fc4068 100644 --- a/cc3200/fatfs/src/drivers/sflash_diskio.c +++ b/cc3200/fatfs/src/drivers/sflash_diskio.c @@ -1,6 +1,6 @@ #include #include -#include "std.h" +#include #include "py/mpconfig.h" #include "py/obj.h" diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c index 9dbc7ca33..22035d6b3 100644 --- a/cc3200/ftp/ftp.c +++ b/cc3200/ftp/ftp.c @@ -25,8 +25,7 @@ */ #include -#include -#include "std.h" +#include #include "py/mpstate.h" #include "py/obj.h" diff --git a/cc3200/misc/mpirq.c b/cc3200/misc/mpirq.c index be5746759..37149089f 100644 --- a/cc3200/misc/mpirq.c +++ b/cc3200/misc/mpirq.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "std.h" +#include #include "py/mpconfig.h" #include "py/obj.h" diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index 3a2b869b1..0235502cf 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -26,7 +26,7 @@ #include #include -#include "std.h" +#include #include "simplelink.h" #include "py/mpconfig.h" diff --git a/cc3200/util/std.h b/cc3200/util/std.h deleted file mode 100644 index 6adcb9463..000000000 --- a/cc3200/util/std.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * 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. - */ - -// This file is needed because in some cases we can't include stdio.h, -// because the CC3100 socket driver has name clashes with it. - -typedef unsigned int size_t; - -int printf(const char *fmt, ...); -int snprintf(char *str, size_t size, const char *fmt, ...); -- cgit v1.2.3 From 26ddd4b6218dfc2033a24a8ea4128c32527fb6c6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 21 Feb 2017 17:27:17 +1100 Subject: cc3200/mods/modwlan: Remove unused header includes; simplify others. --- cc3200/mods/modwlan.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index 0235502cf..8b910b169 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -35,13 +35,8 @@ #include "py/runtime.h" #include "py/stream.h" #include "py/mphal.h" -#include "inc/hw_types.h" -#include "inc/hw_ints.h" -#include "inc/hw_memmap.h" -#include "rom_map.h" -#include "prcm.h" -#include "timeutils.h" -#include "netutils.h" +#include "lib/timeutils/timeutils.h" +#include "lib/netutils/netutils.h" #include "modnetwork.h" #include "modusocket.h" #include "modwlan.h" -- cgit v1.2.3 From a162832b1ab4dc3035ba4810e65e85ac9a3e1159 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 21 Feb 2017 17:28:14 +1100 Subject: cc3200/mods/modwlan: Make multi-threaded a proper compile-time option. --- cc3200/mods/modwlan.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'cc3200') diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index 8b910b169..2b89cb7da 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -156,7 +156,9 @@ STATIC const mp_irq_methods_t wlan_irq_methods; /****************************************************************************** DECLARE PUBLIC DATA ******************************************************************************/ +#ifdef SL_PLATFORM_MULTI_THREADED OsiLockObj_t wlan_LockObj; +#endif /****************************************************************************** DECLARE PRIVATE FUNCTIONS @@ -391,14 +393,18 @@ void SimpleLinkSockEventHandler(SlSockEvent_t *pSock) { __attribute__ ((section (".boot"))) void wlan_pre_init (void) { // create the wlan lock + #ifdef SL_PLATFORM_MULTI_THREADED ASSERT(OSI_OK == sl_LockObjCreate(&wlan_LockObj, "WlanLock")); + #endif } void wlan_first_start (void) { if (wlan_obj.mode < 0) { CLR_STATUS_BIT_ALL(wlan_obj.status); wlan_obj.mode = sl_Start(0, 0, 0); + #ifdef SL_PLATFORM_MULTI_THREADED sl_LockObjUnlock (&wlan_LockObj); + #endif } // get the mac address @@ -507,7 +513,9 @@ void wlan_update(void) { void wlan_stop (uint32_t timeout) { wlan_servers_stop(); + #ifdef SL_PLATFORM_MULTI_THREADED sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER); + #endif sl_Stop(timeout); wlan_clear_data(); wlan_obj.mode = -1; @@ -563,11 +571,15 @@ STATIC void wlan_clear_data (void) { STATIC void wlan_reenable (SlWlanMode_t mode) { // stop and start again + #ifdef SL_PLATFORM_MULTI_THREADED sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER); + #endif sl_Stop(SL_STOP_TIMEOUT); wlan_clear_data(); wlan_obj.mode = sl_Start(0, 0, 0); + #ifdef SL_PLATFORM_MULTI_THREADED sl_LockObjUnlock (&wlan_LockObj); + #endif ASSERT (wlan_obj.mode == mode); } -- cgit v1.2.3 From 0258f819bd311541e754ad6a0b49b7f76ae90c32 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 21 Feb 2017 17:29:02 +1100 Subject: cc3200/mods/modwlan: Allow antenna diversity to be fully compiled out. --- cc3200/mods/modwlan.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'cc3200') diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index 2b89cb7da..f501a1e37 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -817,8 +817,9 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) { wlan_validate_channel(channel); // get the antenna type - uint8_t antenna = args[4].u_int; + uint8_t antenna = 0; #if MICROPY_HW_ANTENNA_DIVERSITY + antenna = args[4].u_int; wlan_validate_antenna(antenna); #endif @@ -834,7 +835,9 @@ STATIC const mp_arg_t wlan_init_args[] = { { MP_QSTR_ssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_auth, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, + #if MICROPY_HW_ANTENNA_DIVERSITY { MP_QSTR_antenna, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = ANTENNA_TYPE_INTERNAL} }, + #endif }; STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args @@ -1295,8 +1298,10 @@ STATIC const mp_map_elem_t wlan_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_WEP), MP_OBJ_NEW_SMALL_INT(SL_SEC_TYPE_WEP) }, { MP_OBJ_NEW_QSTR(MP_QSTR_WPA), MP_OBJ_NEW_SMALL_INT(SL_SEC_TYPE_WPA_WPA2) }, { MP_OBJ_NEW_QSTR(MP_QSTR_WPA2), MP_OBJ_NEW_SMALL_INT(SL_SEC_TYPE_WPA_WPA2) }, + #if MICROPY_HW_ANTENNA_DIVERSITY { MP_OBJ_NEW_QSTR(MP_QSTR_INT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_INTERNAL) }, { MP_OBJ_NEW_QSTR(MP_QSTR_EXT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_EXTERNAL) }, + #endif { MP_OBJ_NEW_QSTR(MP_QSTR_ANY_EVENT), MP_OBJ_NEW_SMALL_INT(MODWLAN_WIFI_EVENT_ANY) }, }; STATIC MP_DEFINE_CONST_DICT(wlan_locals_dict, wlan_locals_dict_table); -- cgit v1.2.3 From 8c5988bf61c10317eccbd5dd15496a404428202f Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 21 Feb 2017 17:29:40 +1100 Subject: cc3200/mods/modwlan: Add int casts to silence compiler warnings. --- cc3200/mods/modwlan.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index f501a1e37..e3a4d67d1 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -1264,9 +1264,9 @@ STATIC mp_obj_t wlan_print_ver(void) { byte config_opt = SL_DEVICE_GENERAL_VERSION; byte config_len = sizeof(ver); sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &config_opt, &config_len, (byte*)&ver); - printf("NWP: %d.%d.%d.%d\n", ver.NwpVersion[0], ver.NwpVersion[1], ver.NwpVersion[2], ver.NwpVersion[3]); - printf("MAC: %d.%d.%d.%d\n", ver.ChipFwAndPhyVersion.FwVersion[0], ver.ChipFwAndPhyVersion.FwVersion[1], - ver.ChipFwAndPhyVersion.FwVersion[2], ver.ChipFwAndPhyVersion.FwVersion[3]); + printf("NWP: %d.%d.%d.%d\n", (int)ver.NwpVersion[0], (int)ver.NwpVersion[1], (int)ver.NwpVersion[2], (int)ver.NwpVersion[3]); + printf("MAC: %d.%d.%d.%d\n", (int)ver.ChipFwAndPhyVersion.FwVersion[0], (int)ver.ChipFwAndPhyVersion.FwVersion[1], + (int)ver.ChipFwAndPhyVersion.FwVersion[2], (int)ver.ChipFwAndPhyVersion.FwVersion[3]); printf("PHY: %d.%d.%d.%d\n", ver.ChipFwAndPhyVersion.PhyVersion[0], ver.ChipFwAndPhyVersion.PhyVersion[1], ver.ChipFwAndPhyVersion.PhyVersion[2], ver.ChipFwAndPhyVersion.PhyVersion[3]); return mp_const_none; -- cgit v1.2.3 From 71ae3f389dbd4b1db6908f117ab224f9d3c9b38e Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 21 Feb 2017 18:01:43 +1100 Subject: cc3200: Remove remaining references to std.h. --- cc3200/bootmgr/main.c | 3 +-- cc3200/mods/modmachine.c | 1 - cc3200/mods/modnetwork.c | 2 -- cc3200/mods/modussl.c | 1 - cc3200/mods/pybrtc.c | 2 -- 5 files changed, 1 insertion(+), 8 deletions(-) (limited to 'cc3200') diff --git a/cc3200/bootmgr/main.c b/cc3200/bootmgr/main.c index 97c8b36af..0d9ab35f8 100644 --- a/cc3200/bootmgr/main.c +++ b/cc3200/bootmgr/main.c @@ -26,8 +26,7 @@ #include #include - -#include "std.h" +#include #include "py/mpconfig.h" #include "hw_ints.h" diff --git a/cc3200/mods/modmachine.c b/cc3200/mods/modmachine.c index 8a57c2eb4..3c4e5a116 100644 --- a/cc3200/mods/modmachine.c +++ b/cc3200/mods/modmachine.c @@ -26,7 +26,6 @@ */ #include -#include "std.h" #include "py/mpstate.h" #include "py/runtime.h" diff --git a/cc3200/mods/modnetwork.c b/cc3200/mods/modnetwork.c index 89d61e939..c592eced2 100644 --- a/cc3200/mods/modnetwork.c +++ b/cc3200/mods/modnetwork.c @@ -25,8 +25,6 @@ * THE SOFTWARE. */ -#include - #include "py/mpstate.h" #include "py/obj.h" #include "py/nlr.h" diff --git a/cc3200/mods/modussl.c b/cc3200/mods/modussl.c index 7a4787b6b..95ecdbce7 100644 --- a/cc3200/mods/modussl.c +++ b/cc3200/mods/modussl.c @@ -25,7 +25,6 @@ */ #include -#include #include "simplelink.h" #include "py/mpconfig.h" diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c index db00f4939..510a9050d 100644 --- a/cc3200/mods/pybrtc.c +++ b/cc3200/mods/pybrtc.c @@ -25,8 +25,6 @@ * THE SOFTWARE. */ -#include - #include "py/mpconfig.h" #include "py/obj.h" #include "py/runtime.h" -- cgit v1.2.3 From 85ab469c64420d4c11c946efd17ddaea57b19278 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 22 Feb 2017 11:05:27 +1100 Subject: cc3200: Move wlan socket glue functions from modwlan to modusocket. It saves about 400 bytes of code space because the functions can now be inlined. --- cc3200/mods/modusocket.c | 244 ++++++++++++++++++++++++++++++++++++++++++++++- cc3200/mods/modwlan.c | 238 --------------------------------------------- cc3200/mods/modwlan.h | 15 --- 3 files changed, 243 insertions(+), 254 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index d48c474ef..35964fa05 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -36,10 +36,252 @@ #include "py/stream.h" #include "netutils.h" #include "modnetwork.h" -#include "modwlan.h" #include "modusocket.h" #include "mpexception.h" +/******************************************************************************/ +// The following set of macros and functions provide a glue between the CC3100 +// simplelink layer and the functions/methods provided by the usocket module. +// They were historically in a separate file because usocket was designed to +// work with multiple NICs, and the wlan_XXX functions just provided one +// particular NIC implementation (that of the CC3100). But the CC3200 port only +// supports a single NIC (being the CC3100) so it's unnecessary and inefficient +// to provide an intermediate wrapper layer. Hence the wlan_XXX functions +// are provided below as static functions so they can be inlined directly by +// the corresponding usocket calls. + +#define WLAN_MAX_RX_SIZE 16000 +#define WLAN_MAX_TX_SIZE 1476 + +#define MAKE_SOCKADDR(addr, ip, port) SlSockAddr_t addr; \ + addr.sa_family = SL_AF_INET; \ + addr.sa_data[0] = port >> 8; \ + addr.sa_data[1] = port; \ + addr.sa_data[2] = ip[3]; \ + addr.sa_data[3] = ip[2]; \ + addr.sa_data[4] = ip[1]; \ + addr.sa_data[5] = ip[0]; + +#define UNPACK_SOCKADDR(addr, ip, port) port = (addr.sa_data[0] << 8) | addr.sa_data[1]; \ + ip[0] = addr.sa_data[5]; \ + ip[1] = addr.sa_data[4]; \ + ip[2] = addr.sa_data[3]; \ + ip[3] = addr.sa_data[2]; + +STATIC int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family) { + uint32_t ip; + int result = sl_NetAppDnsGetHostByName((_i8 *)name, (_u16)len, (_u32*)&ip, (_u8)family); + out_ip[0] = ip; + out_ip[1] = ip >> 8; + out_ip[2] = ip >> 16; + out_ip[3] = ip >> 24; + return result; +} + +STATIC int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno) { + int16_t sd = sl_Socket(s->sock_base.u_param.domain, s->sock_base.u_param.type, s->sock_base.u_param.proto); + if (sd < 0) { + *_errno = sd; + return -1; + } + s->sock_base.sd = sd; + return 0; +} + +STATIC void wlan_socket_close(mod_network_socket_obj_t *s) { + // this is to prevent the finalizer to close a socket that failed when being created + if (s->sock_base.sd >= 0) { + modusocket_socket_delete(s->sock_base.sd); + sl_Close(s->sock_base.sd); + s->sock_base.sd = -1; + } +} + +STATIC int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) { + MAKE_SOCKADDR(addr, ip, port) + int ret = sl_Bind(s->sock_base.sd, &addr, sizeof(addr)); + if (ret != 0) { + *_errno = ret; + return -1; + } + return 0; +} + +STATIC int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errno) { + int ret = sl_Listen(s->sock_base.sd, backlog); + if (ret != 0) { + *_errno = ret; + return -1; + } + return 0; +} + +STATIC int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno) { + // accept incoming connection + int16_t sd; + SlSockAddr_t addr; + SlSocklen_t addr_len = sizeof(addr); + + sd = sl_Accept(s->sock_base.sd, &addr, &addr_len); + // save the socket descriptor + s2->sock_base.sd = sd; + if (sd < 0) { + *_errno = sd; + return -1; + } + + // return ip and port + UNPACK_SOCKADDR(addr, ip, *port); + return 0; +} + +STATIC int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) { + MAKE_SOCKADDR(addr, ip, port) + int ret = sl_Connect(s->sock_base.sd, &addr, sizeof(addr)); + if (ret != 0) { + *_errno = ret; + return -1; + } + return 0; +} + +STATIC int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno) { + mp_int_t bytes = 0; + if (len > 0) { + bytes = sl_Send(s->sock_base.sd, (const void *)buf, len, 0); + } + if (bytes <= 0) { + *_errno = bytes; + return -1; + } + return bytes; +} + +STATIC int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno) { + int ret = sl_Recv(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0); + if (ret < 0) { + *_errno = ret; + return -1; + } + return ret; +} + +STATIC int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) { + MAKE_SOCKADDR(addr, ip, port) + int ret = sl_SendTo(s->sock_base.sd, (byte*)buf, len, 0, (SlSockAddr_t*)&addr, sizeof(addr)); + if (ret < 0) { + *_errno = ret; + return -1; + } + return ret; +} + +STATIC int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { + SlSockAddr_t addr; + SlSocklen_t addr_len = sizeof(addr); + mp_int_t ret = sl_RecvFrom(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0, &addr, &addr_len); + if (ret < 0) { + *_errno = ret; + return -1; + } + UNPACK_SOCKADDR(addr, ip, *port); + return ret; +} + +STATIC int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) { + int ret = sl_SetSockOpt(s->sock_base.sd, level, opt, optval, optlen); + if (ret < 0) { + *_errno = ret; + return -1; + } + return 0; +} + +STATIC int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno) { + int ret; + bool has_timeout; + if (timeout_s == 0 || timeout_s == -1) { + SlSockNonblocking_t option; + if (timeout_s == 0) { + // set non-blocking mode + option.NonblockingEnabled = 1; + } else { + // set blocking mode + option.NonblockingEnabled = 0; + } + ret = sl_SetSockOpt(s->sock_base.sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &option, sizeof(option)); + has_timeout = false; + } else { + // set timeout + struct SlTimeval_t timeVal; + timeVal.tv_sec = timeout_s; // seconds + timeVal.tv_usec = 0; // microseconds. 10000 microseconds resolution + ret = sl_SetSockOpt(s->sock_base.sd, SL_SOL_SOCKET, SL_SO_RCVTIMEO, &timeVal, sizeof(timeVal)); + has_timeout = true; + } + + if (ret != 0) { + *_errno = ret; + return -1; + } + + s->sock_base.has_timeout = has_timeout; + return 0; +} + +STATIC int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno) { + mp_int_t ret; + if (request == MP_STREAM_POLL) { + mp_uint_t flags = arg; + ret = 0; + int32_t sd = s->sock_base.sd; + + // init fds + SlFdSet_t rfds, wfds, xfds; + SL_FD_ZERO(&rfds); + SL_FD_ZERO(&wfds); + SL_FD_ZERO(&xfds); + + // set fds if needed + if (flags & MP_STREAM_POLL_RD) { + SL_FD_SET(sd, &rfds); + } + if (flags & MP_STREAM_POLL_WR) { + SL_FD_SET(sd, &wfds); + } + if (flags & MP_STREAM_POLL_HUP) { + SL_FD_SET(sd, &xfds); + } + + // call simplelink's select with minimum timeout + SlTimeval_t tv; + tv.tv_sec = 0; + tv.tv_usec = 1; + int32_t nfds = sl_Select(sd + 1, &rfds, &wfds, &xfds, &tv); + + // check for errors + if (nfds == -1) { + *_errno = nfds; + return -1; + } + + // check return of select + if (SL_FD_ISSET(sd, &rfds)) { + ret |= MP_STREAM_POLL_RD; + } + if (SL_FD_ISSET(sd, &wfds)) { + ret |= MP_STREAM_POLL_WR; + } + if (SL_FD_ISSET(sd, &xfds)) { + ret |= MP_STREAM_POLL_HUP; + } + } else { + *_errno = EINVAL; + ret = MP_STREAM_ERROR; + } + return ret; +} + /****************************************************************************** DEFINE PRIVATE CONSTANTS ******************************************************************************/ diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index e3a4d67d1..bec8480d6 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -112,26 +112,6 @@ typedef enum{ #define ASSERT_ON_ERROR(x) ASSERT((x) >= 0) -#define IPV4_ADDR_STR_LEN_MAX (16) - -#define WLAN_MAX_RX_SIZE 16000 -#define WLAN_MAX_TX_SIZE 1476 - -#define MAKE_SOCKADDR(addr, ip, port) SlSockAddr_t addr; \ - addr.sa_family = SL_AF_INET; \ - addr.sa_data[0] = port >> 8; \ - addr.sa_data[1] = port; \ - addr.sa_data[2] = ip[3]; \ - addr.sa_data[3] = ip[2]; \ - addr.sa_data[4] = ip[1]; \ - addr.sa_data[5] = ip[0]; - -#define UNPACK_SOCKADDR(addr, ip, port) port = (addr.sa_data[0] << 8) | addr.sa_data[1]; \ - ip[0] = addr.sa_data[5]; \ - ip[1] = addr.sa_data[4]; \ - ip[2] = addr.sa_data[3]; \ - ip[3] = addr.sa_data[2]; - /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ @@ -1321,221 +1301,3 @@ STATIC const mp_irq_methods_t wlan_irq_methods = { .disable = wlan_lpds_irq_disable, .flags = wlan_irq_flags, }; - -/******************************************************************************/ -// Micro Python bindings; WLAN socket - -int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family) { - uint32_t ip; - int result = sl_NetAppDnsGetHostByName((_i8 *)name, (_u16)len, (_u32*)&ip, (_u8)family); - out_ip[0] = ip; - out_ip[1] = ip >> 8; - out_ip[2] = ip >> 16; - out_ip[3] = ip >> 24; - return result; -} - -int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno) { - int16_t sd = sl_Socket(s->sock_base.u_param.domain, s->sock_base.u_param.type, s->sock_base.u_param.proto); - if (sd < 0) { - *_errno = sd; - return -1; - } - s->sock_base.sd = sd; - return 0; -} - -void wlan_socket_close(mod_network_socket_obj_t *s) { - // this is to prevent the finalizer to close a socket that failed when being created - if (s->sock_base.sd >= 0) { - modusocket_socket_delete(s->sock_base.sd); - sl_Close(s->sock_base.sd); - s->sock_base.sd = -1; - } -} - -int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) { - MAKE_SOCKADDR(addr, ip, port) - int ret = sl_Bind(s->sock_base.sd, &addr, sizeof(addr)); - if (ret != 0) { - *_errno = ret; - return -1; - } - return 0; -} - -int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errno) { - int ret = sl_Listen(s->sock_base.sd, backlog); - if (ret != 0) { - *_errno = ret; - return -1; - } - return 0; -} - -int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno) { - // accept incoming connection - int16_t sd; - SlSockAddr_t addr; - SlSocklen_t addr_len = sizeof(addr); - - sd = sl_Accept(s->sock_base.sd, &addr, &addr_len); - // save the socket descriptor - s2->sock_base.sd = sd; - if (sd < 0) { - *_errno = sd; - return -1; - } - - // return ip and port - UNPACK_SOCKADDR(addr, ip, *port); - return 0; -} - -int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) { - MAKE_SOCKADDR(addr, ip, port) - int ret = sl_Connect(s->sock_base.sd, &addr, sizeof(addr)); - if (ret != 0) { - *_errno = ret; - return -1; - } - return 0; -} - -int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno) { - mp_int_t bytes = 0; - if (len > 0) { - bytes = sl_Send(s->sock_base.sd, (const void *)buf, len, 0); - } - if (bytes <= 0) { - *_errno = bytes; - return -1; - } - return bytes; -} - -int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno) { - int ret = sl_Recv(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0); - if (ret < 0) { - *_errno = ret; - return -1; - } - return ret; -} - -int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) { - MAKE_SOCKADDR(addr, ip, port) - int ret = sl_SendTo(s->sock_base.sd, (byte*)buf, len, 0, (SlSockAddr_t*)&addr, sizeof(addr)); - if (ret < 0) { - *_errno = ret; - return -1; - } - return ret; -} - -int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { - SlSockAddr_t addr; - SlSocklen_t addr_len = sizeof(addr); - mp_int_t ret = sl_RecvFrom(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0, &addr, &addr_len); - if (ret < 0) { - *_errno = ret; - return -1; - } - UNPACK_SOCKADDR(addr, ip, *port); - return ret; -} - -int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) { - int ret = sl_SetSockOpt(s->sock_base.sd, level, opt, optval, optlen); - if (ret < 0) { - *_errno = ret; - return -1; - } - return 0; -} - -int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno) { - int ret; - bool has_timeout; - if (timeout_s == 0 || timeout_s == -1) { - SlSockNonblocking_t option; - if (timeout_s == 0) { - // set non-blocking mode - option.NonblockingEnabled = 1; - } else { - // set blocking mode - option.NonblockingEnabled = 0; - } - ret = sl_SetSockOpt(s->sock_base.sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &option, sizeof(option)); - has_timeout = false; - } else { - // set timeout - struct SlTimeval_t timeVal; - timeVal.tv_sec = timeout_s; // seconds - timeVal.tv_usec = 0; // microseconds. 10000 microseconds resolution - ret = sl_SetSockOpt(s->sock_base.sd, SL_SOL_SOCKET, SL_SO_RCVTIMEO, &timeVal, sizeof(timeVal)); - has_timeout = true; - } - - if (ret != 0) { - *_errno = ret; - return -1; - } - - s->sock_base.has_timeout = has_timeout; - return 0; -} - -int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno) { - mp_int_t ret; - if (request == MP_STREAM_POLL) { - mp_uint_t flags = arg; - ret = 0; - int32_t sd = s->sock_base.sd; - - // init fds - SlFdSet_t rfds, wfds, xfds; - SL_FD_ZERO(&rfds); - SL_FD_ZERO(&wfds); - SL_FD_ZERO(&xfds); - - // set fds if needed - if (flags & MP_STREAM_POLL_RD) { - SL_FD_SET(sd, &rfds); - } - if (flags & MP_STREAM_POLL_WR) { - SL_FD_SET(sd, &wfds); - } - if (flags & MP_STREAM_POLL_HUP) { - SL_FD_SET(sd, &xfds); - } - - // call simplelink's select with minimum timeout - SlTimeval_t tv; - tv.tv_sec = 0; - tv.tv_usec = 1; - int32_t nfds = sl_Select(sd + 1, &rfds, &wfds, &xfds, &tv); - - // check for errors - if (nfds == -1) { - *_errno = nfds; - return -1; - } - - // check return of select - if (SL_FD_ISSET(sd, &rfds)) { - ret |= MP_STREAM_POLL_RD; - } - if (SL_FD_ISSET(sd, &wfds)) { - ret |= MP_STREAM_POLL_WR; - } - if (SL_FD_ISSET(sd, &xfds)) { - ret |= MP_STREAM_POLL_HUP; - } - } else { - *_errno = EINVAL; - ret = MP_STREAM_ERROR; - } - return ret; -} - diff --git a/cc3200/mods/modwlan.h b/cc3200/mods/modwlan.h index 5899f87b2..3bfd1fbbf 100644 --- a/cc3200/mods/modwlan.h +++ b/cc3200/mods/modwlan.h @@ -97,19 +97,4 @@ extern bool wlan_is_connected (void); extern void wlan_set_current_time (uint32_t seconds_since_2000); extern void wlan_off_on (void); -extern int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family); -extern int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno); -extern void wlan_socket_close(mod_network_socket_obj_t *s); -extern int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno); -extern int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errno); -extern int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno); -extern int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno); -extern int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno); -extern int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno); -extern int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno); -extern int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno); -extern int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno); -extern int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno); -extern int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno); - #endif /* MODWLAN_H_ */ -- cgit v1.2.3 From 8bb8e97dfe2626b97028f1dad76cdd4050757961 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 22 Feb 2017 11:53:53 +1100 Subject: cc3200: Convert to using uPy internal errno numbers. --- cc3200/mods/modusocket.c | 6 +++--- cc3200/mods/pybuart.c | 6 +++--- cc3200/mpconfigport.h | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index 35964fa05..56e0946a7 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -276,7 +276,7 @@ STATIC int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp ret |= MP_STREAM_POLL_HUP; } } else { - *_errno = EINVAL; + *_errno = MP_EINVAL; ret = MP_STREAM_ERROR; } return ret; @@ -519,7 +519,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { int _errno; mp_int_t ret = wlan_socket_recv(self, (byte*)vstr.buf, len, &_errno); if (ret < 0) { - if (_errno == EAGAIN && self->sock_base.has_timeout) { + if (_errno == MP_EAGAIN && self->sock_base.has_timeout) { mp_raise_msg(&mp_type_TimeoutError, "timed out"); } mp_raise_OSError(-_errno); @@ -565,7 +565,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { int _errno; mp_int_t ret = wlan_socket_recvfrom(self, (byte*)vstr.buf, vstr.len, ip, &port, &_errno); if (ret < 0) { - if (_errno == EAGAIN && self->sock_base.has_timeout) { + if (_errno == MP_EAGAIN && self->sock_base.has_timeout) { mp_raise_msg(&mp_type_TimeoutError, "timed out"); } mp_raise_OSError(-_errno); diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index dceb842d5..f28af9063 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -596,8 +596,8 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i // wait for first char to become available if (!uart_rx_wait(self)) { - // return EAGAIN error to indicate non-blocking (then read() method returns None) - *errcode = EAGAIN; + // return MP_EAGAIN error to indicate non-blocking (then read() method returns None) + *errcode = MP_EAGAIN; return MP_STREAM_ERROR; } @@ -639,7 +639,7 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t a ret |= MP_STREAM_POLL_WR; } } else { - *errcode = EINVAL; + *errcode = MP_EINVAL; ret = MP_STREAM_ERROR; } return ret; diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 944a6c071..91d14dd1e 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -75,6 +75,7 @@ #define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_MODULE_WEAK_LINKS (1) #define MICROPY_CAN_OVERRIDE_BUILTINS (1) +#define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_VFS (1) #define MICROPY_VFS_FAT (1) #define MICROPY_PY_ASYNC_AWAIT (0) -- cgit v1.2.3 From 22a6344ebe032e9e66024614ecbe7d9608fa9288 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 22 Feb 2017 12:36:23 +1100 Subject: cc3200: When raising OSError's use MP_Exxx as arg instead of a string. --- cc3200/misc/mpexception.c | 3 --- cc3200/misc/mpexception.h | 3 --- cc3200/mods/modnetwork.c | 3 ++- cc3200/mods/moduhashlib.c | 4 ++-- cc3200/mods/modwlan.c | 14 +++++++------- cc3200/mods/pybadc.c | 9 +++++---- cc3200/mods/pybi2c.c | 13 +++++++------ cc3200/mods/pybrtc.c | 9 +++++---- cc3200/mods/pybsd.c | 5 +++-- cc3200/mods/pybspi.c | 5 +++-- cc3200/mods/pybtimer.c | 5 +++-- cc3200/mods/pybuart.c | 6 +++--- cc3200/mods/pybwdt.c | 5 +++-- 13 files changed, 43 insertions(+), 41 deletions(-) (limited to 'cc3200') diff --git a/cc3200/misc/mpexception.c b/cc3200/misc/mpexception.c index c45f0244b..068adb70b 100644 --- a/cc3200/misc/mpexception.c +++ b/cc3200/misc/mpexception.c @@ -40,9 +40,6 @@ STATIC void mpexception_set_user_interrupt (int chr, void *data); /****************************************************************************** DECLARE EXPORTED DATA ******************************************************************************/ -const char mpexception_os_resource_not_avaliable[] = "resource not available"; -const char mpexception_os_operation_failed[] = "the requested operation failed"; -const char mpexception_os_request_not_possible[] = "the requested operation is not possible"; const char mpexception_value_invalid_arguments[] = "invalid argument(s) value"; const char mpexception_num_type_invalid_arguments[] = "invalid argument(s) num/type"; const char mpexception_uncaught[] = "uncaught exception"; diff --git a/cc3200/misc/mpexception.h b/cc3200/misc/mpexception.h index f55aa739e..2f9d1877c 100644 --- a/cc3200/misc/mpexception.h +++ b/cc3200/misc/mpexception.h @@ -28,9 +28,6 @@ #ifndef MPEXCEPTION_H_ #define MPEXCEPTION_H_ -extern const char mpexception_os_resource_not_avaliable[]; -extern const char mpexception_os_operation_failed[]; -extern const char mpexception_os_request_not_possible[]; extern const char mpexception_value_invalid_arguments[]; extern const char mpexception_num_type_invalid_arguments[]; extern const char mpexception_uncaught[]; diff --git a/cc3200/mods/modnetwork.c b/cc3200/mods/modnetwork.c index c592eced2..d44f75aca 100644 --- a/cc3200/mods/modnetwork.c +++ b/cc3200/mods/modnetwork.c @@ -29,6 +29,7 @@ #include "py/obj.h" #include "py/nlr.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "py/mphal.h" #include "modnetwork.h" #include "mpexception.h" @@ -99,7 +100,7 @@ STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, size_t n_args // check the server id if (args[0].u_obj != MP_OBJ_NULL) { if (mp_obj_get_int(args[0].u_obj) != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } } diff --git a/cc3200/mods/moduhashlib.c b/cc3200/mods/moduhashlib.c index c22cc8a06..e1145e4d8 100644 --- a/cc3200/mods/moduhashlib.c +++ b/cc3200/mods/moduhashlib.c @@ -93,7 +93,7 @@ STATIC void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest) { self->digested = false; } } else { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } } @@ -106,7 +106,7 @@ STATIC mp_obj_t hash_read (mp_obj_t self_in) { } } else if (self->c_size < self->b_size) { // it's a fixed len block which is still incomplete - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } if (!self->digested) { diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index bec8480d6..2a0d3bf63 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -836,7 +836,7 @@ STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n if (n_args > 1 || n_kw > 0) { // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // start the peripheral wlan_init_helper(self, &args[1]); @@ -860,7 +860,7 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) { // check for correct wlan mode if (wlan_obj.mode == ROLE_AP) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } Sl_WlanNetworkEntry_t wlanEntry; @@ -914,7 +914,7 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ // check for the correct wlan mode if (wlan_obj.mode == ROLE_AP) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } // parse args @@ -962,7 +962,7 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ modwlan_Status_t status; status = wlan_do_connect (ssid, ssid_len, bssid, auth, key, key_len, timeout); if (status == MODWLAN_ERROR_TIMEOUT) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_ETIMEDOUT); } else if (status == MODWLAN_ERROR_INVALID_PARAMS) { mp_raise_ValueError(mpexception_value_invalid_arguments); } @@ -993,7 +993,7 @@ STATIC mp_obj_t wlan_ifconfig (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma // check the interface id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_EPERM); } // get the configuration @@ -1224,13 +1224,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq); // strcpy(urn, p); // // if (sl_NetAppSet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, len, (unsigned char *)urn) < 0) { -// mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); +// mp_raise_OSError(MP_EIO); // } // } // else { // // get the URN // if (sl_NetAppGet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, &len, (uint8_t *)urn) < 0) { -// mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); +// mp_raise_OSError(MP_EIO); // } // return mp_obj_new_str(urn, (len - 1), false); // } diff --git a/cc3200/mods/pybadc.c b/cc3200/mods/pybadc.c index e63bebbd0..696e7650b 100644 --- a/cc3200/mods/pybadc.c +++ b/cc3200/mods/pybadc.c @@ -33,6 +33,7 @@ #include "py/runtime.h" #include "py/binary.h" #include "py/gc.h" +#include "py/mperrno.h" #include "bufhelper.h" #include "inc/hw_types.h" #include "inc/hw_adc.h" @@ -104,7 +105,7 @@ STATIC void pyb_adc_init (pyb_adc_obj_t *self) { STATIC void pyb_adc_check_init(void) { // not initialized if (!pyb_adc_obj.enabled) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } } @@ -149,7 +150,7 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // check the number of bits @@ -206,7 +207,7 @@ STATIC mp_obj_t adc_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t if (args[0].u_obj != MP_OBJ_NULL) { ch_id = mp_obj_get_int(args[0].u_obj); if (ch_id >= PYB_ADC_NUM_CHANNELS) { - mp_raise_ValueError(mpexception_os_resource_not_avaliable); + mp_raise_ValueError(mpexception_value_invalid_arguments); } else if (args[1].u_obj != mp_const_none) { uint pin_ch_id = pin_find_peripheral_type (args[1].u_obj, PIN_FN_ADC, 0); if (ch_id != pin_ch_id) { @@ -277,7 +278,7 @@ STATIC mp_obj_t adc_channel_value(mp_obj_t self_in) { // the channel must be enabled if (!self->enabled) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } // wait until a new value is available diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c index 32451802d..658b2bfcd 100644 --- a/cc3200/mods/pybi2c.c +++ b/cc3200/mods/pybi2c.c @@ -30,6 +30,7 @@ #include "py/mpstate.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "py/mphal.h" #include "bufhelper.h" #include "inc/hw_types.h" @@ -144,7 +145,7 @@ STATIC bool pyb_i2c_transaction(uint cmd) { STATIC void pyb_i2c_check_init(pyb_i2c_obj_t *self) { // not initialized if (!self->baudrate) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } } @@ -256,7 +257,7 @@ STATIC void pyb_i2c_read_into (mp_arg_val_t *args, vstr_t *vstr) { // receive the data if (!pyb_i2c_read(args[0].u_int, (byte *)vstr->buf, vstr->len)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } } @@ -275,7 +276,7 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) { if (pyb_i2c_mem_addr_write (i2c_addr, (byte *)&mem_addr, mem_addr_size)) { // Read the specified length of data if (!pyb_i2c_read (i2c_addr, (byte *)vstr->buf, vstr->len)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } } } @@ -341,7 +342,7 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_ // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // setup the object @@ -445,7 +446,7 @@ STATIC mp_obj_t pyb_i2c_writeto(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m // send the data if (!pyb_i2c_write(args[0].u_int, bufinfo.buf, bufinfo.len, args[2].u_bool)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } // return the number of bytes written @@ -514,7 +515,7 @@ STATIC mp_obj_t pyb_i2c_writeto_mem(mp_uint_t n_args, const mp_obj_t *pos_args, return mp_obj_new_int(bufinfo.len); } - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_mem_obj, 1, pyb_i2c_writeto_mem); diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c index 510a9050d..ddc26faf9 100644 --- a/cc3200/mods/pybrtc.c +++ b/cc3200/mods/pybrtc.c @@ -28,6 +28,7 @@ #include "py/mpconfig.h" #include "py/obj.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" @@ -292,7 +293,7 @@ STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_ // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // setup the object @@ -360,7 +361,7 @@ STATIC mp_obj_t pyb_rtc_alarm (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma // check the alarm id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } uint32_t f_seconds; @@ -395,7 +396,7 @@ STATIC mp_obj_t pyb_rtc_alarm_left (mp_uint_t n_args, const mp_obj_t *args) { // only alarm id 0 is available if (n_args > 1 && mp_obj_get_int(args[1]) != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // get the current time @@ -413,7 +414,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc STATIC mp_obj_t pyb_rtc_alarm_cancel (mp_uint_t n_args, const mp_obj_t *args) { // only alarm id 0 is available if (n_args > 1 && mp_obj_get_int(args[1]) != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // disable the alarm pyb_rtc_disable_alarm(); diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c index 937b8599d..306baea8b 100644 --- a/cc3200/mods/pybsd.c +++ b/cc3200/mods/pybsd.c @@ -27,6 +27,7 @@ #include "py/mpconfig.h" #include "py/obj.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" #include "extmod/vfs_fat.h" @@ -108,7 +109,7 @@ STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args) pyb_sd_hw_init (self); if (sd_disk_init() != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } // register it with the sleep module @@ -133,7 +134,7 @@ STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // setup and initialize the object diff --git a/cc3200/mods/pybspi.c b/cc3200/mods/pybspi.c index 6fc7ee62d..3cd384266 100644 --- a/cc3200/mods/pybspi.c +++ b/cc3200/mods/pybspi.c @@ -30,6 +30,7 @@ #include "py/mpstate.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "bufhelper.h" #include "inc/hw_types.h" #include "inc/hw_mcspi.h" @@ -131,7 +132,7 @@ STATIC void pybspi_rx (pyb_spi_obj_t *self, void *data) { STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxdata, uint32_t len, uint32_t *txchar) { if (!self->baudrate) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } // send and receive the data MAP_SPICSEnable(GSPI_BASE); @@ -234,7 +235,7 @@ STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_ // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // setup the object diff --git a/cc3200/mods/pybtimer.c b/cc3200/mods/pybtimer.c index 0eeb6eefd..d25ac6c2b 100644 --- a/cc3200/mods/pybtimer.c +++ b/cc3200/mods/pybtimer.c @@ -34,6 +34,7 @@ #include "py/nlr.h" #include "py/runtime.h" #include "py/gc.h" +#include "py/mperrno.h" #include "py/mphal.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" @@ -329,7 +330,7 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz // create a new Timer object int32_t timer_idx = mp_obj_get_int(args[0]); if (timer_idx < 0 || timer_idx > (PYBTIMER_NUM_TIMERS - 1)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } pyb_timer_obj_t *tim = &pyb_timer_obj[timer_idx]; @@ -370,7 +371,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp // verify that the timer has been already initialized if (!tim->config) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } if (channel_n != TIMER_A && channel_n != TIMER_B && channel_n != (TIMER_A | TIMER_B)) { // invalid channel diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index f28af9063..bab2b3d22 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -279,7 +279,7 @@ STATIC void UARTGenericIntHandler(uint32_t uart_id) { STATIC void uart_check_init(pyb_uart_obj_t *self) { // not initialized if (!self->baudrate) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } } @@ -471,7 +471,7 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size } if (uart_id > PYB_UART_1) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // get the correct uart instance @@ -619,7 +619,7 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t // write the data if (!uart_tx_strn(self, buf, size)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } return size; } diff --git a/cc3200/mods/pybwdt.c b/cc3200/mods/pybwdt.c index b4c847268..76c701ca0 100644 --- a/cc3200/mods/pybwdt.c +++ b/cc3200/mods/pybwdt.c @@ -29,6 +29,7 @@ #include "py/mpconfig.h" #include "py/obj.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "py/mphal.h" #include "inc/hw_types.h" #include "inc/hw_gpio.h" @@ -100,14 +101,14 @@ STATIC mp_obj_t pyb_wdt_make_new(const mp_obj_type_t *type, size_t n_args, size_ mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(args), pyb_wdt_init_args, args); if (args[0].u_obj != mp_const_none && mp_obj_get_int(args[0].u_obj) > 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } uint timeout_ms = args[1].u_int; if (timeout_ms < PYBWDT_MIN_TIMEOUT_MS) { mp_raise_ValueError(mpexception_value_invalid_arguments); } if (pyb_wdt_obj.running) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } // Enable the WDT peripheral clock -- cgit v1.2.3 From e859ddf3e131cc04275779667e125092a5f3be99 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 22 Feb 2017 12:49:42 +1100 Subject: cc3200: Enable uerrno module with short, custom list of error codes. Since we recently replaced the OSError string messages with simple error codes, having the uerrno module gets back some user friendly error messages. The total code size (after removing strings, replacing with uerrno module) is decreased. --- cc3200/mpconfigport.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'cc3200') diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 91d14dd1e..ad1e8ef2b 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -107,6 +107,8 @@ #define MICROPY_PY_CMATH (0) #define MICROPY_PY_IO (1) #define MICROPY_PY_IO_FILEIO (1) +#define MICROPY_PY_UERRNO (1) +#define MICROPY_PY_UERRNO_ERRORCODE (0) #define MICROPY_PY_THREAD (1) #define MICROPY_PY_THREAD_GIL (1) #define MICROPY_PY_UBINASCII (0) @@ -122,6 +124,14 @@ #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) +// We define our own list of errno constants to include in uerrno module +#define MICROPY_PY_UERRNO_LIST \ + X(EPERM) \ + X(EIO) \ + X(ENODEV) \ + X(EINVAL) \ + X(ETIMEDOUT) \ + // TODO these should be generic, not bound to fatfs #define mp_type_fileio fatfs_type_fileio #define mp_type_textio fatfs_type_textio @@ -161,6 +171,7 @@ extern const struct _mp_obj_module_t mp_module_ussl; { MP_OBJ_NEW_QSTR(MP_QSTR_ussl), (mp_obj_t)&mp_module_ussl }, \ #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \ + { MP_OBJ_NEW_QSTR(MP_QSTR_errno), (mp_obj_t)&mp_module_uerrno }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_ustruct }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_re), (mp_obj_t)&mp_module_ure }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_json), (mp_obj_t)&mp_module_ujson }, \ -- cgit v1.2.3 From d03f089baa674e046da10891be338d14346f8a3a Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 22 Feb 2017 14:58:37 +1100 Subject: cc3200/mods/modusocket: Init vars to 0 to silence compiler warnings. Some compilers can't analyse the code to determine that these variables are always set before being used. --- cc3200/mods/modusocket.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index 56e0946a7..82a85e8a2 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -422,7 +422,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_LITTLE); // call the NIC to bind the socket - int _errno; + int _errno = 0; if (wlan_socket_bind(self, ip, port, &_errno) != 0) { mp_raise_OSError(-_errno); } @@ -459,8 +459,8 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) { // accept the incoming connection uint8_t ip[MOD_NETWORK_IPV4ADDR_BUF_SIZE]; - mp_uint_t port; - int _errno; + mp_uint_t port = 0; + int _errno = 0; if (wlan_socket_accept(self, socket2, ip, &port, &_errno) != 0) { mp_raise_OSError(-_errno); } @@ -546,7 +546,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_ mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_LITTLE); // call the nic to sendto - int _errno; + int _errno = 0; mp_int_t ret = wlan_socket_sendto(self, bufinfo.buf, bufinfo.len, ip, port, &_errno); if (ret < 0) { mp_raise_OSError(-_errno); @@ -561,8 +561,8 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { vstr_t vstr; vstr_init_len(&vstr, mp_obj_get_int(len_in)); byte ip[4]; - mp_uint_t port; - int _errno; + mp_uint_t port = 0; + int _errno = 0; mp_int_t ret = wlan_socket_recvfrom(self, (byte*)vstr.buf, vstr.len, ip, &port, &_errno); if (ret < 0) { if (_errno == MP_EAGAIN && self->sock_base.has_timeout) { -- cgit v1.2.3 From 047af9b10bfc6b0ec412f8450c6bec10ab95254b Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 22 Feb 2017 15:08:32 +1100 Subject: cc3200: Remove socket.timeout class, use OSError(ETIMEDOUT) instead. socket.timeout is a subclass of OSError, and using the latter is more efficient than having a dedicated class. The argument of OSError is ETIMEDOUT so the error can be distinguished from other kinds of OSErrors. This follows how the esp8266 port does it. --- cc3200/mods/modusocket.c | 7 ++----- cc3200/mpconfigport.h | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index 82a85e8a2..02ce3e279 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -520,7 +520,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { mp_int_t ret = wlan_socket_recv(self, (byte*)vstr.buf, len, &_errno); if (ret < 0) { if (_errno == MP_EAGAIN && self->sock_base.has_timeout) { - mp_raise_msg(&mp_type_TimeoutError, "timed out"); + mp_raise_OSError(MP_ETIMEDOUT); } mp_raise_OSError(-_errno); } @@ -566,7 +566,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { mp_int_t ret = wlan_socket_recvfrom(self, (byte*)vstr.buf, vstr.len, ip, &port, &_errno); if (ret < 0) { if (_errno == MP_EAGAIN && self->sock_base.has_timeout) { - mp_raise_msg(&mp_type_TimeoutError, "timed out"); + mp_raise_OSError(MP_ETIMEDOUT); } mp_raise_OSError(-_errno); } @@ -763,9 +763,6 @@ STATIC const mp_map_elem_t mp_module_usocket_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&socket_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&mod_usocket_getaddrinfo_obj }, - // class exceptions - { MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&mp_type_TimeoutError }, - // class constants { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(SL_AF_INET) }, diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index ad1e8ef2b..a8dc0cfeb 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -79,7 +79,6 @@ #define MICROPY_VFS (1) #define MICROPY_VFS_FAT (1) #define MICROPY_PY_ASYNC_AWAIT (0) -#define MICROPY_PY_BUILTINS_TIMEOUTERROR (1) #define MICROPY_PY_ALL_SPECIAL_METHODS (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_TEXT cc3200_help_text -- cgit v1.2.3 From f5ee4d95a9ec199325bf7c3f37288ad11ca650cc Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 23 Feb 2017 22:10:58 -0800 Subject: cc3200/moduos: Remove uos.sep, as it's strictly optional. In MicroPython, the path separator is guaranteed to be "/", extra unneeded things take precious code space (in the port which doesn't have basic things like floating-port support). --- cc3200/mods/moduos.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/moduos.c b/cc3200/mods/moduos.c index 0adc75503..5523c887f 100644 --- a/cc3200/mods/moduos.c +++ b/cc3200/mods/moduos.c @@ -173,9 +173,6 @@ STATIC const mp_map_elem_t os_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_umount), (mp_obj_t)&mp_vfs_umount_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_VfsFat), (mp_obj_t)&mp_fat_vfs_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_dupterm), (mp_obj_t)&os_dupterm_obj }, - - /// \constant sep - separation character used in paths - { MP_OBJ_NEW_QSTR(MP_QSTR_sep), MP_OBJ_NEW_QSTR(MP_QSTR__slash_) }, }; STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); -- cgit v1.2.3 From 70201f40386c42fec8bd20af06fe31a69f3af7db Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2017 19:09:19 +1100 Subject: cc3200/mptask: Allocate flash VFS struct on the heap to trace root ptrs. --- cc3200/mptask.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mptask.c b/cc3200/mptask.c index c7c1832ed..41264fbd0 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -98,7 +98,6 @@ OsiTaskHandle svTaskHandle; DECLARE PRIVATE DATA ******************************************************************************/ static fs_user_mount_t *sflash_vfs_fat; -static mp_vfs_mount_t sflash_vfs_mount; static const char fresh_main_py[] = "# main.py -- put your code here!\r\n"; static const char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n" @@ -328,11 +327,16 @@ STATIC void mptask_init_sflash_filesystem (void) { mptask_create_main_py(); } } else { + fail: __fatal_error("failed to create /flash"); } // mount the flash device (there should be no other devices mounted at this point) - mp_vfs_mount_t *vfs = &sflash_vfs_mount; + // we allocate this structure on the heap because vfs->next is a root pointer + mp_vfs_mount_t *vfs = m_new_obj_maybe(mp_vfs_mount_t); + if (vfs == NULL) { + goto fail; + } vfs->str = "/flash"; vfs->len = 6; vfs->obj = MP_OBJ_FROM_PTR(vfs_fat); -- cgit v1.2.3 From 12d0731b91d8e58ba20ec28adf2d6c1aa995d74a Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2017 19:09:42 +1100 Subject: extmod/vfs_fat: Remove obsolete and unused str/len members. --- cc3200/mptask.c | 2 -- extmod/vfs_fat.c | 2 -- extmod/vfs_fat.h | 2 -- stmhal/main.c | 4 ---- 4 files changed, 10 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mptask.c b/cc3200/mptask.c index 41264fbd0..3c49a5603 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -302,8 +302,6 @@ STATIC void mptask_init_sflash_filesystem (void) { // Initialise the local flash filesystem. // init the vfs object fs_user_mount_t *vfs_fat = sflash_vfs_fat; - vfs_fat->str = NULL; - vfs_fat->len = 0; vfs_fat->flags = 0; pyb_flash_init_vfs(vfs_fat); diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 82dd312b8..8cd5a4674 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -55,8 +55,6 @@ STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_ fs_user_mount_t *vfs = m_new_obj(fs_user_mount_t); vfs->base.type = type; vfs->flags = FSUSER_FREE_OBJ; - vfs->str = NULL; - vfs->len = 0; vfs->fatfs.drv = vfs; // load block protocol methods diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index a5e3c604b..7eb865254 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -36,8 +36,6 @@ typedef struct _fs_user_mount_t { mp_obj_base_t base; - const char *str; - uint16_t len; // length of str uint16_t flags; mp_obj_t readblocks[4]; mp_obj_t writeblocks[4]; diff --git a/stmhal/main.c b/stmhal/main.c index 3c9906ad2..8d076a08b 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -167,8 +167,6 @@ static const char fresh_readme_txt[] = MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) { // init the vfs object fs_user_mount_t *vfs_fat = &fs_user_mount_flash; - vfs_fat->str = NULL; - vfs_fat->len = 0; vfs_fat->flags = 0; pyb_flash_init_vfs(vfs_fat); @@ -274,8 +272,6 @@ STATIC bool init_sdcard_fs(bool first_soft_reset) { if (vfs == NULL || vfs_fat == NULL) { break; } - vfs_fat->str = NULL; - vfs_fat->len = 0; vfs_fat->flags = FSUSER_FREE_OBJ; sdcard_init_vfs(vfs_fat, part_num); -- cgit v1.2.3 From 1110c8873c984f3abf9ee6ceff12ca87a45dd238 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 22 Mar 2017 12:57:51 +1100 Subject: cc3200/mods/modutime: Use generic sleep_ms and sleep_us implementations. --- cc3200/mods/modutime.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/modutime.c b/cc3200/mods/modutime.c index de1f75012..0aa853dd6 100644 --- a/cc3200/mods/modutime.c +++ b/cc3200/mods/modutime.c @@ -131,24 +131,6 @@ STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { } MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep); -STATIC mp_obj_t time_sleep_ms (mp_obj_t ms_in) { - mp_int_t ms = mp_obj_get_int(ms_in); - if (ms > 0) { - mp_hal_delay_ms(ms); - } - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_ms_obj, time_sleep_ms); - -STATIC mp_obj_t time_sleep_us (mp_obj_t usec_in) { - mp_int_t usec = mp_obj_get_int(usec_in); - if (usec > 0) { - mp_hal_delay_us(usec); - } - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_us_obj, time_sleep_us); - STATIC const mp_map_elem_t time_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_utime) }, @@ -158,8 +140,8 @@ STATIC const mp_map_elem_t time_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&time_sleep_obj }, // MicroPython additions - { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_ms), (mp_obj_t)&time_sleep_ms_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_us), (mp_obj_t)&time_sleep_us_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_ms), (mp_obj_t)&mp_utime_sleep_ms_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_us), (mp_obj_t)&mp_utime_sleep_us_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&mp_utime_ticks_ms_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&mp_utime_ticks_us_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&mp_utime_ticks_cpu_obj }, -- cgit v1.2.3 From 75589272ef12d538ab7ce4f4453be85d826b5083 Mon Sep 17 00:00:00 2001 From: Krzysztof Blazewicz Date: Sun, 5 Mar 2017 13:28:27 +0100 Subject: all/Makefile: Remove -ansi from GCC flags, its ignored anyway. The -ansi flag is used for C dialect selection and it is equivalent to -std=c90. Because it goes right before -std=gnu99 it is ignored as for conflicting flags GCC always uses the last one. --- bare-arm/Makefile | 2 +- cc3200/Makefile | 2 +- esp8266/Makefile | 2 +- examples/embedding/Makefile.upylib | 2 +- minimal/Makefile | 4 ++-- mpy-cross/Makefile | 2 +- pic16bit/Makefile | 2 +- qemu-arm/Makefile | 2 +- stmhal/Makefile | 2 +- teensy/Makefile | 2 +- unix/Makefile | 2 +- windows/Makefile | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) (limited to 'cc3200') diff --git a/bare-arm/Makefile b/bare-arm/Makefile index a57ccfd19..6ee855262 100644 --- a/bare-arm/Makefile +++ b/bare-arm/Makefile @@ -13,7 +13,7 @@ INC += -I.. INC += -I$(BUILD) CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion -CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT) +CFLAGS = $(INC) -Wall -Werror -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT) #Debugging/Optimization ifeq ($(DEBUG), 1) diff --git a/cc3200/Makefile b/cc3200/Makefile index 4db3b9e8d..663496435 100644 --- a/cc3200/Makefile +++ b/cc3200/Makefile @@ -20,7 +20,7 @@ include ../py/mkenv.mk CROSS_COMPILE ?= arm-none-eabi- CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -march=armv7e-m -mabi=aapcs -mcpu=cortex-m4 -msoft-float -mfloat-abi=soft -fsingle-precision-constant -Wdouble-promotion -CFLAGS = -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) -Os +CFLAGS = -Wall -Wpointer-arith -Werror -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) -Os CFLAGS += -g -ffunction-sections -fdata-sections -fno-common -fsigned-char -mno-unaligned-access CFLAGS += -Iboards/$(BOARD) CFLAGS += $(CFLAGS_MOD) diff --git a/esp8266/Makefile b/esp8266/Makefile index 5e61fc16d..4710f4cdc 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -41,7 +41,7 @@ CFLAGS_XTENSA = -fsingle-precision-constant -Wdouble-promotion \ -Wl,-EL -mlongcalls -mtext-section-literals -mforce-l32 \ -DLWIP_OPEN_SRC -CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib -DUART_OS=$(UART_OS) \ +CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -std=gnu99 -nostdlib -DUART_OS=$(UART_OS) \ $(CFLAGS_XTENSA) $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) LDSCRIPT = esp8266.ld diff --git a/examples/embedding/Makefile.upylib b/examples/embedding/Makefile.upylib index d8dbade3f..8b506e95e 100644 --- a/examples/embedding/Makefile.upylib +++ b/examples/embedding/Makefile.upylib @@ -20,7 +20,7 @@ INC += -I$(BUILD) # compiler settings CWARN = -Wall -Werror CWARN += -Wpointer-arith -Wuninitialized -CFLAGS = $(INC) $(CWARN) -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) +CFLAGS = $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) # Debugging/Optimization ifdef DEBUG diff --git a/minimal/Makefile b/minimal/Makefile index 411751735..42c2d5312 100644 --- a/minimal/Makefile +++ b/minimal/Makefile @@ -22,9 +22,9 @@ ifeq ($(CROSS), 1) DFU = ../tools/dfu.py PYDFU = ../tools/pydfu.py CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion -CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT) +CFLAGS = $(INC) -Wall -Werror -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT) else -CFLAGS = -m32 $(INC) -Wall -Werror -ansi -std=gnu99 $(COPT) +CFLAGS = -m32 $(INC) -Wall -Werror -std=gnu99 $(COPT) endif #Debugging/Optimization diff --git a/mpy-cross/Makefile b/mpy-cross/Makefile index 3f9956620..3d5e5da2f 100644 --- a/mpy-cross/Makefile +++ b/mpy-cross/Makefile @@ -19,7 +19,7 @@ INC += -I$(BUILD) # compiler settings CWARN = -Wall -Werror CWARN += -Wpointer-arith -Wuninitialized -CFLAGS = $(INC) $(CWARN) -ansi -std=gnu99 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) +CFLAGS = $(INC) $(CWARN) -std=gnu99 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables # Debugging/Optimization diff --git a/pic16bit/Makefile b/pic16bit/Makefile index cfe8af86e..add9a8495 100644 --- a/pic16bit/Makefile +++ b/pic16bit/Makefile @@ -21,7 +21,7 @@ INC += -I$(XC16)/include INC += -I$(XC16)/support/$(PARTFAMILY)/h CFLAGS_PIC16BIT = -mcpu=$(PART) -mlarge-code -CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_PIC16BIT) $(COPT) +CFLAGS = $(INC) -Wall -Werror -std=gnu99 -nostdlib $(CFLAGS_PIC16BIT) $(COPT) #Debugging/Optimization ifeq ($(DEBUG), 1) diff --git a/qemu-arm/Makefile b/qemu-arm/Makefile index 61fc24364..e8f5b359e 100644 --- a/qemu-arm/Makefile +++ b/qemu-arm/Makefile @@ -15,7 +15,7 @@ INC += -I$(BUILD) INC += -I../tools/tinytest/ CFLAGS_CORTEX_M3 = -mthumb -mcpu=cortex-m3 -mfloat-abi=soft -CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M3) $(COPT) \ +CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -std=gnu99 $(CFLAGS_CORTEX_M3) $(COPT) \ -ffunction-sections -fdata-sections #Debugging/Optimization diff --git a/stmhal/Makefile b/stmhal/Makefile index 76579d130..3eef6ffb2 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -56,7 +56,7 @@ CFLAGS_MCU_f4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -DMCU_SERIES CFLAGS_MCU_f7 = $(CFLAGS_CORTEX_M) -mtune=cortex-m7 -mcpu=cortex-m7 -DMCU_SERIES_F7 CFLAGS_MCU_l4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -DMCU_SERIES_L4 -CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_MOD) +CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -std=gnu99 -nostdlib $(CFLAGS_MOD) CFLAGS += -D$(CMSIS_MCU) CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES)) CFLAGS += $(COPT) diff --git a/teensy/Makefile b/teensy/Makefile index 82e04a1ae..e613b8f27 100644 --- a/teensy/Makefile +++ b/teensy/Makefile @@ -36,7 +36,7 @@ INC += -I../lib/mp-readline INC += -I$(BUILD) INC += -Icore -CFLAGS = $(INC) -Wall -Wpointer-arith -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) +CFLAGS = $(INC) -Wall -Wpointer-arith -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) LDFLAGS = -nostdlib -T mk20dx256.ld -msoft-float -mfloat-abi=soft ifeq ($(USE_ARDUINO_TOOLCHAIN),1) diff --git a/unix/Makefile b/unix/Makefile index 83bd3f984..f28a4bcae 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -23,7 +23,7 @@ INC += -I$(BUILD) # compiler settings CWARN = -Wall -Werror CWARN += -Wpointer-arith -Wuninitialized -CFLAGS = $(INC) $(CWARN) -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) +CFLAGS = $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) # Debugging/Optimization ifdef DEBUG diff --git a/windows/Makefile b/windows/Makefile index 68de66a07..72c97381b 100644 --- a/windows/Makefile +++ b/windows/Makefile @@ -15,7 +15,7 @@ INC += -I.. INC += -I$(BUILD) # compiler settings -CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -DUNIX -D__USE_MINGW_ANSI_STDIO=1 $(CFLAGS_MOD) $(COPT) +CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -std=gnu99 -DUNIX -D__USE_MINGW_ANSI_STDIO=1 $(CFLAGS_MOD) $(COPT) LDFLAGS = $(LDFLAGS_MOD) -lm # Debugging/Optimization -- cgit v1.2.3 From 87f068d7d9c53e7fb7e46cf30af7c37ff30d2bd0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 26 Mar 2017 17:17:49 +1100 Subject: cc3200: Update to use size_t for tuple/list accessors. --- cc3200/mods/modutime.c | 2 +- cc3200/mods/pybrtc.c | 2 +- cc3200/mods/pybuart.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/modutime.c b/cc3200/mods/modutime.c index 0aa853dd6..8e3c71402 100644 --- a/cc3200/mods/modutime.c +++ b/cc3200/mods/modutime.c @@ -102,7 +102,7 @@ STATIC mp_obj_t time_localtime(mp_uint_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); STATIC mp_obj_t time_mktime(mp_obj_t tuple) { - mp_uint_t len; + size_t len; mp_obj_t *elem; mp_obj_get_array(tuple, &len, &elem); diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c index ddc26faf9..13d7a49cb 100644 --- a/cc3200/mods/pybrtc.c +++ b/cc3200/mods/pybrtc.c @@ -196,7 +196,7 @@ STATIC uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds) { // set date and time mp_obj_t *items; - uint len; + size_t len; mp_obj_get_array(datetime, &len, &items); // verify the tuple diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index bab2b3d22..7fb51d83d 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -388,7 +388,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *a uint flowcontrol = UART_FLOWCONTROL_NONE; if (pins_o != mp_const_none) { mp_obj_t *pins; - mp_uint_t n_pins = 2; + size_t n_pins = 2; if (pins_o == MP_OBJ_NULL) { // use the default pins pins = (mp_obj_t *)pyb_uart_def_pin[self->uart_id]; @@ -454,7 +454,7 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size if (args[0].u_obj == MP_OBJ_NULL) { if (args[5].u_obj != MP_OBJ_NULL) { mp_obj_t *pins; - mp_uint_t n_pins = 2; + size_t n_pins = 2; mp_obj_get_array(args[5].u_obj, &n_pins, &pins); // check the Tx pin (or the Rx if Tx is None) if (pins[0] == mp_const_none) { -- cgit v1.2.3 From 3a77342719bf056cdc51dc898745909b513f0c77 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 26 Mar 2017 17:35:48 +1100 Subject: cc3200: Update for changes to mp_obj_str_get_data. --- cc3200/mods/modusocket.c | 2 +- cc3200/mods/modwlan.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index 02ce3e279..4e2da6737 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -737,7 +737,7 @@ STATIC const mp_obj_type_t socket_type = { // function usocket.getaddrinfo(host, port) /// \function getaddrinfo(host, port) STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) { - mp_uint_t hlen; + size_t hlen; const char *host = mp_obj_str_get_data(host_in, &hlen); mp_int_t port = mp_obj_get_int(port_in); diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index 2a0d3bf63..68d892364 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -773,7 +773,7 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) { wlan_validate_mode(mode); // get the ssid - mp_uint_t ssid_len = 0; + size_t ssid_len = 0; const char *ssid = NULL; if (args[1].u_obj != NULL) { ssid = mp_obj_str_get_data(args[1].u_obj, &ssid_len); @@ -782,7 +782,7 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) { // get the auth config uint8_t auth = SL_SEC_TYPE_OPEN; - mp_uint_t key_len = 0; + size_t key_len = 0; const char *key = NULL; if (args[2].u_obj != mp_const_none) { mp_obj_t *sec; @@ -922,13 +922,13 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); // get the ssid - mp_uint_t ssid_len; + size_t ssid_len; const char *ssid = mp_obj_str_get_data(args[0].u_obj, &ssid_len); wlan_validate_ssid_len(ssid_len); // get the auth config uint8_t auth = SL_SEC_TYPE_OPEN; - mp_uint_t key_len = 0; + size_t key_len = 0; const char *key = NULL; if (args[1].u_obj != mp_const_none) { mp_obj_t *sec; @@ -1077,7 +1077,7 @@ STATIC mp_obj_t wlan_ssid (mp_uint_t n_args, const mp_obj_t *args) { if (n_args == 1) { return mp_obj_new_str((const char *)self->ssid, strlen((const char *)self->ssid), false); } else { - mp_uint_t len; + size_t len; const char *ssid = mp_obj_str_get_data(args[1], &len); wlan_validate_ssid_len(len); wlan_set_ssid(ssid, len, false); @@ -1101,7 +1101,7 @@ STATIC mp_obj_t wlan_auth (mp_uint_t n_args, const mp_obj_t *args) { } else { // get the auth config uint8_t auth = SL_SEC_TYPE_OPEN; - mp_uint_t key_len = 0; + size_t key_len = 0; const char *key = NULL; if (args[1] != mp_const_none) { mp_obj_t *sec; -- cgit v1.2.3 From 6bfb344a808081aaaf883b7576699e05d9a86882 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 29 Mar 2017 16:09:46 +1100 Subject: cc3200/mods/pybi2c: Raise OSError if readfrom_mem fails to write addr. --- cc3200/mods/pybi2c.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cc3200') diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c index 658b2bfcd..a6009cb77 100644 --- a/cc3200/mods/pybi2c.c +++ b/cc3200/mods/pybi2c.c @@ -278,6 +278,8 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) { if (!pyb_i2c_read (i2c_addr, (byte *)vstr->buf, vstr->len)) { mp_raise_OSError(MP_EIO); } + } else { + mp_raise_OSError(MP_EIO); } } -- cgit v1.2.3 From b6c7e4b143d96ff9f84ccb22d83b1e15ab084250 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 31 Mar 2017 22:29:39 +1100 Subject: all: Use full path name when including mp-readline/timeutils/netutils. This follows the pattern of how all other headers are now included, and makes it explicit where the header file comes from. This patch also removes -I options from Makefile's that specify the mp-readline/timeutils/ netutils directories, which are no longer needed. --- cc3200/application.mk | 3 --- cc3200/ftp/ftp.c | 2 +- cc3200/mods/moduos.c | 2 +- cc3200/mods/modusocket.c | 2 +- cc3200/mods/modutime.c | 2 +- cc3200/mods/pybrtc.c | 2 +- cc3200/mptask.c | 2 +- esp8266/Makefile | 3 --- esp8266/fatfs_port.c | 2 +- esp8266/machine_rtc.c | 2 +- esp8266/modnetwork.c | 2 +- esp8266/modutime.c | 2 +- examples/embedding/Makefile.upylib | 1 - extmod/modlwip.c | 2 +- lib/mp-readline/readline.c | 2 +- lib/netutils/netutils.c | 2 +- lib/timeutils/timeutils.c | 2 +- minimal/Makefile | 1 - pic16bit/Makefile | 1 - pic16bit/main.c | 2 +- py/py.mk | 3 --- stmhal/Makefile | 3 --- stmhal/input.c | 2 +- stmhal/main.c | 2 +- stmhal/modnwcc3k.c | 2 +- stmhal/modnwwiznet5k.c | 2 +- stmhal/moduos.c | 2 +- stmhal/modusocket.c | 2 +- stmhal/modutime.c | 2 +- teensy/Makefile | 1 - teensy/main.c | 2 +- unix/Makefile | 1 - 32 files changed, 23 insertions(+), 40 deletions(-) (limited to 'cc3200') diff --git a/cc3200/application.mk b/cc3200/application.mk index b15dbde7f..5d25424e1 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -18,9 +18,6 @@ APP_INC += -Iutil APP_INC += -Ibootmgr APP_INC += -I$(BUILD) APP_INC += -I$(BUILD)/genhdr -APP_INC += -I../lib/mp-readline -APP_INC += -I../lib/netutils -APP_INC += -I../lib/timeutils APP_INC += -I../stmhal APP_CPPDEFINES = -Dgcc -DTARGET_IS_CC3200 -DSL_FULL -DUSE_FREERTOS diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c index 22035d6b3..1febe291f 100644 --- a/cc3200/ftp/ftp.c +++ b/cc3200/ftp/ftp.c @@ -29,6 +29,7 @@ #include "py/mpstate.h" #include "py/obj.h" +#include "lib/timeutils/timeutils.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" #include "extmod/vfs_fat.h" @@ -48,7 +49,6 @@ #include "fifo.h" #include "socketfifo.h" #include "updater.h" -#include "timeutils.h" #include "moduos.h" /****************************************************************************** diff --git a/cc3200/mods/moduos.c b/cc3200/mods/moduos.c index 5523c887f..add10ec6c 100644 --- a/cc3200/mods/moduos.c +++ b/cc3200/mods/moduos.c @@ -33,6 +33,7 @@ #include "py/objtuple.h" #include "py/objstr.h" #include "py/runtime.h" +#include "lib/timeutils/timeutils.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" #include "genhdr/mpversion.h" @@ -43,7 +44,6 @@ #include "random.h" #include "mpexception.h" #include "version.h" -#include "timeutils.h" #include "pybsd.h" #include "pybuart.h" diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index 4e2da6737..ca28bf7ba 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -34,7 +34,7 @@ #include "py/objstr.h" #include "py/runtime.h" #include "py/stream.h" -#include "netutils.h" +#include "lib/netutils/netutils.h" #include "modnetwork.h" #include "modusocket.h" #include "mpexception.h" diff --git a/cc3200/mods/modutime.c b/cc3200/mods/modutime.c index 8e3c71402..48fde67e7 100644 --- a/cc3200/mods/modutime.c +++ b/cc3200/mods/modutime.c @@ -33,8 +33,8 @@ #include "py/obj.h" #include "py/smallint.h" #include "py/mphal.h" +#include "lib/timeutils/timeutils.h" #include "extmod/utime_mphal.h" -#include "timeutils.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c index 13d7a49cb..134bd440e 100644 --- a/cc3200/mods/pybrtc.c +++ b/cc3200/mods/pybrtc.c @@ -29,6 +29,7 @@ #include "py/obj.h" #include "py/runtime.h" #include "py/mperrno.h" +#include "lib/timeutils/timeutils.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" @@ -37,7 +38,6 @@ #include "pybrtc.h" #include "mpirq.h" #include "pybsleep.h" -#include "timeutils.h" #include "simplelink.h" #include "modnetwork.h" #include "modwlan.h" diff --git a/cc3200/mptask.c b/cc3200/mptask.c index 3c49a5603..d446711a2 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -33,6 +33,7 @@ #include "py/runtime.h" #include "py/gc.h" #include "py/mphal.h" +#include "lib/mp-readline/readline.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" #include "extmod/vfs.h" @@ -51,7 +52,6 @@ #include "lib/utils/pyexec.h" #include "gccollect.h" #include "gchelper.h" -#include "readline.h" #include "mperror.h" #include "simplelink.h" #include "modnetwork.h" diff --git a/esp8266/Makefile b/esp8266/Makefile index 28dbf08a6..a3da9d398 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -25,9 +25,6 @@ ESP_SDK = $(shell $(CC) -print-sysroot)/usr INC += -I. INC += -I.. INC += -I../stmhal -INC += -I../lib/mp-readline -INC += -I../lib/netutils -INC += -I../lib/timeutils INC += -I$(BUILD) INC += -I$(ESP_SDK)/include diff --git a/esp8266/fatfs_port.c b/esp8266/fatfs_port.c index 20c3235d4..02384f605 100644 --- a/esp8266/fatfs_port.c +++ b/esp8266/fatfs_port.c @@ -25,8 +25,8 @@ */ #include "py/obj.h" +#include "lib/timeutils/timeutils.h" #include "lib/oofatfs/ff.h" -#include "timeutils.h" #include "modmachine.h" DWORD get_fattime(void) { diff --git a/esp8266/machine_rtc.c b/esp8266/machine_rtc.c index 8c1fe0779..019b705ba 100644 --- a/esp8266/machine_rtc.c +++ b/esp8266/machine_rtc.c @@ -30,7 +30,7 @@ #include "py/nlr.h" #include "py/obj.h" #include "py/runtime.h" -#include "timeutils.h" +#include "lib/timeutils/timeutils.h" #include "user_interface.h" #include "modmachine.h" diff --git a/esp8266/modnetwork.c b/esp8266/modnetwork.c index 762717b35..627655b36 100644 --- a/esp8266/modnetwork.c +++ b/esp8266/modnetwork.c @@ -32,7 +32,7 @@ #include "py/objlist.h" #include "py/runtime.h" #include "py/mphal.h" -#include "netutils.h" +#include "lib/netutils/netutils.h" #include "queue.h" #include "user_interface.h" #include "espconn.h" diff --git a/esp8266/modutime.c b/esp8266/modutime.c index 117720e6f..bdeb3bb45 100644 --- a/esp8266/modutime.c +++ b/esp8266/modutime.c @@ -34,8 +34,8 @@ #include "py/runtime.h" #include "py/mphal.h" #include "py/smallint.h" +#include "lib/timeutils/timeutils.h" #include "modmachine.h" -#include "timeutils.h" #include "user_interface.h" #include "extmod/utime_mphal.h" diff --git a/examples/embedding/Makefile.upylib b/examples/embedding/Makefile.upylib index 8b506e95e..873c0fd34 100644 --- a/examples/embedding/Makefile.upylib +++ b/examples/embedding/Makefile.upylib @@ -14,7 +14,6 @@ INC += -I. INC += -I.. INC += -I$(MPTOP) INC += -I$(MPTOP)/unix -#INC += -I../lib/timeutils INC += -I$(BUILD) # compiler settings diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 5709413de..fffabb98a 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -36,7 +36,7 @@ #include "py/mperrno.h" #include "py/mphal.h" -#include "netutils.h" +#include "lib/netutils/netutils.h" #include "lwip/init.h" #include "lwip/timers.h" diff --git a/lib/mp-readline/readline.c b/lib/mp-readline/readline.c index cbb99cc94..4b9875136 100644 --- a/lib/mp-readline/readline.c +++ b/lib/mp-readline/readline.c @@ -31,7 +31,7 @@ #include "py/mpstate.h" #include "py/repl.h" #include "py/mphal.h" -#include "readline.h" +#include "lib/mp-readline/readline.h" #if 0 // print debugging info #define DEBUG_PRINT (1) diff --git a/lib/netutils/netutils.c b/lib/netutils/netutils.c index 3a4c600dc..a2ea31cf3 100644 --- a/lib/netutils/netutils.c +++ b/lib/netutils/netutils.c @@ -31,7 +31,7 @@ #include "py/obj.h" #include "py/nlr.h" -#include "netutils.h" +#include "lib/netutils/netutils.h" // Takes an array with a raw IPv4 address and returns something like '192.168.0.1'. mp_obj_t netutils_format_ipv4_addr(uint8_t *ip, netutils_endian_t endian) { diff --git a/lib/timeutils/timeutils.c b/lib/timeutils/timeutils.c index 19d3ddbdd..0af39a295 100644 --- a/lib/timeutils/timeutils.c +++ b/lib/timeutils/timeutils.c @@ -27,7 +27,7 @@ #include "py/obj.h" -#include "timeutils.h" +#include "lib/timeutils/timeutils.h" // LEAPOCH corresponds to 2000-03-01, which is a mod-400 year, immediately // after Feb 29. We calculate seconds as a signed integer relative to that. diff --git a/minimal/Makefile b/minimal/Makefile index 3b446beae..d61515797 100644 --- a/minimal/Makefile +++ b/minimal/Makefile @@ -14,7 +14,6 @@ endif INC += -I. INC += -I.. -INC += -I../lib/mp-readline INC += -I../stmhal INC += -I$(BUILD) diff --git a/pic16bit/Makefile b/pic16bit/Makefile index add9a8495..8c0c1c999 100644 --- a/pic16bit/Makefile +++ b/pic16bit/Makefile @@ -14,7 +14,6 @@ PART = 33FJ256GP506 INC += -I. INC += -I.. -INC += -I../lib/mp-readline INC += -I../stmhal INC += -I$(BUILD) INC += -I$(XC16)/include diff --git a/pic16bit/main.c b/pic16bit/main.c index f2a9debab..7de790069 100644 --- a/pic16bit/main.c +++ b/pic16bit/main.c @@ -35,7 +35,7 @@ #include "py/mphal.h" #include "py/mperrno.h" #include "lib/utils/pyexec.h" -#include "readline.h" +#include "lib/mp-readline/readline.h" #include "board.h" #include "modpyb.h" diff --git a/py/py.mk b/py/py.mk index 37bb5d023..5ff1fd6a6 100644 --- a/py/py.mk +++ b/py/py.mk @@ -16,9 +16,6 @@ endif # some code is performance bottleneck and compiled with other optimization options CSUPEROPT = -O3 -INC += -I../lib -INC += -I../lib/netutils - # this sets the config file for FatFs CFLAGS_MOD += -DFFCONF_H=\"lib/oofatfs/ffconf.h\" diff --git a/stmhal/Makefile b/stmhal/Makefile index 51aa07f3c..09643be94 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -47,9 +47,6 @@ INC += -I$(CMSIS_DIR)/ INC += -I$(HAL_DIR)/inc INC += -I$(USBDEV_DIR)/core/inc -I$(USBDEV_DIR)/class/inc #INC += -I$(USBHOST_DIR) -INC += -I../lib/mp-readline -INC += -I../lib/netutils -INC += -I../lib/timeutils CFLAGS_CORTEX_M = -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion CFLAGS_MCU_f4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -DMCU_SERIES_F4 diff --git a/stmhal/input.c b/stmhal/input.c index 07e7ba35c..c78525cc9 100644 --- a/stmhal/input.c +++ b/stmhal/input.c @@ -26,7 +26,7 @@ #include "py/nlr.h" #include "py/obj.h" -#include "readline.h" +#include "lib/mp-readline/readline.h" STATIC mp_obj_t mp_builtin_input(uint n_args, const mp_obj_t *args) { if (n_args == 1) { diff --git a/stmhal/main.c b/stmhal/main.c index 8d076a08b..566c2db07 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -31,6 +31,7 @@ #include "py/stackctrl.h" #include "py/gc.h" #include "py/mphal.h" +#include "lib/mp-readline/readline.h" #include "lib/utils/pyexec.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" @@ -40,7 +41,6 @@ #include "pendsv.h" #include "pybthread.h" #include "gccollect.h" -#include "readline.h" #include "modmachine.h" #include "i2c.h" #include "spi.h" diff --git a/stmhal/modnwcc3k.c b/stmhal/modnwcc3k.c index ae403cacd..26c6cd48c 100644 --- a/stmhal/modnwcc3k.c +++ b/stmhal/modnwcc3k.c @@ -37,7 +37,7 @@ #include "py/runtime.h" #include "py/mperrno.h" #include "py/mphal.h" -#include "netutils.h" +#include "lib/netutils/netutils.h" #include "modnetwork.h" #include "pin.h" #include "genhdr/pins.h" diff --git a/stmhal/modnwwiznet5k.c b/stmhal/modnwwiznet5k.c index e3d5c6370..b32f16913 100644 --- a/stmhal/modnwwiznet5k.c +++ b/stmhal/modnwwiznet5k.c @@ -33,7 +33,7 @@ #include "py/runtime.h" #include "py/mperrno.h" #include "py/mphal.h" -#include "netutils.h" +#include "lib/netutils/netutils.h" #include "modnetwork.h" #include "pin.h" #include "genhdr/pins.h" diff --git a/stmhal/moduos.c b/stmhal/moduos.c index 0af682612..745c0d5d7 100644 --- a/stmhal/moduos.c +++ b/stmhal/moduos.c @@ -31,12 +31,12 @@ #include "py/runtime.h" #include "py/objtuple.h" #include "py/objstr.h" +#include "lib/timeutils/timeutils.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" #include "extmod/vfs.h" #include "extmod/vfs_fat.h" #include "genhdr/mpversion.h" -#include "timeutils.h" #include "rng.h" #include "uart.h" #include "portmodules.h" diff --git a/stmhal/modusocket.c b/stmhal/modusocket.c index d066501d0..fd60c5ad4 100644 --- a/stmhal/modusocket.c +++ b/stmhal/modusocket.c @@ -32,7 +32,7 @@ #include "py/objlist.h" #include "py/runtime.h" #include "py/mperrno.h" -#include "netutils.h" +#include "lib/netutils/netutils.h" #include "modnetwork.h" #if MICROPY_PY_USOCKET diff --git a/stmhal/modutime.c b/stmhal/modutime.c index 2c7245080..97af35c49 100644 --- a/stmhal/modutime.c +++ b/stmhal/modutime.c @@ -31,9 +31,9 @@ #include "py/nlr.h" #include "py/smallint.h" #include "py/obj.h" +#include "lib/timeutils/timeutils.h" #include "extmod/utime_mphal.h" #include "systick.h" -#include "timeutils.h" #include "portmodules.h" #include "rtc.h" diff --git a/teensy/Makefile b/teensy/Makefile index e613b8f27..9f52cc3c7 100644 --- a/teensy/Makefile +++ b/teensy/Makefile @@ -32,7 +32,6 @@ CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -msoft-float -mfloat INC += -I. INC += -I.. INC += -I../stmhal -INC += -I../lib/mp-readline INC += -I$(BUILD) INC += -Icore diff --git a/teensy/main.c b/teensy/main.c index d62ae3bdb..41bbeb5d9 100644 --- a/teensy/main.c +++ b/teensy/main.c @@ -10,7 +10,7 @@ #include "py/mphal.h" #include "gccollect.h" #include "lib/utils/pyexec.h" -#include "readline.h" +#include "lib/mp-readline/readline.h" #include "lexermemzip.h" #include "Arduino.h" diff --git a/unix/Makefile b/unix/Makefile index f28a4bcae..546985306 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -17,7 +17,6 @@ include ../py/py.mk INC += -I. INC += -I.. -INC += -I../lib/timeutils INC += -I$(BUILD) # compiler settings -- cgit v1.2.3 From 4c307bfba1e5ffa3cec94bd63ba19ba6c322883b Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 1 Apr 2017 11:39:38 +1100 Subject: all: Move BYTES_PER_WORD definition from ports to py/mpconfig.h It can still be overwritten by a port in mpconfigport.h but for almost all cases one can use the provided default. --- bare-arm/mpconfigport.h | 2 -- cc3200/mpconfigport.h | 1 - esp8266/mpconfigport.h | 2 -- examples/embedding/mpconfigport_minimal.h | 2 -- minimal/mpconfigport.h | 2 -- mpy-cross/mpconfigport.h | 2 -- pic16bit/mpconfigport.h | 1 - py/mpconfig.h | 5 +++++ qemu-arm/mpconfigport.h | 2 -- stmhal/mpconfigport.h | 2 -- teensy/mpconfigport.h | 2 -- unix/mpconfigport.h | 2 -- unix/mpconfigport_minimal.h | 2 -- windows/mpconfigport.h | 2 -- zephyr/mpconfigport.h | 2 -- zephyr/mpconfigport_minimal.h | 2 -- 16 files changed, 5 insertions(+), 28 deletions(-) (limited to 'cc3200') diff --git a/bare-arm/mpconfigport.h b/bare-arm/mpconfigport.h index 912fae66f..97e866bdb 100644 --- a/bare-arm/mpconfigport.h +++ b/bare-arm/mpconfigport.h @@ -46,8 +46,6 @@ // type definitions for the specific machine -#define BYTES_PER_WORD (4) - #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1)) #define UINT_FMT "%lu" diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index a8dc0cfeb..4d19900ae 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -200,7 +200,6 @@ extern const struct _mp_obj_module_t mp_module_ussl; // type definitions for the specific machine -#define BYTES_PER_WORD (4) #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1)) #define MP_SSIZE_MAX (0x7FFFFFFF) diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index 07bd48f67..d40eaba91 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -118,8 +118,6 @@ // type definitions for the specific machine -#define BYTES_PER_WORD (4) - #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p))) #define MP_SSIZE_MAX (0x7fffffff) diff --git a/examples/embedding/mpconfigport_minimal.h b/examples/embedding/mpconfigport_minimal.h index 48d200858..d16827fa3 100644 --- a/examples/embedding/mpconfigport_minimal.h +++ b/examples/embedding/mpconfigport_minimal.h @@ -119,8 +119,6 @@ typedef int mp_int_t; // must be pointer size typedef unsigned int mp_uint_t; // must be pointer size #endif -#define BYTES_PER_WORD sizeof(mp_int_t) - // Cannot include , as it may lead to symbol name clashes #if _FILE_OFFSET_BITS == 64 && !defined(__LP64__) typedef long long mp_off_t; diff --git a/minimal/mpconfigport.h b/minimal/mpconfigport.h index e08943860..47fc98429 100644 --- a/minimal/mpconfigport.h +++ b/minimal/mpconfigport.h @@ -57,8 +57,6 @@ // type definitions for the specific machine -#define BYTES_PER_WORD (4) - #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1)) // This port is intended to be 32-bit, but unfortunately, int32_t for diff --git a/mpy-cross/mpconfigport.h b/mpy-cross/mpconfigport.h index 0f7651098..383de1439 100644 --- a/mpy-cross/mpconfigport.h +++ b/mpy-cross/mpconfigport.h @@ -100,8 +100,6 @@ typedef int mp_int_t; // must be pointer size typedef unsigned int mp_uint_t; // must be pointer size #endif -#define BYTES_PER_WORD sizeof(mp_int_t) - // Cannot include , as it may lead to symbol name clashes #if _FILE_OFFSET_BITS == 64 && !defined(__LP64__) typedef long long mp_off_t; diff --git a/pic16bit/mpconfigport.h b/pic16bit/mpconfigport.h index a0371a8ae..e4113956b 100644 --- a/pic16bit/mpconfigport.h +++ b/pic16bit/mpconfigport.h @@ -68,7 +68,6 @@ // type definitions for the specific machine #define MP_ENDIANNESS_LITTLE (1) -#define BYTES_PER_WORD (2) #define MPZ_DIG_SIZE (8) // The xc16 compiler doesn't seem to respect alignment (!!) so we diff --git a/py/mpconfig.h b/py/mpconfig.h index 54cf0f3d3..9c89fc18a 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1105,6 +1105,11 @@ typedef double mp_float_t; #define STATIC static #endif +// Number of bytes in a word +#ifndef BYTES_PER_WORD +#define BYTES_PER_WORD (sizeof(mp_uint_t)) +#endif + #define BITS_PER_BYTE (8) #define BITS_PER_WORD (BITS_PER_BYTE * BYTES_PER_WORD) // mp_int_t value with most significant bit set diff --git a/qemu-arm/mpconfigport.h b/qemu-arm/mpconfigport.h index f642c6428..974d3520b 100644 --- a/qemu-arm/mpconfigport.h +++ b/qemu-arm/mpconfigport.h @@ -39,8 +39,6 @@ // type definitions for the specific machine -#define BYTES_PER_WORD (4) - #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1)) #define MP_SSIZE_MAX (0x7fffffff) diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 339360bae..3f3683199 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -264,8 +264,6 @@ extern const struct _mp_obj_module_t mp_module_network; // type definitions for the specific machine -#define BYTES_PER_WORD (4) - #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1)) #define MP_SSIZE_MAX (0x7fffffff) diff --git a/teensy/mpconfigport.h b/teensy/mpconfigport.h index 07f60c43f..8c4022046 100644 --- a/teensy/mpconfigport.h +++ b/teensy/mpconfigport.h @@ -54,8 +54,6 @@ extern const struct _mp_obj_module_t time_module; // type definitions for the specific machine -#define BYTES_PER_WORD (4) - #define UINT_FMT "%u" #define INT_FMT "%d" diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index a85884594..7ecfc28c0 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -233,8 +233,6 @@ typedef unsigned int mp_uint_t; // must be pointer size #endif #endif -#define BYTES_PER_WORD sizeof(mp_int_t) - // Cannot include , as it may lead to symbol name clashes #if _FILE_OFFSET_BITS == 64 && !defined(__LP64__) typedef long long mp_off_t; diff --git a/unix/mpconfigport_minimal.h b/unix/mpconfigport_minimal.h index 65e35c8d9..788c8519d 100644 --- a/unix/mpconfigport_minimal.h +++ b/unix/mpconfigport_minimal.h @@ -127,8 +127,6 @@ typedef int mp_int_t; // must be pointer size typedef unsigned int mp_uint_t; // must be pointer size #endif -#define BYTES_PER_WORD sizeof(mp_int_t) - // Cannot include , as it may lead to symbol name clashes #if _FILE_OFFSET_BITS == 64 && !defined(__LP64__) typedef long long mp_off_t; diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h index 6156ad39e..844e2618f 100644 --- a/windows/mpconfigport.h +++ b/windows/mpconfigport.h @@ -128,8 +128,6 @@ typedef int mp_int_t; // must be pointer size typedef unsigned int mp_uint_t; // must be pointer size #endif -#define BYTES_PER_WORD sizeof(mp_int_t) - // Just assume Windows is little-endian - mingw32 gcc doesn't // define standard endianness macros. #define MP_ENDIANNESS_LITTLE (1) diff --git a/zephyr/mpconfigport.h b/zephyr/mpconfigport.h index e0586dcfc..0949d1374 100644 --- a/zephyr/mpconfigport.h +++ b/zephyr/mpconfigport.h @@ -99,8 +99,6 @@ typedef void *machine_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size typedef long mp_off_t; -#define BYTES_PER_WORD (sizeof(mp_int_t)) - #define MP_STATE_PORT MP_STATE_VM #define MICROPY_PORT_ROOT_POINTERS \ diff --git a/zephyr/mpconfigport_minimal.h b/zephyr/mpconfigport_minimal.h index 04383f6e3..772335c0a 100644 --- a/zephyr/mpconfigport_minimal.h +++ b/zephyr/mpconfigport_minimal.h @@ -85,8 +85,6 @@ typedef void *machine_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size typedef long mp_off_t; -#define BYTES_PER_WORD (sizeof(mp_int_t)) - #define MP_STATE_PORT MP_STATE_VM #define MICROPY_PORT_ROOT_POINTERS \ -- cgit v1.2.3 From 9a38b7afe0058620c09cf54b0bbc1c20f32a5e22 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 5 Apr 2017 11:58:17 +0300 Subject: cc3200/modmachine: Return frequency value directly, like other ports. --- cc3200/mods/modmachine.c | 5 +---- docs/library/machine.rst | 11 +---------- 2 files changed, 2 insertions(+), 14 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/modmachine.c b/cc3200/mods/modmachine.c index 3c4e5a116..fd1485607 100644 --- a/cc3200/mods/modmachine.c +++ b/cc3200/mods/modmachine.c @@ -111,10 +111,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info) #endif STATIC mp_obj_t machine_freq(void) { - mp_obj_t tuple[1] = { - mp_obj_new_int(HAL_FCPU_HZ), - }; - return mp_obj_new_tuple(1, tuple); + return mp_obj_new_int(HAL_FCPU_HZ); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_freq_obj, machine_freq); diff --git a/docs/library/machine.rst b/docs/library/machine.rst index c677bcbf0..1007f142f 100644 --- a/docs/library/machine.rst +++ b/docs/library/machine.rst @@ -52,16 +52,7 @@ Power related functions .. function:: freq() - .. only:: not port_wipy - - Returns CPU frequency in hertz. - - .. only:: port_wipy - - Returns a tuple of clock frequencies: ``(sysclk,)`` - These correspond to: - - - sysclk: frequency of the CPU + Returns CPU frequency in hertz. .. function:: idle() -- cgit v1.2.3 From e322b2afbf5a8795033a2e9807b561a05ea744bf Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 9 Apr 2017 00:17:29 +0300 Subject: cc3200/pybuart: Make parity specifications consistent with HW API. parity=0 means even parity, parity=1 - odd. --- cc3200/mods/pybuart.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index 7fb51d83d..92bb3e46e 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -375,10 +375,13 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *a config |= UART_CONFIG_PAR_NONE; } else { uint parity = mp_obj_get_int(args[2].u_obj); - if (parity != UART_CONFIG_PAR_ODD && parity != UART_CONFIG_PAR_EVEN) { + if (parity == 0) { + config |= UART_CONFIG_PAR_EVEN; + } else if (parity == 1) { + config |= UART_CONFIG_PAR_ODD; + } else { goto error; } - config |= parity; } // stop bits config |= (args[3].u_int == 1 ? UART_CONFIG_STOP_ONE : UART_CONFIG_STOP_TWO); @@ -577,8 +580,6 @@ STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj }, // class constants - { MP_OBJ_NEW_QSTR(MP_QSTR_EVEN), MP_OBJ_NEW_SMALL_INT(UART_CONFIG_PAR_EVEN) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ODD), MP_OBJ_NEW_SMALL_INT(UART_CONFIG_PAR_ODD) }, { MP_OBJ_NEW_QSTR(MP_QSTR_RX_ANY), MP_OBJ_NEW_SMALL_INT(UART_TRIGGER_RX_ANY) }, }; -- cgit v1.2.3 From 8f205c2c9bed1f3f167f2b0a5abba1e676a6aa01 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 18 Apr 2017 13:16:05 +1000 Subject: cc3200/mods/pybi2c: Make machine.I2C constructor/init conform to HW API. This is a user-facing change to the cc3200's API, to make it conform to the new machine hardware API. The changes are: - change I2C constructor to: I2C(id=0, *, freq=100000, scl=None, sda=None) - change I2C init to: init(*, freq, scl, sda) - removal of machine.I2C.MASTER constant - I2C str/repr no longer prints I2C.MASTER To update existing code it should be enough to just remove the I2C.MASTER constant from contructor/init for I2C. --- cc3200/mods/pybi2c.c | 75 +++++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 45 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c index a6009cb77..b2e536056 100644 --- a/cc3200/mods/pybi2c.c +++ b/cc3200/mods/pybi2c.c @@ -59,8 +59,6 @@ typedef struct _pyb_i2c_obj_t { /****************************************************************************** DEFINE CONSTANTS ******************************************************************************/ -#define PYBI2C_MASTER (0) - #define PYBI2C_MIN_BAUD_RATE_HZ (50000) #define PYBI2C_MAX_BAUD_RATE_HZ (400000) @@ -79,7 +77,6 @@ typedef struct _pyb_i2c_obj_t { DECLARE PRIVATE DATA ******************************************************************************/ STATIC pyb_i2c_obj_t pyb_i2c_obj = {.baudrate = 0}; -STATIC const mp_obj_t pyb_i2c_def_pin[2] = {&pin_GP13, &pin_GP23}; /****************************************************************************** DECLARE PRIVATE FUNCTIONS @@ -289,33 +286,34 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) { STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_i2c_obj_t *self = self_in; if (self->baudrate > 0) { - mp_printf(print, "I2C(0, I2C.MASTER, baudrate=%u)", self->baudrate); + mp_printf(print, "I2C(0, baudrate=%u)", self->baudrate); } else { mp_print_str(print, "I2C(0)"); } } -STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, const mp_arg_val_t *args) { - // verify that mode is master - if (args[0].u_int != PYBI2C_MASTER) { - goto invalid_args; - } +STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_scl, ARG_sda, ARG_freq }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_scl, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_sda, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 100000} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); // make sure the baudrate is between the valid range - self->baudrate = MIN(MAX(args[1].u_int, PYBI2C_MIN_BAUD_RATE_HZ), PYBI2C_MAX_BAUD_RATE_HZ); + self->baudrate = MIN(MAX(args[ARG_freq].u_int, PYBI2C_MIN_BAUD_RATE_HZ), PYBI2C_MAX_BAUD_RATE_HZ); // assign the pins - mp_obj_t pins_o = args[2].u_obj; - if (pins_o != mp_const_none) { - mp_obj_t *pins; - if (pins_o == MP_OBJ_NULL) { - // use the default pins - pins = (mp_obj_t *)pyb_i2c_def_pin; - } else { - mp_obj_get_array_fixed_n(pins_o, 2, &pins); - } - pin_assign_pins_af (pins, 2, PIN_TYPE_STD_PU, PIN_FN_I2C, 0); + mp_obj_t pins[2] = {&pin_GP13, &pin_GP23}; // default (SDA, SCL) pins + if (args[ARG_scl].u_obj != MP_OBJ_NULL) { + pins[1] = args[ARG_scl].u_obj; + } + if (args[ARG_sda].u_obj != MP_OBJ_NULL) { + pins[0] = args[ARG_sda].u_obj; } + pin_assign_pins_af(pins, 2, PIN_TYPE_STD_PU, PIN_FN_I2C, 0); // init the I2C bus i2c_init(self); @@ -324,44 +322,34 @@ STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, const mp_arg_val_t *arg pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)i2c_init); return mp_const_none; - -invalid_args: - mp_raise_ValueError(mpexception_value_invalid_arguments); } -STATIC const mp_arg_t pyb_i2c_init_args[] = { - { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_mode, MP_ARG_INT, {.u_int = PYBI2C_MASTER} }, - { MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 100000} }, - { MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, -}; STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + // check the id argument, if given + if (n_args > 0) { + if (all_args[0] != MP_OBJ_NEW_SMALL_INT(0)) { + mp_raise_OSError(MP_ENODEV); + } + --n_args; + ++all_args; + } + // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); - mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_init_args)]; - mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(args), pyb_i2c_init_args, args); - - // check the peripheral id - if (args[0].u_int != 0) { - mp_raise_OSError(MP_ENODEV); - } // setup the object pyb_i2c_obj_t *self = &pyb_i2c_obj; self->base.type = &pyb_i2c_type; // start the peripheral - pyb_i2c_init_helper(self, &args[1]); + pyb_i2c_init_helper(self, n_args, all_args, &kw_args); return (mp_obj_t)self; } -STATIC mp_obj_t pyb_i2c_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - // parse args - mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_init_args) - 1]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_i2c_init_args[1], args); - return pyb_i2c_init_helper(pos_args[0], args); +STATIC mp_obj_t pyb_i2c_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + return pyb_i2c_init_helper(pos_args[0], n_args - 1, pos_args + 1, kw_args); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init); @@ -532,9 +520,6 @@ STATIC const mp_map_elem_t pyb_i2c_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_readfrom_mem), (mp_obj_t)&pyb_i2c_readfrom_mem_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_readfrom_mem_into), (mp_obj_t)&pyb_i2c_readfrom_mem_into_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_writeto_mem), (mp_obj_t)&pyb_i2c_writeto_mem_obj }, - - // class constants - { MP_OBJ_NEW_QSTR(MP_QSTR_MASTER), MP_OBJ_NEW_SMALL_INT(PYBI2C_MASTER) }, }; STATIC MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table); -- cgit v1.2.3 From 9d7c53734c5eee6b4fbcc18be59148bbdaf95a1d Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 18 Apr 2017 15:31:08 +1000 Subject: cc3200/mods/pybi2c: Make readfnom_mem_into/writeto_mem return None. This aligns the I2C class to match the standard machine.I2C API. Note that this is a (small) breaking change to the existing cc3200 API. The original API just returned the size of the input buffer so there's no information lost by this change. To update scripts users should just use the size of the buffer passed to these functions to get the number of bytes that are read/written. --- cc3200/mods/pybi2c.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c index b2e536056..9fc97d914 100644 --- a/cc3200/mods/pybi2c.c +++ b/cc3200/mods/pybi2c.c @@ -477,7 +477,7 @@ STATIC mp_obj_t pyb_i2c_readfrom_mem_into(mp_uint_t n_args, const mp_obj_t *pos_ // get the buffer to read into vstr_t vstr; pyb_i2c_readmem_into (args, &vstr); - return mp_obj_new_int(vstr.len); + return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_into_obj, 1, pyb_i2c_readfrom_mem_into); @@ -501,8 +501,7 @@ STATIC mp_obj_t pyb_i2c_writeto_mem(mp_uint_t n_args, const mp_obj_t *pos_args, // write the register address to write to. if (pyb_i2c_mem_write (i2c_addr, (byte *)&mem_addr, mem_addr_size, bufinfo.buf, bufinfo.len)) { - // return the number of bytes written - return mp_obj_new_int(bufinfo.len); + return mp_const_none; } mp_raise_OSError(MP_EIO); -- cgit v1.2.3 From f1609bc843f1c30117cf9dfae8fb22ee36512446 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 May 2017 23:36:17 +1000 Subject: ports: Add ilistdir in uos module. --- cc3200/mods/moduos.c | 1 + esp8266/moduos.c | 1 + qemu-arm/moduos.c | 1 + stmhal/moduos.c | 1 + unix/moduos_vfs.c | 1 + 5 files changed, 5 insertions(+) (limited to 'cc3200') diff --git a/cc3200/mods/moduos.c b/cc3200/mods/moduos.c index add10ec6c..ed8879bf3 100644 --- a/cc3200/mods/moduos.c +++ b/cc3200/mods/moduos.c @@ -155,6 +155,7 @@ STATIC const mp_map_elem_t os_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_chdir), (mp_obj_t)&mp_vfs_chdir_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_getcwd), (mp_obj_t)&mp_vfs_getcwd_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ilistdir), (mp_obj_t)&mp_vfs_ilistdir_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_listdir), (mp_obj_t)&mp_vfs_listdir_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_mkdir), (mp_obj_t)&mp_vfs_mkdir_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_rename), (mp_obj_t)&mp_vfs_rename_obj}, diff --git a/esp8266/moduos.c b/esp8266/moduos.c index a22fbd4df..807d2e18a 100644 --- a/esp8266/moduos.c +++ b/esp8266/moduos.c @@ -93,6 +93,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { #endif #if MICROPY_VFS_FAT { MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) }, + { 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_rmdir), MP_ROM_PTR(&mp_vfs_rmdir_obj) }, diff --git a/qemu-arm/moduos.c b/qemu-arm/moduos.c index dcb67396b..a48b51db0 100644 --- a/qemu-arm/moduos.c +++ b/qemu-arm/moduos.c @@ -31,6 +31,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { 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) }, diff --git a/stmhal/moduos.c b/stmhal/moduos.c index 2d648cb91..ece6019fb 100644 --- a/stmhal/moduos.c +++ b/stmhal/moduos.c @@ -135,6 +135,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { 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) }, diff --git a/unix/moduos_vfs.c b/unix/moduos_vfs.c index 58990b028..96defa554 100644 --- a/unix/moduos_vfs.c +++ b/unix/moduos_vfs.c @@ -42,6 +42,7 @@ STATIC const mp_rom_map_elem_t uos_vfs_module_globals_table[] = { { 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) }, -- cgit v1.2.3 From 19e065294d4c4f28b8df3859f48958f68e7617e2 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 21 May 2017 15:39:27 +0300 Subject: cc3200/mods/pybpin: Remove toggle() method. It's not part of MicroPython HW API and can be easily implemented on Python level in case of need. Saved 56 bytes of binary. --- cc3200/mods/pybpin.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c index ac0ecef25..c2a469117 100644 --- a/cc3200/mods/pybpin.c +++ b/cc3200/mods/pybpin.c @@ -684,13 +684,6 @@ STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value); -STATIC mp_obj_t pin_toggle(mp_obj_t self_in) { - pin_obj_t *self = self_in; - MAP_GPIOPinWrite(self->port, self->bit, ~MAP_GPIOPinRead(self->port, self->bit)); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_toggle_obj, pin_toggle); - STATIC mp_obj_t pin_id(mp_obj_t self_in) { pin_obj_t *self = self_in; return MP_OBJ_NEW_QSTR(self->name); @@ -913,7 +906,6 @@ STATIC const mp_map_elem_t pin_locals_dict_table[] = { // instance methods { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pin_init_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pin_value_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_toggle), (mp_obj_t)&pin_toggle_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_id), (mp_obj_t)&pin_id_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_mode), (mp_obj_t)&pin_mode_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_pull), (mp_obj_t)&pin_pull_obj }, -- cgit v1.2.3 From ca16c3821053e5bf2b87aeb10007f73f31dc1eac Mon Sep 17 00:00:00 2001 From: Ville Skyttä Date: Mon, 29 May 2017 10:08:14 +0300 Subject: various: Spelling fixes --- cc3200/README.md | 2 +- docs/library/btree.rst | 2 +- docs/library/machine.SD.rst | 2 +- docs/library/machine.UART.rst | 2 +- docs/library/uhashlib.rst | 4 ++-- docs/library/utime.rst | 4 ++-- docs/sphinx_selective_exclude/README.md | 2 +- docs/sphinx_selective_exclude/modindex_exclude.py | 2 +- esp8266/README.md | 2 +- esp8266/machine_rtc.c | 2 +- examples/conwaylife.py | 4 ++-- examples/embedding/Makefile.upylib | 2 +- examples/embedding/README.md | 2 +- extmod/modlwip.c | 4 ++-- extmod/modwebsocket.c | 2 +- lib/timeutils/timeutils.c | 2 +- lib/utils/stdout_helpers.c | 2 +- py/asmthumb.c | 2 +- py/builtinimport.c | 4 ++-- py/compile.c | 4 ++-- py/misc.h | 2 +- py/mkenv.mk | 2 +- py/mpconfig.h | 2 +- py/obj.c | 2 +- py/objstr.c | 4 ++-- py/py.mk | 2 +- py/ringbuf.h | 2 +- py/stream.c | 2 +- py/vm.c | 4 ++-- qemu-arm/README.md | 2 +- tests/basics/namedtuple1.py | 2 +- tests/basics/try_reraise2.py | 2 +- tests/pyb/can.py | 2 +- tests/thread/stress_aes.py | 2 +- tests/wipy/uart.py | 2 +- tools/insert-usb-ids.py | 2 +- tools/pyboard.py | 2 +- unix/Makefile | 2 +- unix/modsocket.c | 2 +- windows/windows_mphal.c | 2 +- zephyr/modutime.c | 2 +- 41 files changed, 49 insertions(+), 49 deletions(-) (limited to 'cc3200') diff --git a/cc3200/README.md b/cc3200/README.md index 753fd450a..53cad3ba0 100644 --- a/cc3200/README.md +++ b/cc3200/README.md @@ -138,7 +138,7 @@ If `WIPY_IP`, `WIPY_USER` or `WIPY_PWD` are omitted the default values (the ones ## Regarding old revisions of the CC3200-LAUNCHXL First silicon (pre-release) revisions of the CC3200 had issues with the ram blocks, and MicroPython cannot run -there. Make sure to use a **v4.1 (or higer) LAUNCHXL board** when trying this port, otherwise it won't work. +there. Make sure to use a **v4.1 (or higher) LAUNCHXL board** when trying this port, otherwise it won't work. ### Note regarding FileZilla diff --git a/docs/library/btree.rst b/docs/library/btree.rst index aebcbc160..bd7890586 100644 --- a/docs/library/btree.rst +++ b/docs/library/btree.rst @@ -69,7 +69,7 @@ Functions Open a database from a random-access `stream` (like an open file). All other parameters are optional and keyword-only, and allow to tweak advanced - paramters of the database operation (most users will not need them): + parameters of the database operation (most users will not need them): * `flags` - Currently unused. * `cachesize` - Suggested maximum memory cache size in bytes. For a diff --git a/docs/library/machine.SD.rst b/docs/library/machine.SD.rst index 0eb024602..608e95831 100644 --- a/docs/library/machine.SD.rst +++ b/docs/library/machine.SD.rst @@ -34,7 +34,7 @@ Methods .. method:: SD.init(id=0, pins=('GP10', 'GP11', 'GP15')) - Enable the SD card. In order to initalize the card, give it a 3-tuple: + Enable the SD card. In order to initialize the card, give it a 3-tuple: ``(clk_pin, cmd_pin, dat0_pin)``. .. method:: SD.deinit() diff --git a/docs/library/machine.UART.rst b/docs/library/machine.UART.rst index f9c8efef7..64ff28e1a 100644 --- a/docs/library/machine.UART.rst +++ b/docs/library/machine.UART.rst @@ -16,7 +16,7 @@ UART objects can be created and initialised using:: uart = UART(1, 9600) # init with given baudrate uart.init(9600, bits=8, parity=None, stop=1) # init with given parameters -Supported paramters differ on a board: +Supported parameters differ on a board: Pyboard: Bits can be 7, 8 or 9. Stop can be 1 or 2. With `parity=None`, only 8 and 9 bits are supported. With parity enabled, only 7 and 8 bits diff --git a/docs/library/uhashlib.rst b/docs/library/uhashlib.rst index cd0216dae..6b9a764ba 100644 --- a/docs/library/uhashlib.rst +++ b/docs/library/uhashlib.rst @@ -15,11 +15,11 @@ be implemented: * SHA1 - A previous generation algorithm. Not recommended for new usages, but SHA1 is a part of number of Internet standards and existing - applications, so boards targetting network connectivity and + applications, so boards targeting network connectivity and interoperatiability will try to provide this. * MD5 - A legacy algorithm, not considered cryptographically secure. Only - selected boards, targetting interoperatibility with legacy applications, + selected boards, targeting interoperatibility with legacy applications, will offer this. Constructors diff --git a/docs/library/utime.rst b/docs/library/utime.rst index 871f6c678..f3a067cde 100644 --- a/docs/library/utime.rst +++ b/docs/library/utime.rst @@ -146,8 +146,8 @@ Functions too distant inbetween, see below). The function returns **signed** value in the range [``-TICKS_PERIOD/2`` .. ``TICKS_PERIOD/2-1``] (that's a typical range definition for two's-complement signed binary integers). If the result is negative, it means that - ``ticks1`` occured earlier in time than ``ticks2``. Otherwise, it means that - ``ticks1`` occured after ``ticks2``. This holds ``only`` if ``ticks1`` and ``ticks2`` + ``ticks1`` occurred earlier in time than ``ticks2``. Otherwise, it means that + ``ticks1`` occurred after ``ticks2``. This holds ``only`` if ``ticks1`` and ``ticks2`` are apart from each other for no more than ``TICKS_PERIOD/2-1`` ticks. If that does not hold, incorrect result will be returned. Specifically, if two tick values are apart for ``TICKS_PERIOD/2-1`` ticks, that value will be returned by the function. diff --git a/docs/sphinx_selective_exclude/README.md b/docs/sphinx_selective_exclude/README.md index cc9725c21..dab140739 100644 --- a/docs/sphinx_selective_exclude/README.md +++ b/docs/sphinx_selective_exclude/README.md @@ -66,7 +66,7 @@ index for PDF, just the same as for HTML. search_auto_exclude ------------------- -Even if you exclude soem documents from toctree:: using only:: +Even if you exclude some documents from toctree:: using only:: directive, they will be indexed for full-text search, so user may find them and get confused. This plugin follows very simple idea that if you didn't include some documents in the toctree, then diff --git a/docs/sphinx_selective_exclude/modindex_exclude.py b/docs/sphinx_selective_exclude/modindex_exclude.py index 18b49cc80..bf8db795e 100644 --- a/docs/sphinx_selective_exclude/modindex_exclude.py +++ b/docs/sphinx_selective_exclude/modindex_exclude.py @@ -2,7 +2,7 @@ # This is a Sphinx documentation tool extension which allows to # exclude some Python modules from the generated indexes. Modules # are excluded both from "modindex" and "genindex" index tables -# (in the latter case, all members of a module are exlcuded). +# (in the latter case, all members of a module are excluded). # To control exclusion, set "modindex_exclude" variable in Sphinx # conf.py to the list of modules to exclude. Note: these should be # modules (as defined by py:module directive, not just raw filenames). diff --git a/esp8266/README.md b/esp8266/README.md index 897bb4737..d717d26fe 100644 --- a/esp8266/README.md +++ b/esp8266/README.md @@ -100,7 +100,7 @@ programming). __WiFi__ -Initally, the device configures itself as a WiFi access point (AP). +Initially, the device configures itself as a WiFi access point (AP). - ESSID: MicroPython-xxxxxx (x’s are replaced with part of the MAC address). - Password: micropythoN (note the upper-case N). - IP address of the board: 192.168.4.1. diff --git a/esp8266/machine_rtc.c b/esp8266/machine_rtc.c index 019b705ba..b17bcb261 100644 --- a/esp8266/machine_rtc.c +++ b/esp8266/machine_rtc.c @@ -93,7 +93,7 @@ void pyb_rtc_set_us_since_2000(uint64_t nowus) { int64_t delta = nowus - (((uint64_t)rtc_last_ticks * cal) >> 12); // As the calibration value jitters quite a bit, to make the - // clock at least somewhat practially usable, we need to store it + // clock at least somewhat practically usable, we need to store it system_rtc_mem_write(MEM_CAL_ADDR, &cal, sizeof(cal)); system_rtc_mem_write(MEM_DELTA_ADDR, &delta, sizeof(delta)); }; diff --git a/examples/conwaylife.py b/examples/conwaylife.py index f99796175..323f42e85 100644 --- a/examples/conwaylife.py +++ b/examples/conwaylife.py @@ -8,7 +8,7 @@ lcd.light(1) def conway_step(): for x in range(128): # loop over x coordinates for y in range(32): # loop over y coordinates - # count number of neigbours + # count number of neighbours num_neighbours = (lcd.get(x - 1, y - 1) + lcd.get(x, y - 1) + lcd.get(x + 1, y - 1) + @@ -25,7 +25,7 @@ def conway_step(): if self and not (2 <= num_neighbours <= 3): lcd.pixel(x, y, 0) # not enough, or too many neighbours: cell dies elif not self and num_neighbours == 3: - lcd.pixel(x, y, 1) # exactly 3 neigbours around an empty cell: cell is born + lcd.pixel(x, y, 1) # exactly 3 neighbours around an empty cell: cell is born # randomise the start def conway_rand(): diff --git a/examples/embedding/Makefile.upylib b/examples/embedding/Makefile.upylib index 873c0fd34..4663ad30a 100644 --- a/examples/embedding/Makefile.upylib +++ b/examples/embedding/Makefile.upylib @@ -170,7 +170,7 @@ SRC_QSTR_AUTO_DEPS += include $(MPTOP)/py/mkrules.mk # Value of configure's --host= option (required for cross-compilation). -# Deduce it from CROSS_COMPILE by default, but can be overriden. +# Deduce it from CROSS_COMPILE by default, but can be overridden. ifneq ($(CROSS_COMPILE),) CROSS_COMPILE_HOST = --host=$(patsubst %-,%,$(CROSS_COMPILE)) else diff --git a/examples/embedding/README.md b/examples/embedding/README.md index 989ce1fc8..804dfede6 100644 --- a/examples/embedding/README.md +++ b/examples/embedding/README.md @@ -18,7 +18,7 @@ Building the example is as simple as running: It's worth to trace what's happening behind the scenes though: 1. As a first step, a MicroPython library is built. This is handled by a -seperate makefile, Makefile.upylib. It is more or less complex, but the +separate makefile, Makefile.upylib. It is more or less complex, but the good news is that you won't need to change anything in it, just use it as is, the main Makefile shows how. What may require editing though is a MicroPython configuration file. MicroPython is highly configurable, so diff --git a/extmod/modlwip.c b/extmod/modlwip.c index c72849cf9..47669cb3a 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -373,7 +373,7 @@ STATIC err_t _lwip_tcp_recv(void *arg, struct tcp_pcb *tcpb, struct pbuf *p, err } /*******************************************************************************/ -// Functions for socket send/recieve operations. Socket send/recv and friends call +// Functions for socket send/receive operations. Socket send/recv and friends call // these to do the work. // Helper function for send/sendto to handle UDP packets. @@ -805,7 +805,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { mp_raise_OSError(MP_EINPROGRESS); } } - // Register our recieve callback. + // Register our receive callback. tcp_recv(socket->pcb.tcp, _lwip_tcp_recv); socket->state = STATE_CONNECTING; err = tcp_connect(socket->pcb.tcp, &dest, port, _lwip_tcp_connected); diff --git a/extmod/modwebsocket.c b/extmod/modwebsocket.c index 8200ea708..9e17d6a6d 100644 --- a/extmod/modwebsocket.c +++ b/extmod/modwebsocket.c @@ -132,7 +132,7 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int self->buf_pos = 0; self->to_recv = to_recv; - self->msg_sz = sz; // May be overriden by FRAME_OPT + self->msg_sz = sz; // May be overridden by FRAME_OPT if (to_recv != 0) { self->state = FRAME_OPT; } else { diff --git a/lib/timeutils/timeutils.c b/lib/timeutils/timeutils.c index 0af39a295..06915f25a 100644 --- a/lib/timeutils/timeutils.c +++ b/lib/timeutils/timeutils.c @@ -165,7 +165,7 @@ mp_uint_t timeutils_mktime(mp_uint_t year, mp_int_t month, mp_int_t mday, // // tm_tomorrow = list(time.localtime()) // tm_tomorrow[2] += 1 # Adds 1 to mday - // tomorrow = time.mktime(tm_tommorrow) + // tomorrow = time.mktime(tm_tomorrow) // // And not have to worry about all the weird overflows. // diff --git a/lib/utils/stdout_helpers.c b/lib/utils/stdout_helpers.c index 5f7a17d32..3de119757 100644 --- a/lib/utils/stdout_helpers.c +++ b/lib/utils/stdout_helpers.c @@ -9,7 +9,7 @@ * implementation below can be used. */ -// Send "cooked" string of given length, where every occurance of +// Send "cooked" string of given length, where every occurrence of // LF character is replaced with CR LF. void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) { while (len--) { diff --git a/py/asmthumb.c b/py/asmthumb.c index 749c1e405..7e92e4de4 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -52,7 +52,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) { #if defined(MCU_SERIES_F7) if (as->base.pass == MP_ASM_PASS_EMIT) { - // flush D-cache, so the code emited is stored in memory + // flush D-cache, so the code emitted is stored in memory SCB_CleanDCache_by_Addr((uint32_t*)as->base.code_base, as->base.code_size); // invalidate I-cache SCB_InvalidateICache(); diff --git a/py/builtinimport.c b/py/builtinimport.c index d01ebbe73..6994fc48f 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -271,7 +271,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) { if (level != 0) { // What we want to do here is to take name of current module, // chop trailing components, and concatenate with passed-in - // module name, thus resolving relative import name into absolue. + // module name, thus resolving relative import name into absolute. // This even appears to be correct per // http://legacy.python.org/dev/peps/pep-0328/#relative-imports-and-name // "Relative imports use a module's __name__ attribute to determine that @@ -441,7 +441,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) { #if MICROPY_CPYTHON_COMPAT // Store module as "__main__" in the dictionary of loaded modules (returned by sys.modules). mp_obj_dict_store(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_loaded_modules_dict)), MP_OBJ_NEW_QSTR(MP_QSTR___main__), module_obj); - // Store real name in "__main__" attribute. Choosen semi-randonly, to reuse existing qstr's. + // Store real name in "__main__" attribute. Chosen semi-randonly, to reuse existing qstr's. mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___main__), MP_OBJ_NEW_QSTR(mod_name)); #endif } diff --git a/py/compile.c b/py/compile.c index 8533e0528..3b6a264d6 100644 --- a/py/compile.c +++ b/py/compile.c @@ -939,7 +939,7 @@ STATIC void c_del_stmt(compiler_t *comp, mp_parse_node_t pn) { } } } else { - // some arbitrary statment that we can't delete (eg del 1) + // some arbitrary statement that we can't delete (eg del 1) goto cannot_delete; } @@ -1090,7 +1090,7 @@ STATIC void compile_import_name(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_t pn_import_source = pns->nodes[0]; - // extract the preceeding .'s (if any) for a relative import, to compute the import level + // extract the preceding .'s (if any) for a relative import, to compute the import level uint import_level = 0; do { mp_parse_node_t pn_rel; diff --git a/py/misc.h b/py/misc.h index 146b9a8e4..caa5945bf 100644 --- a/py/misc.h +++ b/py/misc.h @@ -197,7 +197,7 @@ int DEBUG_printf(const char *fmt, ...); extern mp_uint_t mp_verbose_flag; // This is useful for unicode handling. Some CPU archs has -// special instructions for efficient implentation of this +// special instructions for efficient implementation of this // function (e.g. CLZ on ARM). // NOTE: this function is unused at the moment #ifndef count_lead_ones diff --git a/py/mkenv.mk b/py/mkenv.mk index eb1e44fef..b167b2533 100644 --- a/py/mkenv.mk +++ b/py/mkenv.mk @@ -32,7 +32,7 @@ ifeq ($(BUILD_VERBOSE),0) $(info Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.) endif -# default settings; can be overriden in main Makefile +# default settings; can be overridden in main Makefile PY_SRC ?= $(TOP)/py BUILD ?= build diff --git a/py/mpconfig.h b/py/mpconfig.h index a61d431e5..78e346d73 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -32,7 +32,7 @@ // mpconfigport.h is a file containing configuration settings for a // particular port. mpconfigport.h is actually a default name for -// such config, and it can be overriden using MP_CONFIGFILE preprocessor +// such config, and it can be overridden using MP_CONFIGFILE preprocessor // define (you can do that by passing CFLAGS_EXTRA='-DMP_CONFIGFILE=""' // argument to make when using standard MicroPython makefiles). // This is useful to have more than one config per port, for example, diff --git a/py/obj.c b/py/obj.c index 98ffa930b..493945a22 100644 --- a/py/obj.c +++ b/py/obj.c @@ -401,7 +401,7 @@ mp_obj_t mp_obj_id(mp_obj_t o_in) { return MP_OBJ_NEW_SMALL_INT(id); } else { // If that didn't work, well, let's return long int, just as - // a (big) positve value, so it will never clash with the range + // a (big) positive value, so it will never clash with the range // of small int returned in previous case. return mp_obj_new_int_from_uint((mp_uint_t)id); } diff --git a/py/objstr.c b/py/objstr.c index 70de0a693..a1e223572 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -798,7 +798,7 @@ STATIC mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) { } assert(last_good_char_pos >= first_good_char_pos); - //+1 to accomodate the last character + //+1 to accommodate the last character size_t stripped_len = last_good_char_pos - first_good_char_pos + 1; if (stripped_len == orig_str_len) { // If nothing was stripped, don't bother to dup original string @@ -1811,7 +1811,7 @@ STATIC mp_obj_t str_islower(mp_obj_t self_in) { } #if MICROPY_CPYTHON_COMPAT -// These methods are superfluous in the presense of str() and bytes() +// These methods are superfluous in the presence of str() and bytes() // constructors. // TODO: should accept kwargs too STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) { diff --git a/py/py.mk b/py/py.mk index 5ff1fd6a6..70891677d 100644 --- a/py/py.mk +++ b/py/py.mk @@ -25,7 +25,7 @@ ifeq ($(MICROPY_SSL_AXTLS),1) CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config LDFLAGS_MOD += -Lbuild -laxtls else ifeq ($(MICROPY_SSL_MBEDTLS),1) -# Can be overriden by ports which have "builtin" mbedTLS +# Can be overridden by ports which have "builtin" mbedTLS MICROPY_SSL_MBEDTLS_INCLUDE ?= ../lib/mbedtls/include CFLAGS_MOD += -DMICROPY_SSL_MBEDTLS=1 -I$(MICROPY_SSL_MBEDTLS_INCLUDE) LDFLAGS_MOD += -L../lib/mbedtls/library -lmbedx509 -lmbedtls -lmbedcrypto diff --git a/py/ringbuf.h b/py/ringbuf.h index 5662594f7..5e108afad 100644 --- a/py/ringbuf.h +++ b/py/ringbuf.h @@ -33,7 +33,7 @@ typedef struct _ringbuf_t { uint16_t iput; } ringbuf_t; -// Static initalization: +// Static initialization: // byte buf_array[N]; // ringbuf_t buf = {buf_array, sizeof(buf_array)}; diff --git a/py/stream.c b/py/stream.c index c915110e0..d3fc767bb 100644 --- a/py/stream.c +++ b/py/stream.c @@ -51,7 +51,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in); #define STREAM_CONTENT_TYPE(stream) (((stream)->is_text) ? &mp_type_str : &mp_type_bytes) // Returns error condition in *errcode, if non-zero, return value is number of bytes written -// before error condition occured. If *errcode == 0, returns total bytes written (which will +// before error condition occurred. If *errcode == 0, returns total bytes written (which will // be equal to input size). mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode, byte flags) { byte *buf = buf_; diff --git a/py/vm.c b/py/vm.c index 5094e3e45..ad3d9e29c 100644 --- a/py/vm.c +++ b/py/vm.c @@ -947,7 +947,7 @@ unwind_jump:; DECODE_UINT; // unum & 0xff == n_positional // (unum >> 8) & 0xff == n_keyword - // We have folowing stack layout here: + // We have following stack layout here: // fun arg0 arg1 ... kw0 val0 kw1 val1 ... seq dict <- TOS sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe) + 2; #if MICROPY_STACKLESS @@ -1018,7 +1018,7 @@ unwind_jump:; DECODE_UINT; // unum & 0xff == n_positional // (unum >> 8) & 0xff == n_keyword - // We have folowing stack layout here: + // We have following stack layout here: // fun self arg0 arg1 ... kw0 val0 kw1 val1 ... seq dict <- TOS sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe) + 3; #if MICROPY_STACKLESS diff --git a/qemu-arm/README.md b/qemu-arm/README.md index 329ae4d92..0cf93c7d5 100644 --- a/qemu-arm/README.md +++ b/qemu-arm/README.md @@ -4,7 +4,7 @@ provided by QEMU (http://qemu.org). The purposes of this port are to enable: 1. Continuous integration - - run tests agains architecture-specific parts of code base + - run tests against architecture-specific parts of code base 2. Experimentation - simulation & prototyping of anything that has architecture-specific code diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py index 132dcf96b..70372f7ca 100644 --- a/tests/basics/namedtuple1.py +++ b/tests/basics/namedtuple1.py @@ -76,7 +76,7 @@ T4 = namedtuple("TupTuple", ("foo", "bar")) t = T4(1, 2) print(t.foo, t.bar) -# Try single string with comma field seperator +# Try single string with comma field separator # Not implemented so far #T2 = namedtuple("TupComma", "foo,bar") #t = T2(1, 2) diff --git a/tests/basics/try_reraise2.py b/tests/basics/try_reraise2.py index d9434397c..5648d2467 100644 --- a/tests/basics/try_reraise2.py +++ b/tests/basics/try_reraise2.py @@ -1,4 +1,4 @@ -# Reraise not the latest occured exception +# Reraise not the latest occurred exception def f(): try: raise ValueError("val", 3) diff --git a/tests/pyb/can.py b/tests/pyb/can.py index 617eb7ccc..7f2d070ec 100644 --- a/tests/pyb/can.py +++ b/tests/pyb/can.py @@ -158,7 +158,7 @@ print(can.recv(1)) del can -# Testing asyncronous send +# Testing asynchronous send can = CAN(1, CAN.LOOPBACK) can.setfilter(0, CAN.MASK16, 0, (0, 0, 0, 0)) diff --git a/tests/thread/stress_aes.py b/tests/thread/stress_aes.py index ecc963c92..df75e616c 100644 --- a/tests/thread/stress_aes.py +++ b/tests/thread/stress_aes.py @@ -8,7 +8,7 @@ # # The AES code comes first (code originates from a C version authored by D.P.George) # and then the test harness at the bottom. It can be tuned to be more/less -# agressive by changing the amount of data to encrypt, the number of loops and +# aggressive by changing the amount of data to encrypt, the number of loops and # the number of threads. # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd diff --git a/tests/wipy/uart.py b/tests/wipy/uart.py index a3a1c14e8..8e794015d 100644 --- a/tests/wipy/uart.py +++ b/tests/wipy/uart.py @@ -95,7 +95,7 @@ print(uart1.read() == None) print(uart1.write(b'123') == 3) print(uart0.read() == b'123') -# no pin assignemnt +# no pin assignment uart0 = UART(0, 1000000, pins=(None, None)) print(uart0.write(b'123456789') == 9) print(uart1.read() == None) diff --git a/tools/insert-usb-ids.py b/tools/insert-usb-ids.py index 420db34c5..cdccd3be9 100644 --- a/tools/insert-usb-ids.py +++ b/tools/insert-usb-ids.py @@ -1,4 +1,4 @@ -# Reads the USB VID and PID from the file specifed by sys.arg[1] and then +# Reads the USB VID and PID from the file specified by sys.argv[1] and then # inserts those values into the template file specified by sys.argv[2], # printing the result to stdout diff --git a/tools/pyboard.py b/tools/pyboard.py index 5eac030bd..921ffc52d 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -69,7 +69,7 @@ class TelnetToSerial: self.tn.write(bytes(password, 'ascii') + b"\r\n") if b'for more information.' in self.tn.read_until(b'Type "help()" for more information.', timeout=read_timeout): - # login succesful + # login successful from collections import deque self.fifo = deque() return diff --git a/unix/Makefile b/unix/Makefile index 837ddf2b7..006bce0ef 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -262,7 +262,7 @@ coverage_test: coverage gcov -o build-coverage/extmod ../extmod/*.c # Value of configure's --host= option (required for cross-compilation). -# Deduce it from CROSS_COMPILE by default, but can be overriden. +# Deduce it from CROSS_COMPILE by default, but can be overridden. ifneq ($(CROSS_COMPILE),) CROSS_COMPILE_HOST = --host=$(patsubst %-,%,$(CROSS_COMPILE)) else diff --git a/unix/modsocket.c b/unix/modsocket.c index 9ca04b88b..c7be6461e 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -58,7 +58,7 @@ from socket_more_funcs2 import * ------------------- I.e. this module should stay lean, and more functions (if needed) - should be add to seperate modules (C or Python level). + should be add to separate modules (C or Python level). */ #define MICROPY_SOCKET_EXTRA (0) diff --git a/windows/windows_mphal.c b/windows/windows_mphal.c index 1dd3105d8..a73140e54 100644 --- a/windows/windows_mphal.c +++ b/windows/windows_mphal.c @@ -72,7 +72,7 @@ void mp_hal_stdio_mode_orig(void) { // Previous versions of the mp_hal code would install a handler whenever Ctrl-C input is // allowed and remove the handler again when it is not. That is not necessary though (1), // and it might introduce problems (2) because console notifications are delivered to the -// application in a seperate thread. +// application in a separate thread. // (1) mp_hal_set_interrupt_char effectively enables/disables processing of Ctrl-C via the // ENABLE_PROCESSED_INPUT flag so in raw mode console_sighandler won't be called. // (2) if mp_hal_set_interrupt_char would remove the handler while Ctrl-C was issued earlier, diff --git a/zephyr/modutime.c b/zephyr/modutime.c index 378068bb3..0c268046a 100644 --- a/zephyr/modutime.c +++ b/zephyr/modutime.c @@ -36,7 +36,7 @@ #include "extmod/utime_mphal.h" STATIC mp_obj_t mod_time_time(void) { - /* The absense of FP support is deliberate. The Zephyr port uses + /* The absence of FP support is deliberate. The Zephyr port uses * single precision floats so the fraction component will start to * lose precision on devices with a long uptime. */ -- cgit v1.2.3 From 6ff0ecfffcea4e7aa6301c54870ae97aa4a0cf72 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 1 Jun 2017 15:43:20 +1000 Subject: ports: Convert from using stmhal's input() to core provided version. --- cc3200/application.mk | 1 - cc3200/mpconfigport.h | 2 +- esp8266/Makefile | 1 - esp8266/mpconfigport.h | 2 +- stmhal/Makefile | 1 - stmhal/input.c | 44 -------------------------------------------- stmhal/mpconfigport.h | 2 +- teensy/Makefile | 1 - teensy/mpconfigport.h | 2 +- 9 files changed, 4 insertions(+), 52 deletions(-) delete mode 100644 stmhal/input.c (limited to 'cc3200') diff --git a/cc3200/application.mk b/cc3200/application.mk index 5d25424e1..1f54b764b 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -151,7 +151,6 @@ APP_LIB_SRC_C = $(addprefix lib/,\ APP_STM_SRC_C = $(addprefix stmhal/,\ bufhelper.c \ - input.c \ irq.c \ pybstdio.c \ ) diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 4d19900ae..4bd583a4b 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -80,6 +80,7 @@ #define MICROPY_VFS_FAT (1) #define MICROPY_PY_ASYNC_AWAIT (0) #define MICROPY_PY_ALL_SPECIAL_METHODS (1) +#define MICROPY_PY_BUILTINS_INPUT (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_TEXT cc3200_help_text #ifndef DEBUG @@ -142,7 +143,6 @@ // extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, \ // extra built in modules to add to the list of known ones diff --git a/esp8266/Makefile b/esp8266/Makefile index a3da9d398..cf4b288ca 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -94,7 +94,6 @@ SRC_C = \ STM_SRC_C = $(addprefix stmhal/,\ pybstdio.c \ - input.c \ ) EXTMOD_SRC_C = $(addprefix extmod/,\ diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index c286bdcdd..483f93d02 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -39,6 +39,7 @@ #define MICROPY_PY_BUILTINS_SLICE (1) #define MICROPY_PY_BUILTINS_SLICE_ATTRS (1) #define MICROPY_PY_BUILTINS_PROPERTY (1) +#define MICROPY_PY_BUILTINS_INPUT (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_TEXT esp_help_text #define MICROPY_PY_BUILTINS_HELP_MODULES (1) @@ -147,7 +148,6 @@ void *esp_native_code_commit(void*, size_t); // extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, // extra built in modules to add to the list of known ones diff --git a/stmhal/Makefile b/stmhal/Makefile index 09643be94..2d9d44afd 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -147,7 +147,6 @@ SRC_C = \ gccollect.c \ pybstdio.c \ help.c \ - input.c \ machine_i2c.c \ modmachine.c \ modpyb.c \ diff --git a/stmhal/input.c b/stmhal/input.c deleted file mode 100644 index c78525cc9..000000000 --- a/stmhal/input.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * 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/nlr.h" -#include "py/obj.h" -#include "lib/mp-readline/readline.h" - -STATIC mp_obj_t mp_builtin_input(uint n_args, const mp_obj_t *args) { - if (n_args == 1) { - mp_obj_print(args[0], PRINT_STR); - } - vstr_t line; - vstr_init(&line, 16); - int ret = readline(&line, ""); - if (line.len == 0 && ret == CHAR_CTRL_D) { - nlr_raise(mp_obj_new_exception(&mp_type_EOFError)); - } - return mp_obj_new_str_from_vstr(&mp_type_str, &line); -} - -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input); diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 444ce9303..ac3c1f247 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -87,6 +87,7 @@ #define MICROPY_PY_ALL_SPECIAL_METHODS (1) #define MICROPY_PY_BUILTINS_COMPILE (1) #define MICROPY_PY_BUILTINS_EXECFILE (1) +#define MICROPY_PY_BUILTINS_INPUT (1) #define MICROPY_PY_BUILTINS_POW3 (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_TEXT stmhal_help_text @@ -159,7 +160,6 @@ // extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, // extra built in modules to add to the list of known ones diff --git a/teensy/Makefile b/teensy/Makefile index 9f52cc3c7..923ea77ec 100644 --- a/teensy/Makefile +++ b/teensy/Makefile @@ -93,7 +93,6 @@ SRC_C = \ STM_SRC_C = $(addprefix stmhal/,\ gccollect.c \ - input.c \ irq.c \ pin.c \ pin_named_pins.c \ diff --git a/teensy/mpconfigport.h b/teensy/mpconfigport.h index 8c4022046..de30924d9 100644 --- a/teensy/mpconfigport.h +++ b/teensy/mpconfigport.h @@ -14,6 +14,7 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #define MICROPY_OPT_COMPUTED_GOTO (1) +#define MICROPY_PY_BUILTINS_INPUT (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_TEXT teensy_help_text @@ -31,7 +32,6 @@ // extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ // extra built in modules to add to the list of known ones extern const struct _mp_obj_module_t os_module; -- cgit v1.2.3