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


  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值