upsilon/gateware/mmio_descr.py

222 lines
10 KiB
Python
Raw Normal View History

2023-06-28 17:38:41 -04:00
import textwrap
class Descr:
def __init__(self, name, blen, rwperm, num, descr):
"""
:param name: Name of the pin without numerical suffix.
:param blen: Bit length of the pin.
:param doc: Restructured text documentation of the register.
:param num: The amount of registers of the same type.
:param read_only: A string that must be either "read-only" or "write-write".
"""
self.name = name
self.blen = blen
2023-06-28 18:49:26 -04:00
self.doc = textwrap.dedent(descr)
2023-08-08 17:06:36 -04:00
self.num = num
2023-06-28 18:49:26 -04:00
self.rwperm = rwperm
2023-06-28 17:38:41 -04:00
@classmethod
def from_dict(cls, jsdict, name):
return cls(name, jsdict[name]["len"], jsdict[name]["ro"], jsdict[name]["num"], jsdict[name]["doc"])
def store_to_dict(self, d):
2023-06-28 18:49:26 -04:00
d[self.name] = {
2023-06-28 17:38:41 -04:00
"len": self.blen,
"doc": self.doc,
"num": self.num,
"ro": ro
}
registers = [
2023-06-28 18:49:26 -04:00
Descr("adc_sel", 3, "read-write", 8, """\
2023-06-28 17:38:41 -04:00
Select which on-FPGA SPI master controls the ADC.
Valid settings:
* ``0``: ADC is controlled by MMIO registers.
* ``0b10``: ADC is controlled by MMIO registers, but conversion is
disabled. This is used to flush output from an out-of-sync ADC.
* ``0b100``: ADC 0 only. ADC is controlled by control loop."""),
2023-06-28 18:49:26 -04:00
Descr("adc_finished", 1, "read-only", 8, """\
2023-06-28 17:38:41 -04:00
Signals that an ADC master has finished an SPI cycle.
Values:
* ``0``: MMIO master is either not armed or currently in a
SPI transfer.
* ``1``: MMIO master has finished.
This flag is on only when ``adc_arm`` is high. The flag does not
mean that data has been received successfully, only that the master
2023-06-28 18:49:26 -04:00
has finished it's SPI transfer."""),
Descr("adc_arm", 1, "read-write", 8, """\
2023-06-28 17:38:41 -04:00
Start a DAC master SPI transfer.
If ``adc_arm`` is raised from and the master is currently not in a SPI
transfer, the SPI master will start an SPI transfer and write data
into ``adc_recv_buf``.
If ``adc_arm`` is raised while the master is in an SPI transfer,
nothing changes.
If ``adc_arm`` is lowered while the master is in an SPI transfer,
nothing changes. The SPI cycle will continue to execute and it will
continue to write data to ``adc_recv_buf``.
If the SPI transfer finishes and ``adc_arm`` is still set to
1, then ``adc_finished`` is raised to 1. If ``adc_arm`` is lowered
in this state, then ``adc_finished`` is lowered.
Linear Technologies ADCs must not have their SPI transfers
interrupted. The transfer can be interrupted by
1. Interrupt the signal physically (i.e. pulling out cable connecting
the FPGA to the ADC)
2. Reset of the ADC master
3. Reset of the FPGA
4. Switching ``adc_sel`` to the control loop
If the ADC is interrupted then it will be in an unknown transfer
state. To recover from an unknown transfer state, set ``adc_sel``
to ``0b10`` and run a SPI transfer cycle. This will run the SPI
clock and flush the ADC buffer. The only other way is to power-cycle
the ADC.
If ``adc_sel`` is not set to 0 then the transfer will proceed
as normal, but no data will be received from the ADC."""),
2023-06-28 18:49:26 -04:00
Descr("adc_recv_buf", 18, "read-only", 8, """\
2023-06-28 17:38:41 -04:00
ADC Master receive buffer.
This buffer is stable if there is no ADC transfer caused by ``adc_arm``
is in process.
This register only changes if an SPI transfer is triggered by the MMIO
registers. SPI transfers by other masters will not affect this register.
buffer."""),
2023-06-28 18:49:26 -04:00
Descr("dac_sel", 2, "read-write", 8, """\
2023-06-28 17:38:41 -04:00
Select which on-FPGA SPI master controls the DAC.
Valid settings:
* ``0``: DAC is controlled by MMIO registers.
* ``0b10``: DAC 0 only. DAC is controlled by control loop."""),
2023-06-28 18:49:26 -04:00
Descr("dac_finished", 1, "read-only", 8, """\
2023-06-28 17:38:41 -04:00
Signals that the DAC master has finished transmitting data.
Values:
* ``0``: MMIO master is either not armed or currently in a
SPI transfer.
* ``1``: MMIO master has finished transmitting.
This flag is on only when ``dac_arm`` is high. The flag does not
mean that data has been received or transmitted successfully, only that
the master has finished it's SPI transfer."""),
2023-06-28 18:49:26 -04:00
Descr("dac_arm", 1, "read-write", 8, """\
2023-06-28 17:38:41 -04:00
Start a DAC master SPI transfer.
If ``dac_arm`` is raised from and the master is currently not in a SPI
transfer, the SPI master reads from the ``dac_send_buf`` register and sends
it over the wire to the DAC, while reading data from the DAC into
``dac_recv_buf``.
If ``dac_arm`` is raised while the master is in an SPI transfer,
nothing changes.
If ``dac_arm`` is lowered while the master is in an SPI transfer,
nothing changes. The SPI cycle will continue to execute and it will
continue to write data to ``dac_recv_buf``.
If the SPI transfer finishes and ``dac_arm`` is still set to
1, then ``dac_finished`` is raised to 1. If ``dac_arm`` is lowered
in this state, then ``dac_finished`` is lowered.
Analog Devices DACs can have their SPI transfers interrupted without
issue. However it is currently not possible to interrupt SPI transfers
in software without resetting the entire device.
If ``dac_sel`` is set to another master then the transfer will proceed
as normal, but no data will be sent to or received from the DAC."""),
2023-06-28 18:49:26 -04:00
Descr("dac_recv_buf", 24, "read-only", 8, """\
2023-06-28 17:38:41 -04:00
DAC master receive buffer.
This buffer is stable if there is no DAC transfer caused by ``dac_arm``
is in process.
This register only changes if an SPI transfer is triggered by the MMIO
registers. SPI transfers by other masters will not affect this register.
buffer."""),
2023-06-28 18:49:26 -04:00
Descr("dac_send_buf", 24, "read-write", 8, """\
2023-06-28 17:38:41 -04:00
DAC master send buffer.
Fill this buffer with a 24 bit Analog Devices DAC command. Updating
this buffer does not start an SPI transfer. To send data to the DAC,
fill this buffer and raise ``dac_arm``.
The DAC copies this buffer into an internal register when writing data.
Modifying this buffer during a transfer does not disrupt an in-process
transfer."""),
2023-06-28 18:49:26 -04:00
Descr("cl_assert_change", 1, "read-write", 1, """\
2023-06-28 17:38:41 -04:00
Flush parameter changes to control loop.
When this bit is raised from low to high, this signals the control
loop that it should read in new values from the MMIO registers.
While the bit is raised high, the control loop will read the constants
at most once.
When this bit is raised from high to low before ``cl_change_made``
is asserted by the control loop, nothing happens."""),
2023-06-28 18:49:26 -04:00
Descr("cl_change_made", 1, "read-only", 1, """\
2023-06-28 17:38:41 -04:00
Signal from the control loop that the parameters have been applied.
This signal goes high only while ``cl_assert_change`` is high. No
change will be applied afterwards while both are high."""),
2023-06-28 18:49:26 -04:00
Descr("cl_in_loop", 1, "read-only", 1, """\
2023-06-28 17:38:41 -04:00
This bit is high if the control loop is running."""),
2023-06-28 18:49:26 -04:00
Descr("cl_run_loop_in", 1, "read-write", 1, """\
Set this bit high to start the control loop."""),
Descr("cl_setpt_in", 18, "read-write", 1, """\
2023-06-28 17:38:41 -04:00
Setpoint of the control loop.
This is a twos-complement number in ADC units.
This is a parameter: see ``cl_assert_change``."""),
2023-06-28 18:49:26 -04:00
Descr("cl_P_in", 64, "read-write", 1, """\
2023-06-28 17:38:41 -04:00
Proportional parameter of the control loop.
This is a twos-complement fixed point number with 21 whole
bits and 43 fractional bits. This is applied to the error
in DAC units.
This is a parameter: see ``cl_assert_change``."""),
2023-06-28 18:49:26 -04:00
Descr("cl_I_in", 64, "read-write", 1, """\
2023-06-28 17:38:41 -04:00
Integral parameter of the control loop.
This is a twos-complement fixed point number with 21 whole
bits and 43 fractional bits. This is applied to the error
in DAC units.
This is a parameter: see ``cl_assert_change``."""),
2023-06-28 18:49:26 -04:00
Descr("cl_delay_in", 16, "read-write", 1, """\
2023-06-28 17:38:41 -04:00
Delay parameter of the loop.
This is an unsigned number denoting the number of cycles
the loop should wait between loop executions.
This is a parameter: see ``cl_assert_change``."""),
2023-06-28 18:49:26 -04:00
Descr("cl_cycle_count", 18, "read-only", 1, """\
2023-06-28 17:38:41 -04:00
Delay parameter of the loop.
This is an unsigned number denoting the number of cycles
the loop should wait between loop executions."""),
2023-06-28 18:49:26 -04:00
Descr("cl_z_pos", 20, "read-only", 1, """\
2023-06-28 17:38:41 -04:00
Control loop DAC Z position.
"""),
2023-06-28 18:49:26 -04:00
Descr("cl_z_measured", 18, "read-only", 1, """\
2023-06-28 17:38:41 -04:00
Control loop ADC Z position.
"""),
]