I'm just getting started with developing for the SAM4E-EK using asf 3.11.0 with arm-none-gcc 4.7 and can't quite get the hang of how interrupt handlers should be added.
I've cannibalized the usart_serial_example code to make a small interrupt-driven "blinky". And using TC0 as in the example everything works fine but when I try to move the code to TC1 (by search and replace) nothing happens.
When going through the code I can't quite understand how the Interrupt handler is registered?
My other question is is there a fundamental difference between timer0 and timer1 that demands a different initiation procedure?
My code:
Code: Select all
#include "asf.h"
#include "conf_board.h"
#include "conf_clock.h"
/** All interrupt mask. */
#define ALL_INTERRUPT_MASK 0xffffffff
/** Timer counter frequency in Hz. */
#define TC_FREQ 10
static unsigned int led_tbl_ptr = 0;
static char led_table[] = {0x01, 0x3, 0x7, 0xf, 0xe, 0xc, 0x8 };
/*
*/
void TC1_Handler(void)
{
/* Read TC1 Status. */
tc_get_status(TC1, 0);
if (led_table[led_tbl_ptr] & 0x01)
LED_On(LED0);
else
LED_Off(LED0);
if (led_table[led_tbl_ptr] & 0x02)
LED_On(LED1);
else
LED_Off(LED1);
if (led_table[led_tbl_ptr] & 0x04)
LED_On(LED2);
else
LED_Off(LED2);
if (led_table[led_tbl_ptr] & 0x08)
LED_On(LED3);
else
LED_Off(LED3);
if (++led_tbl_ptr >= sizeof(led_table))
led_tbl_ptr = 0;
}
/**
* \brief Configure Timer Counter 1 (TC1) to generate an interrupt every 200ms.
* This interrupt will be used to flush USART input and echo back.
*/
static void configure_tc(void)
{
uint32_t ul_div;
uint32_t ul_tcclks;
static uint32_t ul_sysclk;
/* Get system clock. */
ul_sysclk = sysclk_get_cpu_hz();
/* Configure PMC. */
pmc_enable_periph_clk(ID_TC1);
/* Configure TC for a 50Hz frequency and trigger on RC compare. */
tc_find_mck_divisor(TC_FREQ, ul_sysclk, &ul_div, &ul_tcclks, ul_sysclk);
tc_init(TC1, 0, ul_tcclks | TC_CMR_CPCTRG);
tc_write_rc(TC1, 0, (ul_sysclk / ul_div) / TC_FREQ);
/* Configure and enable interrupt on RC compare. */
NVIC_EnableIRQ((IRQn_Type)ID_TC1);
tc_enable_interrupt(TC1, 0, TC_IER_CPCS);
}
int main(void)
{
/* Initialize the SAM system. */
sysclk_init();
board_init();
/* Configure TC. */
configure_tc();
tc_start(TC1, 0);
while (1)
{
}
}
Best regards
/Åke