aboutsummaryrefslogtreecommitdiff
path: root/extmod/utime_mphal.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-10-29 17:30:05 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-10-29 17:30:05 +0300
commitd86cac4b8268bbe9203cdd7ab8d8c2a65d142986 (patch)
treee42a9b6c8c5270fb84786cb4e6421cec4f82533b /extmod/utime_mphal.c
parentc62679bdaadea2277291aa3f8bc1e36757b1c61d (diff)
extmod/utime_mphal: Implement ticks_add(), add to all maintained ports.
Diffstat (limited to 'extmod/utime_mphal.c')
-rw-r--r--extmod/utime_mphal.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/extmod/utime_mphal.c b/extmod/utime_mphal.c
index 9bdf84188..609a0da84 100644
--- a/extmod/utime_mphal.c
+++ b/extmod/utime_mphal.c
@@ -93,4 +93,12 @@ STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) {
}
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
+ uint32_t ticks = MP_OBJ_SMALL_INT_VALUE(ticks_in);
+ uint32_t delta = (uint32_t)mp_obj_get_int(delta_in);
+ return MP_OBJ_NEW_SMALL_INT((ticks + delta) & MP_SMALL_INT_POSITIVE_MASK);
+}
+MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj, time_ticks_add);
+
#endif // MICROPY_PY_UTIME_MP_HAL