【发布时间】:2013-04-28 16:12:10
【问题描述】:
我的目标是使用 python 脚本读取 FPGA 上的一些寄存器。 我已经在硬件(FPGA)上实现了一些寄存器,我正在尝试读取寄存器。C 中有一些程序能够读取寄存器。但是我必须在 python 中编写读/写程序,以便我可以将它与我的验证环境(用 python 编写)集成。我是 python 新手(初级),所以我希望你能指导我完成你的建议和 cmets。下面是我实现的代码。
这是我的代码。
#!/usr/bin/env python
import array
import fcntl
import re
import socket
import struct
import os
#connectedSockets = {}
# IOCTL Commands
SIOCREGREAD = 0x89F0
SIOCREGWRITE = 0x89F1
reg = 0x58000008
# open the NF descriptor
# Open a file
nf = os.open( "/dev/nf10", os.O_RDWR )
print "Opened NF descriptor"
# Now get a file object for the above file.
nf0 = os.fdopen(nf, "w+")
#print "opened nf0 file object"
inner_struct = struct.pack("II", reg, 0x0)
inner_struct_pinned = array.array('c', inner_struct)
print inner_struct_pinned
fcntl.ioctl(nf0, SIOCREGREAD,)
retval = struct.unpack("II", inner_struct_pinned)[0]
print retval
os.fdclose(nf)
【问题讨论】:
-
您的代码有效吗?你实际上并没有说问题是什么。
标签: python cpu-registers