Skip to content
Snippets Groups Projects

Modified the scripts to run on Raspberry Pi.

1 file
+ 67
86
Compare changes
  • Side-by-side
  • Inline
+ 67
86
@@ -31,6 +31,15 @@ device = 0
@@ -31,6 +31,15 @@ device = 0
# Enable SPI
# Enable SPI
spi = spidev.SpiDev()
spi = spidev.SpiDev()
 
# Open a connection to a specific bus and device (chip select pin)
 
spi.open(bus, device)
 
 
# Set SPI speed and mode
 
spi.max_speed_hz = 1000000
 
#spi.max_speed_hz = 50000
 
spi.mode = 1
 
 
cmd_normal_read = 0x60
cmd_normal_read = 0x60
cmd_normal_write = 0x61
cmd_normal_write = 0x61
@@ -75,13 +84,13 @@ def read_switch(page, addr, pr_stri = True):
@@ -75,13 +84,13 @@ def read_switch(page, addr, pr_stri = True):
print("read error")
print("read error")
return ret
return ret
def write_switch_bytes(page, addr, data):
def write_switch_bytes(page, addr, data, pr_stri = True):
stri = '> write switch from page: 0x{0:0>2x}, address: 0x{1:0>2x} data 0x'.format(page, addr)
stri = '> write switch from page: 0x{0:0>2x}, address: 0x{1:0>2x} data 0x'.format(page, addr)
for byte_cnt in range(len(data)):
for byte_cnt in range(len(data)):
# add_stri = "{0:0>2x}".format(data[len(data)-1-byte_cnt])
add_stri = "{0:0>2x}".format(data[-1-byte_cnt])
add_stri = "{0:0>2x}".format(data[-1-byte_cnt])
stri += add_stri
stri += add_stri
print(stri)
if pr_stri:
 
print(stri)
read_register(0xfe)
read_register(0xfe)
ret = spi.xfer2([cmd_normal_write, 0xff, page])
ret = spi.xfer2([cmd_normal_write, 0xff, page])
wr_bytes = [cmd_normal_write, addr]
wr_bytes = [cmd_normal_write, addr]
@@ -112,29 +121,29 @@ def read_link_status(ports=16):
@@ -112,29 +121,29 @@ def read_link_status(ports=16):
ret = read_switch(0x01,0x20+cnt, pr_stri = False)
ret = read_switch(0x01,0x20+cnt, pr_stri = False)
if ret[1] & 0x01:
if ret[1] & 0x01:
stri += "link up "
stri += "link up "
if ret[1] & 0x02:
stri += "dupplex "
else:
stri += "simplex "
if ret[1] & 0x4:
stri += " 100M "
elif ret[1] & 0x8:
stri += "1000M "
else:
stri += " 10M "
ret = read_switch(0x10+cnt,0x28, pr_stri = False)
if ret[1] & 0x01:
stri += "SGMII "
else:
stri += "SERDES "
if ret[2] & 0x08:
stri += "Tx: Er "
if ret[2] & 0x04:
stri += "Rx: Er "
if ret[2] & 0x40:
stri += "Rx FIFO: Er "
else:
else:
stri += "link down "
stri += "link down "
 
if ret[1] & 0x02:
 
stri += "dupplex "
 
else:
 
stri += "simplex "
 
if ret[1] & 0x4:
 
stri += " 100M "
 
elif ret[1] & 0x8:
 
stri += "1000M "
 
else:
 
stri += " 10M "
 
ret = read_switch(0x10+cnt,0x28, pr_stri = False)
 
if ret[1] & 0x01:
 
stri += "SGMII "
 
else:
 
stri += "SERDES "
 
if ret[2] & 0x08:
 
stri += "Tx: Er "
 
if ret[2] & 0x04:
 
stri += "Rx: Er "
 
if ret[2] & 0x40:
 
