summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--cc3200/mods/modutime.c9
-rw-r--r--tests/wipy/time.py3
2 files changed, 6 insertions, 6 deletions
diff --git a/cc3200/mods/modutime.c b/cc3200/mods/modutime.c
index 05e7b5dca1..35ce98acd2 100644
--- a/cc3200/mods/modutime.c
+++ b/cc3200/mods/modutime.c
@@ -32,6 +32,7 @@
#include MICROPY_HAL_H
#include "py/nlr.h"
#include "py/obj.h"
+#include "py/smallint.h"
#include "timeutils.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
@@ -152,7 +153,7 @@ STATIC mp_obj_t time_ticks_ms(void) {
// We want to "cast" the 32 bit unsigned into a small-int. This means
// copying the MSB down 1 bit (extending the sign down), which is
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
- return MP_OBJ_NEW_SMALL_INT(HAL_GetTick());
+ return MP_OBJ_NEW_SMALL_INT(HAL_GetTick() & MP_SMALL_INT_POSITIVE_MASK);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_ms_obj, time_ticks_ms);
@@ -160,7 +161,7 @@ STATIC mp_obj_t time_ticks_us(void) {
// We want to "cast" the 32 bit unsigned into a small-int. This means
// copying the MSB down 1 bit (extending the sign down), which is
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
- return MP_OBJ_NEW_SMALL_INT(sys_tick_get_microseconds());
+ return MP_OBJ_NEW_SMALL_INT(sys_tick_get_microseconds() & MP_SMALL_INT_POSITIVE_MASK);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_us_obj, time_ticks_us);
@@ -168,7 +169,7 @@ STATIC mp_obj_t time_ticks_cpu(void) {
// We want to "cast" the 32 bit unsigned into a small-int. This means
// copying the MSB down 1 bit (extending the sign down), which is
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
- return MP_OBJ_NEW_SMALL_INT(SysTickValueGet());
+ return MP_OBJ_NEW_SMALL_INT(SysTickValueGet() & MP_SMALL_INT_POSITIVE_MASK);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_cpu_obj, time_ticks_cpu);
@@ -178,7 +179,7 @@ STATIC mp_obj_t time_ticks_diff(mp_obj_t t0, mp_obj_t t1) {
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
uint32_t start = mp_obj_get_int(t0);
uint32_t end = mp_obj_get_int(t1);
- return MP_OBJ_NEW_SMALL_INT((end > start) ? (end - start) : (start - end));
+ return MP_OBJ_NEW_SMALL_INT((end - start) & MP_SMALL_INT_POSITIVE_MASK);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(time_ticks_diff_obj, time_ticks_diff);
diff --git a/tests/wipy/time.py b/tests/wipy/time.py
index 416f0cf51c..f0bfc88766 100644
--- a/tests/wipy/time.py
+++ b/tests/wipy/time.py
@@ -43,7 +43,6 @@ def spot_test(seconds, expected_time):
return
print("time.localtime(", seconds, ") returned", actual_time, "(pass)")
-
test()
spot_test( 0, (2000, 1, 1, 0, 0, 0, 5, 1))
spot_test( 1, (2000, 1, 1, 0, 0, 1, 5, 1))
@@ -75,4 +74,4 @@ print(time.ticks_diff(t1, t2) < 2000)
t1 = time.ticks_cpu()
t2 = time.ticks_cpu()
-print(time.ticks_diff(t1, t2) < 16384)
+print(time.ticks_diff(t1, t2) >= 0)