NIOS2 PIO端口寄存器功能定义
https://www.intel.com/content/www/us/en/programmable/documentation/sfo1400787952932.html#iga1401394825911
![](https://img.haomeiwen.com/i1458798/99e94a47e2b56602.png)
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 theedgecapture
register is set to 1 whenever an edge is detected on input portn
. An Avalon® -MM master peripheral can read theedgecapture
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 fromedgecapture
returns an undefined value, and writing toedgecapture
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;
}
}
网友评论