Changed timers on AVR to only disable the timer interrupt, not global interrupts.

This commit is contained in:
skarg
2010-12-10 23:13:50 +00:00
parent 68a2f83638
commit 794e2ea9d4
2 changed files with 17 additions and 9 deletions
+4 -9
View File
@@ -88,12 +88,10 @@ uint16_t Timer_Silence(
void) void)
{ {
uint16_t timer; uint16_t timer;
uint8_t sreg;
sreg = SREG; BIT_CLEAR(TIMSK0, TOIE0);
__disable_interrupt();
timer = SilenceTime; timer = SilenceTime;
SREG = sreg; BIT_SET(TIMSK0, TOIE0);
return timer; return timer;
} }
@@ -102,10 +100,7 @@ uint16_t Timer_Silence(
void Timer_Silence_Reset( void Timer_Silence_Reset(
void) void)
{ {
uint8_t sreg; BIT_CLEAR(TIMSK0, TOIE0);
sreg = SREG;
__disable_interrupt();
SilenceTime = 0; SilenceTime = 0;
SREG = sreg; BIT_SET(TIMSK0, TOIE0);
} }
@@ -57,6 +57,7 @@
/* counter for the the timer which wraps every 49.7 days */ /* counter for the the timer which wraps every 49.7 days */
static volatile uint32_t Millisecond_Counter; static volatile uint32_t Millisecond_Counter;
static volatile uint8_t Millisecond_Counter_Byte;
/* forward prototype */ /* forward prototype */
ISR(TIMER2_OVF_vect); ISR(TIMER2_OVF_vect);
@@ -70,6 +71,7 @@ static inline void timer_interrupt_handler(void)
/* Set the counter for the next interrupt */ /* Set the counter for the next interrupt */
TCNT2 = TIMER2_COUNT; TCNT2 = TIMER2_COUNT;
Millisecond_Counter++; Millisecond_Counter++;
Millisecond_Counter_Byte++;
} }
/************************************************************************* /*************************************************************************
@@ -102,6 +104,17 @@ uint32_t timer_milliseconds(
return timer_value; return timer_value;
} }
/*************************************************************************
* Description: returns the current millisecond count
* Returns: none
* Notes: This method only disables the timer overflow interrupt.
*************************************************************************/
uint8_t timer_milliseconds_byte(
void)
{
return Millisecond_Counter;
}
/************************************************************************* /*************************************************************************
* Description: Initialization for Timer * Description: Initialization for Timer
* Returns: none * Returns: none