NIOS2按键中断与ISR写法

NIOS2 PIO端口寄存器功能定义
https://www.intel.com/content/www/us/en/programmable/documentation/sfo1400787952932.html#iga1401394825911

1458798-99e94a47e2b56602.png
PIO控制寄存器的排列顺序

NIOS 2的PIO

NIOS 2系统总线上的每个PIO设备由各自的一套寄存器进行读写访问

DATA寄存器:读写当前IO端口电平
data = IORD_ALTERA_AVALON_PIO_DATA(base);
IOWR_ALTERA_AVALON_PIO_DATA(base, data);

按位写DATA寄存器
IOWR_ALTERA_AVALON_PIO_SET_BITS(base, mask)
按位清零DATA寄存器
IOWR_ALTERA_AVALON_PIO_CLEAR_BITS(base, mask)
DIRECTION寄存器:读写当前IO端口输入输出方向
假定自定义系统时已将PIO控制器配置为双向IO端口,否则无法修改IO方向
dir = IORD_ALTERA_AVALON_PIO_DIRECTION(base);
IOWR_ALTERA_AVALON_PIO_DIRECTION(base, ALTERA_AVALON_PIO_DIRECTION_OUTPUT);
IOWR_ALTERA_AVALON_PIO_DIRECTION(base, ALTERA_AVALON_PIO_DIRECTION_INPUT);
IRQ_MASK寄存器:通过掩码屏蔽或使能特定IO端口的中断
mask = IORD_ALTERA_AVALON_PIO_IRQ_MASK(base);
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(base, 0x0F);
Edge Capture Register边沿捕获寄存器
edge = IORD_ALTERA_AVALON_PIO_EDGE_CAP(base);
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(base, 0x01);

边沿捕获寄存器用法如下

edgecapture Register

Bit n in the edgecapture register is set to 1 whenever an edge is detected on input port n. An Avalon® -MM master peripheral can read the edgecapture register to determine if an edge has occurred on any of the PIO input ports. If the edge capture register bit has been previously set, in_port toggling activity will not change value.

If the option Enable bit-clearing for the edge capture register is turned off, writing any value to the edgecapture register clears all bits in the register. Otherwise, writing a 1 to a particular bit in the register clears only that bit.

The type of edge(s) to detect is specified during IP generation in Platform Designer. The edgecapture register only exists when the hardware is configured to capture edges. If the core is not configured to capture edges, reading from edgecapture returns an undefined value, and writing to edgecapture has no effect.

API 函数

  • 函数名:alt_ic_isr_register()
    用法:
#include "sys/alt_irq.h"
#include "altera_avalon_pio_regs.h"
#include "system.h"

// 自定义中断服务(ISR)函数
static void my_key_isr_func(void *context) {
    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE, 0x0);
    (void) IORD_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE);
}

void main() {
// ...
int err;
// 注册中断服务函数
err = alt_ic_isr_register(
    KEY_IRQ_INTERRUPT_CONTROLLER_ID, 
    KEY_IRQ,
    my_key_isr_func,
    NULL,
    NULL);
if (err) {
    goto ERROR_EXIT;
}

}
  • 0
    点赞
  • 2
    收藏
  • 打赏
    打赏
  • 0
    评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

liuqun69

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值