From b277fff5cf8e252351158e185ad879d59aedb01f Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Tue, 24 Apr 2012 12:01:22 +0200 Subject: [PATCH] Added callback to ISR (miceuz) --- core/timer32/timer32.c | 65 +++++++++++++++++++++++++++++------------- core/timer32/timer32.h | 2 +- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/core/timer32/timer32.c b/core/timer32/timer32.c index 539e961..31e5b01 100644 --- a/core/timer32/timer32.c +++ b/core/timer32/timer32.c @@ -69,7 +69,7 @@ volatile uint32_t timer32_0_counter = 0; volatile uint32_t timer32_1_counter = 0; -void (*interruptHandler)(void) = NULL; +void (*interruptHandler0)(void) = NULL; /**************************************************************************/ /*! @@ -124,19 +124,6 @@ void timer32Delay(uint8_t timerNum, uint32_t delay) return; } -uint32_t timer32GetCount(uint8_t timerNum) { - if(0 == timerNum) { - return timer32_0_counter; - } else { - return timer32_1_counter; - } - -} - -void timer32SetIntHandler(void (*handler)(void)) { - interruptHandler = handler; -} - /**************************************************************************/ /*! @brief Interrupt handler for 32-bit timer 0 @@ -144,9 +131,12 @@ void timer32SetIntHandler(void (*handler)(void)) { /**************************************************************************/ void TIMER32_0_IRQHandler(void) { - if(NULL != interruptHandler) { - (*interruptHandler)(); + /* Call the callback function if required */ + if(NULL != interruptHandler0) + { + (*interruptHandler0)(); } + /* Clear the interrupt flag */ TMR_TMR32B0IR = TMR_TMR32B0IR_MR0; @@ -358,11 +348,46 @@ void timer32Init(uint8_t timerNum, uint32_t timerInterval) return; } -void timer32ResetCounter(uint8_t timerNum){ - if(0 == timerNum){ +/**************************************************************************/ +/*! + @brief Sets the optional callback function for 32-bit timer 0 +*/ +/**************************************************************************/ +void timer32SetIntHandler(void (*handler)(void)) +{ + interruptHandler0 = handler; +} + +/**************************************************************************/ +/*! + @brief Returns the value of the auto-incrementing timer counter(s) +*/ +/**************************************************************************/ +uint32_t timer32GetCount(uint8_t timerNum) +{ + if (0 == timerNum) + { + return timer32_0_counter; + } + else + { + return timer32_1_counter; + } +} + +/**************************************************************************/ +/*! + @brief Resets the auto-incrementing timer counter(s) +*/ +/**************************************************************************/ +void timer32ResetCounter(uint8_t timerNum) +{ + if (0 == timerNum) + { timer32_0_counter = 0; - } else if(1 == timerNum) { + } + else if (1 == timerNum) + { timer32_1_counter = 0; } } - diff --git a/core/timer32/timer32.h b/core/timer32/timer32.h index f09b995..71ae253 100644 --- a/core/timer32/timer32.h +++ b/core/timer32/timer32.h @@ -62,7 +62,7 @@ void timer32Enable(uint8_t timerNum); void timer32Disable(uint8_t timerNum); void timer32Reset(uint8_t timerNum); void timer32Init(uint8_t timerNum, uint32_t timerInterval); -uint32_t timer32GetCount(uint8_t timerNum); void timer32SetIntHandler(void (*handler)(void)); +uint32_t timer32GetCount(uint8_t timerNum); void timer32ResetCounter(uint8_t); #endif -- 2.20.1