Fix exception due to divide by 0

Fix exception due to divide by 0
This commit is contained in:
Theo Arends 2018-11-25 16:41:29 +01:00
parent d438007d35
commit 05be1ee21c
1 changed files with 5 additions and 3 deletions

View File

@ -2587,9 +2587,11 @@ void GpioInit(void)
void UpdateLoopLoadAvg(uint32_t loop_activity)
{
uint32_t loops_per_second = 1000 / (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]; // We need to keep track of this many loops per second
uint32_t this_cycle_ratio = 100 * loop_activity / (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY];
loop_load_avg = loop_load_avg - (loop_load_avg / loops_per_second) + this_cycle_ratio; // Take away one loop average away and add the new one
uint32_t loop_delay = Settings.param[P_LOOP_SLEEP_DELAY];
if (!loop_delay) { loop_delay = 1; } // We cannot devide by 0
uint32_t loops_per_second = 1000 / loop_delay; // We need to keep track of this many loops per second
uint32_t this_cycle_ratio = 100 * loop_activity / loop_delay;
loop_load_avg = loop_load_avg - (loop_load_avg / loops_per_second) + this_cycle_ratio; // Take away one loop average away and add the new one
}
extern "C" {