#!/usr/bin/env python
from datetime import datetime as dt
+import glob
+import os
from time import sleep
import yaml
amux = None
-def close_usb():
+def close_usb(delay=0):
"""
Close the three MPSSE ports from the usb side. If the serial port is also
closed, the kernel will suspend the device. This makes the SUSPEND pin go
low on the usbio board and allows a circuit to cut power to the devboard.
"""
- print 'closing usb ports'
+ print 'closing usb ports, waiting for kernel to suspend port'
for c in (spi0.context, spi1.context, i2c.context):
usbio.ftdi.usb_close(c)
- print 'sleeping...'
- sleep(5)
+ sleep(delay)
def init_devboard(name='devboard-defaults.yaml'):
global chain, mux
global arb, amux
+
+ USB_SUSPEND_DELAY = 0
+
+ # check for appropriate usb autosuspend settings
+ for p in glob.glob('/sys/bus/usb/devices/*'):
+ m = '%s/manufacturer' % p
+ c = '%s/power/control' % p
+ a = '%s/power/autosuspend_delay_ms' % p
+ if os.path.exists(m) and ('White Audio' in open(m).readline()):
+ control = open(c).readline().strip()
+ autosuspend = open(a).readline().strip()
+ ms = int(autosuspend)
+ if 'auto' not in control:
+ print "WARNING: autosuspend is not 'auto', currently: %s" % control
+ print "******* therefore unable to power-cycle devboard."
+ print 'INFO: kernel autosuspend is %i ms' % ms
+ USB_SUSPEND_DELAY = 1.2 * (ms + 1) / 1e3
+
#blank the slate
if is_initialized:
- close_usb()
+ close_usb(USB_SUSPEND_DELAY)
+
_config = {}
spi0 = None
spi1 = None