怎样编写I2C 硬件的中断驱动程序

bestdelpher 2011-06-17 06:06:21
我手头有一块PCA9554的板子,用的主板芯片是intel ICH9R
8-bit I2C-bus and SMBus I/O port with interrupt

里面有一些寄存器一个中断控制器
Command Protocol Function
0 read byte Input Port register
1 read/write byte Output Port register
2 read/write byte Polarity Inversion register
3 read/write byte Configuration register

Interrupt output
The open-drain interrupt output is activated when one of the port pins change state and
the pin is configured as an input. The interrupt is deactivated when the input returns to its
previous state or the Input Port register is read.
Note that changing an I/O from and output to an input may cause a false interrupt to occur
if the state of the pin does not match the contents of the Input Port register.


在操作PCA9554板子时,能通过定时读取到Input Port register的变化,但效率不高,现在希望能通过硬件中断获取系统通知,我实现了一个驱动,在IRP_MN_START_DEVICE时注册中断
case CmResourceTypeInterrupt:
irql = (KIRQL) resource->u.Interrupt.Level;
vector = resource->u.Interrupt.Vector;
affinity = resource->u.Interrupt.Affinity;
mode = (resource->Flags == CM_RESOURCE_INTERRUPT_LATCHED)
? Latched : LevelSensitive;
irqshare = resource->ShareDisposition == CmResourceShareShared;
gotinterrupt = TRUE;

break;

default:
break;
} // switch on resource type
} // for each resource


NTSTATUS status = IoConnectInterrupt(&pdx->InterruptObject, (PKSERVICE_ROUTINE) OnInterrupt,
(PVOID) pdx, NULL, vector, irql, irql, LevelSensitive, TRUE, affinity, FALSE);



IoConnectInterrupt调用返回成功,但是不能进入中断,不知道问题出在哪儿.
...全文
410 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
sinc_mark 2013-06-26
  • 打赏
  • 举报
回复
楼主的问题解决了吗?正在了解pca9554中,也会需要些驱动的情况!
曹大夯 2011-07-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 bestdelpher 的回复:]

就是找不到源码,现在有一个问题是INTEL的驱动和我实现的驱动获取到的硬件资源不一样,但端口读写指令都正常,这是为什么呢?

[/Quote]

端口号是系统动态分配的,在系统初始化的时候,根据端口的使用情况分配的。所以不同驱动,不同的端口分配的不通的Number是正常的。所以,直接使用就好了。

对你的中断没有进去的问题不是很了解。不过,你得先确保你的硬件设计没有问题,对应的PIN的信号是否真的发送了中断请求。

另外,如果板子支持MSI/MSI-X的话,这种中断方式可能被屏蔽掉了。
bestdelpher 2011-07-06
  • 打赏
  • 举报
回复
顶,不能沉.
bestdelpher 2011-06-23
  • 打赏
  • 举报
回复
????????????????????????????,边学边等
念茜 2011-06-22
  • 打赏
  • 举报
回复
表示关注……
恼人的I2C
bestdelpher 2011-06-21
  • 打赏
  • 举报
回复
嗯,我在直接用端口操作寄存器的时候,确实遵循了先选择从设备,再读写数据的原则,
PCA9554可以接8个从设备,但是中断应该是指整个PCA9554芯片的中断吧,只有一个,
不好意思,可能我的问题很菜,还请兄弟们耐心赐教.


根据The open-drain interrupt output is activated when one of the port pins change state and the pin is configured as an input.的解释,在我的输入寄存器发生状态改变时,是应该触发中断的.
allentangtg 2011-06-21
  • 打赏
  • 举报
回复
这是主还是从?主I2C还是比较容易吧。
bestdelpher 2011-06-20
  • 打赏
  • 举报
回复
就是找不到源码,现在有一个问题是INTEL的驱动和我实现的驱动获取到的硬件资源不一样,但端口读写指令都正常,这是为什么呢?


大家可以参考图片:

1、



2、
bestdelpher 2011-06-20
  • 打赏
  • 举报
回复
上面的图所示为同一硬件,资源分配不是由硬件指定的吗,为什么会映射到不同的地方?
huabinsir 2011-06-18
  • 打赏
  • 举报
回复


这个LZ要自已查. 别人帮不了.
haust_wngx 2011-06-18
  • 打赏
  • 举报
回复
I2C总线驱动这个一般IC原厂都有参考代码
lyl_ml 2011-06-18
  • 打赏
  • 举报
回复
关注。。。。。。。。。。

21,597

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