summaryrefslogtreecommitdiff
path: root/stmhal/modpyb.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-11-30 21:23:25 +0000
committerDamien George <damien.p.george@gmail.com>2014-11-30 21:23:25 +0000
commit1960475ed7e190bcf537f8f7714a543b7513e2d5 (patch)
tree63399c90530b3e5d517a0ce1c2e6bc625c529698 /stmhal/modpyb.c
parentc7ca01ad962e70a7ecc3beb4feb41da47a372309 (diff)
stmhal: Make pyb.[u]delay use systick with IRQs, busy loop otherwise.
pyb.delay and pyb.udelay now use systick if IRQs are enabled, otherwise they use a busy loop. Thus they work correctly when IRQs are disabled. The busy loop is computed from the current CPU frequency, so works no matter the CPU frequency.
Diffstat (limited to 'stmhal/modpyb.c')
-rw-r--r--stmhal/modpyb.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/stmhal/modpyb.c b/stmhal/modpyb.c
index 38c5499b0..46ce0e098 100644
--- a/stmhal/modpyb.c
+++ b/stmhal/modpyb.c
@@ -402,10 +402,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_delay_obj, pyb_delay);
STATIC mp_obj_t pyb_udelay(mp_obj_t usec_in) {
mp_int_t usec = mp_obj_get_int(usec_in);
if (usec > 0) {
- uint32_t count = 0;
- const uint32_t utime = (168 * usec / 4);
- while (++count <= utime) {
- }
+ sys_tick_udelay(usec);
}
return mp_const_none;
}