forked from M-Labs/artiq
1
0
Fork 0

Merge branch 'master' into nac3

This commit is contained in:
Sebastien Bourdeauducq 2022-02-25 19:02:07 +08:00
commit 404811cd5c
7 changed files with 159 additions and 57 deletions

View File

@ -207,3 +207,46 @@ class TCA6424A:
self._write24(0x8c, 0) # set all directions to output self._write24(0x8c, 0) # set all directions to output
self._write24(0x84, outputs_le) # set levels self._write24(0x84, outputs_le) # set levels
class PCF8574A:
"""Driver for the PCF8574 I2C remote 8-bit I/O expander.
I2C transactions not real-time, and are performed by the CPU without
involving RTIO.
"""
def __init__(self, dmgr, busno=0, address=0x7c, core_device="core"):
self.core = dmgr.get(core_device)
self.busno = busno
self.address = address
@kernel
def set(self, data):
"""Drive data on the quasi-bidirectional pins.
:param data: Pin data. High bits are weakly driven high
(and thus inputs), low bits are strongly driven low.
"""
i2c_start(self.busno)
try:
if not i2c_write(self.busno, self.address):
raise I2CError("PCF8574A failed to ack address")
if not i2c_write(self.busno, data):
raise I2CError("PCF8574A failed to ack data")
finally:
i2c_stop(self.busno)
@kernel
def get(self):
"""Retrieve quasi-bidirectional pin input data.
:return: Pin data
"""
i2c_start(self.busno)
ret = 0
try:
if not i2c_write(self.busno, self.address | 1):
raise I2CError("PCF8574A failed to ack address")
ret = i2c_read(self.busno, False)
finally:
i2c_stop(self.busno)
return ret

View File

@ -1,47 +0,0 @@
from artiq.experiment import kernel
from artiq.coredevice.i2c import (
i2c_start, i2c_write, i2c_read, i2c_stop, I2CError)
class PCF8574A:
"""Driver for the PCF8574 I2C remote 8-bit I/O expander.
I2C transactions not real-time, and are performed by the CPU without
involving RTIO.
"""
def __init__(self, dmgr, busno=0, address=0x7c, core_device="core"):
self.core = dmgr.get(core_device)
self.busno = busno
self.address = address
@kernel
def set(self, data):
"""Drive data on the quasi-bidirectional pins.
:param data: Pin data. High bits are weakly driven high
(and thus inputs), low bits are strongly driven low.
"""
i2c_start(self.busno)
try:
if not i2c_write(self.busno, self.address):
raise I2CError("PCF8574A failed to ack address")
if not i2c_write(self.busno, data):
raise I2CError("PCF8574A failed to ack data")
finally:
i2c_stop(self.busno)
@kernel
def get(self):
"""Retrieve quasi-bidirectional pin input data.
:return: Pin data
"""
i2c_start(self.busno)
ret = 0
try:
if not i2c_write(self.busno, self.address | 1):
raise I2CError("PCF8574A failed to ack address")
ret = i2c_read(self.busno, False)
finally:
i2c_stop(self.busno)
return ret

View File

@ -0,0 +1,42 @@
# RUN: %python -m artiq.compiler.testbench.jit %s >%t
# RUN: OutputCheck %s --file-to-check=%t
# REQUIRES: exceptions
def run():
loop = 0
print("start")
try:
while True:
print("loop")
try:
if loop == 0:
loop += 1
continue
func()
break
except RuntimeError:
print("except")
return False
finally:
print("finally2")
print("after-while")
finally:
print("finally1")
print("exit")
return True
def func():
print("func")
# CHECK-L: start
# CHECK-NEXT-L: loop
# CHECK-NEXT-L: finally2
# CHECK-NEXT-L: loop
# CHECK-NEXT-L: func
# CHECK-NEXT-L: finally2
# CHECK-NEXT-L: after-while
# CHECK-NEXT-L: finally1
# CHECK-NEXT-L: exit
run()

View File

@ -0,0 +1,42 @@
# RUN: %python -m artiq.compiler.testbench.jit %s >%t
# RUN: OutputCheck %s --file-to-check=%t
# REQUIRES: exceptions
def run():
print("start")
try:
try:
while True:
print("loop")
try:
print("try")
func()
print("unreachable")
return True
except RuntimeError:
print("except1")
raise
print("unreachable")
finally:
print("finally1")
print("unreachable")
return False
except RuntimeError:
print("except2")
raise
finally:
print("finally2")
return True
def func():
raise RuntimeError("Test")
# CHECK-L: start
# CHECK-NEXT-L: loop
# CHECK-NEXT-L: try
# CHECK-NEXT-L: except1
# CHECK-NEXT-L: finally1
# CHECK-NEXT-L: except2
# CHECK-NEXT-L: finally2
run()

View File

@ -0,0 +1,29 @@
# RUN: %python -m artiq.compiler.testbench.jit %s >%t
# RUN: OutputCheck %s --file-to-check=%t
# REQUIRES: exceptions
def run():
try:
while True:
try:
print("try")
func()
return True
except RuntimeError:
print("except")
return False
print("unreachable")
finally:
print("finally")
print("unreachable")
return False
def func():
pass
# CHECK-L: try
# CHECK-NOT-L: except
# CHECK-NOT-L: unreachable
# CHECK-L: finally
run()

View File

@ -65,13 +65,6 @@ Digital I/O drivers
.. automodule:: artiq.coredevice.i2c .. automodule:: artiq.coredevice.i2c
:members: :members:
:mod:`artiq.coredevice.pcf8574a` module
+++++++++++++++++++++++++++++++++++++++
.. automodule:: artiq.coredevice.pcf8574a
:members:
RF generation drivers RF generation drivers
--------------------- ---------------------

View File

@ -378,8 +378,8 @@
}; };
nixConfig = { nixConfig = {
binaryCachePublicKeys = ["nixbld.m-labs.hk-1:5aSRVA5b320xbNvu30tqxVPXpld73bhtOeH6uAjRyHc="]; extra-trusted-public-keys = "nixbld.m-labs.hk-1:5aSRVA5b320xbNvu30tqxVPXpld73bhtOeH6uAjRyHc=";
binaryCaches = ["https://nixbld.m-labs.hk" "https://cache.nixos.org"]; extra-substituters = "https://nixbld.m-labs.hk";
sandboxPaths = ["/opt"]; extra-sandbox-paths = "/opt";
}; };
} }