Page 1 of 1

anyone configured timer interrupt and willing to share

Posted: Tue Jan 21, 2025 8:23 pm
by maslan
I have tried to implement after reading reference manual. It does not work. Here is my honest attempt:

Code: Select all

void timer1_setup(void) {
	PCR.timergroup1_timer_clk_conf.tg1_timer_clk_en = 1;
	PCR.timergroup1_conf.tg1_clk_en = 1;
	PCR.timergroup1_timer_clk_conf.tg1_timer_clk_sel = 2; // 80mhz

	TIMERG1.hw_timer[0].config.tx_en = 0;
	TIMERG1.hw_timer[0].config.tx_divider = 40000;
	TIMERG1.hw_timer[0].config.tx_divcnt_rst = 1;

	TIMERG1.hw_timer[0].alarmhi.tx_alarm_hi = 0;
	TIMERG1.hw_timer[0].alarmlo.tx_alarm_lo = 2000; // 1 sec
	TIMERG1.hw_timer[0].config.tx_increase = 1;


	TIMERG1.hw_timer[0].config.tx_autoreload = 0;
	TIMERG1.hw_timer[0].loadhi.tx_load_hi = 0;
	TIMERG1.hw_timer[0].loadlo.tx_load_lo = 0;
	TIMERG1.hw_timer[0].load.tx_load = 1;

	TIMERG1.hw_timer[0].config.tx_alarm_en = 1;

	TIMERG1.int_clr_timers.t0_int_clr = 1;
	TIMERG1.int_ena_timers.t0_int_ena = 1;

	TIMERG1.hw_timer[0].config.tx_en = 1;
}

void timer1_handler(void *arg){
	printk("Timer1 interrupt\n");
	TIMERG1.int_clr_timers.t0_int_clr = 1;
	TIMERG1.hw_timer[0].loadhi.tx_load_hi = 0;
	TIMERG1.hw_timer[0].loadlo.tx_load_lo = 0;
	TIMERG1.hw_timer[0].load.tx_load = 1;
	TIMERG1.hw_timer[0].config.tx_alarm_en = 1;
	TIMERG1.hw_timer[0].config.tx_en = 1;
}[Codebox=c file=Untitled.c][/Codebox]