zynq+linux定时器,Zynq-7000 FreeRTOS(二)中断:Timer中断

/** main.c

*

* Created on: 2016年6月26日

* Author: Administrator*/#include #include "xadcps.h"#include "xil_types.h"#include "Xscugic.h"#include "Xil_exception.h"#include "xscutimer.h"

//timer info

#define TIMER_DEVICE_ID XPAR_XSCUTIMER_0_DEVICE_ID

#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID

#define TIMER_IRPT_INTR XPAR_SCUTIMER_INTR

#define TIMER_LOAD_VALUE 0x13D92D3Fstatic XScuGic Intc;//GIC

static XScuTimer Timer;//timer

static void TimerIntrHandler(void*CallBackRef)

{

staticint sec = 0; //计数

XScuTimer *TimerInstancePtr = (XScuTimer *) CallBackRef;

XScuTimer_ClearInterruptStatus(TimerInstancePtr);

sec++;

printf("%d Second\n\r",sec); //每秒打印输出一次

}

void SetupInterruptSystem(XScuGic*GicInstancePtr,

XScuTimer*TimerInstancePtr, u16 TimerIntrId)

{

XScuGic_Config*IntcConfig; //GIC config

Xil_ExceptionInit();//initialise the GIC

IntcConfig =XScuGic_LookupConfig(INTC_DEVICE_ID);

XScuGic_CfgInitialize(GicInstancePtr, IntcConfig,

IntcConfig->CpuBaseAddress);

Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,

(Xil_ExceptionHandler)XScuGic_InterruptHandler,//connect to the hardware

GicInstancePtr);

XScuGic_Connect(GicInstancePtr, TimerIntrId,

(Xil_ExceptionHandler)TimerIntrHandler,//set up the timer interrupt

(void *)TimerInstancePtr);

XScuGic_Enable(GicInstancePtr, TimerIntrId);//enable the interrupt for the Timer at GIC

XScuTimer_EnableInterrupt(TimerInstancePtr);//enable interrupt on the timer

Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ); //Enable interrupts in the Processor.

}intmain()

{

XScuTimer_Config*TMRConfigPtr; //timer config

printf("------------START-------------\n");//私有定时器初始化

TMRConfigPtr =XScuTimer_LookupConfig(TIMER_DEVICE_ID);

XScuTimer_CfgInitialize(&Timer, TMRConfigPtr,TMRConfigPtr->BaseAddr);//XScuTimer_SelfTest(&Timer);//加载计数周期,私有定时器的时钟为CPU的一般,为333MHZ,如果计数1S,加载值为1sx(333x1000x1000)(1/s)-1=0x13D92D3F

XScuTimer_LoadTimer(&Timer, TIMER_LOAD_VALUE);//自动装载

XScuTimer_EnableAutoReload(&Timer);//启动定时器

XScuTimer_Start(&Timer);//set up the interrupts

SetupInterruptSystem(&Intc,&Timer,TIMER_IRPT_INTR);while(1);

return0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值