Skip to content

Commit

Permalink
atmega timer: Interrupt Pin
Browse files Browse the repository at this point in the history
  • Loading branch information
Josar committed Apr 25, 2018
1 parent 734944a commit 355453e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cpu/atmega_common/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@
#define ENABLE_DEBUG (0)
#include "debug.h"

/*
* Debug pin can be used to probe timer interrupts. Thus, determine when an
* interrupt occurs and how long the ISR takes.
*
* The timer interrupt times can be probed with a oscilloscope if pin
* `DEBUG_TIMER_PIN`, the respective `DEBUG_TIMER_PORT` and `DDEBUG_TIMER_DDR`
* are defined in the makefile as follows.
*
* CFLAGS += -DDEBUG_TIMER_PORT=PORTF
* CFLAGS += -DDEBUG_TIMER_DDR=DDRF
* CFLAGS += -DDEBUG_TIMER_PIN=PORTF4
*/
#if defined(DEBUG_TIMER_PORT)
#include "board.h"
#endif

/**
* @brief All timers have three channels
*/
Expand Down Expand Up @@ -90,6 +106,14 @@ static ctx_t *ctx[] = {{ NULL }};
*/
int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
{
/* Initialize debug pin */
#if defined(DEBUG_TIMER_PORT)
DEBUG_TIMER_DDR |= (1 << DEBUG_TIMER_PIN);
DEBUG_TIMER_PORT &= ~(1 << DEBUG_TIMER_PIN);
DEBUG("Debug Pin: DDR 0x%02x Port 0x%02x Pin 0x%02x\n",
&DEBUG_TIMER_DDR , &DEBUG_TIMER_PORT,(1<<DEBUG_TIMER_PIN));
#endif

DEBUG("timer.c: freq = %ld\n", freq);
uint8_t pre = 0;

Expand Down Expand Up @@ -169,6 +193,9 @@ void timer_start(tim_t tim)
#ifdef TIMER_NUMOF
static inline void _isr(tim_t tim, int chan)
{
#if defined(DEBUG_TIMER_PORT)
DEBUG_TIMER_PORT |= (1 << DEBUG_TIMER_PIN);
#endif
__enter_isr();

*ctx[tim].mask &= ~(1 << (chan + OCIE1A));
Expand All @@ -179,6 +206,9 @@ static inline void _isr(tim_t tim, int chan)
}

__exit_isr();
#if defined(DEBUG_TIMER_PORT)
DEBUG_TIMER_PORT &= ~(1 << DEBUG_TIMER_PIN);
#endif
}
#endif

Expand Down

0 comments on commit 355453e

Please sign in to comment.