强制I2C通信安全吗?

发布于 2024-08-16 07:43:05 字数 462 浏览 10 评论 0原文

对于我正在进行的一个项目,我必须通过 I2C 与多功能芯片通信。我可以通过 I2C /dev/i2c-1 接口从 Linux 用户空间执行此操作。

然而,驱动程序似乎同时与同一个芯片通信。这会导致我的 I2C_SLAVE 访问失败,错误号值为 EBUSY。好吧 - 我可以通过 ioctl I2C_SLAVE_FORCE 覆盖它。我试过了,它有效。我的命令到达芯片。

问题:这样做安全吗?我确信我编写的地址范围永远不会被任何内核驱动程序访问。但是,我不确定以这种方式强制 I2C 通信是否可能会混淆某些内部状态机等。(我不是 I2C 中的那个,我只是使用它...)

作为参考,硬件事实:

 OS:           Linux
 Architecture: TI OMAP3 3530
 I2C-Chip:     TWL4030 (does power, audio, usb and lots of other things..)

For a project I'm working on I have to talk to a multi-function chip via I2C. I can do this from linux user-space via the I2C /dev/i2c-1 interface.

However, It seems that a driver is talking to the same chip at the same time. This results in my I2C_SLAVE accesses to fail with An errno-value of EBUSY. Well - I can override this via the ioctl I2C_SLAVE_FORCE. I tried it, and it works. My commands reach the chip.

Question: Is it safe to do this? I know for sure that the address-ranges that I write are never accessed by any kernel-driver. However, I am not sure if forcing I2C communication that way may confuse some internal state-machine or so.(I'm not that into I2C, I just use it...)

For reference, the hardware facts:

 OS:           Linux
 Architecture: TI OMAP3 3530
 I2C-Chip:     TWL4030 (does power, audio, usb and lots of other things..)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

决绝 2024-08-23 07:43:05

我不知道那个特定的芯片,但通常你有需要一系列写入的命令,首先到一个地址来设置某种模式,然后你读取或写入另一个地址 - 第二个地址的功能根据你写给第一个的内容。因此,如果驱动程序正在执行其中一项操作,并且您中断了它(反之亦然),则会出现难以调试的竞争条件。为了获得可靠的解决方案,您最好通过芯片的驱动程序进行通信......

I don't know that particular chip, but often you have commands that require a sequence of writes, first to one address to set a certain mode, then you read or write another address -- where the function of the second address changes based on what you wrote to the first one. So if the driver is in the middle of one of those operations, and you interrupt it (or vice versa), you have a race condition that will be difficult to debug. For a reliable solution, you better communicate through the chip's driver...

蓝海 2024-08-23 07:43:05

我基本同意@Wim 的观点。但我想补充一点,这肯定会导致不可逆转的问题或破坏,具体取决于设备。

我知道陀螺仪(L3GD20)要求您不要写入某些位置。根据芯片的设置方式,这些位置包含制造商的设置,这些设置决定设备的功能和执行方式。

这似乎是一个很容易避免的问题,但如果您考虑一下 I2C 的工作原理,就会发现所有字节一次一位地传递。如果在另一个字节的传输过程中中断,结果不仅是不可预测的,而且还会成倍增加永久性损坏的风险。当然,这完全取决于芯片如何处理问题。

由于微控制器的运行速度往往比 I2C 允许的总线速度快得多,并且总线速度本身是动态的,具体取决于设备处理信息的速度,因此最好的选择是在等待的传输之间插入暂停或循环。事情要完成。如果需要,您甚至可以插入超时。如果这些暂停不起作用,则说明实施过程中出现了问题。

I mostly agree with @Wim. But I would like to add that this can definitely cause irreversible problems, or destruction, depending on the device.

I know of a Gyroscope (L3GD20) that requires that you don't write to certain locations. The way that the chip is setup, these locations contain manufacturer's settings which determine how the device functions and performs.

This may seem like an easy problem to avoid, but if you think about how I2C works, all of the bytes are passed one bit at a time. If you interrupt in the middle of the transmission of another byte, results can not only be truly unpredictable, but they can also increase the risk of permanent damage exponentially. This is, of course, entirely up to the chip on how to handle the problem.

Since microcontrollers tend to operate at speeds much faster than the bus speeds allowed on I2C, and since the bus speeds themselves are dynamic based on the speeds at which devices process the information, the best bet is to insert pauses or loops between transmissions that wait for things to finish. If you have to, you can even insert a timeout. If these pauses aren't working, then something is wrong with the implementation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文