diff --git a/tools/lwl/ocdconsole.py b/tools/lwl/ocdconsole.py index 86c2030be69..cfabfcf756c 100755 --- a/tools/lwl/ocdconsole.py +++ b/tools/lwl/ocdconsole.py @@ -65,13 +65,13 @@ LWL_UPSENSESHIFT = 29 LWL_OCTVALSHIFT = 27 LWL_PORTSHIFT = 24 -LWL_PORTMASK = (7<=length): + if downwordaddr >= length: print("ERROR: Cannot find signature\r") exit(1) # We have the base address, so get the variables themselves # ========================================================= - downwordaddr=baseaddr+downwordaddr+4 - upwordaddr=downwordaddr+4 - downword=LWL_ACTIVE + downwordaddr = baseaddr + downwordaddr + 4 + upwordaddr = downwordaddr + 4 + downword = LWL_ACTIVE # Now wake up the link...keep on trying if it goes down # ===================================================== while True: ocd.writeVariable(downwordaddr, downword) upword = ocd.readVariable(upwordaddr) - if (upword&LWL_ACTIVE!=0): + if upword & LWL_ACTIVE != 0: print("==Link Activated\r") break - except (BrokenPipeError, ConnectionRefusedError, ConnectionResetError) as e: + except ( + BrokenPipeError, + ConnectionRefusedError, + ConnectionResetError, + ) as e: raise e # Now run the comms loop until something fails @@ -228,32 +239,48 @@ if __name__ == "__main__": while True: ocd.writeVariable(downwordaddr, downword) upword = ocd.readVariable(upwordaddr) - if (upword&LWL_ACTIVE==0): + if upword & LWL_ACTIVE == 0: print("\r==Link Deactivated\r") break if kbhit(): charin = sys.stdin.read(1) - if (ord(charin)==3): + if ord(charin) == 3: sys.exit(0) - if (downword&LWL_DNSENSEBIT): - downword=(downword&LWL_UPSENSEBIT) + if downword & LWL_DNSENSEBIT: + downword = downword & LWL_UPSENSEBIT else: - downword=(downword&LWL_UPSENSEBIT)|LWL_DNSENSEBIT - downword|=(LWL_PORT_CONSOLE<>LWL_PORTSHIFT - if (incomingPort==LWL_PORT_CONSOLE): - incomingBytes=(upword&LWL_OCTVALMASK)>>LWL_OCTVALSHIFT - if (incomingBytes>=1): dooutput(upword&255); - if (incomingBytes>=2): dooutput((upword>>8)&255); - if (incomingBytes==3): dooutput((upword>>16)&255); + if (upword & LWL_UPSENSEBIT) != (downword & LWL_UPSENSEBIT): + incomingPort = (upword & LWL_PORTMASK) >> LWL_PORTSHIFT + if incomingPort == LWL_PORT_CONSOLE: + incomingBytes = ( + upword & LWL_OCTVALMASK + ) >> LWL_OCTVALSHIFT + if incomingBytes >= 1: + dooutput(upword & 255) + if incomingBytes >= 2: + dooutput((upword >> 8) & 255) + if incomingBytes == 3: + dooutput((upword >> 16) & 255) - if (downword&LWL_UPSENSEBIT): - downword = downword&~LWL_UPSENSEBIT + if downword & LWL_UPSENSEBIT: + downword = downword & ~LWL_UPSENSEBIT else: - downword = downword|LWL_UPSENSEBIT - except (ConnectionResetError, ConnectionResetError, BrokenPipeError) as e: + downword = downword | LWL_UPSENSEBIT + except ( + ConnectionResetError, + ConnectionResetError, + BrokenPipeError, + ) as e: print("\r==Link Lost\r") raise e