从昨天晚上开始计划,到现在终于在我以前写的纯硬件的I2C控制器的基础上写了一个基于AVALON-MM接口的I2C控制器,是一咱最通用的类型,如要以下特点:
1,SCL频率在SOPC中实例时可调
2,可以设置 设备地址 ,读写字节地址,读、写等参数。
3,支持中断模式和查询模式。
在写好IP后,采用了SYSTEM CONSOLE来调试,很快就可以了,非常好用。
#function : test the write/read function of I2C controller
#author : williamhuawu
#Date : 2012.2.27
# set the addresses map
#device address
set device_addr 0x00000000
# (15 downto 8) word address and (7 downto 0) write data
set w_addr_wdata 0x00000004
# read back data
set read_data 0x00000008
# state register 0 busy bit 1 start bit 2 IRQ enable bit
set state_register 0x0000000c
# open jtag_master service
set jtag_master [lindex [get_service_paths master] 0]
open_service master $jtag_master
# set device address to 0xa0 and write mode
master_write_8 $jtag_master $device_addr 0x00a0
#write 0 to 0x0e to address 0x0 to 0x0e
for { set i 0x0000 } { $i < 0x0f } { incr i 1 } {
while { ([master_read_8 $jtag_master $state_register 0x01] & 0x01) } {
}
master_write_16 $jtag_master $w_addr_wdata [expr $i * 256 + $i]
master_write_16 $jtag_master $state_register 0x0003
}
#set device address to 0xa0 and read mode
master_write_8 $jtag_master $device_addr 0x00a1
#read the data of address 0x0 to 0x0e
for { set i 0x00 } { $i < 0x0f } { incr i 1 } {
master_write_16 $jtag_master $w_addr_wdata $i
master_write_16 $jtag_master $state_register 0x0003
puts "[master_read_16 $jtag_master $w_addr_wdata 0x1] : [master_read_16 $jtag_master $read_data 0x1]"
}
#close service
close_service master $jtag_master
以上是用于system console 的测试脚本。
这是做的在SOPC 里的I2C IP 的界面
这个是system console运行测试后输出的结果
再次向大家推荐system console,非常好用!