stri += "Rx FIFO Er "
print(stri)
print(stri)
# Read phy registister status
# Read phy registister status
for cnt in range(4):
for cnt in range(4):
@@ -148,11 +157,15 @@ def read_link_status(ports=16):
@@ -148,11 +157,15 @@ def read_link_status(ports=16):
stri += "remote fault "
stri += "remote fault "
# print(stri)
# print(stri)
ret = read_switch(0x80+cnt,0x14, pr_stri = False)
ret = read_switch(0x80+cnt,0x14, pr_stri = False)
stri += " 1000BASE-T status ch{} ".format(cnt)
stri += " link status ch{} ".format(cnt)
if ret[2] & 0x10:
if ret[2] & 0x10:
stri += "remote status is good "
stri += "remote status is good "
 
else:
 
stri += "remote status is NOK "
if ret[2] & 0x20:
if ret[2] & 0x20:
stri += "local status is good "
stri += "local status is good "
 
else:
 
stri += "local status is NOK "
if ret[2] & 0x40:
if ret[2] & 0x40:
stri += "local master"
stri += "local master"
else:
else:
@@ -160,8 +173,9 @@ def read_link_status(ports=16):
@@ -160,8 +173,9 @@ def read_link_status(ports=16):
else:
else:
stri += " No link "
stri += " No link "
print(stri)
print(stri)
write_switch_bytes(0x80+cnt, 0x3c, [0x35, 0x08])
if 0:
ret = read_switch(0x80+cnt,0x3e)
write_switch_bytes(0x80+cnt, 0x3c, [0x35, 0x08], pr_stri = False)
 
ret = read_switch(0x80+cnt,0x3e)
if 0:
if 0:
print("Drop packet count register")
print("Drop packet count register")
for cnt in range(16):
for cnt in range(16):
@@ -173,25 +187,16 @@ def read_link_status(ports=16):
@@ -173,25 +187,16 @@ def read_link_status(ports=16):
read_switch(0x0,0x60 + cnt)
read_switch(0x0,0x60 + cnt)
read_switch(0x0,0x10)
read_switch(0x0,0x10)
read_switch(0x0,0x20)
read_switch(0x0,0x20)
if 1:
print("Receive count register")
if 1:
if 1:
print("Receive count register")
print("Receive count register")
for cnt in range(16):
for cnt in range(16):
write_switch_bytes(0x10+cnt, 0x20, [0xD0, 0x09])
# Set to receive packet count
 
write_switch_bytes(0x10+cnt, 0x20, [0xD0, 0x09], pr_stri = False)
time.sleep(0.5)
time.sleep(0.5)
for cnt in range(16):
for cnt in range(16):
# read_switch(0x41,0x80+2*cnt)
read_switch(0x10+cnt,0x2e)
read_switch(0x10+cnt,0x2e)
# Open a connection to a specific bus and device (chip select pin)
spi.open(bus, device)
# Set SPI speed and mode
spi.max_speed_hz = 1000000
#spi.max_speed_hz = 50000
spi.mode = 1
if len(sys.argv) < 2:
if len(sys.argv) < 2:
@@ -208,57 +213,33 @@ if len(sys.argv) < 2:
@@ -208,57 +213,33 @@ if len(sys.argv) < 2:
elif sys.argv[1] == "stat":
elif sys.argv[1] == "stat":
read_link_status(16)
read_link_status(16)
elif sys.argv[1] == "set":
elif sys.argv[1] == "set":
#b print("write and read led register")
# Extra setting for the switch, not needed, bonus settings
#b write_switch_bytes(0x00, 0x24, [0x20, 0x02]) #LSB first
if 0:
#b read_switch(0x00,0x24)
print("write and read led register")
#nth print("write and read jumbo register")
write_switch_bytes(0x00, 0x24, [0x20, 0x02]) #LSB first
#nth write_switch_bytes(0x40, 0x01, [0xff, 0xff, 0x00, 0x00])
read_switch(0x00,0x24)
#nth read_switch(0x40,0x01)
print("write and read jumbo register")
#b print("strap resistors")
write_switch_bytes(0x40, 0x01, [0xff, 0xff, 0x00, 0x00])
#b read_switch(0x01,0x70)
read_switch(0x40,0x01)
 
