m1n1.fw.asc: Add boot_or_start()

This tries both ways so it'll work regardless of how the ASC was shut
down.

Signed-off-by: Asahi Lina <lina@asahilina.net>
This commit is contained in:
Asahi Lina 2022-05-21 03:09:38 +09:00
parent f3830c034f
commit cbe0e98f4c
3 changed files with 22 additions and 5 deletions

View file

@ -7,7 +7,7 @@ from .mgmt import ASCManagementEndpoint
from .kdebug import ASCKDebugEndpoint
from .ioreporting import ASCIOReportingEndpoint
from .oslog import ASCOSLogEndpoint
from .base import ASCBaseEndpoint
from .base import ASCBaseEndpoint, ASCTimeout
from ...hw.asc import ASC
__all__ = []
@ -83,17 +83,25 @@ class StandardASC(ASC):
self.mgmt.start()
self.mgmt.wait_boot()
def stop(self):
def stop(self, state=0x10):
for ep in list(self.epmap.values())[::-1]:
if ep.epnum < 0x10:
continue
ep.stop()
self.mgmt.stop()
self.mgmt.stop(state=state)
def boot(self):
print("Booting ASC...")
super().boot()
self.mgmt.wait_boot()
def boot_or_start(self):
super().boot()
try:
self.mgmt.wait_boot(0.2)
except ASCTimeout:
self.mgmt.start()
self.mgmt.wait_boot(0.2)
__all__.extend(k for k, v in globals().items()
if (callable(v) or isinstance(v, type)) and v.__module__ == __name__)

View file

@ -14,6 +14,9 @@ def msg_handler(message, regtype=None):
class ASCMessage1(Register64):
EP = 7, 0
class ASCTimeout(Exception):
pass
class ASCBaseEndpoint:
BASE_MESSAGE = Register64
SHORT = None

View file

@ -1,4 +1,6 @@
# SPDX-License-Identifier: MIT
import time
from .base import *
from ...utils import *
@ -107,10 +109,14 @@ class ASCManagementEndpoint(ASCBaseEndpoint):
self.log("Starting via message")
self.send(Mgmt_SetIOPPower(STATE=0x220))
def wait_boot(self):
def wait_boot(self, timeout=None):
if timeout is not None:
timeout += time.time()
while self.iop_power_state != 0x20 or self.ap_power_state != 0x20:
self.asc.work()
self.log("startup complete")
if timeout and time.time() > timeout:
raise ASCTimeout("Boot timed out")
self.log("Startup complete")
def start_ep(self, epno):
self.send(Mgmt_StartEP(EP=epno, FLAG=2))