all the other commands
This commit is contained in:
parent
a093bc8def
commit
2823f33039
|
@ -40,6 +40,12 @@ static int lc_brate = PINOUT_UART_BAUDRATE,
|
|||
lc_data = 8, lc_parity = 0, lc_stop = 1;
|
||||
|
||||
void cdc_uart_init(void) {
|
||||
/*lc_brate = PINOUT_UART_BAUDRATE;
|
||||
lc_data = 8;
|
||||
lc_parity = 0;
|
||||
lc_stop = 1;
|
||||
hwflow = false;*/
|
||||
|
||||
gpio_set_function(PINOUT_UART_TX, GPIO_FUNC_UART);
|
||||
gpio_set_function(PINOUT_UART_RX, GPIO_FUNC_UART);
|
||||
uart_init(PINOUT_UART_INTERFACE, lc_brate/*PINOUT_UART_BAUDRATE*/);
|
||||
|
@ -81,7 +87,7 @@ bool cdc_uart_get_hwflow(void) {
|
|||
}
|
||||
bool cdc_uart_set_hwflow(bool enable) {
|
||||
hwflow = enable;
|
||||
uart_set_hw_flow(PINOUT_UART_INTERFACE, enable, enable);
|
||||
//uart_set_hw_flow(PINOUT_UART_INTERFACE, enable, enable);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -92,14 +98,18 @@ uint32_t cdc_uart_set_coding(uint32_t brate,
|
|||
int picopar = 0;
|
||||
switch (parity) {
|
||||
case 0: break;
|
||||
case 1: picopar = 2; break;
|
||||
case 2: picopar = 1; break;
|
||||
default: picopar = -1; break;
|
||||
case 1: picopar = 2; break;
|
||||
default: picopar = lc_parity; break;
|
||||
}
|
||||
|
||||
if (picopar >= 0)
|
||||
uart_set_format(PINOUT_UART_INTERFACE, data, stop, picopar);
|
||||
return uart_set_baudrate(PINOUT_UART_INTERFACE, brate);
|
||||
// FIXME: this is broken fsr
|
||||
/*uart_set_format(PINOUT_UART_INTERFACE, data, stop, picopar);
|
||||
|
||||
lc_data = data;
|
||||
lc_parity = picopar;
|
||||
lc_stop = stop;*/
|
||||
return (lc_brate = uart_set_baudrate(PINOUT_UART_INTERFACE, brate));
|
||||
}
|
||||
|
||||
// idk where to put this otherwise
|
||||
|
|
|
@ -304,7 +304,6 @@ void sump_hw_capture_stop(void) {
|
|||
}
|
||||
|
||||
void sump_hw_init(void) {
|
||||
// TODO: make this configurable
|
||||
if (overclock) {
|
||||
vreg_set_voltage(VREG_VOLTAGE_1_15);
|
||||
set_sys_clock_khz(200000, true);
|
||||
|
|
|
@ -104,7 +104,7 @@ print(res)
|
|||
|
||||
### ATTEMPT A MODESET ###
|
||||
|
||||
epout.write(b'\x03\x04') # set cur mode
|
||||
print('[%s]'%(', '.join(hex(x) for x in epin.read(3)))) # result: status, payload len, mode
|
||||
#epout.write(b'\x03\x04') # set cur mode
|
||||
#print('[%s]'%(', '.join(hex(x) for x in epin.read(3)))) # result: status, payload len, mode
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ def dmctl_do(args: Any) -> int:
|
|||
def uart_hw_flowctl(conn, args):
|
||||
if args.get: return devcmds.uart_hw_flowctl_get(conn)
|
||||
fcen = args.set
|
||||
if isinstance(fcen, list): fcen = fcen[0]
|
||||
if fcen is None:
|
||||
if args.enable: fcen = True
|
||||
elif args.disable: fcen = False
|
||||
|
@ -29,8 +30,9 @@ def dmctl_do(args: Any) -> int:
|
|||
def tempsensor(conn, args):
|
||||
if args.get: return devcmds.tempsensor_get(conn)
|
||||
tsen = args.set
|
||||
if isinstance(tsen, list): tsen = tsen[0]
|
||||
if tsen is None:
|
||||
if args.disable: tsen = 0
|
||||
if args.disable: tsen = 0xff
|
||||
if tsen is None:
|
||||
print("Error: none of '--get', '--set' or '--disable' specified.")
|
||||
return 1
|
||||
|
@ -40,6 +42,7 @@ def dmctl_do(args: Any) -> int:
|
|||
def sump_ovclk(conn, args):
|
||||
if args.get: return devcmds.sump_overclock_get(conn)
|
||||
oven = args.set
|
||||
if isinstance(oven, list): oven = oven[0]
|
||||
if oven is None:
|
||||
if args.enable: oven = 1
|
||||
elif args.disable: oven = 0
|
||||
|
@ -80,7 +83,7 @@ def dmctl_do(args: Any) -> int:
|
|||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser = argparse.ArgumentParser(prog="dmctl")
|
||||
|
||||
def auto_int(x):
|
||||
return int(x, 0)
|
||||
|
@ -136,7 +139,7 @@ def main() -> int:
|
|||
setmode.add_argument('mode', type=int, help="Mode to switch to, required.")
|
||||
|
||||
# mode 1 commands
|
||||
usbhwfctl = subcmds.add_parser("uart-cts-rts", help="Get, Enable/disable"+\
|
||||
usbhwfctl = subcmds.add_parser("uart-cts-rts", help="Get, enable/disable"+\
|
||||
" UART hardware flow control")
|
||||
uartopts = usbhwfctl.add_mutually_exclusive_group()
|
||||
uartopts.add_argument('--get', default=False, action='store_true',
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
import traceback
|
||||
|
||||
from typing import *
|
||||
|
||||
from .protocol import *
|
||||
|
@ -71,38 +73,108 @@ def set_mode(dev: DmjDevice, mode: int) -> int:
|
|||
|
||||
|
||||
def uart_hw_flowctl_get(dev: DmjDevice) -> int:
|
||||
return 0
|
||||
try:
|
||||
res = dev.m1_usb_hw_flowctl_get()
|
||||
print("Flow control %sabled" % ("en" if res else "dis"))
|
||||
return 0
|
||||
except Exception as e:
|
||||
print("Could not get flow control state: %s" % str(e))
|
||||
return 1
|
||||
|
||||
|
||||
def uart_hw_flowctl_set(dev: DmjDevice, v: bool) -> int:
|
||||
return 0
|
||||
try:
|
||||
dev.m1_usb_hw_flowctl_set(v)
|
||||
return 0
|
||||
except Exception as e:
|
||||
print("Could not set flow control state: %s" % str(e))
|
||||
return 1
|
||||
|
||||
|
||||
# ---
|
||||
|
||||
|
||||
def tempsensor_get(dev: DmjDevice) -> int:
|
||||
return 0
|
||||
try:
|
||||
res = dev.m1_tempsensor_i2cemul_get()
|
||||
if res is None:
|
||||
print("Temperature sensor I2C emulation disabled")
|
||||
else:
|
||||
print("Temperature sensor I2C device at address 0x%02x" % res)
|
||||
return 0
|
||||
except Exception as e:
|
||||
print("Could not get temperature sensor I2C emulation: %s" % str(e))
|
||||
return 1
|
||||
|
||||
|
||||
def tempsensor_set(dev, v: int) -> int:
|
||||
return 0
|
||||
try:
|
||||
old, new = dev.m1_tempsensor_i2cemul_set(v)
|
||||
olds = "disabled" if old is None else ("0x%02x" % old)
|
||||
news = "disabled" if new is None else ("0x%02x" % new)
|
||||
print("Temperature sensor I2C device changed from %s to %s" % (olds, news))
|
||||
return 0
|
||||
except Exception as e:
|
||||
print("Could not set temperature sensor I2C emulation: %s" % str(e))
|
||||
return 1
|
||||
|
||||
|
||||
# ---
|
||||
|
||||
|
||||
def jtag_scan(dev: DmjDevice) -> int:
|
||||
return 0
|
||||
def jtag_scan(dev: DmjDevice, start_pin: int, end_pin: int) -> int:
|
||||
SCAN_IDLE = 0x00
|
||||
SCAN_BUSY = 0x01
|
||||
SCAN_FAIL = 0x03
|
||||
SCAN_SUCCESS = 0x04
|
||||
|
||||
try:
|
||||
stat = dev.m3_jtagscan_get_status()
|
||||
|
||||
if stat == SCAN_BUSY:
|
||||
print("Another scan already in progress, aborting")
|
||||
return 1
|
||||
|
||||
dev.m3_jtagscan_start(start_pin, end_pin)
|
||||
|
||||
stat = SCAN_BUSY
|
||||
while stat == SCAN_BUSY: # TODO: timeout?
|
||||
stat = dev.m3_jtagscan_get_status()
|
||||
|
||||
if stat == SCAN_SUCCESS:
|
||||
result = dev.m3_jtagscan_get_result()
|
||||
print("JTAG scan result: %s" % ', '.join("%s=%d" % kvp for kvp in result.items()))
|
||||
return 0
|
||||
elif stat == SCAN_FAIL:
|
||||
print("JTAG scan failure: %s" % dev.m3_jtagscan_get_Error())
|
||||
return 0
|
||||
else:
|
||||
print("Huh, device replied weird status %d?" % stat)
|
||||
return 1
|
||||
except Exception as e:
|
||||
print("Could not perform JTAG scan: %s" % str(e))
|
||||
return 1
|
||||
|
||||
|
||||
# ---
|
||||
|
||||
|
||||
def sump_overclock_get(dev: DmjDevice) -> int:
|
||||
return 0
|
||||
try:
|
||||
stat = dev.m4_sump_overclock_get()
|
||||
print("SUMP overclocking mode: %d" % stat)
|
||||
return 0
|
||||
except Exception as e:
|
||||
print("Could not get SUMP overclocking: %s" % str(e))
|
||||
return 1
|
||||
|
||||
|
||||
def sump_overclock_set(dev: DmjDevice, v: int) -> int:
|
||||
return 0
|
||||
try:
|
||||
stat = dev.m4_sump_overclock_set(v)
|
||||
return 0
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
print("Could not set SUMP overclocking: %s" % str(e))
|
||||
return 1
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ class UsbConn(DevConn):
|
|||
return "Version of device (%04x) too new, must be max. %04x" \
|
||||
% (hex(verno, DevConn._VER_MAX))
|
||||
|
||||
return UsbConn(dev, cfg, itf, epout, epin)
|
||||
return UsbConn(dev, cfg, itf, epin, epout)
|
||||
|
||||
def try_find() -> Optional[UsbConn]:
|
||||
import usb.core
|
||||
|
|
|
@ -24,11 +24,11 @@ def check_statpl(stat, pl, defmsg, minl=None, maxl=None):
|
|||
}
|
||||
|
||||
if stat != STAT_OK:
|
||||
if len(pl):
|
||||
if len(pl) != 0:
|
||||
raise Exception(pl.rstrip(b'\0').decode('utf-8'))
|
||||
else:
|
||||
errstr = statmsgs.get(stat, str(stat))
|
||||
raise Exception("%s: bad response: %s" % (defmsg, errstr))
|
||||
raise Exception("%s: %s" % (defmsg, errstr))
|
||||
|
||||
if minl is not None:
|
||||
if len(pl) < minl:
|
||||
|
@ -136,7 +136,7 @@ class DmjDevice:
|
|||
|
||||
# TODO: need to invalidate all fncalls after this one because the device will be gone
|
||||
def set_mode(self, mode: int):
|
||||
cmd = b'\x03\xff'
|
||||
cmd = bytearray(b'\x03\xff')
|
||||
cmd[1] = mode
|
||||
self.write(cmd)
|
||||
stat, pl = self.read_resp()
|
||||
|
@ -188,7 +188,7 @@ class DmjDevice:
|
|||
return pl[0] != 0
|
||||
|
||||
def m1_usb_hw_flowctl_set(self, enabled: bool):
|
||||
cmd = b'\x16\xc3'
|
||||
cmd = bytearray(b'\x16\xc3')
|
||||
cmd[1] = 1 if enabled else 0
|
||||
self.write(cmd)
|
||||
stat, pl = self.read_resp()
|
||||
|
@ -202,7 +202,7 @@ class DmjDevice:
|
|||
return None if pl[0] == 0xff else pl[0]
|
||||
|
||||
def m1_tempsensor_i2cemul_set(self, addr: Optional[int]) -> Tuple[Optional[int], Optional[int]]:
|
||||
cmd = b'\x15\x01\xff'
|
||||
cmd = bytearray(b'\x15\x01\xff')
|
||||
cmd[2] = 0xff if addr is None else addr
|
||||
self.write(cmd)
|
||||
stat, pl = self.read_resp()
|
||||
|
@ -217,7 +217,7 @@ class DmjDevice:
|
|||
# mode 3 commands
|
||||
|
||||
def m3_jtagscan_get_status(self) -> int:
|
||||
self.write(b'\x30')
|
||||
self.write(b'\x33')
|
||||
stat, pl = self.read_resp()
|
||||
check_statpl(stat, pl, "m3: jtag scan status", 1, 1)
|
||||
|
||||
|
@ -226,14 +226,21 @@ class DmjDevice:
|
|||
def m3_jtagscan_get_result(self) -> Dict[str, int]:
|
||||
pinassign = ['TCK', 'TMS', 'TDI', 'TDO', 'TRST']
|
||||
|
||||
self.write(b'\x31')
|
||||
self.write(b'\x34')
|
||||
stat, pl = self.read_resp()
|
||||
check_statpl(stat, pl, "m3: jtag scan result", 5, 5)
|
||||
|
||||
return { pinassign[i]: pl[i] for i in range(len(pl)) }
|
||||
|
||||
def m3_jtagscan_get_error(self) -> str:
|
||||
self.write(b'\x34')
|
||||
stat, pl = self.read_resp()
|
||||
check_statpl(stat, pl, "m3: jtag scan error", 1)
|
||||
|
||||
return pl.rstrip(b'\0').decode('utf-8')
|
||||
|
||||
def m3_jtagscan_start(self, min_pin: int, max_pin: int):
|
||||
cmd = b'\x32\xff\x00'
|
||||
cmd = bytearray(b'\x35\xff\x00')
|
||||
cmd[1], cmd[2] = min_pin, max_pin
|
||||
self.write(cmd)
|
||||
stat, pl = self.read_resp()
|
||||
|
@ -242,14 +249,14 @@ class DmjDevice:
|
|||
# mode 4 commands
|
||||
|
||||
def m4_sump_overclock_get(self) -> int:
|
||||
self.write(b'\x40')
|
||||
self.write(b'\x43')
|
||||
stat, pl = self.read_resp()
|
||||
check_statpl(stat, pl, "m4: sump overclock get", 1, 1)
|
||||
|
||||
return pl[0]
|
||||
|
||||
def m4_sump_overclock_set(self, ovclk: int):
|
||||
cmd = b'\x41\xff'
|
||||
cmd = bytearray(b'\x44\xff')
|
||||
cmd[1] = ovclk
|
||||
self.write(cmd)
|
||||
stat, pl = self.read_resp()
|
||||
|
|
Loading…
Reference in New Issue