Skip to main content

I2C modules for cocotb

Project description

I2C interface modules for Cocotb

Regression Tests codecov PyPI version Downloads

GitHub repository: https://github.com/alexforencich/cocotbext-i2c

Introduction

I2C simulation models for cocotb.

Installation

Installation from pip (release version, stable):

$ pip install cocotbext-i2c

Installation from git (latest development version, potentially unstable):

$ pip install https://github.com/alexforencich/cocotbext-i2c/archive/master.zip

Installation for active development:

$ git clone https://github.com/alexforencich/cocotbext-i2c
$ pip install -e cocotbext-i2c

Documentation and usage examples

See the tests directory, taxi, and verilog-i2c for complete testbenches using these modules.

I2C Master

The I2cMaster class can be used to issue read and write operations on an I2C bus.

Example:

from cocotbext.i2c import I2cMaster

i2c_master = I2cMaster(dut.sda_i, dut.sda_o, dut.scl_i, dut.scl_o, 400e3)

To issue I2C operations with an I2cMaster, call read() or write(). These are the preferred methods, as they will manage the bus state automatically. Lower-level methods must be called in the appropriate order. The read() and write() methods will leave the bus active, so call send_stop() to release the bus.

Constructor parameters:

  • sda: serial data in/out
  • sda_o: serial data output
  • scl: clock in/out
  • scl_o: clock output
  • speed: nominal data rate in bits per second (default 400e3)

Attributes:

  • speed: nominal data rate in bits per second

Methods

  • write(addr, data): send data to device at address addr (blocking)
  • read(addr, count): read count bytes from device at address addr (blocking)
  • send_start(): send a start condition on the bus
  • send_stop(): send a stop condition and release the bus
  • send_byte(): send a byte on the bus
  • recv_byte(): read a byte from the bus

I2C Device

The I2cDevice class emulates an I2C device. This class cannot be used directly, instead it should extended and the methods handle_start(), handle_write(), handle_read(), and handle_stop() implemented appropriately. See I2cMem for an example.

Constructor parameters:

  • sda: serial data in/out
  • sda_o: serial data output
  • scl: clock in/out
  • scl_o: clock output

I2C Memory

The I2cMemory class emulates a simple memory like an I2C EEPROM.

Example:

from cocotbext.i2c import I2cMemory

i2c_mem = I2cMemory(dut.sda_i, dut.sda_o, dut.scl_i, dut.scl_o, 0x50, 256)

The memory can then be read/written via I2C operations on the bus, with the first bytes written after a start bit setting the address, and subsequent reads/writes advancing the internal address and reading/writing the memory. The memory can also be accessed via read_mem() and write_mem().

Constructor parameters:

  • sda: serial data in/out
  • sda_o: serial data output
  • scl: clock in/out
  • scl_o: clock output
  • addr: device address (default 0x50)
  • size: size in bytes (default 256)

Methods

  • read_mem(addr, count): read count bytes from memory, starting at addr
  • write_mem(addr, data): write data to memory, starting at addr

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cocotbext_i2c-0.1.2.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cocotbext_i2c-0.1.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file cocotbext_i2c-0.1.2.tar.gz.

File metadata

  • Download URL: cocotbext_i2c-0.1.2.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cocotbext_i2c-0.1.2.tar.gz
Algorithm Hash digest
SHA256 188c6ff9cc999858eeb50560b41a2c7af0040f334abefb0971f8c40bf8818867
MD5 12c745ef01b6643c2faacff7cf05876c
BLAKE2b-256 55a53936214377140bee2b582fc6326dd98df1f8c7b9ecbef8094044d69d52bf

See more details on using hashes here.

File details

Details for the file cocotbext_i2c-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: cocotbext_i2c-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cocotbext_i2c-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d50d1c5f86c0841bfa3456d0de6700bab9ceb1d26c9e672dfd637e02bc4f84e2
MD5 3c08d56fe0759f53d36d559206c02e30
BLAKE2b-256 d2215e1d2b2b1b30431bec7461df6ccc267fb447629f780ea196b92f1c8b3f50

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page