ZYNQ essays --PL end button to interrupt the bare metal design

1. DESCRIPTION ZYNQ interrupt
ZYNQ Interrupt Type: Normal Interrupt Request (IRQ, Interrupt Request) and the fast interrupt request (FIQ, Fast Interrupt Request).
ZYNQ interrupt sources: software interrupt (SGI, Software Generated Interrupt), CPU interrupt private facilities (PPI, Private Peripheral Interrupt) interrupts and shared equipment (SPI, Shared Peripheral Interrupt). PL and end keys are shared interrupt device interrupts.
ZYNQ essays --PL end button to interrupt the bare metal design
2. Hardware platform structures
in Block Design was added and AXI_GPIO module ZYNQ7 Processing System, double AXI_GPIO set input, and allows interrupts to drive external IO device (e.g., KEY).
ZYNQ essays --PL end button to interrupt the bare metal design
Double-ZYNQ, enabling IRQ_F2P, as shown in FIG.
ZYNQ essays --PL end button to interrupt the bare metal design
Build a good system structure as shown below, indicate Orange ××× connection disconnect:
ZYNQ essays --PL end button to interrupt the bare metal design
2. Design Software SDK
SDK software design can refer to the official design documents, there are major API function,

  • int XGpio_Initialize(XGpio * InstancePtr,u16 DeviceId)
  • void XGpio_SetDataDirection(XGpio * InstancePtr,unsigned Channel,u32 DirectionMask)
  • XScuGic_Config *XScuGic_LookupConfig(u16 DeviceId)
  • s32 XScuGic_CfgInitialize(XScuGic InstancePtr,XScuGic_Config ConfigPtr,u32 EffectiveAddr)
  • void Xil_ExceptionRegisterHandler(u32 Exception_id, Xil_ExceptionHandler Handler,void *Data)
  • Xil_ExceptionEnable()
  • s32 XScuGic_Connect(XScuGic InstancePtr, u32 Int_Id,Xil_InterruptHandler Handler, void CallBackRef)
  • void XGpio_InterruptEnable(XGpio *InstancePtr, u32 Mask)
  • void XGpio_InterruptGlobalEnable(XGpio *InstancePtr)
  • void XScuGic_Enable(XScuGic *InstancePtr, u32 Int_Id)
    具体代码如下:
    
    XGpio KEYInst;
    XScuGic INTCInst;

int main(void)
{
// initial KEY
int status;
status = XGpio_Initialize(&KEYInst, KEY_DEVICE_ID);
if(status != XST_SUCCESS)
return XST_FAILURE;

// set KEY IO direction as in
XGpio_SetDataDirection(&KEYInst, 1, 0xFF);

// initial interrupt controller
status = IntcInitFunction(INTC_DEVICE_ID, &KEYInst);
if(status != XST_SUCCESS)
    return XST_FAILURE;

while(1);

return 0;

}

//----------------------------------------------------------------------------
// This is the interrupt handler routine for the GPIO for this example
//----------------------------------------------------------------------------
void GpioHandler(void CallbackRef)
{
XGpio
GpioPtr = (XGpio *)CallbackRef;

/* Clear the Interrupt */
XGpio_InterruptClear(GpioPtr, GlobalIntrMask);

}

//----------------------------------------------------------------------------
// Interrupt controller initial function
//----------------------------------------------------------------------------
static int IntcInitFunction(u16 DeviceId, XGpio GpioInstancePtr)
{
XScuGic_Config
IntcConfig;
int status;

// Interrupt controller initialization
IntcConfig = XScuGic_LookupConfig(DeviceId);
status = XScuGic_CfgInitialize(&INTCInst, IntcConfig, IntcConfig->CpuBaseAddress);
if(status != XST_SUCCESS)
    return XST_FAILURE;

// Call interrupt setup function
Xil_ExceptionInit();

Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
        (Xil_ExceptionHandler)XScuGic_InterruptHandler, XScuGicInstancePtr);

Xil_ExceptionEnable();

// Register GPIO interrupt handler
status = XScuGic_Connect(&INTCInst, INTC_GPIO_INTERRUPT_ID,
        (Xil_ExceptionHandler)GpioHandler, (void*)GpioInstancePtr);
if(status != XST_SUCCESS)
    return XST_FAILURE;

// Enable GPIO interrupts
XGpio_InterruptEnable(GpioInstancePtr, 1);
XGpio_InterruptGlobalEnable(GpioInstancePtr);

// Enable GPIO interrupts in the controller
XScuGic_Enable(&INTCInst, INTC_GPIO_INTERRUPT_ID);

return XST_SUCCESS;

}


**3. 编译运行**
下载FPGA代码,以Hardware运行软件

Guess you like

Origin blog.51cto.com/shugenyin/2429397