Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f2b4b975a3f0
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2770d9c729df
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Mar 5, 2016

  1. Copy the full SHA
    125ab3e View commit details
  2. Copy the full SHA
    36387af View commit details
  3. Copy the full SHA
    6837160 View commit details
  4. doc: I2C/QC2

    sbourdeauducq committed Mar 5, 2016
    Copy the full SHA
    2770d9c View commit details
Showing with 94 additions and 1 deletion.
  1. +36 −0 artiq/coredevice/i2c.py
  2. +1 −1 artiq/runtime/i2c.c
  3. +25 −0 artiq/test/coredevice/test_i2c.py
  4. +20 −0 doc/manual/core_device.rst
  5. +6 −0 doc/manual/core_drivers_reference.rst
  6. +6 −0 examples/master/device_db.pyon
36 changes: 36 additions & 0 deletions artiq/coredevice/i2c.py
Original file line number Diff line number Diff line change
@@ -29,13 +29,24 @@ def i2c_read(busno: TInt32, ack: TBool) -> TInt32:


class PCA9548:
"""Driver for the PCA9548 I2C bus switch.
On the KC705, this chip is used for selecting the I2C buses on the two FMC
connectors. HPC=1, LPC=2.
"""
def __init__(self, dmgr, busno=0, address=0xe8):
self.core = dmgr.get("core")
self.busno = busno
self.address = address

@kernel
def set(self, channel):
"""Select one channel.
Selecting multiple channels is not supported by this driver.
:param channel: channel number (0-7)
"""
i2c_init(self.busno)
i2c_start(self.busno)
try:
@@ -46,8 +57,25 @@ def set(self, channel):
finally:
i2c_stop(self.busno)

@kernel
def readback(self):
i2c_init(self.busno)
i2c_start(self.busno)
r = 0
try:
if not i2c_write(self.busno, self.address | 1):
raise I2CError("PCA9548 failed to ack address")
r = i2c_read(self.busno, False)
finally:
i2c_stop(self.busno)
return r


class TCA6424A:
"""Driver for the TCA6424A I2C I/O expander.
On the NIST QC2 hardware, this chip is used for switching the directions
of TTL buffers."""
def __init__(self, dmgr, busno=0, address=0x44):
self.core = dmgr.get("core")
self.busno = busno
@@ -71,5 +99,13 @@ def _write24(self, command, value):

@kernel
def set(self, outputs):
"""Drive all pins of the chip to the levels given by the
specified 24-bit word.
On the QC2 hardware, the LSB of the word determines the direction of
TTL0 (on a given FMC card) and the MSB that of TTL23.
A bit set to 1 means the TTL is an output.
"""
self._write24(0x8c, 0) # set all directions to output
self._write24(0x84, output) # set levels
2 changes: 1 addition & 1 deletion artiq/runtime/i2c.c
Original file line number Diff line number Diff line change
@@ -160,7 +160,7 @@ int i2c_write(int busno, int b)
int i2c_read(int busno, int ack)
{
int i;
char b;
unsigned char b;

/* Set SCL low first, otherwise setting SDA as input may cause a transition
* on SDA with SCL high which will be interpreted as START/STOP condition.
25 changes: 25 additions & 0 deletions artiq/test/coredevice/test_i2c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os, unittest

from artiq.experiment import *
from artiq.test.hardware_testbench import ExperimentCase


class I2CSwitch(EnvExperiment):
def build(self):
self.setattr_device("core")
self.setattr_device("i2c_switch")

@kernel
def run(self):
passed = True
for i in range(8):
self.i2c_switch.set(i)
if self.i2c_switch.readback() != 1 << i:
passed = False
self.set_dataset("passed", passed)


class I2CTest(ExperimentCase):
def test_i2c_switch(self):
self.execute(I2CSwitch)
self.assertTrue(self.dataset_mgr.get("passed"))
20 changes: 20 additions & 0 deletions doc/manual/core_device.rst
Original file line number Diff line number Diff line change
@@ -29,6 +29,9 @@ KC705

The main target board for the ARTIQ core device is the KC705 development board from Xilinx. It supports the NIST QC1 hardware via an adapter, and the NIST CLOCK and QC2 hardware (FMC).

NIST QC1
++++++++

With the QC1 hardware, the TTL lines are mapped as follows:

+--------------+------------+--------------+
@@ -47,6 +50,9 @@ With the QC1 hardware, the TTL lines are mapped as follows:
| 19 | TTL15 | Clock |
+--------------+------------+--------------+

NIST CLOCK
++++++++++

With the CLOCK hardware, the TTL lines are mapped as follows:

+--------------------+-----------------------+--------------+
@@ -70,6 +76,20 @@ With the CLOCK hardware, the TTL lines are mapped as follows:
+--------------------+-----------------------+--------------+


NIST QC2
++++++++

With the QC2 hardware, the TTL lines are mapped as follows:

TODO

The QC2 hardware uses TCA6424A I2C I/O expanders to define the directions of its TTL buffers. There is one such expander per FMC card, and they are selected using the PCA9548 on the KC705.

To avoid I/O contention, the startup kernel should first program the TCA6424A expanders and then call ``output()`` on all ``TTLInOut`` channels that should be configured as outputs.

See :mod:`artiq.coredevice.i2c` for more details.


Pipistrello
-----------

6 changes: 6 additions & 0 deletions doc/manual/core_drivers_reference.rst
Original file line number Diff line number Diff line change
@@ -36,6 +36,12 @@ These drivers are for the core device and the peripherals closely integrated int
.. automodule:: artiq.coredevice.ad5360
:members:

:mod:`artiq.coredevice.i2c` module
----------------------------------

.. automodule:: artiq.coredevice.i2c
:members:

:mod:`artiq.coredevice.exceptions` module
-----------------------------------------

6 changes: 6 additions & 0 deletions examples/master/device_db.pyon
Original file line number Diff line number Diff line change
@@ -15,6 +15,12 @@
"arguments": {"ref_period": 1e-9}
},

"i2c_switch": {
"type": "local",
"module": "artiq.coredevice.i2c",
"class": "PCA9548"
},

"ttl0": {
"type": "local",
"module": "artiq.coredevice.ttl",