diff --git a/lib/micropython b/lib/micropython index 294baf5..9feb068 160000 --- a/lib/micropython +++ b/lib/micropython @@ -1 +1 @@ -Subproject commit 294baf52b346e400e2255c6c1e82af5b978b18f7 +Subproject commit 9feb0689eeaca5ce88aedcc680f997a3b4d0221c diff --git a/src/codal_app/microbithal.cpp b/src/codal_app/microbithal.cpp index 258e4de..e21fdba 100644 --- a/src/codal_app/microbithal.cpp +++ b/src/codal_app/microbithal.cpp @@ -95,7 +95,7 @@ void microbit_hal_idle(void) { __WFI(); } -void microbit_hal_reset(void) { +__attribute__((noreturn)) void microbit_hal_reset(void) { microbit_reset(); } diff --git a/src/codal_app/microbithal.h b/src/codal_app/microbithal.h index ca137f3..e276bea 100644 --- a/src/codal_app/microbithal.h +++ b/src/codal_app/microbithal.h @@ -104,7 +104,7 @@ extern "C" { void microbit_hal_idle(void); -void microbit_hal_reset(void); +__attribute__((noreturn)) void microbit_hal_reset(void); void microbit_hal_panic(int); int microbit_hal_temperature(void); diff --git a/src/codal_port/Makefile b/src/codal_port/Makefile index 2d8d033..f7694e6 100644 --- a/src/codal_port/Makefile +++ b/src/codal_port/Makefile @@ -98,7 +98,6 @@ SRC_C += \ modradio.c \ modspeech.c \ modthis.c \ - modutime.c \ mphalport.c \ SRC_C += \ @@ -135,11 +134,7 @@ all: lib $(MBIT_VER_FILE) # Also rebuild MicroPython version header in correct directory to pick up git hash. $(MBIT_VER_FILE): FORCE (cd $(TOP) && $(PYTHON) py/makeversionhdr.py $(abspath $(MP_VER_FILE))) - $(PYTHON) $(TOP)/py/makeversionhdr.py $(MBIT_VER_FILE).pre - $(CAT) $(MBIT_VER_FILE).pre | $(SED) s/MICROPY_/MICROBIT_/ > $(MBIT_VER_FILE) - -# Suppress warnings bulding stackctrl.c (fixed post v1.20.0). -$(BUILD)/py/stackctrl.o: CWARN += -Wno-dangling-pointer + $(PYTHON) make_microbit_version_hdr.py $(MBIT_VER_FILE) # Suppress warnings from SAM library. $(BUILD)/$(abspath $(LOCAL_LIB_DIR))/sam/sam.o: CWARN += -Wno-array-bounds diff --git a/src/codal_port/drv_image.c b/src/codal_port/drv_image.c index 03f9e15..7e650b8 100644 --- a/src/codal_port/drv_image.c +++ b/src/codal_port/drv_image.c @@ -43,7 +43,7 @@ STATIC uint8_t monochrome_get_pixel(monochrome_5by5_t *self, mp_int_t x, mp_int_ } greyscale_t *greyscale_new(mp_int_t w, mp_int_t h) { - greyscale_t *result = m_new_obj_var(greyscale_t, uint8_t, (w*h+1)>>1); + greyscale_t *result = m_new_obj_var(greyscale_t, byte_data, uint8_t, (w*h+1)>>1); result->base.type = µbit_image_type; result->five = 0; result->width = w; diff --git a/src/codal_port/main.c b/src/codal_port/main.c index 500b9ad..8592e9b 100644 --- a/src/codal_port/main.c +++ b/src/codal_port/main.c @@ -36,7 +36,7 @@ #include "shared/readline/readline.h" #include "shared/runtime/gchelper.h" #include "shared/runtime/pyexec.h" -#include "ports/nrf/modules/uos/microbitfs.h" +#include "ports/nrf/modules/os/microbitfs.h" #include "drv_softtimer.h" #include "drv_system.h" #include "drv_display.h" @@ -136,7 +136,7 @@ void microbit_pyexec_file(const char *filename) { nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { // Parse and comple the file. - mp_lexer_t *lex = mp_lexer_new_from_file(filename); + mp_lexer_t *lex = mp_lexer_new_from_file(qstr_from_str(filename)); qstr source_name = lex->source_name; mp_parse_tree_t parse_tree = mp_parse(lex, MP_PARSE_FILE_INPUT); mp_obj_t module_fun = mp_compile(&parse_tree, source_name, false); @@ -194,16 +194,16 @@ void microbit_file_opened_for_writing(const char *name, size_t name_len) { } #if MICROPY_MBFS -mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - return uos_mbfs_new_reader(filename); +mp_lexer_t *mp_lexer_new_from_file(qstr filename) { + return os_mbfs_new_reader(qstr_str(filename)); } mp_import_stat_t mp_import_stat(const char *path) { - return uos_mbfs_import_stat(path); + return os_mbfs_import_stat(path); } mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { - return uos_mbfs_open(n_args, args); + return os_mbfs_open(n_args, args); } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); #endif diff --git a/src/codal_port/make_microbit_version_hdr.py b/src/codal_port/make_microbit_version_hdr.py new file mode 100644 index 0000000..3d532ea --- /dev/null +++ b/src/codal_port/make_microbit_version_hdr.py @@ -0,0 +1,120 @@ +""" +Generate header file with macros defining micro:bit version info. + +Adapted from MicroPython's py/makeversionhdr.py file at v1.21.0. +""" + +import argparse +import sys +import os +import datetime +import subprocess + + +def get_version_info_from_git(repo_path): + # Note: git describe doesn't work if no tag is available + try: + git_tag = subprocess.check_output( + ["git", "describe", "--tags", "--dirty", "--always", "--match", "v[1-9].*"], + cwd=repo_path, + stderr=subprocess.STDOUT, + universal_newlines=True, + ).strip() + except subprocess.CalledProcessError as er: + if er.returncode == 128: + # git exit code of 128 means no repository found + return None + git_tag = "" + except OSError: + return None + try: + git_hash = subprocess.check_output( + ["git", "rev-parse", "--short", "HEAD"], + cwd=repo_path, + stderr=subprocess.STDOUT, + universal_newlines=True, + ).strip() + except subprocess.CalledProcessError: + git_hash = "unknown" + except OSError: + return None + + try: + # Check if there are any modified files. + subprocess.check_call( + ["git", "diff", "--no-ext-diff", "--quiet", "--exit-code"], + cwd=repo_path, + stderr=subprocess.STDOUT, + ) + # Check if there are any staged files. + subprocess.check_call( + ["git", "diff-index", "--cached", "--quiet", "HEAD", "--"], + cwd=repo_path, + stderr=subprocess.STDOUT, + ) + except subprocess.CalledProcessError: + git_hash += "-dirty" + except OSError: + return None + + return git_tag, git_hash + + +def make_version_header(repo_path, filename): + info = None + if "MICROBIT_GIT_TAG" in os.environ: + info = [os.environ["MICROBIT_GIT_TAG"], os.environ["MICROBIT_GIT_HASH"]] + if info is None: + info = get_version_info_from_git(repo_path) + + git_tag, git_hash = info + + build_date = datetime.date.today() + if "SOURCE_DATE_EPOCH" in os.environ: + build_date = datetime.datetime.utcfromtimestamp( + int(os.environ["SOURCE_DATE_EPOCH"]) + ).date() + + # Generate the file with the git and version info + file_data = """\ +// This file was generated by py/makeversionhdr.py +#define MICROBIT_GIT_TAG "%s" +#define MICROBIT_GIT_HASH "%s" +#define MICROBIT_BUILD_DATE "%s" +""" % ( + git_tag, + git_hash, + build_date.strftime("%Y-%m-%d"), + ) + + # Check if the file contents changed from last time + write_file = True + if os.path.isfile(filename): + with open(filename, "r") as f: + existing_data = f.read() + if existing_data == file_data: + write_file = False + + # Only write the file if we need to + if write_file: + print("GEN %s" % filename) + with open(filename, "w") as f: + f.write(file_data) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + "-r", + "--repo-path", + default=os.path.join(os.path.dirname(sys.argv[0]), ".."), + help="path to git repo to query for version", + ) + parser.add_argument("dest", nargs=1, help="output file path") + args = parser.parse_args() + + make_version_header(args.repo_path, args.dest[0]) + + +if __name__ == "__main__": + main() diff --git a/src/codal_port/microbitfs.c b/src/codal_port/microbitfs.c index a192fab..308f208 100644 --- a/src/codal_port/microbitfs.c +++ b/src/codal_port/microbitfs.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -25,7 +25,7 @@ * THE SOFTWARE. */ -// This is a copy of the file micropython:ports/nrf/modules/uos/microbitfs.c with: +// This is a copy of the file micropython:ports/nrf/modules/os/microbitfs.c with: // - a call to `microbit_file_opened_for_writing` added in `microbit_file_open` // - a fix to `find_chunk_and_erase` to sweep the filesystem if any free chunks are found @@ -33,7 +33,7 @@ #include #include -#include "modules/uos/microbitfs.h" +#include "modules/os/microbitfs.h" #include "drivers/flash.h" #include "drivers/rng.h" #include "py/obj.h" @@ -121,13 +121,13 @@ typedef struct _persistent_config_t { uint8_t marker; // Should always be PERSISTENT_DATA_MARKER } persistent_config_t; -extern const mp_obj_type_t uos_mbfs_fileio_type; -extern const mp_obj_type_t uos_mbfs_textio_type; +extern const mp_obj_type_t os_mbfs_fileio_type; +extern const mp_obj_type_t os_mbfs_textio_type; // Page indexes count down from the end of ROM. STATIC uint8_t first_page_index; STATIC uint8_t last_page_index; -// The number of useable chunks in the file system. +// The number of usable chunks in the file system. STATIC uint8_t chunks_in_file_system; // Index of chunk to start searches. This is randomised to even out wear. STATIC uint8_t start_index; @@ -361,12 +361,7 @@ STATIC file_descriptor_obj *microbit_file_open(const char *name, size_t name_len } STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary) { - file_descriptor_obj *res = m_new_obj(file_descriptor_obj); - if (binary) { - res->base.type = &uos_mbfs_fileio_type; - } else { - res->base.type = &uos_mbfs_textio_type; - } + file_descriptor_obj *res = mp_obj_malloc(file_descriptor_obj, binary ? &os_mbfs_fileio_type : &os_mbfs_textio_type); res->start_chunk = start_chunk; res->seek_chunk = start_chunk; res->seek_offset = file_system_chunks[start_chunk].header.name_len+2; @@ -517,9 +512,9 @@ STATIC mp_uint_t file_read_byte(file_descriptor_obj *fd) { return res; } -// Now follows the code to integrate this filesystem into the uos module. +// Now follows the code to integrate this filesystem into the os module. -mp_lexer_t *uos_mbfs_new_reader(const char *filename) { +mp_lexer_t *os_mbfs_new_reader(const char *filename) { file_descriptor_obj *fd = microbit_file_open(filename, strlen(filename), false, false); if (fd == NULL) { mp_raise_OSError(MP_ENOENT); @@ -531,7 +526,7 @@ mp_lexer_t *uos_mbfs_new_reader(const char *filename) { return mp_lexer_new(qstr_from_str(filename), reader); } -mp_import_stat_t uos_mbfs_import_stat(const char *path) { +mp_import_stat_t os_mbfs_import_stat(const char *path) { uint8_t chunk = microbit_find_file(path, strlen(path)); if (chunk == FILE_NOT_FOUND) { return MP_IMPORT_STAT_NO_EXIST; @@ -540,38 +535,38 @@ mp_import_stat_t uos_mbfs_import_stat(const char *path) { } } -STATIC mp_obj_t uos_mbfs_file_name(mp_obj_t self) { +STATIC mp_obj_t os_mbfs_file_name(mp_obj_t self) { file_descriptor_obj *fd = (file_descriptor_obj*)self; return microbit_file_name(fd); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_file_name_obj, uos_mbfs_file_name); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_name_obj, os_mbfs_file_name); -STATIC mp_obj_t uos_mbfs_file_close(mp_obj_t self) { +STATIC mp_obj_t os_mbfs_file_close(mp_obj_t self) { file_descriptor_obj *fd = (file_descriptor_obj*)self; microbit_file_close(fd); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_file_close_obj, uos_mbfs_file_close); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_close_obj, os_mbfs_file_close); -STATIC mp_obj_t uos_mbfs_remove(mp_obj_t name) { +STATIC mp_obj_t os_mbfs_remove(mp_obj_t name) { return microbit_remove(name); } -MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_remove_obj, uos_mbfs_remove); +MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_remove_obj, os_mbfs_remove); -STATIC mp_obj_t uos_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t os_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; - return uos_mbfs_file_close(args[0]); + return os_mbfs_file_close(args[0]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(uos_mbfs_file___exit___obj, 4, 4, uos_mbfs_file___exit__); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_mbfs_file___exit___obj, 4, 4, os_mbfs_file___exit__); typedef struct { mp_obj_base_t base; mp_fun_1_t iternext; uint8_t index; -} uos_mbfs_ilistdir_it_t; +} os_mbfs_ilistdir_it_t; -STATIC mp_obj_t uos_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { - uos_mbfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { + os_mbfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); // Read until the next FILE_START chunk. for (; self->index <= chunks_in_file_system; self->index++) { @@ -595,28 +590,27 @@ STATIC mp_obj_t uos_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC mp_obj_t uos_mbfs_ilistdir(void) { - uos_mbfs_ilistdir_it_t *iter = m_new_obj(uos_mbfs_ilistdir_it_t); - iter->base.type = &mp_type_polymorph_iter; - iter->iternext = uos_mbfs_ilistdir_it_iternext; +STATIC mp_obj_t os_mbfs_ilistdir(void) { + os_mbfs_ilistdir_it_t *iter = mp_obj_malloc(os_mbfs_ilistdir_it_t, &mp_type_polymorph_iter); + iter->iternext = os_mbfs_ilistdir_it_iternext; iter->index = 1; return MP_OBJ_FROM_PTR(iter); } -MP_DEFINE_CONST_FUN_OBJ_0(uos_mbfs_ilistdir_obj, uos_mbfs_ilistdir); +MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_ilistdir_obj, os_mbfs_ilistdir); -MP_DEFINE_CONST_FUN_OBJ_0(uos_mbfs_listdir_obj, microbit_file_list); +MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_listdir_obj, microbit_file_list); STATIC mp_obj_t microbit_file_writable(mp_obj_t self) { return mp_obj_new_bool(((file_descriptor_obj *)self)->writable); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_file_writable_obj, microbit_file_writable); -STATIC const mp_map_elem_t uos_mbfs_file_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&uos_mbfs_file_close_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&uos_mbfs_file_name_obj }, +STATIC const mp_map_elem_t os_mbfs_file_locals_dict_table[] = { + { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&os_mbfs_file_close_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&os_mbfs_file_name_obj }, { MP_ROM_QSTR(MP_QSTR___enter__), (mp_obj_t)&mp_identity_obj }, - { MP_ROM_QSTR(MP_QSTR___exit__), (mp_obj_t)&uos_mbfs_file___exit___obj }, + { MP_ROM_QSTR(MP_QSTR___exit__), (mp_obj_t)&os_mbfs_file___exit___obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_writable), (mp_obj_t)µbit_file_writable_obj }, /* Stream methods */ { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj }, @@ -624,7 +618,7 @@ STATIC const mp_map_elem_t uos_mbfs_file_locals_dict_table[] = { { 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}, }; -STATIC MP_DEFINE_CONST_DICT(uos_mbfs_file_locals_dict, uos_mbfs_file_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(os_mbfs_file_locals_dict, os_mbfs_file_locals_dict_table); STATIC const mp_stream_p_t textio_stream_p = { @@ -634,11 +628,11 @@ STATIC const mp_stream_p_t textio_stream_p = { }; MP_DEFINE_CONST_OBJ_TYPE( - uos_mbfs_textio_type, + os_mbfs_textio_type, MP_QSTR_TextIO, MP_TYPE_FLAG_NONE, protocol, &textio_stream_p, - locals_dict, &uos_mbfs_file_locals_dict + locals_dict, &os_mbfs_file_locals_dict ); @@ -648,15 +642,15 @@ STATIC const mp_stream_p_t fileio_stream_p = { }; MP_DEFINE_CONST_OBJ_TYPE( - uos_mbfs_fileio_type, + os_mbfs_fileio_type, MP_QSTR_FileIO, MP_TYPE_FLAG_NONE, protocol, &fileio_stream_p, - locals_dict, &uos_mbfs_file_locals_dict + locals_dict, &os_mbfs_file_locals_dict ); // From micro:bit fileobj.c -mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args) { +mp_obj_t os_mbfs_open(size_t n_args, const mp_obj_t *args) { /// -1 means default; 0 explicitly false; 1 explicitly true. int read = -1; int text = -1; @@ -690,7 +684,7 @@ mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args) { mp_raise_ValueError(MP_ERROR_TEXT("illegal mode")); } -STATIC mp_obj_t uos_mbfs_stat(mp_obj_t filename) { +STATIC mp_obj_t os_mbfs_stat(mp_obj_t filename) { mp_obj_t file_size = microbit_file_size(filename); mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL)); @@ -706,6 +700,6 @@ STATIC mp_obj_t uos_mbfs_stat(mp_obj_t filename) { t->items[9] = MP_OBJ_NEW_SMALL_INT(0); // st_ctime return MP_OBJ_FROM_PTR(t); } -MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_stat_obj, uos_mbfs_stat); +MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_stat_obj, os_mbfs_stat); #endif // MICROPY_MBFS diff --git a/src/codal_port/modmachine.c b/src/codal_port/modmachine.c index 447cc73..08094ad 100644 --- a/src/codal_port/modmachine.c +++ b/src/codal_port/modmachine.c @@ -24,12 +24,13 @@ * THE SOFTWARE. */ -#include "py/mpconfig.h" -#include "extmod/machine_mem.h" -#include "extmod/machine_pulse.h" +#include "py/runtime.h" #include "modmicrobit.h" -#if MICROPY_PY_MACHINE +#undef MICROPY_PY_MACHINE +#define MICROPY_PY_MACHINE (1) +#include "extmod/machine_mem.c" +#undef MICROPY_PY_MACHINE // Returns a string of 8 bytes (64 bits), which is the unique ID for the MCU STATIC mp_obj_t machine_unique_id(void) { @@ -37,13 +38,13 @@ STATIC mp_obj_t machine_unique_id(void) { mp_hal_unique_id(dev_id); return mp_obj_new_bytes((const void*)&dev_id, 8); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(microbit_unique_id_obj, machine_unique_id); // Get the MCU frequency STATIC mp_obj_t machine_freq(void) { return MP_OBJ_NEW_SMALL_INT(64000000); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_freq_obj, machine_freq); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(microbit_freq_obj, machine_freq); // Disable interrupt requests STATIC mp_obj_t machine_disable_irq(void) { @@ -61,9 +62,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq); STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, - { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, + { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(µbit_unique_id_obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(µbit_reset_obj) }, - { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, + { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(µbit_freq_obj) }, { MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, { MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, @@ -82,5 +83,3 @@ const mp_obj_module_t machine_module = { }; MP_REGISTER_MODULE(MP_QSTR_machine, machine_module); - -#endif // MICROPY_PY_MACHINE diff --git a/src/codal_port/modos.c b/src/codal_port/modos.c index 5465a2d..731a5ba 100644 --- a/src/codal_port/modos.c +++ b/src/codal_port/modos.c @@ -27,7 +27,7 @@ #include "py/obj.h" #include "py/objtuple.h" #include "py/objstr.h" -#include "ports/nrf/modules/uos/microbitfs.h" +#include "ports/nrf/modules/os/microbitfs.h" // Include MicroPython and micro:bit version information. #include "genhdr/mpversion.h" @@ -68,7 +68,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname); #if MICROPY_MBFS STATIC mp_obj_t os_size(mp_obj_t filename) { - mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(uos_mbfs_stat_obj.fun._1(filename)); + mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(os_mbfs_stat_obj.fun._1(filename)); return tuple->items[6]; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_size_obj, os_size); @@ -80,10 +80,10 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) }, #if MICROPY_MBFS - { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&uos_mbfs_listdir_obj) }, - { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&uos_mbfs_ilistdir_obj) }, - { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&uos_mbfs_remove_obj) }, - { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&uos_mbfs_stat_obj) }, + { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&os_mbfs_listdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&os_mbfs_ilistdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_mbfs_remove_obj) }, + { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&os_mbfs_stat_obj) }, // micro:bit v1 specific { MP_ROM_QSTR(MP_QSTR_size), MP_ROM_PTR(&os_size_obj) }, diff --git a/src/codal_port/modradio.c b/src/codal_port/modradio.c index 373bbde..5bd89f0 100644 --- a/src/codal_port/modradio.c +++ b/src/codal_port/modradio.c @@ -252,7 +252,7 @@ STATIC mp_obj_t mod_radio_receive_full(void) { mp_obj_t tuple[3] = { mp_obj_new_bytes(buf + 1, len), MP_OBJ_NEW_SMALL_INT(rssi), - MP_OBJ_NEW_SMALL_INT(timestamp_us & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)) + MP_OBJ_NEW_SMALL_INT(timestamp_us & (MICROPY_PY_TIME_TICKS_PERIOD - 1)) }; microbit_radio_pop(); return mp_obj_new_tuple(3, tuple); diff --git a/src/codal_port/modutime.c b/src/codal_port/modutime.c deleted file mode 100644 index 5d12a26..0000000 --- a/src/codal_port/modutime.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013-2017 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "extmod/utime_mphal.h" - -STATIC const mp_rom_map_elem_t utime_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(utime_module_globals, utime_module_globals_table); - -const mp_obj_module_t utime_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&utime_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, utime_module); diff --git a/src/codal_port/mpconfigport.h b/src/codal_port/mpconfigport.h index 2253a25..fcf2546 100644 --- a/src/codal_port/mpconfigport.h +++ b/src/codal_port/mpconfigport.h @@ -59,9 +59,6 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_MODULE_BUILTIN_INIT (1) -#define MICROPY_MODULE_WEAK_LINKS (1) -#define MICROPY_MODULE_FROZEN_MPY (1) -#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool #define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_ENABLE_SCHEDULER (1) @@ -81,19 +78,18 @@ #define MICROPY_PY_SYS_PLATFORM "microbit" // Extended modules -#define MICROPY_PY_UERRNO (1) -#define MICROPY_PY_UTIME_MP_HAL (1) -#define MICROPY_PY_URANDOM (1) -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (rng_generate_random_word()) -#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) -#define MICROPY_PY_MACHINE (1) +#define MICROPY_PY_ERRNO (1) +#define MICROPY_PY_RANDOM (1) +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (rng_generate_random_word()) +#define MICROPY_PY_RANDOM_EXTRA_FUNCS (1) +#define MICROPY_PY_TIME (1) #define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_HW_ENABLE_RNG (1) #define MICROPY_MBFS (1) // Custom errno list. -#define MICROPY_PY_UERRNO_LIST \ +#define MICROPY_PY_ERRNO_LIST \ X(EPERM) \ X(ENOENT) \ X(EIO) \ @@ -154,7 +150,7 @@ typedef long mp_off_t; // We need to provide a declaration/definition of alloca() #include -// Needed for MICROPY_PY_URANDOM_SEED_INIT_FUNC. +// Needed for MICROPY_PY_RANDOM_SEED_INIT_FUNC. extern uint32_t rng_generate_random_word(void); // Needed for microbitfs.c:microbit_file_open. diff --git a/src/codal_port/mphalport.h b/src/codal_port/mphalport.h index 86d965a..951a8e1 100644 --- a/src/codal_port/mphalport.h +++ b/src/codal_port/mphalport.h @@ -28,8 +28,14 @@ #include "microbithal.h" #include "nrf.h" -// Not implemented and not exposed in utime module. -#define mp_hal_ticks_cpu() (0) +static inline mp_uint_t mp_hal_ticks_cpu(void) { + if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) { + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; + DWT->CYCCNT = 0; + DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; + } + return DWT->CYCCNT; +} void mp_hal_set_interrupt_char(int c);