From d35113f8a65e8146c15980ab83b752c07ddd07d5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 Dec 2011 07:25:00 +1100 Subject: [PATCH] TimerProcess: check for duplicate registrations if a driver gets initialised twice, make sure it doesn't get called twice in the timer loop --- libraries/AP_PeriodicProcess/AP_TimerProcess.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/AP_PeriodicProcess/AP_TimerProcess.cpp b/libraries/AP_PeriodicProcess/AP_TimerProcess.cpp index 58d05b9816..38e1edbfb7 100644 --- a/libraries/AP_PeriodicProcess/AP_TimerProcess.cpp +++ b/libraries/AP_PeriodicProcess/AP_TimerProcess.cpp @@ -33,14 +33,22 @@ void AP_TimerProcess::init( Arduino_Mega_ISR_Registry * isr_reg ) _failsafe = NULL; _in_timer_call = false; - for (int i = 0; i < AP_TIMERPROCESS_MAX_PROCS; i++) + for (uint8_t i = 0; i < AP_TIMERPROCESS_MAX_PROCS; i++) _proc[i] = NULL; isr_reg->register_signal( ISR_REGISTRY_TIMER2_OVF, AP_TimerProcess::run); } +/* + register a process to be called at the timer interrupt rate + */ void AP_TimerProcess::register_process(ap_procedure proc) { + // see if its already registered (due to double initialisation + // of a driver) + for (uint8_t i=0; i<_pidx; i++) { + if (_proc[i] == proc) return; + } if (_pidx < AP_TIMERPROCESS_MAX_PROCS) _proc[_pidx++] = proc; }