2015-12-31 21:54:54 +08:00
|
|
|
import builtins
|
2016-01-26 07:48:13 +08:00
|
|
|
import linecache
|
|
|
|
import re
|
|
|
|
import os
|
|
|
|
|
2016-01-26 09:04:06 +08:00
|
|
|
from artiq import __artiq_dir__ as artiq_dir
|
2016-01-26 06:52:52 +08:00
|
|
|
from artiq.coredevice.runtime import source_loader
|
2015-08-07 16:44:49 +08:00
|
|
|
|
2015-12-22 12:03:11 +08:00
|
|
|
|
2015-12-31 21:54:54 +08:00
|
|
|
ZeroDivisionError = builtins.ZeroDivisionError
|
|
|
|
ValueError = builtins.ValueError
|
|
|
|
IndexError = builtins.IndexError
|
2018-08-07 13:53:13 +08:00
|
|
|
RuntimeError = builtins.RuntimeError
|
2015-08-08 21:01:08 +08:00
|
|
|
|
2015-12-22 12:03:11 +08:00
|
|
|
|
2016-01-26 06:52:52 +08:00
|
|
|
class CoreException:
|
|
|
|
"""Information about an exception raised or passed through the core device."""
|
|
|
|
|
|
|
|
def __init__(self, name, message, params, traceback):
|
|
|
|
if ':' in name:
|
|
|
|
exn_id, self.name = name.split(':', 2)
|
|
|
|
self.id = int(exn_id)
|
|
|
|
else:
|
|
|
|
self.id, self.name = 0, name
|
|
|
|
self.message, self.params = message, params
|
|
|
|
self.traceback = list(traceback)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
lines = []
|
|
|
|
lines.append("Core Device Traceback (most recent call last):")
|
2016-02-25 01:44:07 +08:00
|
|
|
last_address = 0
|
2016-01-26 06:52:52 +08:00
|
|
|
for (filename, line, column, function, address) in self.traceback:
|
|
|
|
stub_globals = {"__name__": filename, "__loader__": source_loader}
|
|
|
|
source_line = linecache.getline(filename, line, stub_globals)
|
|
|
|
indentation = re.search(r"^\s*", source_line).end()
|
|
|
|
|
|
|
|
if address is None:
|
|
|
|
formatted_address = ""
|
2016-02-25 01:44:07 +08:00
|
|
|
elif address == last_address:
|
|
|
|
formatted_address = " (inlined)"
|
2016-01-26 06:52:52 +08:00
|
|
|
else:
|
2016-04-03 01:48:09 +08:00
|
|
|
formatted_address = " (RA=+0x{:x})".format(address)
|
2016-02-25 01:44:07 +08:00
|
|
|
last_address = address
|
2016-01-26 06:52:52 +08:00
|
|
|
|
2016-01-26 09:04:06 +08:00
|
|
|
filename = filename.replace(artiq_dir, "<artiq>")
|
2016-01-26 06:52:52 +08:00
|
|
|
if column == -1:
|
|
|
|
lines.append(" File \"{file}\", line {line}, in {function}{address}".
|
|
|
|
format(file=filename, line=line, function=function,
|
|
|
|
address=formatted_address))
|
|
|
|
lines.append(" {}".format(source_line.strip() if source_line else "<unknown>"))
|
|
|
|
else:
|
|
|
|
lines.append(" File \"{file}\", line {line}, column {column},"
|
|
|
|
" in {function}{address}".
|
|
|
|
format(file=filename, line=line, column=column + 1,
|
|
|
|
function=function, address=formatted_address))
|
|
|
|
lines.append(" {}".format(source_line.strip() if source_line else "<unknown>"))
|
|
|
|
lines.append(" {}^".format(" " * (column - indentation)))
|
|
|
|
|
|
|
|
lines.append("{}({}): {}".format(self.name, self.id,
|
|
|
|
self.message.format(*self.params)))
|
|
|
|
return "\n".join(lines)
|
|
|
|
|
|
|
|
|
2015-12-31 21:54:54 +08:00
|
|
|
class InternalError(Exception):
|
2015-08-07 16:44:49 +08:00
|
|
|
"""Raised when the runtime encounters an internal error condition."""
|
2016-01-19 09:45:25 +08:00
|
|
|
artiq_builtin = True
|
2015-08-07 16:44:49 +08:00
|
|
|
|
2015-12-22 12:03:11 +08:00
|
|
|
|
2016-01-10 22:43:30 +08:00
|
|
|
class CacheError(Exception):
|
|
|
|
"""Raised when putting a value into a cache row would violate memory safety."""
|
2016-01-19 09:45:25 +08:00
|
|
|
artiq_builtin = True
|
2016-01-10 22:43:30 +08:00
|
|
|
|
|
|
|
|
2015-12-31 21:54:54 +08:00
|
|
|
class RTIOUnderflow(Exception):
|
2018-03-03 13:14:34 +08:00
|
|
|
"""Raised when the CPU or DMA core fails to submit a RTIO event early
|
|
|
|
enough (with respect to the event's timestamp).
|
2015-08-07 16:44:49 +08:00
|
|
|
|
|
|
|
The offending event is discarded and the RTIO core keeps operating.
|
|
|
|
"""
|
2016-01-19 09:45:25 +08:00
|
|
|
artiq_builtin = True
|
2015-08-07 16:44:49 +08:00
|
|
|
|
|
|
|
|
2015-12-31 21:54:54 +08:00
|
|
|
class RTIOOverflow(Exception):
|
2015-08-07 16:44:49 +08:00
|
|
|
"""Raised when at least one event could not be registered into the RTIO
|
|
|
|
input FIFO because it was full (CPU not reading fast enough).
|
|
|
|
|
|
|
|
This does not interrupt operations further than cancelling the current
|
|
|
|
read attempt and discarding some events. Reading can be reattempted after
|
|
|
|
the exception is caught, and events will be partially retrieved.
|
|
|
|
"""
|
2016-01-19 09:45:25 +08:00
|
|
|
artiq_builtin = True
|
2015-08-07 16:44:49 +08:00
|
|
|
|
2017-09-29 14:40:06 +08:00
|
|
|
|
2018-09-15 15:55:45 +08:00
|
|
|
class RTIODestinationUnreachable(Exception):
|
2018-03-04 01:02:53 +08:00
|
|
|
"""Raised with a RTIO operation could not be completed due to a DRTIO link
|
|
|
|
being down.
|
|
|
|
"""
|
|
|
|
artiq_builtin = True
|
|
|
|
|
|
|
|
|
2017-02-26 10:50:20 +08:00
|
|
|
class DMAError(Exception):
|
|
|
|
"""Raised when performing an invalid DMA operation."""
|
|
|
|
artiq_builtin = True
|
|
|
|
|
2017-09-29 14:40:06 +08:00
|
|
|
|
2016-03-19 06:29:42 +08:00
|
|
|
class WatchdogExpired(Exception):
|
|
|
|
"""Raised when a watchdog expires."""
|
|
|
|
|
2017-09-29 14:40:06 +08:00
|
|
|
|
2016-03-19 06:29:42 +08:00
|
|
|
class ClockFailure(Exception):
|
2016-03-19 18:01:00 +08:00
|
|
|
"""Raised when RTIO PLL has lost lock."""
|
2017-06-19 14:22:59 +08:00
|
|
|
|
2017-09-29 14:40:06 +08:00
|
|
|
|
2017-06-19 14:22:59 +08:00
|
|
|
class I2CError(Exception):
|
|
|
|
"""Raised when a I2C transaction fails."""
|
|
|
|
pass
|
|
|
|
|
2017-09-29 14:40:06 +08:00
|
|
|
|
2017-06-19 14:22:59 +08:00
|
|
|
class SPIError(Exception):
|
2017-06-19 15:42:10 +08:00
|
|
|
"""Raised when a SPI transaction fails."""
|
2017-06-19 14:22:59 +08:00
|
|
|
pass
|