Synchronous Serial modules for cocotb
Project description
HDLC encoded Synchronous Serial interface modules for Cocotb
Introduction
Synchronous HDLC simulation models for cocotb.
Installation
Installation from respository:
$ git clone https://github.com/cameronweston/cocotbext-syncserial.git
$ pip install cocotbext-syncserial
Documentation and usage examples
See the tests
directory for a testbench using this module.
Synchronous Serial
The SyncSerialSource
and SyncSerialSink
classes can be used to drive, receive, and monitor HDLC encoded synchronous serial data.
To use these modules, import the module you need and connect it to the DUT.
from cocotbext.syncserial import SyncSerialSource, SyncSerialSink
sync_serial_source = SyncSerialSource(dut.data, dut.clk)
sync_serial_sink = SyncSerialSink(dut.data, dut.clk)
To send data with SyncSerialSource
, call write()
or write_nowait()
. Accepted data types are iterables of 8-bit ints, including lists, bytes, bytearrays, etc.
To receive data with SyncSerialSink
, call read()
or read_nowait()
. read()
will block until at least 1 packet is available.
Constructor parameters:
- data: data signal
- clock: clock signal
- clock_rate_mhz: clock rate in megahertz (optional, default = 10)
- append_crc: appends crc to packet (optional, default = True)
- crc_polynomial: crc polynomial to use (optional, default = 0x1021)
- crc_init: crc initial value to use (optional, default = 0xFFFF)
- crc_final_xor: crc final xor to use (optional, default = 0x0000)
- validate_crc: validates incoming packet's crc (optional, default = True)
- strip_crc: Strips off crc after validation on incoming packet (optional, default = True)
Methods
write()
: send packet of data (blocking) (source)write_nowait()
: send packet of data (non-blocking) (source)read()
: read one packet of data (blocking) (sink)read_nowait()
: read one packet of data (non-blocking) (sink)count()
: returns the number of packets in the queue (all)empty()
: returns True if the queue is empty (all)clear()
: drop all data from the queue (all)wait(timeout=0, timeout_unit='ns')
: wait for packet received (sink)
CRC-16
The Crc_16
classes can be used to calculate or validate a 16 bit CRC. To use this module:
from cocotbext.syncserial import Crc_16
crc = Crc_16(crc_polynomial, crc_init, crc_final_xor)
To calculate a CRC, call calculate_crc()
. Accepted data types are iterables of 8-bit ints, including lists, bytes, bytearrays, etc.
To validate a CRC, call validate_crc()
. Accepted data types are iterables of 8-bit ints, including lists, bytes, bytearrays, etc.
Constructor parameters:
- crc_polynomial: CRC polynomial to use (optional, default = 0x1021)
- crc_init: CRC initial value to use (optional, default = 0xFFFF)
- crc_final_xor: CRC final XOR value to use (optional, default = 0x0000)
Methods
validate_crc(data, crc)
: Calculates a CRC for data and compared to crccalculate_crc(data)
: Calucalates and returns a CRC for data
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cocotbext-syncserial-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b580b9dd5cf28be9a758b276122d1c70994e6a0298e9c54dd149d759a8151a0 |
|
MD5 | 2207e2285ced74cb1f8227c2fe9b9fbb |
|
BLAKE2b-256 | 200b4cee33edfcf6690a4dd35ffbd323da9d8b5813c8dea062ddc473d4c547ad |
Hashes for cocotbext_syncserial-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 969b9c7e443f1be48467d5ece916a015d6cc69de577c078f907ab820b42a8077 |
|
MD5 | 4f0056a7d3854ba2e2b3a2ecd93f33c4 |
|
BLAKE2b-256 | 7d3a33cc5fa28435176bf18f030a98aa2d6c5a587ed26722a6e1c5aa80288352 |