diff --git a/spi_switch_Unb2c.py b/spi_switch_Unb2c.py index fb7e05f05423f70b9e1fa416903bfb7036b372c7..5f45ef8239515e24bc20b24b11737ec8f901ff1e 100644 --- a/spi_switch_Unb2c.py +++ b/spi_switch_Unb2c.py @@ -137,9 +137,53 @@ def read_link_status(ports=4): stri += "link down " print(stri) # Read phy registister status -# read_switch(0x80+cnt,0x1e) - - + for cnt in range(4): + ret = read_switch(0x80+cnt,0x02, pr_stri = False) + stri = " Phy status ch {} ".format(cnt) + if ret[1] & 0x20 : + stri += "AN_complete " + if ret[1] & 0x04: + stri += "link up " + if ret[1] & 0x10: + stri += "remote fault " +# print(stri) + ret = read_switch(0x80+cnt,0x14, pr_stri = False) + stri += " 1000BASE-T status ch{} ".format(cnt) + if ret[2] & 0x10: + stri += "remote status is good " + if ret[2] & 0x20: + stri += "local status is good " + if ret[2] & 0x40: + stri += "local master" + else: + stri += "local slave" + else: + stri += " No link " + print(stri) + write_switch_bytes(0x80+cnt, 0x3c, [0x35, 0x08]) + ret = read_switch(0x80+cnt,0x3e) + if 0: + print("Drop packet count register") + for cnt in range(16): +# read_switch(0x41,0x80+2*cnt) + read_switch(0x0,0x0 + cnt) + print("Port State Override") + for cnt in range(16): + # read_switch(0x41,0x80+2*cnt) + read_switch(0x0,0x60 + cnt) + read_switch(0x0,0x10) + read_switch(0x0,0x20) + if 1: + print("Receive count register") + if 1: + print("Receive count register") + for cnt in range(16): + write_switch_bytes(0x10+cnt, 0x20, [0xD0, 0x09]) + time.sleep(0.5) + for cnt in range(16): +# read_switch(0x41,0x80+2*cnt) + read_switch(0x10+cnt,0x2e) + # Open a connection to a specific bus and device (chip select pin) spi.open(bus, device) @@ -172,12 +216,23 @@ elif sys.argv[1] == "set": read_switch(0x40,0x01) print("strap resistors") read_switch(0x01,0x70) - print("write and read SGMII register CH0") - write_switch_bytes(0x10, 0x24, [0x44, 0x00]) - read_switch(0x10,0x24) - print("write and read SGMII register CH3") - write_switch_bytes(0x13, 0x24, [0x44, 0x00]) - read_switch(0x13,0x24) + if 1: + print("write and read SGMII register CH0") + write_switch_bytes(0x10, 0x24, [0x44, 0x00]) + read_switch(0x10,0x24) + print("write and read SGMII register CH3") + write_switch_bytes(0x13, 0x24, [0x44, 0x00]) + read_switch(0x13,0x24) + write_switch_bytes(0x0, 0x20, [0x06]) + for cnt in range(16): + write_switch_bytes(0x0, 0x0+cnt, [0x00]) + for cnt in range(4): + write_switch_bytes(0x80+cnt, 0x00, [0x00, 0x01]) + ret = read_switch(0x80+cnt,0x00) + for cnt in range(16): + write_switch_bytes(0x10+cnt, 0x00, [0x40, 0x11]) + write_switch_bytes(0x10+cnt, 0x20, [0xD0, 0x09]) + else: print("spi_switch_Unb2c stat for status") print("spi_switch_Unb2c set to set registers")