summaryrefslogtreecommitdiff
path: root/extmod
diff options
context:
space:
mode:
Diffstat (limited to 'extmod')
-rw-r--r--extmod/fsusermount.h6
-rw-r--r--extmod/machine_pulse.h2
-rw-r--r--extmod/machine_spi.h8
-rw-r--r--extmod/misc.h2
-rw-r--r--extmod/modubinascii.h10
-rw-r--r--extmod/uos_dupterm.c (renamed from extmod/moduos_dupterm.c)0
-rw-r--r--extmod/utime_mphal.c33
-rw-r--r--extmod/utime_mphal.h15
-rw-r--r--extmod/vfs_fat_file.c9
-rw-r--r--extmod/vfs_fat_file.h2
10 files changed, 55 insertions, 32 deletions
diff --git a/extmod/fsusermount.h b/extmod/fsusermount.h
index 7f2912b7f..efc68a05d 100644
--- a/extmod/fsusermount.h
+++ b/extmod/fsusermount.h
@@ -62,6 +62,6 @@ typedef struct _fs_user_mount_t {
fs_user_mount_t *fatfs_mount_mkfs(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, bool mkfs);
mp_obj_t fatfs_umount(mp_obj_t bdev_or_path_in);
-MP_DECLARE_CONST_FUN_OBJ(fsuser_mount_obj);
-MP_DECLARE_CONST_FUN_OBJ(fsuser_umount_obj);
-MP_DECLARE_CONST_FUN_OBJ(fsuser_mkfs_obj);
+MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mount_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(fsuser_umount_obj);
+MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj);
diff --git a/extmod/machine_pulse.h b/extmod/machine_pulse.h
index 3d5d81c07..cc1c4eda5 100644
--- a/extmod/machine_pulse.h
+++ b/extmod/machine_pulse.h
@@ -32,6 +32,6 @@
mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t timeout_us);
-MP_DECLARE_CONST_FUN_OBJ(machine_time_pulse_us_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_time_pulse_us_obj);
#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H__
diff --git a/extmod/machine_spi.h b/extmod/machine_spi.h
index 316d06646..62f42a885 100644
--- a/extmod/machine_spi.h
+++ b/extmod/machine_spi.h
@@ -47,9 +47,9 @@ typedef struct _mp_machine_soft_spi_obj_t {
void mp_machine_soft_spi_transfer(mp_obj_base_t *self, size_t len, const uint8_t *src, uint8_t *dest);
-MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_read_obj);
-MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_readinto_obj);
-MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_write_obj);
-MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_write_readinto_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_read_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_readinto_obj);
+MP_DECLARE_CONST_FUN_OBJ_2(mp_machine_spi_write_obj);
+MP_DECLARE_CONST_FUN_OBJ_3(mp_machine_spi_write_readinto_obj);
#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_SPI_H
diff --git a/extmod/misc.h b/extmod/misc.h
index 634ea924d..d7ead0654 100644
--- a/extmod/misc.h
+++ b/extmod/misc.h
@@ -30,7 +30,7 @@
#include <stddef.h>
#include "py/runtime.h"
-MP_DECLARE_CONST_FUN_OBJ(mp_uos_dupterm_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj);
#if MICROPY_PY_OS_DUPTERM
void mp_uos_dupterm_tx_strn(const char *str, size_t len);
diff --git a/extmod/modubinascii.h b/extmod/modubinascii.h
index 71dd8a693..33d0f1cbd 100644
--- a/extmod/modubinascii.h
+++ b/extmod/modubinascii.h
@@ -33,10 +33,10 @@ extern mp_obj_t mod_binascii_a2b_base64(mp_obj_t data);
extern mp_obj_t mod_binascii_b2a_base64(mp_obj_t data);
extern mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args);
-MP_DECLARE_CONST_FUN_OBJ(mod_binascii_hexlify_obj);
-MP_DECLARE_CONST_FUN_OBJ(mod_binascii_unhexlify_obj);
-MP_DECLARE_CONST_FUN_OBJ(mod_binascii_a2b_base64_obj);
-MP_DECLARE_CONST_FUN_OBJ(mod_binascii_b2a_base64_obj);
-MP_DECLARE_CONST_FUN_OBJ(mod_binascii_crc32_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_hexlify_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mod_binascii_unhexlify_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mod_binascii_a2b_base64_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mod_binascii_b2a_base64_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_crc32_obj);
#endif /* MICROPY_EXTMOD_MODUBINASCII */
diff --git a/extmod/moduos_dupterm.c b/extmod/uos_dupterm.c
index d888099df..d888099df 100644
--- a/extmod/moduos_dupterm.c
+++ b/extmod/uos_dupterm.c
diff --git a/extmod/utime_mphal.c b/extmod/utime_mphal.c
index 3ecdc9446..f447b3a68 100644
--- a/extmod/utime_mphal.c
+++ b/extmod/utime_mphal.c
@@ -33,14 +33,17 @@
#include "py/obj.h"
#include "py/mphal.h"
#include "py/smallint.h"
+#include "py/runtime.h"
#include "extmod/utime_mphal.h"
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
+ MP_THREAD_GIL_EXIT();
#if MICROPY_PY_BUILTINS_FLOAT
mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o));
#else
mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
#endif
+ MP_THREAD_GIL_ENTER();
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep);
@@ -48,7 +51,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep);
STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) {
mp_int_t ms = mp_obj_get_int(arg);
if (ms > 0) {
+ MP_THREAD_GIL_EXIT();
mp_hal_delay_ms(ms);
+ MP_THREAD_GIL_ENTER();
}
return mp_const_none;
}
@@ -57,33 +62,47 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj, time_sleep_ms);
STATIC mp_obj_t time_sleep_us(mp_obj_t arg) {
mp_int_t us = mp_obj_get_int(arg);
if (us > 0) {
+ MP_THREAD_GIL_EXIT();
mp_hal_delay_us(us);
+ MP_THREAD_GIL_ENTER();
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_us_obj, time_sleep_us);
STATIC mp_obj_t time_ticks_ms(void) {
- return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & MP_SMALL_INT_POSITIVE_MASK);
+ return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
}
MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_ticks_ms_obj, time_ticks_ms);
STATIC mp_obj_t time_ticks_us(void) {
- return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_us() & MP_SMALL_INT_POSITIVE_MASK);
+ return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_us() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
}
MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_ticks_us_obj, time_ticks_us);
STATIC mp_obj_t time_ticks_cpu(void) {
- return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_cpu() & MP_SMALL_INT_POSITIVE_MASK);
+ return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_cpu() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
}
MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_ticks_cpu_obj, time_ticks_cpu);
-STATIC mp_obj_t time_ticks_diff(mp_obj_t start_in, mp_obj_t end_in) {
+STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) {
// we assume that the arguments come from ticks_xx so are small ints
- uint32_t start = MP_OBJ_SMALL_INT_VALUE(start_in);
- uint32_t end = MP_OBJ_SMALL_INT_VALUE(end_in);
- return MP_OBJ_NEW_SMALL_INT((end - start) & MP_SMALL_INT_POSITIVE_MASK);
+ mp_uint_t start = MP_OBJ_SMALL_INT_VALUE(start_in);
+ mp_uint_t end = MP_OBJ_SMALL_INT_VALUE(end_in);
+ // Optimized formula avoiding if conditions. We adjust difference "forward",
+ // wrap it around and adjust back.
+ mp_int_t diff = ((end - start + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1))
+ - MICROPY_PY_UTIME_TICKS_PERIOD / 2;
+ return MP_OBJ_NEW_SMALL_INT(diff);
}
MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj, time_ticks_diff);
+STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) {
+ // we assume that first argument come from ticks_xx so is small int
+ mp_uint_t ticks = MP_OBJ_SMALL_INT_VALUE(ticks_in);
+ mp_uint_t delta = mp_obj_get_int(delta_in);
+ return MP_OBJ_NEW_SMALL_INT((ticks + delta) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
+}
+MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj, time_ticks_add);
+
#endif // MICROPY_PY_UTIME_MP_HAL
diff --git a/extmod/utime_mphal.h b/extmod/utime_mphal.h
index 4f2395a09..644387b67 100644
--- a/extmod/utime_mphal.h
+++ b/extmod/utime_mphal.h
@@ -27,10 +27,11 @@
#include "py/obj.h"
-MP_DECLARE_CONST_FUN_OBJ(mp_utime_sleep_obj);
-MP_DECLARE_CONST_FUN_OBJ(mp_utime_sleep_ms_obj);
-MP_DECLARE_CONST_FUN_OBJ(mp_utime_sleep_us_obj);
-MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_ms_obj);
-MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_us_obj);
-MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_cpu_obj);
-MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_diff_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_us_obj);
+MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_ms_obj);
+MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_us_obj);
+MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_cpu_obj);
+MP_DECLARE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj);
+MP_DECLARE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj);
diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c
index e269ef593..76ac23685 100644
--- a/extmod/vfs_fat_file.c
+++ b/extmod/vfs_fat_file.c
@@ -120,9 +120,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(file_obj_flush_obj, file_obj_flush);
STATIC mp_obj_t file_obj_close(mp_obj_t self_in) {
pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in);
- FRESULT res = f_close(&self->fp);
- if (res != FR_OK) {
- mp_raise_OSError(fresult_to_errno_table[res]);
+ // if fs==NULL then the file is closed and in that case this method is a no-op
+ if (self->fp.fs != NULL) {
+ FRESULT res = f_close(&self->fp);
+ if (res != FR_OK) {
+ mp_raise_OSError(fresult_to_errno_table[res]);
+ }
}
return mp_const_none;
}
diff --git a/extmod/vfs_fat_file.h b/extmod/vfs_fat_file.h
index 6d6888955..5c271b6ee 100644
--- a/extmod/vfs_fat_file.h
+++ b/extmod/vfs_fat_file.h
@@ -27,6 +27,6 @@
extern const byte fresult_to_errno_table[20];
mp_obj_t fatfs_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
-MP_DECLARE_CONST_FUN_OBJ(mp_builtin_open_obj);
+MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj);
mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type);