Xilinx AXI INTC简单中断实现

/*
 * led_button.c
 *
 *  Created on: 2014-9-30
 *      Author: 
 */
#include <stdio.h>
#include <math.h>
#include "xparameters.h"
#include "xgpio.h"
#include "xgpio_l.h"
#include "xintc.h"

XGpio Gpio_LEDS;
XGpio Gpio_Buttons;
XIntc Intc_Ctrl;

#define LED_DELAY   6000000
#define LED_NUM     8
#define DATA_CHANNEL 1

void pushButtonHandle(void *pshButton);

int led_button()
{
    int status;
    int index = 0;
    u32 DATAS[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
    volatile int Delay;
    //初始化LED
    status = XGpio_Initialize(&Gpio_LEDS, XPAR_LEDS_8BITS_DEVICE_ID);
    if (status != XST_SUCCESS) {
    	return XST_FAILURE;
    }
    //led全灭
    XGpio_SetDataDirection(&Gpio_LEDS, DATA_CHANNEL, 0x00000000);
    XGpio_DiscreteWrite(&Gpio_LEDS, DATA_CHANNEL, 0x00);
    xil_printf("LEDs have been Initialized\r\n");
    //初始化按钮
    status = XGpio_Initialize(&Gpio_Buttons, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID);
    if (status != XST_SUCCESS)
    {
    	return XST_FAILURE;
    }
    status = XIntc_Initialize(&Intc_Ctrl, XPAR_INTC_0_DEVICE_ID);
    if (status != XST_SUCCESS)
    {
    	return XST_FAILURE;
    }
    status = XIntc_Connect(&Intc_Ctrl, XPAR_INTC_0_GPIO_1_VEC_ID, pushButtonHandle, &Gpio_Buttons);
    if (status != XST_SUCCESS)
    {
    	return XST_FAILURE;
    }
    XIntc_Enable(&Intc_Ctrl, XPAR_INTC_0_GPIO_1_VEC_ID);
    XGpio_InterruptEnable(&Gpio_Buttons, XGPIO_IR_CH1_MASK);
    XGpio_InterruptGlobalEnable(&Gpio_Buttons);
//    microblaze_register_handler(XIntc_DeviceInterruptHandler, XPAR_INTC_0_DEVICE_ID);
    microblaze_enable_interrupts();
    XIntc_Start(&Intc_Ctrl, XIN_REAL_MODE);
    xil_printf("Push Buttons have been Initialized\r\n");
    while (1)
    {
        XGpio_SetDataDirection(&Gpio_LEDS, DATA_CHANNEL, 0x00000000);
        XGpio_DiscreteWrite(&Gpio_LEDS, DATA_CHANNEL, DATAS[index]);
        index ++;
        index = index % LED_NUM;
        for (Delay = 0; Delay < LED_DELAY; Delay++);
//        XGpio_SetDataDirection(&Gpio_LEDS, DATA_CHANNEL, 0xFFFFFFFF);
//        u32 tmp = XGpio_DiscreteRead(&Gpio_LEDS, DATA_CHANNEL);
//        xil_printf("Read the data:%d\r\n", tmp);
    }
    return XST_SUCCESS;
}


void pushButtonHandle(void *pshButton)
{
	XGpio* PushButton = (XGpio*) pshButton;
//	u32 buttonData = XGpio_DiscreteRead(PushButton, DATA_CHANNEL);
//	int buttonIndex = log2(buttonData);
//	xil_printf("Button[%d] has been pushed!\r\n", buttonIndex);
	XGpio_InterruptClear(PushButton, 0xff);
	//使LED全灭
	XGpio_SetDataDirection(&Gpio_LEDS, DATA_CHANNEL, 0x00000000);
	XGpio_DiscreteWrite(&Gpio_LEDS, DATA_CHANNEL, 0x00);
}

原文:http://blog.csdn.net/StormrageWang/article/details/39959951

原文:http://www.cnblogs.com/elitezhe/p/axi-atyls-Interrupt-MicroBlaze.html



猜你喜欢

转载自blog.csdn.net/liuzq/article/details/79356877