📄 含有中断的定时器内核程序.c
字号:
#include "system.h" //硬件信息描述
#include "altera_avalon_timer_regs.h" //定时器内核硬件
#include "sys/alt_irq.h" //中断访问文件
#include "alt_types.h" //定义数据类型
Volatile alt_u32 status_state; //声明支持中断函数格式的变量
Alt_u16 cycle; //声明计数周期低16位的数据变量
//定时器中断服务函数
static void timer_interrupt(void *context,alt_u32 id)
{
volatile alt_u32 * status_state_ptr=(Volatile alt_u32 *)context;//声明支持中断函数格式的变量
IOWR_ALTERA_AVALON_TIMER_STATUS (IRQ_TIMER_BASE,0X0000);//状态寄存器清零
If (cycle<0xf000)
{
Cycle= cycle+1;
}
IOWR_ALTERA_AVALON_TIMER_PERIODH (IRQ_TIMER_BASE,0X0000);
IOWR_ALTERA_AVALON_TIMER_PERIODL (IRQ_TIMER_BASE,cycle);
//用程序设置计数器计数周期
IOWR_ALTERA_AVALON_TIMER_CONTROL (IRQ_TIMER_BASE,0X007);
//启动计数器,连续计数
}
int main (void)
{
void* status_state_ptr=(void*)& status_state;// 声明支持中断函数格式的变量
IOWR_ALTERA_AVALON_TIMER_STATUS (IRQ_TIMER_BASE,0X0000);//状态寄存器清零
IOWR_ALTERA_AVALON_TIMER_PERIODH (IRQ_TIMER_BASE,0X0000);
IOWR_ALTERA_AVALON_TIMER_PERIODL (IRQ_TIMER_BASE,0X2000);
//用程序设置计数器计数周期
IOWR_ALTERA_AVALON_TIMER_CONTROL (IRQ_TIMER_BASE,0X0007);
//启动计数器,连续计数
alt_irq_register(IRQ_TIMER_IRQ, status_state_ptr,timer_interrupt);// 注册中断服务函数
cycle=0x1000; //计数周期赋初值
while(1) //等待中断
{
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -