From 1627531870f694a2ca48ac14f86b138d9171dcaa Mon Sep 17 00:00:00 2001 From: Miceuz Date: Thu, 19 Apr 2012 18:36:28 +0200 Subject: [PATCH] added timer interrupt handler hook for 32 bit timer and couple of utility functions --- core/timer32/timer32.c | 34 +++++++++++++++++++++++++++++----- core/timer32/timer32.h | 4 +++- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/core/timer32/timer32.c b/core/timer32/timer32.c index b768905..539e961 100644 --- a/core/timer32/timer32.c +++ b/core/timer32/timer32.c @@ -69,6 +69,7 @@ volatile uint32_t timer32_0_counter = 0; volatile uint32_t timer32_1_counter = 0; +void (*interruptHandler)(void) = NULL; /**************************************************************************/ /*! @@ -123,6 +124,19 @@ 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 @@ -130,14 +144,17 @@ void timer32Delay(uint8_t timerNum, uint32_t delay) /**************************************************************************/ void TIMER32_0_IRQHandler(void) { - /* Clear the interrupt flag */ - TMR_TMR32B0IR = TMR_TMR32B0IR_MR0; + if(NULL != interruptHandler) { + (*interruptHandler)(); + } + /* Clear the interrupt flag */ + TMR_TMR32B0IR = TMR_TMR32B0IR_MR0; - /* If you wish to perform some action after each timer 'tick' (such as + /* If you wish to perform some action after each timer 'tick' (such as incrementing a counter variable) you can do so here */ - timer32_0_counter++; + timer32_0_counter++; - return; + return; } /**************************************************************************/ @@ -341,4 +358,11 @@ void timer32Init(uint8_t timerNum, uint32_t timerInterval) return; } +void timer32ResetCounter(uint8_t timerNum){ + if(0 == timerNum){ + timer32_0_counter = 0; + } else if(1 == timerNum) { + timer32_1_counter = 0; + } +} diff --git a/core/timer32/timer32.h b/core/timer32/timer32.h index b7135a8..f09b995 100644 --- a/core/timer32/timer32.h +++ b/core/timer32/timer32.h @@ -62,5 +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)); +void timer32ResetCounter(uint8_t); #endif -- 2.20.1