umi_fifo
is a module that implements a FIFO for SUMI packets that can be used for buffering in a UMI-based system. This example shows how to use switchboard to send a stream of random SUMI packets into the umi_fifo
while reading packets out of the FIFO and verifying that the sequence of packets sent out matches the sequence of packets sent in.
Assuming that switchboard
is installed in your current Python environment, you can run the example with ./test.py
. The output will look like this:
...
* TX *
opcode: UMI_REQ_POSTED
dstaddr: 0x25de24da84c70740
size: 3
len: 1
eom: 1
eof: 1
data: [0x89cce9686d531664, 0x684cb99843c6232]
* RX *
opcode: UMI_REQ_WRITE
dstaddr: 0xfefd2a9ed38f9c0c
srcaddr: 0x9158589f508e47b4
size: 2
len: 0
eom: 1
eof: 1
data: [0x90f64317]
...
With reference to test.py, the interaction is set up as a loop where:
- A random SUMI packet is generated.
- We attempt to send that packet into the FIFO (which may fail if the FIFO is full)
- We attempt to read a packet from the FIFO (which may fail if the FIFO is empty)
This example highlights some convenient features of switchboard for lower-level testing:
- A random SUMI packet can be generated with the
random_umi_packet()
function, which can be imported directly from theswitchboard
package. Various optional arguments can be used to constrain the random packet generation. For example,random_umi_packet(size=0)
will generate only packets withSIZE=0
(i.e., 8-bit payload), whilerandom_umi_packet(size=[1, 2])
will generate only packets with 16- and 32-bit payloads. The datatype returned byrandom_umi_packet()
isPyUmiPacket
. - The
UmiTxRx.send()
method sends a singlePyUmiPacket
through a switchboard connection. Whenblocking=False
, switchboard will return immediately if the connection can't accept the packet and returnFalse
, rather than blocking until the packet can be sent. - The
UmiTxRx.recv()
method receives a singlePyUmiPacket
from a switchboard connection. Whenblocking=False
, switchboard will returnNone
immediately if there isn't a packet, rather than blocking until there is. - The
==
and!=
operators can be used to comparePyUmiPacket
objects.