我想在从输入鼠标接收数据包的嵌入式系统中捕获鼠标移动数据包(初始化为ps/2模式)。如何调用我的异常处理程序?中断处理程序从未被触发。我设置处理器使用外部中断运行,并且只将一个信号连接到处理器的中断输入端口,我没有使用中断控制器。为了捕获输入移动,我使用基于软件的循环缓冲区。
请帮帮我。
#include "xparameters.h"
#include "xil_exception.h"
#include "ps2_core.h"
Ps2Core::Ps2Core(uint32_t core_base_addr) {
base_addr = core_base_addr;
registerCallback();
}
Ps2Core::~Ps2Core() {
}
void Ps2Core::enqueue(unsigned char value) {
if ((tail + 1) % QUEUE_SIZE == head) {
// queue is full, do nothing
return;
}
queue[tail] = value;
queueCount++;
tail = (tail + 1) % QUEUE_SIZE;
}
unsigned char Ps2Core::dequeue(void) {
if (head == tail) {
// queue is empty, do nothing
return 0;
}
unsigned char value = queue[head];
queueCount--;
head = (head + 1) % QUEUE_SIZE;
return value;
}
void Ps2Core::handleInterrupt(Ps2Core *ps2) {
uint8_t byte;
byte = ps2->rx_byte();
ps2->enqueue(byte);
}
void Ps2Core::registerCallback(){
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)handleInterrupt,
this);
Xil_ExceptionEnable();
}
int Ps2Core::get_mouse_activity(int *lbtn, int *rbtn, int *xmov,
int *ymov, int *zmov) {
uint8_t b1, b2, b3, b4;
uint32_t tmp;
/* retrieve bytes only if 4 or a multiple of 4 exist in queue */
if (queueCount >= 4) {
b1 = dequeue();
b2 = dequeue();
b3 = dequeue();
b4 = dequeue();
}
else
return (0);
/* extract button info */
*lbtn = (int) (b1 & 0x01); // extract bit 0
*rbtn = (int) (b1 & 0x02) >> 1; // extract bit 1
/* extract x movement; manually convert 9-bit 2's comp to int */
tmp = (uint32_t) b2;
if (b1 & 0x10) // check MSB (sign bit) of x movement
tmp = tmp | 0xffffff00; // manual sign-extension if negative
*xmov = (int) tmp; // data conversion
/* extract y movement; manually convert 9-bit 2's comp to int */
tmp = (uint32_t) b3;
if (b1 & 0x20) // check MSB (sign bit) of y movement
tmp = tmp | 0xffffff00; // manual sign-extension if negative
*ymov = (int) tmp; // data conversion
tmp = (uint32_t) b4;
if (b4 & 0x08) // check MSB (sign bit) of z movement
tmp = tmp | 0xfffffff0; // manual sign-extension if negative
*zmov = (int) tmp; // data conversion
/* success */
return (1);
}
- 模块示例**
//instantiate uBlaze MCS
cpu cpu_unit (
.Clk(clk_100M),
.Reset(reset),
.IO_addr_strobe(io_addr_strobe),
.IO_address(io_address),
.IO_byte_enable(io_byte_enable),
.IO_read_data(io_read_data),
.IO_read_strobe(io_read_strobe),
.IO_ready(io_ready),
.IO_write_data(io_write_data),
.IO_write_strobe(io_write_strobe),
.INTC_Interrupt(interrupt)
);
// instantiated i/o subsystem
mmio_sys_sampler_arty_a7 mmio_unit (
.clk(clk_100M),
.reset(reset),
.mmio_cs(fp_mmio_cs),
.mmio_wr(fp_wr),
.mmio_rd(fp_rd),
.mmio_addr(fp_addr),
.mmio_wr_data(fp_wr_data),
.mmio_rd_data(fp_rd_data),
.rx_done_tick(interrupt),
.ps2d_in(ps2d_in),
.ps2c_in(ps2c_in),
.tri_c(tri_c),
.tri_d(tri_d),
.ps2c_out(ps2c_out),
.ps2d_out(ps2d_out),
.rx(rx),
.tx(tx)
);
1条答案
按热度按时间juzqafwq1#
从端口名称判断,看起来你的“cpu”模块中有一个中断控制器。但我没有看到任何配置代码--相反,它直接连接到MicroBlaze CPU的异常处理程序。Xilinx的中断控制器驱动程序应该将自己连接到异常处理程序,你的代码应该通过
register_int_handler
/enable_interrupt
连接到它。