/*
*Date 2010-12-27
*author Qi Yao
*decription main function code for interrupt program
* such as timer or keyboard and mouse interrupt.
*/
/* FPGA includes */
#include /* for printf */
#include /* for usleep */
#include “xparameters.h”
#include “xutil.h”
#include “xintc.h”
#include “plb_ps2_controller.h”
#include “mb_interface.h”
#define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID
int init_input(void);
XStatus SetUpInterruptSystem(XIntc *XIntcInstancePtr);
static XIntc InterruptController;/*Instance of the Interrupt Control*/
/**
* Input interrupt handler
*/
void PS2_InterruptHandler(void *CallbackRef)
{
u32 mouse_state, keybd_state, flags;
Xuint32 baseaddr = (Xuint32) XPAR_PLB_PS2_CONTROLLER_0_BASEADDR;
/* read information from device registers */
keybd_state = ((u32 *)baseaddr)[0];
mouse_state = ((u32 *)baseaddr)[1];
flags = PLB_PS2_CONTROLLER_mReadReg(baseaddr, PLB_PS2_CONTROLLER_INTR_IPISR_OFFSET);
if (flags & EVENT_FROM_MOUSE)
/*mouse event handler*/
handle_mouse_event(mouse_state);
if (flags & EVENT_FROM_KEYBD)
/*keyboard event handler*/
handle_keybd_event(keybd_state);
/* clear interrupt flags in PS/2 controller */
PLB_PS2_CONTROLLER_mWriteReg(baseaddr, PLB_PS2_CONTROLLER_INTR_IPISR_OFFSET, flags);
}
XStatus init_input(void)
{
XStatus Status;
Xuint32 baseaddr = (Xuint32) XPAR_PLB_PS2_CONTROLLER_0_BASEADDR;
/* initialize PS/2 interrupts */
PLB_PS2_CONTROLLER_mWriteReg(baseaddr, PLB_PS2_CONTROLLER_INTR_DIER_OFFSET, 0);
PLB_PS2_CONTROLLER_mWriteReg(baseaddr, PLB_PS2_CONTROLLER_INTR_DGIER_OFFSET, 0xFFFFFFFF);
PLB_PS2_CONTROLLER_mWriteReg(baseaddr, PLB_PS2_CONTROLLER_INTR_IPIER_OFFSET, 0xFFFFFFFF);
PLB_PS2_CONTROLLER_mWriteReg(baseaddr, PLB_PS2_CONTROLLER_INTR_IPISR_OFFSET, 0);
/* initialize Interrupt controller */
Status = XIntc_Initialize(&InterruptController, (Xuint16)INTC_DEVICE_ID);
if (Status != XST_SUCCESS)
{ return XST_FAILURE; }
Status = XIntc_SelfTest(&InterruptController);
if (Status != XST_SUCCESS)
{ return XST_FAILURE; }
/*
* Connect a device driver handler that will be called when an interrupt
* for the device occurs, the device driver handler performs the specific
* interrupt processing for the device
*/
Status = XIntc_Connect(XIntcInstancePtr, XPAR_XPS_INTC_0_PLB_PS2_CONTROLLER_0_IP2INTC_IRPT_INTR,
(XInterruptHandler)PS2_InterruptHandler,
(void *)0);
if (Status != XST_SUCCESS)
{ return XST_FAILURE;}
/*
* Start the interrupt controller such that interrupts are enabled for
* all devices that cause interrupts, specify simulation mode so that
* an interrupt can be caused by software rather than a real hardware
* interrupt
*/
Status = XIntc_Start(XIntcInstancePtr, XIN_REAL_MODE);
if (Status != XST_SUCCESS)
{
return XST_FAILURE;
}
/*
* Enable the interrupt for the device and then cause (simulate) an
* interrupt so the handlers will be called
*/
XIntc_Enable(XIntcInstancePtr, XPAR_XPS_INTC_0_PLB_PS2_CONTROLLER_0_IP2INTC_IRPT_INTR);
/*
* Enable the Interrupts for the MicroBlaze Processor
*/
microblaze_enable_interrupts();
return XST_SUCCESS;
}
int main(void){
/*Initialization*/
init_input();
/*wait for interrupt*/
while(1);
return 1;
}