Skip to content

Commit 9300377

Browse files
authored
Merge branch 'master' into cosimulation
2 parents 81cffc7 + c2ad913 commit 9300377

13 files changed

Lines changed: 429 additions & 148 deletions

File tree

basil/HL/bram_fifo.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@
1616

1717

1818
class bram_fifo(RegisterHardwareLayer):
19-
"""BRAM FIFO controller interface for bram_fifo FPGA module."""
19+
"""BRAM-backed FIFO controller.
20+
21+
The corresponding firmware module stores incoming 32-bit FIFO words in
22+
FPGA BRAM. The regular ``base_addr`` configuration key addresses the
23+
control registers, while ``base_data_addr`` must point to the 32-bit data
24+
window used by :meth:`get_data`.
25+
26+
``FIFO_SIZE`` reports the amount of buffered data in bytes. The driver
27+
rounds this down to complete 32-bit words before reading data.
28+
"""
2029

2130
_registers = {
2231
"RESET": {"descr": {"addr": 0, "size": 8, "properties": ["writeonly"]}},
@@ -29,9 +38,20 @@ class bram_fifo(RegisterHardwareLayer):
2938
_require_version = "==2"
3039

3140
def __init__(self, intf, conf):
41+
"""Create a BRAM FIFO driver.
42+
43+
Parameters
44+
----------
45+
intf : basil transfer layer
46+
Interface used for control-register and data-window access.
47+
conf : dict
48+
Driver configuration. Requires ``base_addr`` for the control
49+
registers and ``base_data_addr`` for the FIFO data window.
50+
"""
3251
super(bram_fifo, self).__init__(intf, conf)
3352

3453
def reset(self):
54+
"""Soft-reset the FIFO and wait briefly for the firmware to settle."""
3555
self.RESET = 0
3656
sleep(0.01) # wait some time for initialization
3757

@@ -59,12 +79,17 @@ def get_FIFO_INT_SIZE(self):
5979
return self.FIFO_INT_SIZE
6080

6181
def get_data(self):
62-
"""Reading data in BRAM.
82+
"""Read all currently buffered complete 32-bit words.
83+
84+
The method reads ``FIFO_SIZE`` twice and uses the smaller value to
85+
avoid requesting more data while the FIFO size is changing. Data are
86+
read from ``base_data_addr`` and returned as little-endian unsigned
87+
32-bit integers.
6388
6489
Returns
6590
-------
6691
array : numpy.ndarray
67-
Array of unsigned integers (32 bit).
92+
Array of unsigned 32-bit FIFO words.
6893
"""
6994
fifo_int_size_1 = self.FIFO_INT_SIZE
7095
fifo_int_size_2 = self.FIFO_INT_SIZE

basil/HL/sram_fifo.py

Lines changed: 158 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,158 @@
1-
#
2-
# ------------------------------------------------------------
3-
# Copyright (c) All rights reserved
4-
# SiLab, Institute of Physics, University of Bonn
5-
# ------------------------------------------------------------
6-
#
7-
8-
import logging
9-
from time import sleep
10-
11-
import numpy as np
12-
13-
from basil.HL.RegisterHardwareLayer import RegisterHardwareLayer
14-
15-
logger = logging.getLogger(__name__)
16-
17-
18-
class sram_fifo(RegisterHardwareLayer):
19-
"""SRAM FIFO controller interface for sram_fifo FPGA module."""
20-
21-
_registers = {
22-
"RESET": {"descr": {"addr": 0, "size": 8, "properties": ["writeonly"]}},
23-
"VERSION": {"descr": {"addr": 0, "size": 8, "properties": ["ro"]}},
24-
"ALMOST_FULL_THRESHOLD": {"descr": {"addr": 1, "size": 8}},
25-
"ALMOST_EMPTY_THRESHOLD": {"descr": {"addr": 2, "size": 8}},
26-
"READ_ERROR_COUNTER": {"descr": {"addr": 3, "size": 8, "properties": ["ro"]}},
27-
"FIFO_SIZE": {"descr": {"addr": 4, "size": 32, "properties": ["ro"]}},
28-
}
29-
_require_version = "==2"
30-
31-
def __init__(self, intf, conf):
32-
super(sram_fifo, self).__init__(intf, conf)
33-
34-
def reset(self):
35-
self.RESET = 0
36-
sleep(0.01) # wait some time for initialization
37-
38-
def set_almost_full_threshold(self, value):
39-
self.ALMOST_FULL_THRESHOLD = value # no get function possible
40-
41-
def set_almost_empty_threshold(self, value):
42-
self.ALMOST_EMPTY_THRESHOLD = value # no get function possible
43-
44-
def get_fifo_size(self):
45-
"""*Deprecated* Get FIFO size in units of bytes (8 bit).
46-
47-
Returns
48-
-------
49-
fifo_size : int
50-
FIFO size in units of bytes (8 bit).
51-
"""
52-
logger.warning("Deprecated: Use get_FIFO_SIZE()")
53-
return self.FIFO_SIZE
54-
55-
@property
56-
def FIFO_INT_SIZE(self):
57-
"""Get FIFO size in units of integers (32 bit).
58-
59-
Returns
60-
-------
61-
fifo_size : int
62-
FIFO size in units of integers (32 bit).
63-
"""
64-
fifo_size = self.FIFO_SIZE
65-
# sometimes reading of FIFO size happens during writing to SRAM, but we want to have a multiplicity of 32 bits
66-
return int((fifo_size - (fifo_size % 4)) / 4)
67-
68-
def get_fifo_int_size(self):
69-
"""*Deprecated* Get FIFO size in units of integers (32 bit).
70-
71-
Returns
72-
-------
73-
fifo_size : int
74-
FIFO size in units of integers (32 bit).
75-
"""
76-
logger.warning("Deprecated: Use get_FIFO_INT_SIZE()")
77-
return self.FIFO_INT_SIZE
78-
79-
def get_FIFO_INT_SIZE(self):
80-
"""Get FIFO size in units of integers (32 bit).
81-
82-
Returns
83-
-------
84-
fifo_size : int
85-
FIFO size in units of integers (32 bit).
86-
"""
87-
return self.FIFO_INT_SIZE
88-
89-
def get_read_error_counter(self):
90-
"""*Deprecated* Get read error counter.
91-
92-
Returns
93-
-------
94-
fifo_size : int
95-
Read error counter (read attempts when SRAM is empty).
96-
"""
97-
logger.warning("Deprecated: Use get_READ_ERROR_COUNTER()")
98-
return self.READ_ERROR_COUNTER
99-
100-
def get_data(self):
101-
"""Reading data in SRAM.
102-
103-
Returns
104-
-------
105-
array : numpy.ndarray
106-
Array of unsigned integers (32 bit).
107-
"""
108-
fifo_int_size_1 = self.FIFO_INT_SIZE
109-
fifo_int_size_2 = self.FIFO_INT_SIZE
110-
if fifo_int_size_1 > fifo_int_size_2:
111-
fifo_int_size = fifo_int_size_2 # use smaller chunk
112-
logger.warning("Reading wrong FIFO size. Expected: %d <= %d" % (fifo_int_size_1, fifo_int_size_2))
113-
else:
114-
fifo_int_size = fifo_int_size_1 # use smaller chunk
115-
return np.frombuffer(
116-
self._intf.read(self._conf["base_data_addr"], size=4 * fifo_int_size), dtype=np.dtype("<u4")
117-
) # size in number of bytes
118-
119-
def get_size(self):
120-
"""*Deprecated*"""
121-
logger.warning("Deprecated: Use get_FIFO_SIZE()")
122-
return self.FIFO_SIZE
1+
#
2+
# ------------------------------------------------------------
3+
# Copyright (c) All rights reserved
4+
# SiLab, Institute of Physics, University of Bonn
5+
# ------------------------------------------------------------
6+
#
7+
8+
import logging
9+
from time import sleep
10+
11+
import numpy as np
12+
13+
from basil.HL.RegisterHardwareLayer import RegisterHardwareLayer
14+
15+
logger = logging.getLogger(__name__)
16+
17+
18+
class sram_fifo(RegisterHardwareLayer):
19+
"""External-SRAM-backed FIFO controller.
20+
21+
The corresponding firmware module stores incoming 32-bit FIFO words in an
22+
external 16-bit SRAM. The regular ``base_addr`` configuration key addresses
23+
the control registers. ``base_data_addr`` must point to the transfer-layer
24+
data path used by :meth:`get_data` to drain buffered FIFO words.
25+
26+
``FIFO_SIZE`` reports the amount of buffered data in bytes. The driver
27+
rounds this down to complete 32-bit words before reading data.
28+
"""
29+
30+
_registers = {
31+
"RESET": {"descr": {"addr": 0, "size": 8, "properties": ["writeonly"]}},
32+
"VERSION": {"descr": {"addr": 0, "size": 8, "properties": ["ro"]}},
33+
"ALMOST_FULL_THRESHOLD": {"descr": {"addr": 1, "size": 8}},
34+
"ALMOST_EMPTY_THRESHOLD": {"descr": {"addr": 2, "size": 8}},
35+
"READ_ERROR_COUNTER": {"descr": {"addr": 3, "size": 8, "properties": ["ro"]}},
36+
"FIFO_SIZE": {"descr": {"addr": 4, "size": 32, "properties": ["ro"]}},
37+
}
38+
_require_version = "==2"
39+
40+
def __init__(self, intf, conf):
41+
"""Create an SRAM FIFO driver.
42+
43+
Parameters
44+
----------
45+
intf : basil transfer layer
46+
Interface used for control-register and data-path access.
47+
conf : dict
48+
Driver configuration. Requires ``base_addr`` for the control
49+
registers and ``base_data_addr`` for the FIFO data path.
50+
"""
51+
super(sram_fifo, self).__init__(intf, conf)
52+
53+
def reset(self):
54+
"""Soft-reset the FIFO and wait briefly for the firmware to settle."""
55+
self.RESET = 0
56+
sleep(0.01) # wait some time for initialization
57+
58+
def set_almost_full_threshold(self, value):
59+
"""Set the 8-bit almost-full threshold register.
60+
61+
The firmware compares this value against the SRAM occupancy as a
62+
fraction of ``DEPTH`` and asserts ``FIFO_NEAR_FULL`` once the threshold
63+
is reached.
64+
"""
65+
self.ALMOST_FULL_THRESHOLD = value # no get function possible
66+
67+
def set_almost_empty_threshold(self, value):
68+
"""Set the 8-bit almost-empty threshold register.
69+
70+
``FIFO_NEAR_FULL`` is deasserted again once the SRAM occupancy falls
71+
below the fraction of ``DEPTH`` represented by this value.
72+
"""
73+
self.ALMOST_EMPTY_THRESHOLD = value # no get function possible
74+
75+
def get_fifo_size(self):
76+
"""*Deprecated* Get FIFO size in units of bytes (8 bit).
77+
78+
Returns
79+
-------
80+
fifo_size : int
81+
FIFO size in units of bytes (8 bit).
82+
"""
83+
logger.warning("Deprecated: Use get_FIFO_SIZE()")
84+
return self.FIFO_SIZE
85+
86+
@property
87+
def FIFO_INT_SIZE(self):
88+
"""Get FIFO size in units of integers (32 bit).
89+
90+
Returns
91+
-------
92+
fifo_size : int
93+
FIFO size in units of integers (32 bit).
94+
"""
95+
fifo_size = self.FIFO_SIZE
96+
# sometimes reading of FIFO size happens during writing to SRAM, but we want to have a multiplicity of 32 bits
97+
return int((fifo_size - (fifo_size % 4)) / 4)
98+
99+
def get_fifo_int_size(self):
100+
"""*Deprecated* Get FIFO size in units of integers (32 bit).
101+
102+
Returns
103+
-------
104+
fifo_size : int
105+
FIFO size in units of integers (32 bit).
106+
"""
107+
logger.warning("Deprecated: Use get_FIFO_INT_SIZE()")
108+
return self.FIFO_INT_SIZE
109+
110+
def get_FIFO_INT_SIZE(self):
111+
"""Get FIFO size in units of integers (32 bit).
112+
113+
Returns
114+
-------
115+
fifo_size : int
116+
FIFO size in units of integers (32 bit).
117+
"""
118+
return self.FIFO_INT_SIZE
119+
120+
def get_read_error_counter(self):
121+
"""*Deprecated* Get read error counter.
122+
123+
Returns
124+
-------
125+
fifo_size : int
126+
Read error counter (read attempts when SRAM is empty).
127+
"""
128+
logger.warning("Deprecated: Use get_READ_ERROR_COUNTER()")
129+
return self.READ_ERROR_COUNTER
130+
131+
def get_data(self):
132+
"""Read all currently buffered complete 32-bit words.
133+
134+
The method reads ``FIFO_SIZE`` twice and uses the smaller value to
135+
avoid requesting more data while the FIFO size is changing. Data are
136+
read from ``base_data_addr`` and returned as little-endian unsigned
137+
32-bit integers.
138+
139+
Returns
140+
-------
141+
array : numpy.ndarray
142+
Array of unsigned 32-bit FIFO words.
143+
"""
144+
fifo_int_size_1 = self.FIFO_INT_SIZE
145+
fifo_int_size_2 = self.FIFO_INT_SIZE
146+
if fifo_int_size_1 > fifo_int_size_2:
147+
fifo_int_size = fifo_int_size_2 # use smaller chunk
148+
logger.warning("Reading wrong FIFO size. Expected: %d <= %d" % (fifo_int_size_1, fifo_int_size_2))
149+
else:
150+
fifo_int_size = fifo_int_size_1 # use smaller chunk
151+
return np.frombuffer(
152+
self._intf.read(self._conf["base_data_addr"], size=4 * fifo_int_size), dtype=np.dtype("<u4")
153+
) # size in number of bytes
154+
155+
def get_size(self):
156+
"""*Deprecated*"""
157+
logger.warning("Deprecated: Use get_FIFO_SIZE()")
158+
return self.FIFO_SIZE

basil/firmware/arduino/EnvironmentReadout/Readme.rst renamed to basil/firmware/arduino/EnvironmentReadout/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
======================================
1+
=========================================================================
22
Arduino Firmware for Environment Readout (temperature, humidity/pressure)
3-
======================================
3+
=========================================================================
44

55
Arduino Nano firmware to read out NTCs via the 8 analog input pins A0 to A7 and the internal (multiplexed) ADC.
66

0 commit comments

Comments
 (0)