print("strap resistors")
 
read_switch(0x01,0x70)
 
# required setting for the switch
if 1:
if 1:
# print("write and read SGMII register CH0, fifo size max")
# for ch_cnt in range(16):
# write_switch_bytes(0x10, 0x24, [0x44, 0x00])
# print("write and read SGMII register CH0, fifo size max")
# read_switch(0x10,0x24)
# write_switch_bytes(0x10+ch_cnt, 0x24, [0x44, 0x00])
# print("write and read SGMII register CH3, fifo size max")
# read_switch(0x10+ch_cnt,0x24)
# write_switch_bytes(0x13, 0x24, [0x44, 0x00])
speed_100Mbit = False
# read_switch(0x13,0x24)
speed_1000Mbit = False
# write_switch_bytes(0x0, 0x20, [0x06]) #Switch mode)
for ch_cnt in range(4):
# for cnt in range(16):
print("Set PHY ch 0 and read back to 10 Mbit 0x01 100Mbit 0x21")
# write_switch_bytes(0x0, 0x0+cnt, [0x00]) #Overwrite strapping resistor unmanaged mode
write_switch_bytes(0x80 + ch_cnt, 0x00, [(0x00 | (speed_1000Mbit << 6)), (0x01 | (speed_100Mbit << 5))])
print("Set PHY ch 0 and read back to 10 Mbit 0x01 100Mbit 0x21")
write_switch_bytes(0x00, 0x60 + ch_cnt, [(0x83 | (speed_100Mbit << 2) | (speed_1000Mbit << 3))]) # fix PHY ports to 10 Mbit
write_switch_bytes(0x80+0, 0x00, [0x00, 0x01])
# Set the FPGA links to disable Auto negatiation
#b ret = read_switch(0x80,0x00)
for cnt in [15, 13, 11, 9]: # only ETH0 interface
print("Set PHY ch 1 and read back to 10 Mbit 0x01 100Mbit 0x21")
write_switch_bytes(0x00, 0x60+cnt, [0x8B]) #Fix FPGA links
write_switch_bytes(0x00, 0x60+1, [0x8B])
write_switch_bytes(0x10+1, 0x00, [0x40, 0x11])
write_switch_bytes(0x80+1, 0x00, [0x40, 0x01])
#1 write_switch_bytes(0x10+1, 0x00, [0x00, 0x01])
#1 print("Set PHY ch 3 and read back to 10 Mbit 0x01 100Mbit 0x21")
#1 write_switch_bytes(0x80+3, 0x00, [0x00, 0x01])
#b ret = read_switch(0x80+3,0x00)
#1 write_switch_bytes(0x00, 0x86, [0xa0]) # no polling (make no difference)
for cnt in [15, 14, 13, 12, 11, 10, 9, 8]: #, 7, 6, 5, 4]:
write_switch_bytes(0x00, 0x60+cnt, [0x8B])
else:
else:
print("spi_switch_Unb2c stat for status")
print("spi_switch_Unb2c stat for status")
print("spi_switch_Unb2c set to set registers")
print("spi_switch_Unb2c set to set registers")
# Not working as espected
#print("switch off ch 0")
#write_switch_bytes(0x10, 0x00, [0x18, 0x40, 0x18, 0x40])
#read_switch(0x10,0x00)
if 0:
print("Tx pause status ")
read_switch(0x01,0x14)
print("Rx pause status ")
read_switch(0x01,0x18)
write_switch_bytes(0x30, 0x00, [0x40])
read_switch(0x30,0x00)
write_switch_bytes(0x00, 0x20, [0x11])
read_switch(0x00,0x20)
spi.close()
spi.close()
Loading