nios定时器
#include "altera_avalon_pio_regs.h" #include "altera_avalon_timer_regs.h" #include "system.h" #include <stdio.h> unsigned int timerVal = 0; static void ISR_timer1(void *context, alt_u32 id) { timerVal++; IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_BASE, 0x00); IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_BASE, 0x05); } int main() { printf("Hello from Nios II!\n"); IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_BASE, 0x00); IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_BASE, (TIMER_FREQ / TIMER_TICKS_PER_SEC) >>16); IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_BASE, (TIMER_FREQ / TIMER_TICKS_PER_SEC) & 0xffff); alt_irq_register(TIMER_IRQ,NULL,ISR_timer1); IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_BASE, 0x05); while(1) { if(( (timerVal+1 )% 1000)==0) { printf("timerVal=%d\n",timerVal); } } return 0; }
联系方式:heshengjun@tinywsn.com