summaryrefslogtreecommitdiffstatshomepage
path: root/extmod
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-11-03 23:54:16 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-11-03 23:54:16 +0300
commit9b345a9e482f28547e270b5c86ed3e022e56e237 (patch)
treeefbf93ad1eb61b6fb3cc71f99b657cb8698c6f8c /extmod
parent3272afe57f3303ee178c6d0a3d08614a2a154e4e (diff)
downloadmicropython-9b345a9e482f28547e270b5c86ed3e022e56e237.tar.gz
micropython-9b345a9e482f28547e270b5c86ed3e022e56e237.zip
extmod/utime_mphal: ticks_diff/ticks_add: Don't hardcode 32-bit types.
Use normal mp_int_t/mp_uint_t types, algorithms (hm, formulas) can work with any type width.
Diffstat (limited to 'extmod')
-rw-r--r--extmod/utime_mphal.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/extmod/utime_mphal.c b/extmod/utime_mphal.c
index a563b17576..f447b3a686 100644
--- a/extmod/utime_mphal.c
+++ b/extmod/utime_mphal.c
@@ -87,11 +87,11 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_ticks_cpu_obj, time_ticks_cpu);
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);
+ 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.
- int32_t diff = ((end - start + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1))
+ 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);
}
@@ -99,8 +99,8 @@ 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);
+ 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);