|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
下面是我的程序,用xilinx edk 编写的,主要想法是通过调用一个中断,来输出一个方波,可是不知原因的,却没有调用中断过程。
我把我的TestApp_Memory\source.c文件拷了过来,请高手帮我看看。
#include "xparameters.h"
#include "xcache_l.h"
#include "stdio.h"
#include "xutil.h"
#include "xgpio_l.h"
#include "xtmrctr.h"
#include "xintc.h"
#include "xexception_l.h"
//====================================================
/*********************constants*******************/
#define LED_DELAY 3000
#define LED_CHANNEL 1
#define PPCGPIO Generic_GPIO
#define GPIO_REG_BASEADDR 0x40000000
#define LED 0x28 /* Assumes bit 0 of GPIO is connected to an LED */
#define TMRCTR_DEVICE_ID XPAR_OPB_INTC_0_DEVICE_ID
#define INTC_DEVICE_ID XPAR_OPB_INTC_0_DEVICE_ID
#define TMRCTR_INTERRUPT_ID XPAR_OPB_INTC_0_OPB_TIMER_0_INTERRUPT_INTR
#define RESET_VALUE 0xFFFFF000
#define TIMER_COUNTER_0 0
volatile int TimerExpired;
XIntc InterruptController;
XTmrCtr TimerCounter;
//void XTmrCtr_InterruptHandler(void *CallBackRef, Xuint8 TmrCtrNumber);
void TimerCounterHandler(void *CallBackRef, Xuint8 TmrCtrNumber);
//void TimerCounterHandler(void *CallBackRef);
/****************************************************/
int main (void)
{
XStatus Status;
volatile int Delay;
int i=0;
//XTmrCtr *InstancePtr = (XTmrCtr *)CallBackRef;
XCache_EnableICache(0x80000001);
XCache_EnableDCache(0x80000001);
print("-- Exiting testmemory main() --\r\n");
XGpio_mSetDataDirection(GPIO_REG_BASEADDR, LED_CHANNEL, 0X0);
// initialize the timer
Status = XTmrCtr_Initialize(&TimerCounter, TMRCTR_DEVICE_ID);
if (Status != XST_SUCCESS)
{ print("XTmrCtr_Initialize failure\r\n");
return XST_FAILURE;
}
print("XTmrCtr_Initialize successed\r\n");
// selftest
Status = XTmrCtr_SelfTest(&TimerCounter,TIMER_COUNTER_0);
if (Status != XST_SUCCESS)
{ print("XTmrCtr_SelfTest failure\r\n");
return XST_FAILURE;
}
print("XTmrCtr_SelfTest successed\r\n");
// initialize the Intc
Status = XIntc_Initialize(&InterruptController, INTC_DEVICE_ID);
if (Status != XST_SUCCESS)
{
print("XIntc_Initialize failure\r\n");
return XST_FAILURE;
}
print("XIntc_Initialize successed\r\n");
//connect the Intr
// Status = XIntc_Connect(&InterruptController, TMRCTR_INTERRUPT_ID,
// (XInterruptHandler)XTmrCtr_InterruptHandler,
// (void *)&TimerCounter);
Status = XIntc_Connect(&InterruptController, TMRCTR_INTERRUPT_ID,
(XInterruptHandler)TimerCounterHandler,
(void *)&TimerCounter);
if (Status != XST_SUCCESS)
{
print("XIntc_Connect failure\r\n");
return XST_FAILURE;
}
print("XIntc_Connect successed\r\n");
// start the Intc
Status = XIntc_Start(&InterruptController, XIN_REAL_MODE);
if (Status != XST_SUCCESS)
{
print("XIntc_Start failure\r\n");
return XST_FAILURE;
}
print("XIntc_Start successed\r\n");
// enable the intc
XIntc_Enable(&InterruptController, INTC_DEVICE_ID);
print("XIntc_Enable successed\r\n");
//Initialize the PPC405 exception table
XExc_Init();
// Register the interrupt controller handler with the exception table
XExc_RegisterHandler(XEXC_ID_NON_CRITICAL_INT,
(XExceptionHandler)XIntc_InterruptHandler,
&InterruptController);
// Enable non-critical exceptions
XExc_mEnableExceptions(XEXC_NON_CRITICAL);
print("XExc routine success\r\n");
//set the handler
XTmrCtr_SetHandler(&TimerCounter, TimerCounterHandler,
&TimerCounter);
// set options
XTmrCtr_SetOptions(&TimerCounter, TIMER_COUNTER_0,
XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION);
//set reset value
XTmrCtr_SetResetValue(&TimerCounter, TIMER_COUNTER_0, RESET_VALUE);
//start the timer
XTmrCtr_Start(&TimerCounter, TIMER_COUNTER_0);
//TimerExpired=XTmrCtr_GetValue(&TimerCounter, TIMER_COUNTER_0);
while(1);
return 0;
}
void TimerCounterHandler(void *CallBackRef, Xuint8 TmrCtrNumber)
// void XTmrCtr_InterruptHandler(void *CallBackRef, Xuint8 TmrCtrNumber)
//void TimerCounterHandler(void *CallBackRef)
{
int Delay;
XGpio_mSetDataReg(GPIO_REG_BASEADDR, LED_CHANNEL, 0x0);
for (Delay = 0; Delay < 300; Delay++);
XGpio_mSetDataReg(GPIO_REG_BASEADDR, LED_CHANNEL, 0x3);
for (Delay = 0; Delay <300; Delay++);
} |
|