我正在开发一些用户空间验证工具。我需要验证i2c freq。
在我的DT文件中,我设置了clock-frequency = <400000>;
,然后我从用户空间的/proc/device-tree/i2c@XXXXX/clock-frequency
读回来。但是我得到了一些垃圾数据。
输出:
root@mymachine:~# od -bc /proc/device-tree/i2c\@XXXXXX/clock-frequency
0000000 000 006 032 200
\0 006 032 200
0000004
是压缩形式吗?如果是,我该如何解压缩?
file
命令的输出:
root@nvidia:/proc/device-tree# file i2c\@7000*/clock-frequency
i2c@7000XXXX/clock-frequency: TTComp archive data
i2c@7000XXXX/clock-frequency: raw G3 data, byte-padded
i2c@7000XXXX/clock-frequency: TTComp archive data
i2c@7000XXXX/clock-frequency: raw G3 data, byte-padded
i2c@7000XXXX/clock-frequency: TTComp archive data
i2c@7000XXXX/clock-frequency: TTComp archive data
答案 0 :(得分:0)
它没有被压缩,它只是一个原始二进制无符号32位int存储的big-endian。你在那里的四个字节以八进制显示:0,6,32,200,十进制为0,6,26和128,而32位int为6 * 65536 + 26 * 256 + 128 = 400000
解压缩的方法有很多种;来自python,在我的RPi 2上,目前的i2c频率为100000:
>>> import struct; struct.unpack(">I", open('/proc/device-tree/soc/i2c@7e205000/clock-frequency').read())
(100000,)