From 3a7a46d1c02ecc633d65035b9c536858c1fccc3a Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Fri, 23 Oct 2020 11:29:38 -0400 Subject: [PATCH] Hosted targets Fix timer cycle calculation overflow at 1 GHZ the intermediate calculation for cycles overflows 32 bits this makes timer fail even with sensible values solution divide both sides by 100 Change-Id: I18a4054c2d06fb72531d5496bba562f71b03984f --- apps/plugins/lua/rocklib_events.c | 5 ++++- firmware/target/hosted/kernel-unix.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/plugins/lua/rocklib_events.c b/apps/plugins/lua/rocklib_events.c index dc15c363a4..1c13a6758f 100644 --- a/apps/plugins/lua/rocklib_events.c +++ b/apps/plugins/lua/rocklib_events.c @@ -424,7 +424,10 @@ static void init_event_thread(bool init, struct event_data *ev_data) IF_COP(, COP)); /* Timer is used to poll waiting events */ - rb->timer_register(1, NULL, EV_TIMER_FREQ, rev_timer_isr IF_COP(, CPU)); + if (!rb->timer_register(1, NULL, EV_TIMER_FREQ, rev_timer_isr IF_COP(, CPU))) + { + rb->splash(100, "No timer available!"); + } } static void playback_event_callback(unsigned short id, void *data) diff --git a/firmware/target/hosted/kernel-unix.c b/firmware/target/hosted/kernel-unix.c index 1ce4dd8a10..5e9204effd 100644 --- a/firmware/target/hosted/kernel-unix.c +++ b/firmware/target/hosted/kernel-unix.c @@ -104,7 +104,7 @@ void tick_start(unsigned int interval_in_ms) } #define cycles_to_microseconds(cycles) \ - ((int)((1000000*cycles)/TIMER_FREQ)) + ((int)((10000*cycles)/(TIMER_FREQ / 100))) static timer_t timer_tid;