Commit c2a76b5d authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

sw: Work on RS485 pulse test

parent 276f1d32
...@@ -133,6 +133,8 @@ if __name__ == '__main__': ...@@ -133,6 +133,8 @@ if __name__ == '__main__':
# Scan the first barcode # Scan the first barcode
while True: while True:
sn1 = raw_input("--> Scan the 1st barcode: ") sn1 = raw_input("--> Scan the 1st barcode: ")
if (not len(sn1)):
sn1 = "0"
m = re.search(r"[^a-z\-A-Z0-9_]+",sn1) m = re.search(r"[^a-z\-A-Z0-9_]+",sn1)
if m: if m:
print "Bad character in barcode" print "Bad character in barcode"
......
...@@ -95,16 +95,19 @@ def mux_sel(bus, sel): ...@@ -95,16 +95,19 @@ def mux_sel(bus, sel):
if (sel & 0x2): if (sel & 0x2):
val |= (1 << CSR_TESTER_MUX_S1_OFS) val |= (1 << CSR_TESTER_MUX_S1_OFS)
bus.vv_write(CSR, val) bus.vv_write(CSR, val)
time.sleep(0.1)
def en_pulse_gen(bus): def en_pulse_gen(bus):
val = bus.vv_read(CSR) val = bus.vv_read(CSR)
val |= (1 << CSR_REAR_EN_OFS) val |= (1 << CSR_REAR_EN_OFS)
bus.vv_write(CSR, val) bus.vv_write(CSR, val)
time.sleep(0.1)
def dis_pulse_gen(bus): def dis_pulse_gen(bus):
val = bus.vv_read(CSR) val = bus.vv_read(CSR)
val &= ~(1 << CSR_REAR_EN_OFS) val &= ~(1 << CSR_REAR_EN_OFS)
bus.vv_write(CSR, val) bus.vv_write(CSR, val)
time.sleep(0.1)
def clear_counters(pc): def clear_counters(pc):
# Clear pulse counters for the TTL channels # Clear pulse counters for the TTL channels
...@@ -118,6 +121,7 @@ def check_counters(pc, inf, pel): ...@@ -118,6 +121,7 @@ def check_counters(pc, inf, pel):
for i in range(11, 17): for i in range(11, 17):
ic_arr.append(pc.rd_in_cnt(i)) ic_arr.append(pc.rd_in_cnt(i))
oc_arr.append(pc.rd_out_cnt(i)) oc_arr.append(pc.rd_out_cnt(i))
for i in range(len(ic_arr)): for i in range(len(ic_arr)):
if (ic_arr[i] == oc_arr[i]): if (ic_arr[i] == oc_arr[i]):
msg = "Ch%d input counter (%d) matches the output counter (%d) - good\n" % (i+1, msg = "Ch%d input counter (%d) matches the output counter (%d) - good\n" % (i+1,
...@@ -205,20 +209,27 @@ def main(bus, tname, inf, log): ...@@ -205,20 +209,27 @@ def main(bus, tname, inf, log):
val = bus.vv_read(CSR) val = bus.vv_read(CSR)
val |= (1 << CSR_TESTER_MUX_EN_OFS) val |= (1 << CSR_TESTER_MUX_EN_OFS)
bus.vv_write(CSR, val) bus.vv_write(CSR, val)
time.sleep(1)
# Generate pulses from different outputs to inputs msg = "Testing RS-485 fail-safe on short-circuit case (term. OFF)"
msg = "Testing channel connections (term. OFF): O1 -> I"
print(msg) print(msg)
mux_sel(bus, 0x0) mux_sel(bus, 0x0)
inf.write('\n') inf.write('\n')
inf.write(msg+'\n') inf.write(msg+'\n')
en_pulse_gen(bus) en_pulse_gen(bus)
time.sleep(2) val = bus.vv_read(LSR)
val >>= LSR_REARFS_OFS
if (val == 0x3f):
msg = "RS-485 failsafe lines read as expected: 0x%02X\n" % val
inf.write(msg)
else:
msg = "ERROR: Failsafe lines readout (0x%02X) incorrect - expected 0x3F" % val
pel.set(msg)
dis_pulse_gen(bus) dis_pulse_gen(bus)
check_counters(pc, inf, pel) time.sleep(1)
clear_counters(pc)
msg = "Testing channel connections (term. OFF): O2 -> I" # Generate pulses from different outputs to inputs
msg = "Testing channel connections (term. OFF): O1 -> I"
print(msg) print(msg)
mux_sel(bus, 0x1) mux_sel(bus, 0x1)
inf.write('\n') inf.write('\n')
...@@ -228,8 +239,9 @@ def main(bus, tname, inf, log): ...@@ -228,8 +239,9 @@ def main(bus, tname, inf, log):
dis_pulse_gen(bus) dis_pulse_gen(bus)
check_counters(pc, inf, pel) check_counters(pc, inf, pel)
clear_counters(pc) clear_counters(pc)
time.sleep(1)
msg = "Testing channel connections (term. OFF): O3 -> I" msg = "Testing channel connections (term. OFF): O2 -> I"
print(msg) print(msg)
mux_sel(bus, 0x2) mux_sel(bus, 0x2)
inf.write('\n') inf.write('\n')
...@@ -239,28 +251,26 @@ def main(bus, tname, inf, log): ...@@ -239,28 +251,26 @@ def main(bus, tname, inf, log):
dis_pulse_gen(bus) dis_pulse_gen(bus)
check_counters(pc, inf, pel) check_counters(pc, inf, pel)
clear_counters(pc) clear_counters(pc)
time.sleep(1)
msg = "Testing RS-485 fail-safe on short-circuit case (term. OFF)" msg = "Testing channel connections (term. OFF): O3 -> I"
print(msg) print(msg)
mux_sel(bus, 0x3) mux_sel(bus, 0x3)
inf.write('\n') inf.write('\n')
inf.write(msg+'\n') inf.write(msg+'\n')
en_pulse_gen(bus) en_pulse_gen(bus)
val = bus.vv_read(LSR) time.sleep(2)
val >>= LSR_REARFS_OFS
if (val == 0x3f):
msg = "RS-485 failsafe lines read as expected: 0x%02X\n" % val
inf.write(msg)
else:
msg = "ERROR: Failsafe lines readout (0x%02X) incorrect - expected 0x3F" % val
pel.set(msg)
dis_pulse_gen(bus) dis_pulse_gen(bus)
check_counters(pc, inf, pel)
clear_counters(pc)
time.sleep(1)
# Disable multiplexer # Disable multiplexer
print("Disabling multiplexers") print("Disabling multiplexers")
val = bus.vv_read(CSR) val = bus.vv_read(CSR)
val &= ~(1 << CSR_TESTER_MUX_EN_OFS) val &= ~(1 << CSR_TESTER_MUX_EN_OFS)
bus.vv_write(CSR, val) bus.vv_write(CSR, val)
time.sleep(1)
#-------------------------- #--------------------------
# Test with terminations ON # Test with terminations ON
...@@ -289,20 +299,27 @@ def main(bus, tname, inf, log): ...@@ -289,20 +299,27 @@ def main(bus, tname, inf, log):
val = bus.vv_read(CSR) val = bus.vv_read(CSR)
val |= (1 << CSR_TESTER_MUX_EN_OFS) val |= (1 << CSR_TESTER_MUX_EN_OFS)
bus.vv_write(CSR, val) bus.vv_write(CSR, val)
time.sleep(1)
# Generate pulses from different outputs to inputs msg = "Testing RS-485 fail-safe on short-circuit case (term. ON)"
msg = "Testing channel connections (term. ON): O1 -> I"
print(msg) print(msg)
mux_sel(bus, 0x0) mux_sel(bus, 0x0)
inf.write('\n') inf.write('\n')
inf.write(msg+'\n') inf.write(msg+'\n')
en_pulse_gen(bus) en_pulse_gen(bus)
time.sleep(2) val = bus.vv_read(LSR)
val >>= LSR_REARFS_OFS
if (val == 0x3f):
msg = "RS-485 failsafe lines read as expected: 0x%02X\n" % val
inf.write(msg)
else:
msg = "ERROR: Failsafe lines readout (0x%02X) incorrect - expected 0x3F" % val
pel.set(msg)
dis_pulse_gen(bus) dis_pulse_gen(bus)
check_counters(pc, inf, pel) time.sleep(1)
clear_counters(pc)
msg = "Testing channel connections (term. ON): O2 -> I" # Generate pulses from different outputs to inputs
msg = "Testing channel connections (term. ON): O1 -> I"
print(msg) print(msg)
mux_sel(bus, 0x1) mux_sel(bus, 0x1)
inf.write('\n') inf.write('\n')
...@@ -312,8 +329,9 @@ def main(bus, tname, inf, log): ...@@ -312,8 +329,9 @@ def main(bus, tname, inf, log):
dis_pulse_gen(bus) dis_pulse_gen(bus)
check_counters(pc, inf, pel) check_counters(pc, inf, pel)
clear_counters(pc) clear_counters(pc)
time.sleep(1)
msg = "Testing channel connections (term. ON): O3 -> I" msg = "Testing channel connections (term. ON): O2 -> I"
print(msg) print(msg)
mux_sel(bus, 0x2) mux_sel(bus, 0x2)
inf.write('\n') inf.write('\n')
...@@ -323,22 +341,19 @@ def main(bus, tname, inf, log): ...@@ -323,22 +341,19 @@ def main(bus, tname, inf, log):
dis_pulse_gen(bus) dis_pulse_gen(bus)
check_counters(pc, inf, pel) check_counters(pc, inf, pel)
clear_counters(pc) clear_counters(pc)
time.sleep(1)
msg = "Testing RS-485 fail-safe on short-circuit case (term. ON)" msg = "Testing channel connections (term. ON): O3 -> I"
print(msg) print(msg)
mux_sel(bus, 0x3) mux_sel(bus, 0x3)
inf.write('\n') inf.write('\n')
inf.write(msg+'\n') inf.write(msg+'\n')
en_pulse_gen(bus) en_pulse_gen(bus)
val = bus.vv_read(LSR) time.sleep(2)
val >>= LSR_REARFS_OFS
if (val == 0x3f):
msg = "RS-485 failsafe lines read as expected: 0x%02X\n" % val
inf.write(msg)
else:
msg = "ERROR: Failsafe lines readout (0x%02X) incorrect - expected 0x3F" % val
pel.set(msg)
dis_pulse_gen(bus) dis_pulse_gen(bus)
check_counters(pc, inf, pel)
clear_counters(pc)
time.sleep(1)
# Disable multiplexer # Disable multiplexer
print("Disabling multiplexers") print("Disabling multiplexers")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment