From 59a1201da959ab01895361c0b5bb8bc1409f2b39 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 14 Nov 2016 00:24:22 +0300 Subject: all: Remove readall() method, which is equivalent to read() w/o args. Its addition was due to an early exploration on how to add CPython-like stream interface. It's clear that it's not needed and just takes up bytes in all ports. --- cc3200/mods/modusocket.c | 3 +-- cc3200/mods/pybuart.c | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index 81a4c2e19..44e7f7f42 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -434,7 +434,6 @@ STATIC const mp_map_elem_t socket_locals_dict_table[] = { // stream methods { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_readall), (mp_obj_t)&mp_stream_readall_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj}, { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj }, @@ -446,7 +445,7 @@ STATIC mp_uint_t socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *e mod_network_socket_obj_t *self = self_in; mp_int_t ret = wlan_socket_recv(self, buf, size, errcode); if (ret < 0) { - // we need to ignore the socket closed error here because a readall() or read() without params + // we need to ignore the socket closed error here because a read() without params // only returns when the socket is closed by the other end if (*errcode != SL_ESECCLOSED) { ret = MP_STREAM_ERROR; diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index 493522f83..f6b917ab8 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -570,8 +570,6 @@ STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = { /// \method read([nbytes]) { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj }, - /// \method readall() - { MP_OBJ_NEW_QSTR(MP_QSTR_readall), (mp_obj_t)&mp_stream_readall_obj }, /// \method readline() { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj}, /// \method readinto(buf[, nbytes]) -- cgit v1.2.3 From aed3b5b7baa379b991be8d15f5a3e39ba90967a4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 14 Nov 2016 23:31:08 +1100 Subject: cc3200/tools/smoke.py: Change readall() to read(). --- cc3200/tools/smoke.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cc3200') diff --git a/cc3200/tools/smoke.py b/cc3200/tools/smoke.py index 20a837787..3ade11cf8 100644 --- a/cc3200/tools/smoke.py +++ b/cc3200/tools/smoke.py @@ -51,7 +51,7 @@ n_w = f.write(test_bytes) print(n_w == len(test_bytes)) f.close() f = open('test.txt', 'r') -r = bytes(f.readall(), 'ascii') +r = bytes(f.read(), 'ascii') # check that we can write and read it correctly print(r == test_bytes) f.close() -- cgit v1.2.3 From 7602dc5f327215d5d4b7f58852e53f3084d9ac15 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 26 Oct 2016 01:11:14 +0300 Subject: cc3200/pybspi: Remove static mode=SPI.MASTER parameter for latest HW API. Per the latest HW API, "SPI" class implements only master side of the protocol, so mode=SPI.MASTER (which was static for WiPy anyway) is not required (or allowed). This change is required to correspond to updated documentation of machine.SPI class which no longer lists "mode". --- cc3200/mods/pybspi.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mods/pybspi.c b/cc3200/mods/pybspi.c index 5a040e3f5..dd52e81b9 100644 --- a/cc3200/mods/pybspi.c +++ b/cc3200/mods/pybspi.c @@ -148,7 +148,7 @@ STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxda STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_spi_obj_t *self = self_in; if (self->baudrate > 0) { - mp_printf(print, "SPI(0, SPI.MASTER, baudrate=%u, bits=%u, polarity=%u, phase=%u, firstbit=SPI.MSB)", + mp_printf(print, "SPI(0, baudrate=%u, bits=%u, polarity=%u, phase=%u, firstbit=SPI.MSB)", self->baudrate, (self->wlen * 8), self->polarity, self->phase); } else { mp_print_str(print, "SPI(0)"); @@ -156,13 +156,8 @@ STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki } STATIC mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, const mp_arg_val_t *args) { - // verify that mode is master - if (args[0].u_int != SPI_MODE_MASTER) { - goto invalid_args; - } - uint bits; - switch (args[2].u_int) { + switch (args[1].u_int) { case 8: bits = SPI_WL_8; break; @@ -177,27 +172,27 @@ STATIC mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, const mp_arg_val_t *arg break; } - uint polarity = args[3].u_int; - uint phase = args[4].u_int; + uint polarity = args[2].u_int; + uint phase = args[3].u_int; if (polarity > 1 || phase > 1) { goto invalid_args; } - uint firstbit = args[5].u_int; + uint firstbit = args[4].u_int; if (firstbit != PYBSPI_FIRST_BIT_MSB) { goto invalid_args; } // build the configuration - self->baudrate = args[1].u_int; - self->wlen = args[2].u_int >> 3; + self->baudrate = args[0].u_int; + self->wlen = args[1].u_int >> 3; self->config = bits | SPI_CS_ACTIVELOW | SPI_SW_CTRL_CS | SPI_4PIN_MODE | SPI_TURBO_OFF; self->polarity = polarity; self->phase = phase; self->submode = (polarity << 1) | phase; // assign the pins - mp_obj_t pins_o = args[6].u_obj; + mp_obj_t pins_o = args[5].u_obj; if (pins_o != mp_const_none) { mp_obj_t *pins; if (pins_o == MP_OBJ_NULL) { @@ -223,7 +218,6 @@ invalid_args: static const mp_arg_t pyb_spi_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_mode, MP_ARG_INT, {.u_int = SPI_MODE_MASTER} }, { MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000000} }, // 1MHz { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} }, { MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, -- cgit v1.2.3 From 3f8bb80eb2da1c2b5228a69f7c580d0bc2d37219 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 15 Nov 2016 16:35:54 +1100 Subject: cc3200/mods/pybspi: Remove SPI.MASTER constant, it's no longer needed. --- cc3200/mods/pybspi.c | 1 - 1 file changed, 1 deletion(-) (limited to 'cc3200') diff --git a/cc3200/mods/pybspi.c b/cc3200/mods/pybspi.c index dd52e81b9..5841065db 100644 --- a/cc3200/mods/pybspi.c +++ b/cc3200/mods/pybspi.c @@ -373,7 +373,6 @@ STATIC const mp_map_elem_t pyb_spi_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_write_readinto), (mp_obj_t)&pyb_spi_write_readinto_obj }, // class constants - { MP_OBJ_NEW_QSTR(MP_QSTR_MASTER), MP_OBJ_NEW_SMALL_INT(SPI_MODE_MASTER) }, { MP_OBJ_NEW_QSTR(MP_QSTR_MSB), MP_OBJ_NEW_SMALL_INT(PYBSPI_FIRST_BIT_MSB) }, }; -- cgit v1.2.3 From 6b239c271c9c7041f9741c2a0f348f350808ad8a Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 16 Nov 2016 16:04:57 +1100 Subject: py: Factor out persistent-code reader into separate files. Implementations of persistent-code reader are provided for POSIX systems and systems using FatFS. Macros to use these are MICROPY_READER_POSIX and MICROPY_READER_FATFS respectively. If an alternative implementation is needed then a port can define the function mp_reader_new_file. --- cc3200/mpconfigport.h | 1 + esp8266/esp8266.ld | 1 + esp8266/esp8266_512k.ld | 1 + esp8266/mpconfigport.h | 1 + examples/embedding/mpconfigport_minimal.h | 1 + extmod/vfs_fat_reader.c | 88 ++++++++++++++++++ py/mpconfig.h | 10 ++ py/persistentcode.c | 129 +++----------------------- py/persistentcode.h | 10 +- py/py.mk | 2 + py/reader.c | 146 ++++++++++++++++++++++++++++++ py/reader.h | 45 +++++++++ stmhal/mpconfigport.h | 1 + unix/mpconfigport.h | 1 + 14 files changed, 316 insertions(+), 121 deletions(-) create mode 100644 extmod/vfs_fat_reader.c create mode 100644 py/reader.c create mode 100644 py/reader.h (limited to 'cc3200') diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index bf3e691bd..08f926f40 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -55,6 +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) #ifndef DEBUG // we need ram on the launchxl while debugging #define MICROPY_CPYTHON_COMPAT (1) #else diff --git a/esp8266/esp8266.ld b/esp8266/esp8266.ld index 546ffd8c5..a6a4b930b 100644 --- a/esp8266/esp8266.ld +++ b/esp8266/esp8266.ld @@ -92,6 +92,7 @@ SECTIONS *py/formatfloat.o*(.literal* .text*) *py/frozenmod.o*(.literal* .text*) *py/gc.o*(.literal* .text*) + *py/reader*.o*(.literal* .text*) *py/lexer*.o*(.literal* .text*) *py/malloc*.o*(.literal* .text*) *py/map*.o*(.literal* .text*) diff --git a/esp8266/esp8266_512k.ld b/esp8266/esp8266_512k.ld index e744d0f46..2bffcab80 100644 --- a/esp8266/esp8266_512k.ld +++ b/esp8266/esp8266_512k.ld @@ -92,6 +92,7 @@ SECTIONS *py/formatfloat.o*(.literal* .text*) *py/frozenmod.o*(.literal* .text*) *py/gc.o*(.literal* .text*) + *py/reader*.o*(.literal* .text*) *py/lexer*.o*(.literal* .text*) *py/malloc*.o*(.literal* .text*) *py/map*.o*(.literal* .text*) diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index 602b3e9c8..adbec5d0d 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -16,6 +16,7 @@ #define MICROPY_MEM_STATS (0) #define MICROPY_DEBUG_PRINTERS (1) #define MICROPY_DEBUG_PRINTER_DEST mp_debug_print +#define MICROPY_READER_FATFS (1) #define MICROPY_ENABLE_GC (1) #define MICROPY_STACK_CHECK (1) #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) diff --git a/examples/embedding/mpconfigport_minimal.h b/examples/embedding/mpconfigport_minimal.h index 90011b3f8..48d200858 100644 --- a/examples/embedding/mpconfigport_minimal.h +++ b/examples/embedding/mpconfigport_minimal.h @@ -33,6 +33,7 @@ #define MICROPY_COMP_CONST (0) #define MICROPY_MEM_STATS (0) #define MICROPY_DEBUG_PRINTERS (0) +#define MICROPY_READER_POSIX (1) #define MICROPY_HELPER_REPL (1) #define MICROPY_HELPER_LEXER_UNIX (1) #define MICROPY_ENABLE_SOURCE_LINE (0) diff --git a/extmod/vfs_fat_reader.c b/extmod/vfs_fat_reader.c new file mode 100644 index 000000000..7a00f18de --- /dev/null +++ b/extmod/vfs_fat_reader.c @@ -0,0 +1,88 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2016 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/mperrno.h" +#include "py/reader.h" + +#if MICROPY_READER_FATFS + +#include "lib/fatfs/ff.h" +#include "extmod/vfs_fat_file.h" + +typedef struct _mp_reader_fatfs_t { + FIL fp; + uint16_t len; + uint16_t pos; + byte buf[20]; +} mp_reader_fatfs_t; + +STATIC mp_uint_t mp_reader_fatfs_readbyte(void *data) { + mp_reader_fatfs_t *reader = (mp_reader_fatfs_t*)data; + if (reader->pos >= reader->len) { + if (reader->len < sizeof(reader->buf)) { + return MP_READER_EOF; + } else { + UINT n; + f_read(&reader->fp, reader->buf, sizeof(reader->buf), &n); + if (n == 0) { + return MP_READER_EOF; + } + reader->len = n; + reader->pos = 0; + } + } + return reader->buf[reader->pos++]; +} + +STATIC void mp_reader_fatfs_close(void *data) { + mp_reader_fatfs_t *reader = (mp_reader_fatfs_t*)data; + f_close(&reader->fp); + m_del_obj(mp_reader_fatfs_t, reader); +} + +int mp_reader_new_file(mp_reader_t *reader, const char *filename) { + mp_reader_fatfs_t *rf = m_new_obj_maybe(mp_reader_fatfs_t); + if (rf == NULL) { + return MP_ENOMEM; + } + FRESULT res = f_open(&rf->fp, filename, FA_READ); + if (res != FR_OK) { + return fresult_to_errno_table[res]; + } + UINT n; + f_read(&rf->fp, rf->buf, sizeof(rf->buf), &n); + rf->len = n; + rf->pos = 0; + reader->data = rf; + reader->readbyte = mp_reader_fatfs_readbyte; + reader->close = mp_reader_fatfs_close; + return 0; // success +} + +#endif diff --git a/py/mpconfig.h b/py/mpconfig.h index 3945a1a5a..1980e649c 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -381,6 +381,16 @@ /*****************************************************************************/ /* Python internal features */ +// Whether to use the POSIX reader for importing files +#ifndef MICROPY_READER_POSIX +#define MICROPY_READER_POSIX (0) +#endif + +// Whether to use the FatFS reader for importing files +#ifndef MICROPY_READER_FATFS +#define MICROPY_READER_FATFS (0) +#endif + // Hook for the VM at the start of the opcode loop (can contain variable // definitions usable by the other hook functions) #ifndef MICROPY_VM_HOOK_INIT diff --git a/py/persistentcode.c b/py/persistentcode.c index 31f147a09..99b01f8e2 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -29,6 +29,7 @@ #include #include +#include "py/reader.h" #include "py/emitglue.h" #include "py/persistentcode.h" #include "py/bc.h" @@ -98,19 +99,19 @@ STATIC void extract_prelude(const byte **ip, const byte **ip2, bytecode_prelude_ #include "py/bc0.h" STATIC int read_byte(mp_reader_t *reader) { - return reader->read_byte(reader->data); + return reader->readbyte(reader->data); } STATIC void read_bytes(mp_reader_t *reader, byte *buf, size_t len) { while (len-- > 0) { - *buf++ = reader->read_byte(reader->data); + *buf++ = reader->readbyte(reader->data); } } STATIC mp_uint_t read_uint(mp_reader_t *reader) { mp_uint_t unum = 0; for (;;) { - byte b = reader->read_byte(reader->data); + byte b = reader->readbyte(reader->data); unum = (unum << 7) | (b & 0x7f); if ((b & 0x80) == 0) { break; @@ -214,128 +215,28 @@ mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader) { if (header[2] != MPY_FEATURE_FLAGS || header[3] > mp_small_int_bits()) { mp_raise_ValueError("incompatible .mpy file"); } - return load_raw_code(reader); -} - -typedef struct _mp_mem_reader_t { - const byte *cur; - const byte *end; -} mp_mem_reader_t; - -STATIC mp_uint_t mp_mem_reader_next_byte(void *br_in) { - mp_mem_reader_t *br = br_in; - if (br->cur < br->end) { - return *br->cur++; - } else { - return (mp_uint_t)-1; - } + mp_raw_code_t *rc = load_raw_code(reader); + reader->close(reader->data); + return rc; } mp_raw_code_t *mp_raw_code_load_mem(const byte *buf, size_t len) { - mp_mem_reader_t mr = {buf, buf + len}; - mp_reader_t reader = {&mr, mp_mem_reader_next_byte}; - return mp_raw_code_load(&reader); -} - -// here we define mp_raw_code_load_file depending on the port -// TODO abstract this away properly - -#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || defined(__unix__) -// unix file reader - -#include -#include -#include - -typedef struct _mp_lexer_file_buf_t { - int fd; - byte buf[20]; - mp_uint_t len; - mp_uint_t pos; -} mp_lexer_file_buf_t; - -STATIC mp_uint_t file_buf_next_byte(void *fb_in) { - mp_lexer_file_buf_t *fb = fb_in; - if (fb->pos >= fb->len) { - if (fb->len == 0) { - return (mp_uint_t)-1; - } else { - int n = read(fb->fd, fb->buf, sizeof(fb->buf)); - if (n <= 0) { - fb->len = 0; - return (mp_uint_t)-1; - } - fb->len = n; - fb->pos = 0; - } - } - return fb->buf[fb->pos++]; -} - -mp_raw_code_t *mp_raw_code_load_file(const char *filename) { - mp_lexer_file_buf_t fb; - fb.fd = open(filename, O_RDONLY, 0644); - int n = read(fb.fd, fb.buf, sizeof(fb.buf)); - fb.len = n; - fb.pos = 0; mp_reader_t reader; - reader.data = &fb; - reader.read_byte = file_buf_next_byte; - mp_raw_code_t *rc = mp_raw_code_load(&reader); - close(fb.fd); - return rc; -} - -#elif defined(__thumb2__) || defined(__xtensa__) -// fatfs file reader (assume thumb2 arch uses fatfs...) - -#include "lib/fatfs/ff.h" - -typedef struct _mp_lexer_file_buf_t { - FIL fp; - byte buf[20]; - uint16_t len; - uint16_t pos; -} mp_lexer_file_buf_t; - -STATIC mp_uint_t file_buf_next_byte(void *fb_in) { - mp_lexer_file_buf_t *fb = fb_in; - if (fb->pos >= fb->len) { - if (fb->len < sizeof(fb->buf)) { - return (mp_uint_t)-1; - } else { - UINT n; - f_read(&fb->fp, fb->buf, sizeof(fb->buf), &n); - if (n == 0) { - return (mp_uint_t)-1; - } - fb->len = n; - fb->pos = 0; - } + if (!mp_reader_new_mem(&reader, buf, len, 0)) { + m_malloc_fail(BYTES_PER_WORD); // we need to raise a MemoryError } - return fb->buf[fb->pos++]; + return mp_raw_code_load(&reader); } mp_raw_code_t *mp_raw_code_load_file(const char *filename) { - mp_lexer_file_buf_t fb; - /*FRESULT res =*/ f_open(&fb.fp, filename, FA_READ); - UINT n; - f_read(&fb.fp, fb.buf, sizeof(fb.buf), &n); - fb.len = n; - fb.pos = 0; - mp_reader_t reader; - reader.data = &fb; - reader.read_byte = file_buf_next_byte; - mp_raw_code_t *rc = mp_raw_code_load(&reader); - - f_close(&fb.fp); - - return rc; + int ret = mp_reader_new_file(&reader, filename); + if (ret != 0) { + mp_raise_OSError(ret); + } + return mp_raw_code_load(&reader); } -#endif - #endif // MICROPY_PERSISTENT_CODE_LOAD #if MICROPY_PERSISTENT_CODE_SAVE diff --git a/py/persistentcode.h b/py/persistentcode.h index 8859bc577..d04e0b633 100644 --- a/py/persistentcode.h +++ b/py/persistentcode.h @@ -26,13 +26,9 @@ #ifndef MICROPY_INCLUDED_PY_PERSISTENTCODE_H #define MICROPY_INCLUDED_PY_PERSISTENTCODE_H -#include "py/obj.h" - -typedef struct _mp_reader_t { - void *data; - mp_uint_t (*read_byte)(void *data); - void (*close)(void *data); -} mp_reader_t; +#include "py/mpprint.h" +#include "py/reader.h" +#include "py/emitglue.h" mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader); mp_raw_code_t *mp_raw_code_load_mem(const byte *buf, size_t len); diff --git a/py/py.mk b/py/py.mk index b0962d178..4630c21a9 100644 --- a/py/py.mk +++ b/py/py.mk @@ -113,6 +113,7 @@ PY_O_BASENAME = \ mpprint.o \ unicode.o \ mpz.o \ + reader.o \ lexer.o \ lexerstr.o \ lexerunix.o \ @@ -228,6 +229,7 @@ PY_O_BASENAME = \ ../extmod/vfs_fat_ffconf.o \ ../extmod/vfs_fat_diskio.o \ ../extmod/vfs_fat_file.o \ + ../extmod/vfs_fat_reader.o \ ../extmod/vfs_fat_lexer.o \ ../extmod/vfs_fat_misc.o \ ../extmod/utime_mphal.o \ diff --git a/py/reader.c b/py/reader.c new file mode 100644 index 000000000..d14fc416c --- /dev/null +++ b/py/reader.c @@ -0,0 +1,146 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2016 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/mperrno.h" +#include "py/reader.h" + +typedef struct _mp_reader_mem_t { + size_t free_len; // if >0 mem is freed on close by: m_free(beg, free_len) + const byte *beg; + const byte *cur; + const byte *end; +} mp_reader_mem_t; + +STATIC mp_uint_t mp_reader_mem_readbyte(void *data) { + mp_reader_mem_t *reader = (mp_reader_mem_t*)data; + if (reader->cur < reader->end) { + return *reader->cur++; + } else { + return MP_READER_EOF; + } +} + +STATIC void mp_reader_mem_close(void *data) { + mp_reader_mem_t *reader = (mp_reader_mem_t*)data; + if (reader->free_len > 0) { + m_del(char, (char*)reader->beg, reader->free_len); + } + m_del_obj(mp_reader_mem_t, reader); +} + +bool mp_reader_new_mem(mp_reader_t *reader, const byte *buf, size_t len, size_t free_len) { + mp_reader_mem_t *rm = m_new_obj_maybe(mp_reader_mem_t); + if (rm == NULL) { + return false; + } + rm->free_len = free_len; + rm->beg = buf; + rm->cur = buf; + rm->end = buf + len; + reader->data = rm; + reader->readbyte = mp_reader_mem_readbyte; + reader->close = mp_reader_mem_close; + return true; +} + +#if MICROPY_READER_POSIX + +#include +#include +#include +#include + +typedef struct _mp_reader_posix_t { + bool close_fd; + int fd; + size_t len; + size_t pos; + byte buf[20]; +} mp_reader_posix_t; + +STATIC mp_uint_t mp_reader_posix_readbyte(void *data) { + mp_reader_posix_t *reader = (mp_reader_posix_t*)data; + if (reader->pos >= reader->len) { + if (reader->len == 0) { + return MP_READER_EOF; + } else { + int n = read(reader->fd, reader->buf, sizeof(reader->buf)); + if (n <= 0) { + reader->len = 0; + return MP_READER_EOF; + } + reader->len = n; + reader->pos = 0; + } + } + return reader->buf[reader->pos++]; +} + +STATIC void mp_reader_posix_close(void *data) { + mp_reader_posix_t *reader = (mp_reader_posix_t*)data; + if (reader->close_fd) { + close(reader->fd); + } + m_del_obj(mp_reader_posix_t, reader); +} + +STATIC int mp_reader_new_file_from_fd(mp_reader_t *reader, int fd, bool close_fd) { + mp_reader_posix_t *rp = m_new_obj_maybe(mp_reader_posix_t); + if (rp == NULL) { + if (close_fd) { + close(fd); + } + return MP_ENOMEM; + } + rp->close_fd = close_fd; + rp->fd = fd; + int n = read(rp->fd, rp->buf, sizeof(rp->buf)); + if (n == -1) { + if (close_fd) { + close(fd); + } + return errno; + } + rp->len = n; + rp->pos = 0; + reader->data = rp; + reader->readbyte = mp_reader_posix_readbyte; + reader->close = mp_reader_posix_close; + return 0; // success +} + +int mp_reader_new_file(mp_reader_t *reader, const char *filename) { + int fd = open(filename, O_RDONLY, 0644); + if (fd < 0) { + return errno; + } + return mp_reader_new_file_from_fd(reader, fd, true); +} + +#endif diff --git a/py/reader.h b/py/reader.h new file mode 100644 index 000000000..f39cc90f8 --- /dev/null +++ b/py/reader.h @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2016 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_PY_READER_H +#define MICROPY_INCLUDED_PY_READER_H + +#include "py/obj.h" + +// the readbyte function must return the next byte in the input stream +// it must return MP_READER_EOF if end of stream +// it can be called again after returning MP_READER_EOF, and in that case must return MP_READER_EOF +#define MP_READER_EOF ((mp_uint_t)(-1)) + +typedef struct _mp_reader_t { + void *data; + mp_uint_t (*readbyte)(void *data); + void (*close)(void *data); +} mp_reader_t; + +bool mp_reader_new_mem(mp_reader_t *reader, const byte *buf, size_t len, size_t free_len); +int mp_reader_new_file(mp_reader_t *reader, const char *filename); + +#endif // MICROPY_INCLUDED_PY_READER_H diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 264db3029..3eec0fcce 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -51,6 +51,7 @@ #define MICROPY_OPT_COMPUTED_GOTO (1) #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0) #define MICROPY_OPT_MPZ_BITWISE (1) +#define MICROPY_READER_FATFS (1) // fatfs configuration used in ffconf.h #define MICROPY_FATFS_ENABLE_LFN (1) diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index f4f8d2d20..86e460566 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -54,6 +54,7 @@ // Printing debug to stderr may give tests which // check stdout a chance to pass, etc. #define MICROPY_DEBUG_PRINTER_DEST mp_stderr_print +#define MICROPY_READER_POSIX (1) #define MICROPY_USE_READLINE_HISTORY (1) #define MICROPY_HELPER_REPL (1) #define MICROPY_REPL_EMACS_KEYS (1) -- cgit v1.2.3 From e5ef15a9d7bead2a60009caedbc128a8906c7ecd Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 16 Nov 2016 16:25:06 +1100 Subject: py/lexer: Provide generic mp_lexer_new_from_file based on mp_reader. If a port defines MICROPY_READER_POSIX or MICROPY_READER_FATFS then lexer.c now provides an implementation of mp_lexer_new_from_file using the mp_reader_new_file function. --- cc3200/application.mk | 1 - esp8266/main.c | 8 ++--- esp8266/mpconfigport.h | 2 +- extmod/vfs_fat_lexer.c | 83 -------------------------------------------------- py/lexer.c | 13 ++++++++ py/lexerunix.c | 8 ----- py/py.mk | 1 - stmhal/Makefile | 1 - stmhal/lexerfatfs.c | 35 --------------------- teensy/lexerfatfs.c | 15 --------- 10 files changed, 16 insertions(+), 151 deletions(-) delete mode 100644 extmod/vfs_fat_lexer.c delete mode 100644 stmhal/lexerfatfs.c delete mode 100644 teensy/lexerfatfs.c (limited to 'cc3200') diff --git a/cc3200/application.mk b/cc3200/application.mk index 300262c97..3ebc4b0d3 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -162,7 +162,6 @@ APP_STM_SRC_C = $(addprefix stmhal/,\ import.c \ input.c \ irq.c \ - lexerfatfs.c \ moduselect.c \ pybstdio.c \ ) diff --git a/esp8266/main.c b/esp8266/main.c index a2e747d21..5087c7d6a 100644 --- a/esp8266/main.c +++ b/esp8266/main.c @@ -109,17 +109,13 @@ void user_init(void) { system_init_done_cb(init_done); } -mp_lexer_t *fat_vfs_lexer_new_from_file(const char *filename); mp_import_stat_t fat_vfs_import_stat(const char *path); +#if !MICROPY_VFS_FAT mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - #if MICROPY_VFS_FAT - return fat_vfs_lexer_new_from_file(filename); - #else - (void)filename; return NULL; - #endif } +#endif mp_import_stat_t mp_import_stat(const char *path) { #if MICROPY_VFS_FAT diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index adbec5d0d..cc0b22986 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -16,7 +16,7 @@ #define MICROPY_MEM_STATS (0) #define MICROPY_DEBUG_PRINTERS (1) #define MICROPY_DEBUG_PRINTER_DEST mp_debug_print -#define MICROPY_READER_FATFS (1) +#define MICROPY_READER_FATFS (MICROPY_VFS_FAT) #define MICROPY_ENABLE_GC (1) #define MICROPY_STACK_CHECK (1) #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) diff --git a/extmod/vfs_fat_lexer.c b/extmod/vfs_fat_lexer.c deleted file mode 100644 index 91acdb830..000000000 --- a/extmod/vfs_fat_lexer.c +++ /dev/null @@ -1,83 +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/mpconfig.h" -// *_ADHOC part is for cc3200 port which doesn't use general uPy -// infrastructure and instead duplicates code. TODO: Resolve. -#if MICROPY_VFS_FAT || MICROPY_FSUSERMOUNT || MICROPY_FSUSERMOUNT_ADHOC - -#include "py/lexer.h" -#include "lib/fatfs/ff.h" - -typedef struct _mp_lexer_file_buf_t { - FIL fp; - byte buf[20]; - uint16_t len; - uint16_t pos; -} mp_lexer_file_buf_t; - -STATIC mp_uint_t file_buf_next_byte(mp_lexer_file_buf_t *fb) { - if (fb->pos >= fb->len) { - if (fb->len < sizeof(fb->buf)) { - return MP_LEXER_EOF; - } else { - UINT n; - f_read(&fb->fp, fb->buf, sizeof(fb->buf), &n); - if (n == 0) { - return MP_LEXER_EOF; - } - fb->len = n; - fb->pos = 0; - } - } - return fb->buf[fb->pos++]; -} - -STATIC void file_buf_close(mp_lexer_file_buf_t *fb) { - f_close(&fb->fp); - m_del_obj(mp_lexer_file_buf_t, fb); -} - -mp_lexer_t *fat_vfs_lexer_new_from_file(const char *filename); - -mp_lexer_t *fat_vfs_lexer_new_from_file(const char *filename) { - mp_lexer_file_buf_t *fb = m_new_obj_maybe(mp_lexer_file_buf_t); - if (fb == NULL) { - return NULL; - } - FRESULT res = f_open(&fb->fp, filename, FA_READ); - if (res != FR_OK) { - m_del_obj(mp_lexer_file_buf_t, fb); - return NULL; - } - UINT n; - f_read(&fb->fp, fb->buf, sizeof(fb->buf), &n); - fb->len = n; - fb->pos = 0; - return mp_lexer_new(qstr_from_str(filename), fb, (mp_lexer_stream_next_byte_t)file_buf_next_byte, (mp_lexer_stream_close_t)file_buf_close); -} - -#endif // MICROPY_VFS_FAT diff --git a/py/lexer.c b/py/lexer.c index f1be77805..d3e61b3b4 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -759,6 +759,19 @@ mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, mp_uint_t return mp_lexer_new(src_name, reader.data, (mp_lexer_stream_next_byte_t)reader.readbyte, (mp_lexer_stream_close_t)reader.close); } +#if MICROPY_READER_POSIX || MICROPY_READER_FATFS + +mp_lexer_t *mp_lexer_new_from_file(const char *filename) { + mp_reader_t reader; + int ret = mp_reader_new_file(&reader, filename); + if (ret != 0) { + return NULL; + } + return mp_lexer_new(qstr_from_str(filename), reader.data, (mp_lexer_stream_next_byte_t)reader.readbyte, (mp_lexer_stream_close_t)reader.close); +} + +#endif + void mp_lexer_free(mp_lexer_t *lex) { if (lex) { if (lex->stream_close) { diff --git a/py/lexerunix.c b/py/lexerunix.c index e8f8994a6..9e3755e76 100644 --- a/py/lexerunix.c +++ b/py/lexerunix.c @@ -85,12 +85,4 @@ mp_lexer_t *mp_lexer_new_from_fd(qstr filename, int fd, bool close_fd) { return mp_lexer_new(filename, fb, (mp_lexer_stream_next_byte_t)file_buf_next_byte, (mp_lexer_stream_close_t)file_buf_close); } -mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - int fd = open(filename, O_RDONLY); - if (fd < 0) { - return NULL; - } - return mp_lexer_new_from_fd(qstr_from_str(filename), fd, true); -} - #endif // MICROPY_HELPER_LEXER_UNIX diff --git a/py/py.mk b/py/py.mk index 1557e07b7..1683b7b4b 100644 --- a/py/py.mk +++ b/py/py.mk @@ -229,7 +229,6 @@ PY_O_BASENAME = \ ../extmod/vfs_fat_diskio.o \ ../extmod/vfs_fat_file.o \ ../extmod/vfs_fat_reader.o \ - ../extmod/vfs_fat_lexer.o \ ../extmod/vfs_fat_misc.o \ ../extmod/utime_mphal.o \ ../extmod/uos_dupterm.o \ diff --git a/stmhal/Makefile b/stmhal/Makefile index 59199ea0a..c08484db1 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -154,7 +154,6 @@ SRC_C = \ modusocket.c \ modnetwork.c \ import.c \ - lexerfatfs.c \ extint.c \ usrsw.c \ rng.c \ diff --git a/stmhal/lexerfatfs.c b/stmhal/lexerfatfs.c deleted file mode 100644 index fd7f62dfd..000000000 --- a/stmhal/lexerfatfs.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the MicroPython 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/lexer.h" - -mp_lexer_t *fat_vfs_lexer_new_from_file(const char *filename); - -// TODO: Instead of such shims, probably better to let port #define -// mp_lexer_new_from_file to a function it wants to use. -mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - return fat_vfs_lexer_new_from_file(filename); -} diff --git a/teensy/lexerfatfs.c b/teensy/lexerfatfs.c deleted file mode 100644 index 84245f887..000000000 --- a/teensy/lexerfatfs.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -#include "misc.h" -#include "mpconfig.h" -#include "qstr.h" -#include "lexer.h" -typedef int FIL; -#include "../stmhal/lexerfatfs.h" - -mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - printf("import not implemented\n"); - return NULL; -} - -- cgit v1.2.3 From f14e9187accfbaddad9ca682670181e379d1a652 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 21 Nov 2016 01:08:15 +0300 Subject: cc3200: Update for moduselect moved to extmod/. --- cc3200/application.mk | 1 - cc3200/mpconfigport.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'cc3200') diff --git a/cc3200/application.mk b/cc3200/application.mk index 3ebc4b0d3..ff5c44cd6 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -162,7 +162,6 @@ APP_STM_SRC_C = $(addprefix stmhal/,\ import.c \ input.c \ irq.c \ - moduselect.c \ pybstdio.c \ ) diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 08f926f40..7a8aa15d5 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -113,6 +113,7 @@ #define MICROPY_PY_URE (1) #define MICROPY_PY_UHEAPQ (0) #define MICROPY_PY_UHASHLIB (0) +#define MICROPY_PY_USELECT (1) #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) -- cgit v1.2.3 From 304cfda8c466920b1d29903bfca8bca5ed110f3b Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Dec 2016 16:37:29 +1100 Subject: py/stream: Move ad-hoc ioctl constants to stream.h and rename them. The constants MP_IOCTL_POLL_xxx, which were stmhal-specific, are moved from stmhal/pybioctl.h (now deleted) to py/stream.h. And they are renamed to MP_STREAM_POLL_xxx to be consistent with other such constants. All uses of these constants have been updated. --- cc3200/mods/modwlan.c | 15 +++++++-------- cc3200/mods/pybuart.c | 11 +++++------ extmod/moduselect.c | 32 ++++++++++++++++---------------- py/stream.h | 6 ++++++ stmhal/can.c | 12 ++++++------ stmhal/modnwcc3k.c | 17 ++++++++--------- stmhal/pybioctl.h | 8 -------- stmhal/uart.c | 11 +++++------ stmhal/usb.c | 17 ++++++++--------- 9 files changed, 61 insertions(+), 68 deletions(-) delete mode 100644 stmhal/pybioctl.h (limited to 'cc3200') diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index 4b3dd4ec3..c1af5879f 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -45,7 +45,6 @@ #include "modnetwork.h" #include "modusocket.h" #include "modwlan.h" -#include "pybioctl.h" #include "pybrtc.h" #include "debug.h" #if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP) @@ -1461,7 +1460,7 @@ int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int 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_IOCTL_POLL) { + if (request == MP_STREAM_POLL) { mp_uint_t flags = arg; ret = 0; int32_t sd = s->sock_base.sd; @@ -1473,13 +1472,13 @@ int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t FD_ZERO(&xfds); // set fds if needed - if (flags & MP_IOCTL_POLL_RD) { + if (flags & MP_STREAM_POLL_RD) { FD_SET(sd, &rfds); } - if (flags & MP_IOCTL_POLL_WR) { + if (flags & MP_STREAM_POLL_WR) { FD_SET(sd, &wfds); } - if (flags & MP_IOCTL_POLL_HUP) { + if (flags & MP_STREAM_POLL_HUP) { FD_SET(sd, &xfds); } @@ -1497,13 +1496,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)) { - ret |= MP_IOCTL_POLL_RD; + ret |= MP_STREAM_POLL_RD; } if (FD_ISSET(sd, &wfds)) { - ret |= MP_IOCTL_POLL_WR; + ret |= MP_STREAM_POLL_WR; } if (FD_ISSET(sd, &xfds)) { - ret |= MP_IOCTL_POLL_HUP; + ret |= MP_STREAM_POLL_HUP; } } else { *_errno = EINVAL; diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index f6b917ab8..9dc4f0a00 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -46,7 +46,6 @@ #include "uart.h" #include "pybuart.h" #include "mpirq.h" -#include "pybioctl.h" #include "pybsleep.h" #include "mpexception.h" #include "py/mpstate.h" @@ -630,14 +629,14 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t a mp_uint_t ret; uart_check_init(self); - if (request == MP_IOCTL_POLL) { + if (request == MP_STREAM_POLL) { mp_uint_t flags = arg; ret = 0; - if ((flags & MP_IOCTL_POLL_RD) && uart_rx_any(self)) { - ret |= MP_IOCTL_POLL_RD; + if ((flags & MP_STREAM_POLL_RD) && uart_rx_any(self)) { + ret |= MP_STREAM_POLL_RD; } - if ((flags & MP_IOCTL_POLL_WR) && MAP_UARTSpaceAvail(self->reg)) { - ret |= MP_IOCTL_POLL_WR; + if ((flags & MP_STREAM_POLL_WR) && MAP_UARTSpaceAvail(self->reg)) { + ret |= MP_STREAM_POLL_WR; } } else { *errcode = EINVAL; diff --git a/extmod/moduselect.c b/extmod/moduselect.c index 8765ca2b0..2fc19cdf0 100644 --- a/extmod/moduselect.c +++ b/extmod/moduselect.c @@ -32,9 +32,9 @@ #include "py/runtime.h" #include "py/obj.h" #include "py/objlist.h" +#include "py/stream.h" #include "py/mperrno.h" #include "py/mphal.h" -#include "pybioctl.h" // Flags for poll() #define FLAG_ONESHOT (1) @@ -87,7 +87,7 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, mp_uint_t *rwx_num) { poll_obj_t *poll_obj = (poll_obj_t*)poll_map->table[i].value; int errcode; - mp_int_t ret = poll_obj->ioctl(poll_obj->obj, MP_IOCTL_POLL, poll_obj->flags, &errcode); + mp_int_t ret = poll_obj->ioctl(poll_obj->obj, MP_STREAM_POLL, poll_obj->flags, &errcode); poll_obj->flags_ret = ret; if (ret == -1) { @@ -99,13 +99,13 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, mp_uint_t *rwx_num) { // object is ready n_ready += 1; if (rwx_num != NULL) { - if (ret & MP_IOCTL_POLL_RD) { + if (ret & MP_STREAM_POLL_RD) { rwx_num[0] += 1; } - if (ret & MP_IOCTL_POLL_WR) { + if (ret & MP_STREAM_POLL_WR) { rwx_num[1] += 1; } - if ((ret & ~(MP_IOCTL_POLL_RD | MP_IOCTL_POLL_WR)) != 0) { + if ((ret & ~(MP_STREAM_POLL_RD | MP_STREAM_POLL_WR)) != 0) { rwx_num[2] += 1; } } @@ -141,9 +141,9 @@ STATIC mp_obj_t select_select(uint n_args, const mp_obj_t *args) { // merge separate lists and get the ioctl function for each object mp_map_t poll_map; mp_map_init(&poll_map, rwx_len[0] + rwx_len[1] + rwx_len[2]); - poll_map_add(&poll_map, r_array, rwx_len[0], MP_IOCTL_POLL_RD, true); - poll_map_add(&poll_map, w_array, rwx_len[1], MP_IOCTL_POLL_WR, true); - poll_map_add(&poll_map, x_array, rwx_len[2], MP_IOCTL_POLL_ERR | MP_IOCTL_POLL_HUP, true); + poll_map_add(&poll_map, r_array, rwx_len[0], MP_STREAM_POLL_RD, true); + poll_map_add(&poll_map, w_array, rwx_len[1], MP_STREAM_POLL_WR, true); + poll_map_add(&poll_map, x_array, rwx_len[2], MP_STREAM_POLL_ERR | MP_STREAM_POLL_HUP, true); mp_uint_t start_tick = mp_hal_ticks_ms(); rwx_len[0] = rwx_len[1] = rwx_len[2] = 0; @@ -163,13 +163,13 @@ STATIC mp_obj_t select_select(uint n_args, const mp_obj_t *args) { continue; } poll_obj_t *poll_obj = (poll_obj_t*)poll_map.table[i].value; - if (poll_obj->flags_ret & MP_IOCTL_POLL_RD) { + if (poll_obj->flags_ret & MP_STREAM_POLL_RD) { ((mp_obj_list_t*)list_array[0])->items[rwx_len[0]++] = poll_obj->obj; } - if (poll_obj->flags_ret & MP_IOCTL_POLL_WR) { + if (poll_obj->flags_ret & MP_STREAM_POLL_WR) { ((mp_obj_list_t*)list_array[1])->items[rwx_len[1]++] = poll_obj->obj; } - if ((poll_obj->flags_ret & ~(MP_IOCTL_POLL_RD | MP_IOCTL_POLL_WR)) != 0) { + if ((poll_obj->flags_ret & ~(MP_STREAM_POLL_RD | MP_STREAM_POLL_WR)) != 0) { ((mp_obj_list_t*)list_array[2])->items[rwx_len[2]++] = poll_obj->obj; } } @@ -195,7 +195,7 @@ STATIC mp_obj_t poll_register(uint n_args, const mp_obj_t *args) { if (n_args == 3) { flags = mp_obj_get_int(args[2]); } else { - flags = MP_IOCTL_POLL_RD | MP_IOCTL_POLL_WR; + flags = MP_STREAM_POLL_RD | MP_STREAM_POLL_WR; } poll_map_add(&self->poll_map, &args[1], 1, flags, false); return mp_const_none; @@ -300,10 +300,10 @@ STATIC const mp_map_elem_t mp_module_select_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_uselect) }, { MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_select_select_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_poll), (mp_obj_t)&mp_select_poll_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_POLLIN), MP_OBJ_NEW_SMALL_INT(MP_IOCTL_POLL_RD) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_POLLOUT), MP_OBJ_NEW_SMALL_INT(MP_IOCTL_POLL_WR) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_POLLERR), MP_OBJ_NEW_SMALL_INT(MP_IOCTL_POLL_ERR) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_POLLHUP), MP_OBJ_NEW_SMALL_INT(MP_IOCTL_POLL_HUP) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_POLLIN), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_RD) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_POLLOUT), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_WR) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_POLLERR), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_ERR) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_POLLHUP), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_HUP) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_table); diff --git a/py/stream.h b/py/stream.h index 94002e252..01199ab60 100644 --- a/py/stream.h +++ b/py/stream.h @@ -42,6 +42,12 @@ #define MP_STREAM_GET_DATA_OPTS (8) // Get data/message options #define MP_STREAM_SET_DATA_OPTS (9) // Set data/message options +// These poll ioctl values are compatible with Linux +#define MP_STREAM_POLL_RD (0x0001) +#define MP_STREAM_POLL_WR (0x0004) +#define MP_STREAM_POLL_ERR (0x0008) +#define MP_STREAM_POLL_HUP (0x0010) + // Argument structure for MP_STREAM_SEEK struct mp_stream_seek_t { mp_off_t offset; diff --git a/stmhal/can.c b/stmhal/can.c index a8ec7930e..3157bfadc 100644 --- a/stmhal/can.c +++ b/stmhal/can.c @@ -32,11 +32,11 @@ #include "py/objtuple.h" #include "py/runtime.h" #include "py/gc.h" +#include "py/stream.h" #include "py/mperrno.h" #include "py/mphal.h" #include "bufhelper.h" #include "can.h" -#include "pybioctl.h" #include "irq.h" #if MICROPY_HW_ENABLE_CAN @@ -807,16 +807,16 @@ STATIC MP_DEFINE_CONST_DICT(pyb_can_locals_dict, pyb_can_locals_dict_table); mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) { pyb_can_obj_t *self = self_in; mp_uint_t ret; - if (request == MP_IOCTL_POLL) { + if (request == MP_STREAM_POLL) { mp_uint_t flags = arg; ret = 0; - if ((flags & MP_IOCTL_POLL_RD) + if ((flags & MP_STREAM_POLL_RD) && ((__HAL_CAN_MSG_PENDING(&self->can, CAN_FIFO0) != 0) || (__HAL_CAN_MSG_PENDING(&self->can, CAN_FIFO1) != 0))) { - ret |= MP_IOCTL_POLL_RD; + ret |= MP_STREAM_POLL_RD; } - if ((flags & MP_IOCTL_POLL_WR) && (self->can.Instance->TSR & CAN_TSR_TME)) { - ret |= MP_IOCTL_POLL_WR; + if ((flags & MP_STREAM_POLL_WR) && (self->can.Instance->TSR & CAN_TSR_TME)) { + ret |= MP_STREAM_POLL_WR; } } else { *errcode = MP_EINVAL; diff --git a/stmhal/modnwcc3k.c b/stmhal/modnwcc3k.c index 591057602..dcef1f99b 100644 --- a/stmhal/modnwcc3k.c +++ b/stmhal/modnwcc3k.c @@ -41,7 +41,6 @@ #include "pin.h" #include "genhdr/pins.h" #include "spi.h" -#include "pybioctl.h" #include "hci.h" #include "socket.h" @@ -354,7 +353,7 @@ STATIC int cc3k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_t ti STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno) { mp_uint_t ret; - if (request == MP_IOCTL_POLL) { + if (request == MP_STREAM_POLL) { mp_uint_t flags = arg; ret = 0; int fd = socket->u_state; @@ -366,19 +365,19 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request FD_ZERO(&xfds); // set fds if needed - if (flags & MP_IOCTL_POLL_RD) { + if (flags & MP_STREAM_POLL_RD) { FD_SET(fd, &rfds); // A socked that just closed is available for reading. A call to // recv() returns 0 which is consistent with BSD. if (cc3k_get_fd_closed_state(fd)) { - ret |= MP_IOCTL_POLL_RD; + ret |= MP_STREAM_POLL_RD; } } - if (flags & MP_IOCTL_POLL_WR) { + if (flags & MP_STREAM_POLL_WR) { FD_SET(fd, &wfds); } - if (flags & MP_IOCTL_POLL_HUP) { + if (flags & MP_STREAM_POLL_HUP) { FD_SET(fd, &xfds); } @@ -396,13 +395,13 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request // check return of select if (FD_ISSET(fd, &rfds)) { - ret |= MP_IOCTL_POLL_RD; + ret |= MP_STREAM_POLL_RD; } if (FD_ISSET(fd, &wfds)) { - ret |= MP_IOCTL_POLL_WR; + ret |= MP_STREAM_POLL_WR; } if (FD_ISSET(fd, &xfds)) { - ret |= MP_IOCTL_POLL_HUP; + ret |= MP_STREAM_POLL_HUP; } } else { *_errno = MP_EINVAL; diff --git a/stmhal/pybioctl.h b/stmhal/pybioctl.h deleted file mode 100644 index b71e04ed5..000000000 --- a/stmhal/pybioctl.h +++ /dev/null @@ -1,8 +0,0 @@ -#define MP_IOCTL_POLL (0x100 | 1) - -// These values are compatible with Linux, which are in turn -// compatible with iBCS2 spec. -#define MP_IOCTL_POLL_RD (0x0001) -#define MP_IOCTL_POLL_WR (0x0004) -#define MP_IOCTL_POLL_ERR (0x0008) -#define MP_IOCTL_POLL_HUP (0x0010) diff --git a/stmhal/uart.c b/stmhal/uart.c index 37c1906c1..b16cf3481 100644 --- a/stmhal/uart.c +++ b/stmhal/uart.c @@ -34,7 +34,6 @@ #include "py/mperrno.h" #include "py/mphal.h" #include "uart.h" -#include "pybioctl.h" #include "irq.h" //TODO: Add UART7/8 support for MCU_SERIES_F7 @@ -901,14 +900,14 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) { pyb_uart_obj_t *self = self_in; mp_uint_t ret; - if (request == MP_IOCTL_POLL) { + if (request == MP_STREAM_POLL) { mp_uint_t flags = arg; ret = 0; - if ((flags & MP_IOCTL_POLL_RD) && uart_rx_any(self)) { - ret |= MP_IOCTL_POLL_RD; + if ((flags & MP_STREAM_POLL_RD) && uart_rx_any(self)) { + ret |= MP_STREAM_POLL_RD; } - if ((flags & MP_IOCTL_POLL_WR) && __HAL_UART_GET_FLAG(&self->uart, UART_FLAG_TXE)) { - ret |= MP_IOCTL_POLL_WR; + if ((flags & MP_STREAM_POLL_WR) && __HAL_UART_GET_FLAG(&self->uart, UART_FLAG_TXE)) { + ret |= MP_STREAM_POLL_WR; } } else { *errcode = MP_EINVAL; diff --git a/stmhal/usb.c b/stmhal/usb.c index dd6daf8e5..b0a66ef9b 100644 --- a/stmhal/usb.c +++ b/stmhal/usb.c @@ -40,7 +40,6 @@ #include "py/mperrno.h" #include "bufhelper.h" #include "usb.h" -#include "pybioctl.h" #if defined(USE_USB_FS) #define USB_PHY_ID USB_PHY_FS_ID @@ -502,14 +501,14 @@ STATIC mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) { mp_uint_t ret; - if (request == MP_IOCTL_POLL) { + if (request == MP_STREAM_POLL) { mp_uint_t flags = arg; ret = 0; - if ((flags & MP_IOCTL_POLL_RD) && USBD_CDC_RxNum() > 0) { - ret |= MP_IOCTL_POLL_RD; + if ((flags & MP_STREAM_POLL_RD) && USBD_CDC_RxNum() > 0) { + ret |= MP_STREAM_POLL_RD; } - if ((flags & MP_IOCTL_POLL_WR) && USBD_CDC_TxHalfEmpty()) { - ret |= MP_IOCTL_POLL_WR; + if ((flags & MP_STREAM_POLL_WR) && USBD_CDC_TxHalfEmpty()) { + ret |= MP_STREAM_POLL_WR; } } else { *errcode = MP_EINVAL; @@ -632,11 +631,11 @@ STATIC MP_DEFINE_CONST_DICT(pyb_usb_hid_locals_dict, pyb_usb_hid_locals_dict_tab STATIC mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) { mp_uint_t ret; - if (request == MP_IOCTL_POLL) { + if (request == MP_STREAM_POLL) { mp_uint_t flags = arg; ret = 0; - if ((flags & MP_IOCTL_POLL_WR) && USBD_HID_CanSendReport(&hUSBDDevice)) { - ret |= MP_IOCTL_POLL_WR; + if ((flags & MP_STREAM_POLL_WR) && USBD_HID_CanSendReport(&hUSBDDevice)) { + ret |= MP_STREAM_POLL_WR; } } else { *errcode = MP_EINVAL; -- cgit v1.2.3 From 2d329c4a56580e17781febbfe6e42038fc3d9d03 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Dec 2016 16:40:39 +1100 Subject: extmod/moduselect: Use configurable EVENT_POLL_HOOK instead of WFI. To make moduselect be usable by any port. --- cc3200/mpconfigport.h | 1 + extmod/moduselect.c | 4 ++-- stmhal/mpconfigport.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'cc3200') diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 7a8aa15d5..5b6a035d5 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -194,6 +194,7 @@ typedef long mp_off_t; #define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq() #define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state) +#define MICROPY_EVENT_POLL_HOOK __WFI(); // assembly functions to handle critical sections, interrupt // disabling/enabling and sleep mode enter/exit diff --git a/extmod/moduselect.c b/extmod/moduselect.c index a19901e17..5b00f6bad 100644 --- a/extmod/moduselect.c +++ b/extmod/moduselect.c @@ -172,7 +172,7 @@ STATIC mp_obj_t select_select(uint n_args, const mp_obj_t *args) { mp_map_deinit(&poll_map); return mp_obj_new_tuple(3, list_array); } - __WFI(); + MICROPY_EVENT_POLL_HOOK } } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_select_obj, 3, 4, select_select); @@ -264,7 +264,7 @@ STATIC mp_obj_t poll_poll(uint n_args, const mp_obj_t *args) { } return ret_list; } - __WFI(); + MICROPY_EVENT_POLL_HOOK } } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_poll_obj, 1, 3, poll_poll); diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index ed9e26f37..81959555c 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -262,6 +262,7 @@ static inline mp_uint_t disable_irq(void) { #define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq() #define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state) +#define MICROPY_EVENT_POLL_HOOK __WFI(); // There is no classical C heap in bare-metal ports, only Python // garbage-collected heap. For completeness, emulate C heap via -- cgit v1.2.3 From 25f44c19f17085a09ad0f857c6ccc0d33d7c0344 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 27 Dec 2016 01:00:12 +0300 Subject: cc3200: Re-add support for UART REPL (MICROPY_STDIO_UART setting). UART REPL support was lost in os.dupterm() refactorings, etc. As os.dupterm() is there, implement UART REPL support at the high level - if MICROPY_STDIO_UART is set, make default boot.py contain os.dupterm() call for a UART. This means that changing MICROPY_STDIO_UART value will also require erasing flash on a module to force boot.py re-creation. --- cc3200/mptask.c | 7 ++++++- py/misc.h | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'cc3200') diff --git a/cc3200/mptask.c b/cc3200/mptask.c index eb673b08c..3c34ceeca 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -98,7 +98,12 @@ static FATFS *sflash_fatfs; 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" - "# can run arbitrary Python, but best to keep it minimal\r\n"; + "# can run arbitrary Python, but best to keep it minimal\r\n" + #if MICROPY_STDIO_UART + "import os, machine\r\n" + "os.dupterm(machine.UART(0, " MP_STRINGIFY(MICROPY_STDIO_UART_BAUD) "))\r\n" + #endif + ; /****************************************************************************** DECLARE PUBLIC FUNCTIONS diff --git a/py/misc.h b/py/misc.h index 7584bc017..146b9a8e4 100644 --- a/py/misc.h +++ b/py/misc.h @@ -46,6 +46,10 @@ typedef unsigned int uint; #define MAX(x, y) ((x) > (y) ? (x) : (y)) #endif +// Classical double-indirection stringification of preprocessor macro's value +#define _MP_STRINGIFY(x) #x +#define MP_STRINGIFY(x) _MP_STRINGIFY(x) + /** memory allocation ******************************************/ // TODO make a lazy m_renew that can increase by a smaller amount than requested (but by at least 1 more element) -- cgit v1.2.3 From 076b80467b74cbdfca5585d43e01a01ba4f8ff9c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 28 Dec 2016 14:43:34 +0300 Subject: cc3200: Enable UART REPL by default. To allow access and testing without complex access methods like WiFi. Enabled for both WiPy and TI LaunchXL. --- cc3200/boards/LAUNCHXL/mpconfigboard.h | 2 +- cc3200/boards/WIPY/mpconfigboard.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'cc3200') diff --git a/cc3200/boards/LAUNCHXL/mpconfigboard.h b/cc3200/boards/LAUNCHXL/mpconfigboard.h index ac7b41f5d..32ef5290b 100644 --- a/cc3200/boards/LAUNCHXL/mpconfigboard.h +++ b/cc3200/boards/LAUNCHXL/mpconfigboard.h @@ -32,7 +32,7 @@ #define MICROPY_HW_ANTENNA_DIVERSITY (0) -#define MICROPY_STDIO_UART 0 +#define MICROPY_STDIO_UART 1 #define MICROPY_STDIO_UART_BAUD 115200 #define MICROPY_SYS_LED_PRCM PRCM_GPIOA1 diff --git a/cc3200/boards/WIPY/mpconfigboard.h b/cc3200/boards/WIPY/mpconfigboard.h index 57fdc9a60..9f04dbf23 100644 --- a/cc3200/boards/WIPY/mpconfigboard.h +++ b/cc3200/boards/WIPY/mpconfigboard.h @@ -32,6 +32,9 @@ #define MICROPY_HW_ANTENNA_DIVERSITY (1) +#define MICROPY_STDIO_UART 1 +#define MICROPY_STDIO_UART_BAUD 115200 + #define MICROPY_SYS_LED_PRCM PRCM_GPIOA3 #define MICROPY_SAFE_BOOT_PRCM PRCM_GPIOA3 #define MICROPY_SYS_LED_PORT GPIOA3_BASE -- cgit v1.2.3 From 514b82900c02808b8ad9bf5ecaa0e5bff270b33c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 28 Dec 2016 21:43:53 +0300 Subject: cc3200/README: (Re)add information about accessing REPL on serial. --- cc3200/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'cc3200') diff --git a/cc3200/README.md b/cc3200/README.md index 2fa39d670..34e177b50 100644 --- a/cc3200/README.md +++ b/cc3200/README.md @@ -60,6 +60,19 @@ Once the software is running, you have two options to access the MicroPython REP * Use your favourite telnet client with the following settings: **host = 192.168.1.1, port = 23.** * Log in with **user = "micro" and password = "python"** +- Thru UART (serial). + * This is enabled by default in the standard configuration, for UART0 (speed 115200). + * For CC3200-LAUNCHXL, you will need to configure Linux `ftdi_sio` driver as described + in the [blog post](http://www.achanceofbrainshowers.com/blog/tech/2014/8/19/cc3200-development-under-linux/). + After that, connecting a board will create two `/dev/ttyUSB*` devices, a serial + console is available on the 2nd one (usually `/dev/ttyUSB1`). + * WiPy doesn't have onboard USB-UART converter, so you will need an external one, + connected to GPIO01 (Tx) and GPIO02 (Rx). + * Usage of UART port for REPL is controlled by MICROPY_STDIO_UART setting (and + is done at the high level, using a suitable call to `os.dupterm()` function + in boot.py, so you can override it at runtime regardless of MICROPY_STDIO_UART + setting). + The board has a small file system of 192K (WiPy) or 64K (Launchpad) located in the serial flash connected to the CC3200. SD cards are also supported, you can connect any SD card and configure the pinout using the SD class API. -- cgit v1.2.3 From 45a8cc8f0b29f447eba6047112f38780ca8a89da Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 29 Dec 2016 01:23:09 +0300 Subject: cc3200: make: Rename "deploy" target to "deploy-ota". There should be target to deploy uPy over wired (UART) connection, and wired and OTA targets should be named differently. --- cc3200/README.md | 19 ++++++++++--------- cc3200/application.mk | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'cc3200') diff --git a/cc3200/README.md b/cc3200/README.md index 34e177b50..313153608 100644 --- a/cc3200/README.md +++ b/cc3200/README.md @@ -40,15 +40,6 @@ there. Make sure to use a **v4.1 (or higer) LAUNCHXL board** when trying this po - Flash the latest service pack (servicepack_1.0.0.10.0.bin) using the "Service Pack Update" button. - Close CCS_Uniflash, remove the SOP2 jumper and reset the board. -## Updating the board to with new software version -- Make sure the board is running and connected to the same network as the computer. - -```bash -make BTARGET=application BTYPE=release BOARD=LAUNCHXL WIPY_IP=192.168.1.1 WIPY_USER=micro WIPY_PWD=python deploy -``` - -If `WIPY_IP`, `WIPY_USER` or `WIPY_PWD` are omitted the default values (the ones shown above) will be used. - ## Playing with MicroPython and the CC3200: Once the software is running, you have two options to access the MicroPython REPL: @@ -97,6 +88,16 @@ import machine machine.reset() ``` +There's a script which automates this process from the host side: + +- Make sure the board is running and connected to the same network as the computer. + +```bash +make BTARGET=application BTYPE=release BOARD=LAUNCHXL WIPY_IP=192.168.1.1 WIPY_USER=micro WIPY_PWD=python deploy-ota +``` + +If `WIPY_IP`, `WIPY_USER` or `WIPY_PWD` are omitted the default values (the ones shown above) will be used. + ### Note regarding FileZilla: Do not use the quick connect button, instead, open the site manager and create a new configuration. In the "General" tab make diff --git a/cc3200/application.mk b/cc3200/application.mk index ff5c44cd6..f2801c337 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -206,9 +206,9 @@ WIPY_PWD ?= 'python' all: $(BUILD)/mcuimg.bin -.PHONY: deploy +.PHONY: deploy-ota -deploy: $(BUILD)/mcuimg.bin +deploy-ota: $(BUILD)/mcuimg.bin $(ECHO) "Writing $< to the board" $(Q)$(PYTHON) $(UPDATE_WIPY) --verify --ip $(WIPY_IP) --user $(WIPY_USER) --password $(WIPY_PWD) --file $< -- cgit v1.2.3 From 0748143a4c648ad7bcdbbf125d039ceb7490f4e6 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 29 Dec 2016 16:57:00 +0300 Subject: cc3200: Add targets to erase flash, deploy firmware using cc3200tool. cc3200tool, https://github.com/ALLTERCO/cc3200tool is a (mostly, some binary blobs present) open-source, Linux-friendly tool to flash a cc3200 devices. It's an alternative to fully proprietary, Windows-only Uniflash from TI. The provided make targets are for erasing flash, flashing the uPy bootloader and firmware, and flashing vendor's WiFi firmware "servicepacks" (the latter needs to be downloaded from vendor side, a link is present inside Makefile). --- cc3200/Makefile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'cc3200') diff --git a/cc3200/Makefile b/cc3200/Makefile index 7623d20e7..1798ac927 100644 --- a/cc3200/Makefile +++ b/cc3200/Makefile @@ -8,6 +8,9 @@ endif # Make 'release' the default build type BTYPE ?= release +# Port for flashing firmware +PORT ?= /dev/ttyUSB1 + # If the build directory is not given, make it reflect the board name. BUILD ?= build/$(BOARD)/$(BTYPE) @@ -23,6 +26,9 @@ CFLAGS += -Iboards/$(BOARD) LDFLAGS = -Wl,-nostdlib -Wl,--gc-sections -Wl,-Map=$@.map +FLASH_SIZE_WIPY = 2M +FLASH_SIZE_LAUNCHXL = 1M + ifeq ($(BTARGET), application) # qstr definitions (must come before including py.mk) QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h @@ -39,3 +45,18 @@ endif # always include MicroPython make rules include ../py/mkrules.mk + +erase: + cc3200tool -p $(PORT) format_flash --size $(FLASH_SIZE_$(BOARD)) + +deploy: + cc3200tool -p $(PORT) \ + write_file bootmgr/build/$(BOARD)/$(BTYPE)/bootloader.bin /sys/mcuimg.bin \ + write_file build/$(BOARD)/$(BTYPE)/mcuimg.bin /sys/factimg.bin + +# Files *.ucf and *ucf.signed.bin come from CC3200SDK-SERVICEPACK +# package from http://www.ti.com/tool/cc3200sdk +servicepack: + cc3200tool -p $(PORT) \ + write_file --file-size=0x20000 --signature ota_1.0.1.6-2.7.0.0.ucf.signed.bin \ + ota_1.0.1.6-2.7.0.0.ucf /sys/servicepack.ucf -- cgit v1.2.3 From b315d76b6b76a81a11d1456fa43e195b711e406b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 29 Dec 2016 19:39:42 +0300 Subject: cc3200/README: Reorganize and update to the current state of affairs. Try to put sections in more logical order, and information about cc3200tool to be the default flashing method. --- cc3200/README.md | 103 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 31 deletions(-) (limited to 'cc3200') diff --git a/cc3200/README.md b/cc3200/README.md index 313153608..753fd450a 100644 --- a/cc3200/README.md +++ b/cc3200/README.md @@ -1,36 +1,66 @@ -# Build Instructions for the CC3200 +MicroPython port to CC3200 WiFi SoC +=================================== -Currently the CC3200 port of MicroPython builds under Linux and OSX **but not under Windows**. +This is a MicroPython port to Texas Instruments CC3200 WiFi SoC (ARM Cortex-M4 +architecture). This port supports 2 boards: WiPy and TI CC3200-LAUNCHXL. -The tool chain required for the build can be found at . +## Build Instructions for the CC3200 -In order to download the image to the CC3200 you will need the CCS_Uniflash tool from TI, which at this -moment is only available for Windows, so, you need Linux/OSX to build and Windows to flash the image. +Currently the CC3200 port of MicroPython builds under Linux and OSX, +but not under Windows. -## To build an image suitable for debugging: +The toolchain required for the build can be found at +. + +In order to flash the image to the CC3200 you will need the +[cc3200tool](https://github.com/ALLTERCO/cc3200tool). An alternative is +to use CCS_Uniflash tool from TI, which works only under Windows, and all +support is provided by TI itself. + +Building the bootloader: + +``` +make BTARGET=bootloader BTYPE=release BOARD=LAUNCHXL +``` + +Building the "release" image: -In order to debug the port specific code, optimizations need to be disabled on the -port file (check the Makefile for specific details). You can use CCS from TI. -Use the CC3200.ccxml file supplied with this distribution for the debuuger configuration. -```bash -make BTARGET=application BTYPE=debug BOARD=LAUNCHXL ``` -## To build an image suitable to be flashed to the device: -```bash make BTARGET=application BTYPE=release BOARD=LAUNCHXL ``` -## Building the bootloader -```bash -make BTARGET=bootloader BTYPE=release BOARD=LAUNCHXL + +To build an image suitable for debugging: + +In order to debug the port specific code, optimizations need to be disabled on the +port file (check the Makefile for specific details). You can use CCS from TI. +Use the CC3200.ccxml file supplied with this distribution for the debuuger configuration. + +``` +make BTARGET=application BTYPE=debug BOARD=LAUNCHXL ``` -## 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. +## Flashing the CC3200-LAUNCHXL + +Note that WiPy comes factory programmed with a default version of MicroPython, +it cannot be programmed via serial, and can be upgraded only with OTA (see +below). -## Flashing the CC3200 - Make sure that you have built both the *bootloader* and the *application* in **release** mode. - Make sure the SOP2 jumper is in position. +- Make sure you Linux system recognized the board and created `ttyUSB*` + devices (see below for configuration of `ftdi_sio` driver). +- Run "make erase" and immediately press Reset button on the device. +- Wait few seconds. +- Run "make deploy" and immediately press Reset button on the device. +- You are recommended to install the latest vendor WiFi firmware + servicepack from http://www.ti.com/tool/cc3200sdk. Download + CC3200SDK-SERVICEPACK package, install it, and locate `ota_*.ucf` + and `ota_*.ucf.signed.bin` files. Copy them to the port's directory + and run "make servicepack", with immediate press of Reset button. +- Remove the SOP2 jumper and reset the board. + +Flashing process using TI Uniflash: + - Open CCS_Uniflash and connect to the board (by default on port 22). - Format the serial flash (select 1MB size in case of the CC3200-LAUNCHXL, 2MB in case of the WiPy, leave the rest unchecked). - Mark the following files for erasing: `/cert/ca.pem`, `/cert/client.pem`, `/cert/private.key` and `/tmp/pac.bin`. @@ -44,14 +74,14 @@ there. Make sure to use a **v4.1 (or higer) LAUNCHXL board** when trying this po Once the software is running, you have two options to access the MicroPython REPL: -- Through telnet. +- Through telnet. * Connect to the network created by the board (as boots up in AP mode), **ssid = "wipy-wlan", key = "www.wipy.io"**. * You can also reinitialize the WLAN in station mode and connect to another AP, or in AP mode but with a different ssid and/or key. * Use your favourite telnet client with the following settings: **host = 192.168.1.1, port = 23.** * Log in with **user = "micro" and password = "python"** -- Thru UART (serial). +- Through UART (serial). * This is enabled by default in the standard configuration, for UART0 (speed 115200). * For CC3200-LAUNCHXL, you will need to configure Linux `ftdi_sio` driver as described in the [blog post](http://www.achanceofbrainshowers.com/blog/tech/2014/8/19/cc3200-development-under-linux/). @@ -72,15 +102,19 @@ SD cards are also supported, you can connect any SD card and configure the pinou To upload your MicroPython scripts to the FTP server, open your FTP client of choice and connect to: **ftp://192.168.1.1, user = "micro", password = "python"** -I have tested the FTP server with **FileZilla, FireFTP, FireFox, IE and Chrome,** other clients should work as well, but I am -not 100% sure of it. +Tested FTP clients are: FileZilla, FireFTP, FireFox, IE and Chrome. Other +clients should work as well, but you may need to configure them to use a +single connection (this should be the default for any compliant FTP client). -## Upgrading the firmware Over The Air: +## Upgrading the firmware Over The Air (OTA) -OTA software updates can be performed through the FTP server. After building a new **mcuimg.bin** in release mode, upload it to: -`/flash/sys/mcuimg.bin` it will take around 6s (The TI simplelink file system is quite slow because every file is mirrored for -safety). You won't see the file being stored inside `/flash/sys/` because it's actually saved bypassing FatFS, but rest assured that -the file was successfully transferred, and it has been signed with a MD5 checksum to verify its integrity. +OTA software updates can be performed through the builtin FTP server. After +building a new `mcuimg.bin` in release mode, upload it to: +`/flash/sys/mcuimg.bin`. It will take around 6s (The TI SimpleLink file +system is quite slow because every file is mirrored for safety). You won't +see the file being stored inside `/flash/sys/` because it's actually saved +bypassing FatFS, but rest assured that the file was successfully transferred, +and it has been signed with a MD5 checksum to verify its integrity. Now, reset the MCU by pressing the switch on the board, or by typing: ```python @@ -98,10 +132,17 @@ make BTARGET=application BTYPE=release BOARD=LAUNCHXL WIPY_IP=192.168.1.1 WIPY_U If `WIPY_IP`, `WIPY_USER` or `WIPY_PWD` are omitted the default values (the ones shown above) will be used. -### Note regarding FileZilla: + +## Notes and known issues + +## 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. + +### Note regarding FileZilla Do not use the quick connect button, instead, open the site manager and create a new configuration. In the "General" tab make sure that encryption is set to: "Only use plain FTP (insecure)". In the Transfer Settings tab limit the max number of connections to one, otherwise FileZilla will try to open a second command connection when retrieving and saving files, and for simplicity and to reduce code size, only one command and one data connections are possible. - -- cgit v1.2.3 From eac22e29a5844e5aa5c865c2e73900e6ef039ad6 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 4 Jan 2017 16:10:42 +0300 Subject: all: Consistently update signatures of .make_new and .call methods. Otherwise, they serve reoccurring source of copy-paste mistakes and breaking nanbox build. --- cc3200/misc/mpirq.c | 2 +- cc3200/mods/modnetwork.c | 2 +- cc3200/mods/moduhashlib.c | 2 +- cc3200/mods/modusocket.c | 2 +- cc3200/mods/modwlan.c | 2 +- cc3200/mods/pybadc.c | 4 ++-- cc3200/mods/pybi2c.c | 2 +- cc3200/mods/pybpin.c | 4 ++-- cc3200/mods/pybrtc.c | 2 +- cc3200/mods/pybsd.c | 4 ++-- cc3200/mods/pybspi.c | 2 +- cc3200/mods/pybtimer.c | 2 +- cc3200/mods/pybuart.c | 2 +- cc3200/mods/pybwdt.c | 2 +- esp8266/machine_adc.c | 2 +- esp8266/machine_pin.c | 4 ++-- esp8266/machine_rtc.c | 2 +- esp8266/machine_wdt.c | 2 +- esp8266/modmachine.c | 2 +- extmod/modlwip.c | 5 ++--- stmhal/accel.c | 2 +- stmhal/adc.c | 4 ++-- stmhal/can.c | 2 +- stmhal/dac.c | 2 +- stmhal/extint.c | 2 +- stmhal/i2c.c | 2 +- stmhal/lcd.c | 2 +- stmhal/led.c | 2 +- stmhal/modnwcc3k.c | 2 +- stmhal/modnwwiznet5k.c | 2 +- stmhal/modusocket.c | 2 +- stmhal/pin.c | 4 ++-- stmhal/rtc.c | 2 +- stmhal/servo.c | 2 +- stmhal/spi.c | 2 +- stmhal/timer.c | 2 +- stmhal/uart.c | 2 +- stmhal/usb.c | 4 ++-- stmhal/usrsw.c | 4 ++-- teensy/timer.c | 2 +- unix/modjni.c | 4 ++-- 41 files changed, 51 insertions(+), 52 deletions(-) (limited to 'cc3200') diff --git a/cc3200/misc/mpirq.c b/cc3200/misc/mpirq.c index 4389ab0c3..be5746759 100644 --- a/cc3200/misc/mpirq.c +++ b/cc3200/misc/mpirq.c @@ -176,7 +176,7 @@ STATIC mp_obj_t mp_irq_flags (mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags); -STATIC mp_obj_t mp_irq_call (mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_irq_handler (self_in); return mp_const_none; diff --git a/cc3200/mods/modnetwork.c b/cc3200/mods/modnetwork.c index f98d9a88a..89d61e939 100644 --- a/cc3200/mods/modnetwork.c +++ b/cc3200/mods/modnetwork.c @@ -91,7 +91,7 @@ STATIC const mp_arg_t network_server_args[] = { { MP_QSTR_login, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/moduhashlib.c b/cc3200/mods/moduhashlib.c index 46f30be21..c22cc8a06 100644 --- a/cc3200/mods/moduhashlib.c +++ b/cc3200/mods/moduhashlib.c @@ -121,7 +121,7 @@ STATIC mp_obj_t hash_read (mp_obj_t self_in) { /// \classmethod \constructor([data[, block_size]]) /// initial data must be given if block_size wants to be passed -STATIC mp_obj_t hash_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t hash_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 2, false); mp_obj_hash_t *self = m_new0(mp_obj_hash_t, 1); self->base.type = type_in; diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index 44e7f7f42..9554c2608 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -127,7 +127,7 @@ void modusocket_close_all_user_sockets (void) { // socket class // constructor socket(family=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP, fileno=None) -STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); // create socket object diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index c1af5879f..5e825a627 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -829,7 +829,7 @@ STATIC const mp_arg_t wlan_init_args[] = { { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, { MP_QSTR_antenna, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = ANTENNA_TYPE_INTERNAL} }, }; -STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +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 mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybadc.c b/cc3200/mods/pybadc.c index f8c9b3da5..e63bebbd0 100644 --- a/cc3200/mods/pybadc.c +++ b/cc3200/mods/pybadc.c @@ -140,7 +140,7 @@ STATIC const mp_arg_t pyb_adc_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 12} }, }; -STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); @@ -289,7 +289,7 @@ STATIC mp_obj_t adc_channel_value(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_value_obj, adc_channel_value); -STATIC mp_obj_t adc_channel_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t adc_channel_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); return adc_channel_value (self_in); } diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c index d92782d8a..32451802d 100644 --- a/cc3200/mods/pybi2c.c +++ b/cc3200/mods/pybi2c.c @@ -332,7 +332,7 @@ STATIC const mp_arg_t pyb_i2c_init_args[] = { { 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, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +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) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c index f59e65fc2..ac0ecef25 100644 --- a/cc3200/mods/pybpin.c +++ b/cc3200/mods/pybpin.c @@ -647,7 +647,7 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t mp_printf(print, ", alt=%d)", alt); } -STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Run an argument through the mapper and return the result. @@ -747,7 +747,7 @@ STATIC mp_obj_t pin_drive(mp_uint_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_drive_obj, 1, 2, pin_drive); -STATIC mp_obj_t pin_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_t _args[2] = {self_in, *args}; return pin_value (n_args + 1, _args); diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c index 4662edbe7..db00f4939 100644 --- a/cc3200/mods/pybrtc.c +++ b/cc3200/mods/pybrtc.c @@ -285,7 +285,7 @@ STATIC const mp_arg_t pyb_rtc_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_datetime, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c index d7efbe872..b8d5b4cc1 100644 --- a/cc3200/mods/pybsd.c +++ b/cc3200/mods/pybsd.c @@ -64,7 +64,7 @@ STATIC const mp_obj_t pyb_sd_def_pin[3] = {&pin_GP10, &pin_GP11, &pin_GP15}; DECLARE PRIVATE FUNCTIONS ******************************************************************************/ STATIC void pyb_sd_hw_init (pybsd_obj_t *self); -STATIC mp_obj_t pyb_sd_make_new (const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args); +STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in); /****************************************************************************** @@ -123,7 +123,7 @@ STATIC const mp_arg_t pyb_sd_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_pins, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_sd_make_new (const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybspi.c b/cc3200/mods/pybspi.c index 5841065db..6fc7ee62d 100644 --- a/cc3200/mods/pybspi.c +++ b/cc3200/mods/pybspi.c @@ -225,7 +225,7 @@ static const mp_arg_t pyb_spi_init_args[] = { { MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = PYBSPI_FIRST_BIT_MSB} }, { MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybtimer.c b/cc3200/mods/pybtimer.c index 2ac71cccb..0eeb6eefd 100644 --- a/cc3200/mods/pybtimer.c +++ b/cc3200/mods/pybtimer.c @@ -322,7 +322,7 @@ error: mp_raise_ValueError(mpexception_value_invalid_arguments); } -STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_timer_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, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index 9dc4f0a00..fe710be92 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -442,7 +442,7 @@ STATIC const mp_arg_t pyb_uart_init_args[] = { { MP_QSTR_stop, MP_ARG_INT, {.u_int = 1} }, { MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybwdt.c b/cc3200/mods/pybwdt.c index 30478c83c..b4c847268 100644 --- a/cc3200/mods/pybwdt.c +++ b/cc3200/mods/pybwdt.c @@ -92,7 +92,7 @@ STATIC const mp_arg_t pyb_wdt_init_args[] = { { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_timeout, MP_ARG_INT, {.u_int = 5000} }, // 5 s }; -STATIC mp_obj_t pyb_wdt_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t pyb_wdt_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // check the arguments mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/esp8266/machine_adc.c b/esp8266/machine_adc.c index 26b28c50b..f1fb5be31 100644 --- a/esp8266/machine_adc.c +++ b/esp8266/machine_adc.c @@ -42,7 +42,7 @@ typedef struct _pyb_adc_obj_t { STATIC pyb_adc_obj_t pyb_adc_vdd3 = {{&pyb_adc_type}, true}; STATIC pyb_adc_obj_t pyb_adc_adc = {{&pyb_adc_type}, false}; -STATIC mp_obj_t pyb_adc_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, +STATIC mp_obj_t pyb_adc_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); diff --git a/esp8266/machine_pin.c b/esp8266/machine_pin.c index 205c58aae..e10b2cfb7 100644 --- a/esp8266/machine_pin.c +++ b/esp8266/machine_pin.c @@ -276,7 +276,7 @@ STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, mp_uint_t n_args, c } // constructor(id, ...) -STATIC mp_obj_t pyb_pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // get the wanted pin object @@ -300,7 +300,7 @@ STATIC mp_obj_t pyb_pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp } // fast method for getting/setting pin value -STATIC mp_obj_t pyb_pin_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); pyb_pin_obj_t *self = self_in; if (n_args == 0) { diff --git a/esp8266/machine_rtc.c b/esp8266/machine_rtc.c index 54eeea6f6..8c1fe0779 100644 --- a/esp8266/machine_rtc.c +++ b/esp8266/machine_rtc.c @@ -78,7 +78,7 @@ void mp_hal_rtc_init(void) { pyb_rtc_alarm0_expiry = 0; } -STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_rtc_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); diff --git a/esp8266/machine_wdt.c b/esp8266/machine_wdt.c index 6dc4c0d18..83b5e8f32 100644 --- a/esp8266/machine_wdt.c +++ b/esp8266/machine_wdt.c @@ -41,7 +41,7 @@ typedef struct _machine_wdt_obj_t { STATIC machine_wdt_obj_t wdt_default = {{&esp_wdt_type}}; -STATIC mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_int_t id = 0; diff --git a/esp8266/modmachine.c b/esp8266/modmachine.c index a92362ce6..a5073d96c 100644 --- a/esp8266/modmachine.c +++ b/esp8266/modmachine.c @@ -147,7 +147,7 @@ STATIC void esp_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ mp_printf(print, "Timer(%p)", &self->timer); } -STATIC mp_obj_t esp_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t esp_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); esp_timer_obj_t *tim = m_new_obj(esp_timer_obj_t); tim->base.type = &esp_timer_type; diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 5bd498dcf..62699bd41 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -114,7 +114,7 @@ u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len) { } // constructor lwip.slip(device=integer, iplocal=string, ipremote=string) -STATIC mp_obj_t lwip_slip_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t lwip_slip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 3, 3, false); lwip_slip_obj.base.type = &lwip_slip_type; @@ -578,8 +578,7 @@ STATIC void lwip_socket_print(const mp_print_t *print, mp_obj_t self_in, mp_prin } // FIXME: Only supports two arguments at present -STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, mp_uint_t n_args, - mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); lwip_socket_obj_t *socket = m_new_obj_with_finaliser(lwip_socket_obj_t); diff --git a/stmhal/accel.c b/stmhal/accel.c index ec517fe43..827e9177a 100644 --- a/stmhal/accel.c +++ b/stmhal/accel.c @@ -125,7 +125,7 @@ STATIC pyb_accel_obj_t pyb_accel_obj; /// accel = pyb.Accel() /// pyb.delay(20) /// print(accel.x()) -STATIC mp_obj_t pyb_accel_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_accel_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); diff --git a/stmhal/adc.c b/stmhal/adc.c index be735e087..11259546b 100644 --- a/stmhal/adc.c +++ b/stmhal/adc.c @@ -275,7 +275,7 @@ STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t /// \classmethod \constructor(pin) /// Create an ADC object associated with the given pin. /// This allows you to then read analog values on that pin. -STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check number of arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -598,7 +598,7 @@ float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) { /******************************************************************************/ /* Micro Python bindings : adc_all object */ -STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check number of arguments mp_arg_check_num(n_args, n_kw, 1, 2, false); diff --git a/stmhal/can.c b/stmhal/can.c index 3157bfadc..e293b8742 100644 --- a/stmhal/can.c +++ b/stmhal/can.c @@ -339,7 +339,7 @@ STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, mp_uint_t n_args, const /// /// - `CAN(1)` is on `YA`: `(RX, TX) = (Y3, Y4) = (PB8, PB9)` /// - `CAN(2)` is on `YB`: `(RX, TX) = (Y5, Y6) = (PB12, PB13)` -STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_can_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, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/dac.c b/stmhal/dac.c index a9b1b9eca..48c0ce8bd 100644 --- a/stmhal/dac.c +++ b/stmhal/dac.c @@ -206,7 +206,7 @@ STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, mp_uint_t n_args, const /// /// `port` can be a pin object, or an integer (1 or 2). /// DAC(1) is on pin X5 and DAC(2) is on pin X6. -STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_dac_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, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/extint.c b/stmhal/extint.c index 02b06fde5..dacf8dd56 100644 --- a/stmhal/extint.c +++ b/stmhal/extint.c @@ -350,7 +350,7 @@ STATIC const mp_arg_t pyb_extint_make_new_args[] = { }; #define PYB_EXTINT_MAKE_NEW_NUM_ARGS MP_ARRAY_SIZE(pyb_extint_make_new_args) -STATIC mp_obj_t extint_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // type_in == extint_obj_type // parse args diff --git a/stmhal/i2c.c b/stmhal/i2c.c index 8e1970962..29c350d22 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -576,7 +576,7 @@ STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, mp_uint_t n_args, /// /// - `I2C(1)` is on the X position: `(SCL, SDA) = (X9, X10) = (PB6, PB7)` /// - `I2C(2)` is on the Y position: `(SCL, SDA) = (Y9, Y10) = (PB10, PB11)` -STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +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 *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/lcd.c b/stmhal/lcd.c index c406d6447..e73b6e16d 100644 --- a/stmhal/lcd.c +++ b/stmhal/lcd.c @@ -194,7 +194,7 @@ STATIC void lcd_write_strn(pyb_lcd_obj_t *lcd, const char *str, unsigned int len /// /// Construct an LCD object in the given skin position. `skin_position` can be 'X' or 'Y', and /// should match the position where the LCD pyskin is plugged in. -STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_lcd_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, 1, 1, false); diff --git a/stmhal/led.c b/stmhal/led.c index 399d4e729..357aed407 100644 --- a/stmhal/led.c +++ b/stmhal/led.c @@ -290,7 +290,7 @@ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki /// Create an LED object associated with the given LED: /// /// - `id` is the LED number, 1-4. -STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t led_obj_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, 1, 1, false); diff --git a/stmhal/modnwcc3k.c b/stmhal/modnwcc3k.c index dcef1f99b..19aeabf5c 100644 --- a/stmhal/modnwcc3k.c +++ b/stmhal/modnwcc3k.c @@ -427,7 +427,7 @@ STATIC const cc3k_obj_t cc3k_obj = {{(mp_obj_type_t*)&mod_network_nic_type_cc3k} // [SPI on Y position; Y6=B13=SCK, Y7=B14=MISO, Y8=B15=MOSI] // // STM32F4DISC: init(pyb.SPI(2), pyb.Pin.cpu.A15, pyb.Pin.cpu.B10, pyb.Pin.cpu.B11) -STATIC mp_obj_t cc3k_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t cc3k_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, 4, 4, false); diff --git a/stmhal/modnwwiznet5k.c b/stmhal/modnwwiznet5k.c index f349e40af..04d37ccee 100644 --- a/stmhal/modnwwiznet5k.c +++ b/stmhal/modnwwiznet5k.c @@ -318,7 +318,7 @@ STATIC mp_obj_t wiznet5k_socket_disconnect(mp_obj_t self_in) { /// \classmethod \constructor(spi, pin_cs, pin_rst) /// Create and return a WIZNET5K object. -STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t wiznet5k_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, 3, 3, false); diff --git a/stmhal/modusocket.c b/stmhal/modusocket.c index afc2462df..7ff890264 100644 --- a/stmhal/modusocket.c +++ b/stmhal/modusocket.c @@ -43,7 +43,7 @@ STATIC const mp_obj_type_t socket_type; // constructor socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None) -STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); // create socket object (not bound to any NIC yet) diff --git a/stmhal/pin.c b/stmhal/pin.c index 21012d186..9c4eb8ba1 100644 --- a/stmhal/pin.c +++ b/stmhal/pin.c @@ -244,7 +244,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, cons /// \classmethod \constructor(id, ...) /// Create a new Pin object associated with the id. If additional arguments are given, /// they are used to initialise the pin. See `init`. -STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Run an argument through the mapper and return the result. @@ -261,7 +261,7 @@ STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uin } // fast method for getting/setting pin value -STATIC mp_obj_t pin_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); pin_obj_t *self = self_in; if (n_args == 0) { diff --git a/stmhal/rtc.c b/stmhal/rtc.c index 9045a76bd..4fa26d25b 100644 --- a/stmhal/rtc.c +++ b/stmhal/rtc.c @@ -425,7 +425,7 @@ STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}}; /// \classmethod \constructor() /// Create an RTC object. -STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_rtc_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); diff --git a/stmhal/servo.c b/stmhal/servo.c index 382b48f67..dff549582 100644 --- a/stmhal/servo.c +++ b/stmhal/servo.c @@ -185,7 +185,7 @@ STATIC void pyb_servo_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ /// \classmethod \constructor(id) /// Create a servo object. `id` is 1-4. -STATIC mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_servo_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, 1, 1, false); diff --git a/stmhal/spi.c b/stmhal/spi.c index 670da360e..234d4bab7 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -600,7 +600,7 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, mp_uint_t n_args, /// /// At the moment, the NSS pin is not used by the SPI driver and is free /// for other use. -STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_spi_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, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/timer.c b/stmhal/timer.c index 5727a95b7..494045c28 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -636,7 +636,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, c /// Construct a new timer object of the given id. If additional /// arguments are given, then the timer is initialised by `init(...)`. /// `id` can be 1 to 14, excluding 3. -STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_timer_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, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/uart.c b/stmhal/uart.c index abe413bbf..81e6f69a5 100644 --- a/stmhal/uart.c +++ b/stmhal/uart.c @@ -717,7 +717,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con /// - `UART(6)` is on `YA`: `(TX, RX) = (Y1, Y2) = (PC6, PC7)` /// - `UART(3)` is on `YB`: `(TX, RX) = (Y9, Y10) = (PB10, PB11)` /// - `UART(2)` is on: `(TX, RX) = (X3, X4) = (PA2, PA3)` -STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_uart_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, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/usb.c b/stmhal/usb.c index 95da04aba..5ba5ddc6e 100644 --- a/stmhal/usb.c +++ b/stmhal/usb.c @@ -353,7 +353,7 @@ STATIC void pyb_usb_vcp_print(const mp_print_t *print, mp_obj_t self_in, mp_prin /// \classmethod \constructor() /// Create a new USB_VCP object. -STATIC mp_obj_t pyb_usb_vcp_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_usb_vcp_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); @@ -541,7 +541,7 @@ typedef struct _pyb_usb_hid_obj_t { STATIC const pyb_usb_hid_obj_t pyb_usb_hid_obj = {{&pyb_usb_hid_type}}; -STATIC mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_usb_hid_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); diff --git a/stmhal/usrsw.c b/stmhal/usrsw.c index 1e07a5534..5bf4cc767 100644 --- a/stmhal/usrsw.c +++ b/stmhal/usrsw.c @@ -77,7 +77,7 @@ void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t /// \classmethod \constructor() /// Create and return a switch object. -STATIC mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_switch_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); @@ -91,7 +91,7 @@ STATIC mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, mp_uint_t n_args, /// \method \call() /// Return the switch state: `True` if pressed down, `False` otherwise. -mp_obj_t pyb_switch_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +mp_obj_t pyb_switch_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { // get switch state mp_arg_check_num(n_args, n_kw, 0, 0, false); return switch_get() ? mp_const_true : mp_const_false; diff --git a/teensy/timer.c b/teensy/timer.c index af64ac708..45bcc2b8f 100644 --- a/teensy/timer.c +++ b/teensy/timer.c @@ -304,7 +304,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, uint n_args, const /// Construct a new timer object of the given id. If additional /// arguments are given, then the timer is initialised by `init(...)`. /// `id` can be 1 to 14, excluding 3. -STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_timer_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, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/unix/modjni.c b/unix/modjni.c index b54da8b15..b474e26ea 100644 --- a/unix/modjni.c +++ b/unix/modjni.c @@ -157,7 +157,7 @@ STATIC void jclass_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { } } -STATIC mp_obj_t jclass_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t jclass_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { if (n_kw != 0) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "kwargs not supported")); } @@ -554,7 +554,7 @@ next_method: } -STATIC mp_obj_t jmethod_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t jmethod_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { if (n_kw != 0) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "kwargs not supported")); } -- cgit v1.2.3 From 044f96c33010ae99cd5423358f4e41021423777b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 7 Jan 2017 19:48:12 +0300 Subject: cc3200/modwlan: Add network.WLAN.print_ver() diagnostic function. Prints NWP/MAC/PHY version, as affected by servicepack installed. --- cc3200/mods/modwlan.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'cc3200') diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index 5e825a627..d9b018350 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -1249,6 +1249,21 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq); //} //STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_urn_obj, 1, 2, wlan_urn); +STATIC mp_obj_t wlan_print_ver(void) { + SlVersionFull ver; + 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("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; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(wlan_print_ver_fun_obj, wlan_print_ver); +STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(wlan_print_ver_obj, MP_ROM_PTR(&wlan_print_ver_fun_obj)); + STATIC const mp_map_elem_t wlan_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&wlan_init_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_scan), (mp_obj_t)&wlan_scan_obj }, @@ -1265,6 +1280,7 @@ STATIC const mp_map_elem_t wlan_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&wlan_irq_obj }, // { MP_OBJ_NEW_QSTR(MP_QSTR_connections), (mp_obj_t)&wlan_connections_obj }, // { MP_OBJ_NEW_QSTR(MP_QSTR_urn), (mp_obj_t)&wlan_urn_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_print_ver), (mp_obj_t)&wlan_print_ver_obj }, // class constants { MP_OBJ_NEW_QSTR(MP_QSTR_STA), MP_OBJ_NEW_SMALL_INT(ROLE_STA) }, -- cgit v1.2.3