Skip to content

Commit ae70e98

Browse files
author
danicampora
committed
cc3200: Fix time.ticks_* functions.
1 parent 8faf2dc commit ae70e98

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

cc3200/mods/modutime.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include MICROPY_HAL_H
3333
#include "py/nlr.h"
3434
#include "py/obj.h"
35+
#include "py/smallint.h"
3536
#include "timeutils.h"
3637
#include "inc/hw_types.h"
3738
#include "inc/hw_ints.h"
@@ -152,23 +153,23 @@ STATIC mp_obj_t time_ticks_ms(void) {
152153
// We want to "cast" the 32 bit unsigned into a small-int. This means
153154
// copying the MSB down 1 bit (extending the sign down), which is
154155
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
155-
return MP_OBJ_NEW_SMALL_INT(HAL_GetTick());
156+
return MP_OBJ_NEW_SMALL_INT(HAL_GetTick() & MP_SMALL_INT_POSITIVE_MASK);
156157
}
157158
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_ms_obj, time_ticks_ms);
158159

159160
STATIC mp_obj_t time_ticks_us(void) {
160161
// We want to "cast" the 32 bit unsigned into a small-int. This means
161162
// copying the MSB down 1 bit (extending the sign down), which is
162163
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
163-
return MP_OBJ_NEW_SMALL_INT(sys_tick_get_microseconds());
164+
return MP_OBJ_NEW_SMALL_INT(sys_tick_get_microseconds() & MP_SMALL_INT_POSITIVE_MASK);
164165
}
165166
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_us_obj, time_ticks_us);
166167

167168
STATIC mp_obj_t time_ticks_cpu(void) {
168169
// We want to "cast" the 32 bit unsigned into a small-int. This means
169170
// copying the MSB down 1 bit (extending the sign down), which is
170171
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
171-
return MP_OBJ_NEW_SMALL_INT(SysTickValueGet());
172+
return MP_OBJ_NEW_SMALL_INT(SysTickValueGet() & MP_SMALL_INT_POSITIVE_MASK);
172173
}
173174
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_cpu_obj, time_ticks_cpu);
174175

@@ -178,7 +179,7 @@ STATIC mp_obj_t time_ticks_diff(mp_obj_t t0, mp_obj_t t1) {
178179
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
179180
uint32_t start = mp_obj_get_int(t0);
180181
uint32_t end = mp_obj_get_int(t1);
181-
return MP_OBJ_NEW_SMALL_INT((end > start) ? (end - start) : (start - end));
182+
return MP_OBJ_NEW_SMALL_INT((end - start) & MP_SMALL_INT_POSITIVE_MASK);
182183
}
183184
STATIC MP_DEFINE_CONST_FUN_OBJ_2(time_ticks_diff_obj, time_ticks_diff);
184185

tests/wipy/time.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def spot_test(seconds, expected_time):
4343
return
4444
print("time.localtime(", seconds, ") returned", actual_time, "(pass)")
4545

46-
4746
test()
4847
spot_test( 0, (2000, 1, 1, 0, 0, 0, 5, 1))
4948
spot_test( 1, (2000, 1, 1, 0, 0, 1, 5, 1))
@@ -75,4 +74,4 @@ def spot_test(seconds, expected_time):
7574

7675
t1 = time.ticks_cpu()
7776
t2 = time.ticks_cpu()
78-
print(time.ticks_diff(t1, t2) < 16384)
77+
print(time.ticks_diff(t1, t2) >= 0)

0 commit comments

Comments
 (0)