Module zio :: Class SPI

Class SPI

object --+    
         |    
    Module --+
             |
            SPI

SPI class is used to access devices over the SPI bus. Bus parameters - bus clock frequency, clock polarity, data sampling edge, and endianess can be configured.
Instance Methods
 
__init__(self, agent)
Constructs a SPI object.
int
config(self, freq, cpol, cphase, endian)
Configures the SPI module with the specified bus clock frequency and parameters.
list
read(self, rlen)
Reads and returns specified no.
 
write(self, wlist)
Writes the specified bytes to the device.
list
write_read(self, wlist)
Writes the specified bytes to the device, and reads equal no.

Inherited from Module: do_op

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables
  CPHASE_LEAD_EDGE = 0
Constant indicates data is sampled on leading edge.
  CPHASE_TRAIL_EDGE = 1
Constant indicates data is sampled on trailing edge.
  CPOL_IDLE_HIGH = 1
Constant indicates clock is idle high.
  CPOL_IDLE_LOW = 0
Constant indicates clock is idle low.
  ENDIAN_LSB_FIRST = 1
Constant indicates data is sent LSB first.
  ENDIAN_MSB_FIRST = 0
Constant indicates data is sent MSB first.
Properties

Inherited from object: __class__

Method Details

__init__(self, agent)
(Constructor)

 
Constructs a SPI object.
Parameters:
  • agent (Agent) - the agent interface object
Overrides: object.__init__

config(self, freq, cpol, cphase, endian)

 
Configures the SPI module with the specified bus clock frequency and parameters. Returns the actual frequency set. The actual frequency set is the nearest available frequency.
Parameters:
  • freq (int) - the bus frequency in kHz
  • cpol (int) - specifies if the clock polarity is idle high or idle low
  • cphase (int) - specifies if the data is sample on the leading edge or trailing edge
  • endian (bool) - specifies if the data is transmitted LSB first or MSB first
Returns: int
the actual bus clock frequency set
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

read(self, rlen)

 
Reads and returns specified no. of bytes from the device.
Parameters:
  • rlen (int) - the no. of bytes to read.
Returns: list
the bytes read from the device
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

write(self, wlist)

 
Writes the specified bytes to the device.
Parameters:
  • wlist (list) - the bytes to be written
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

write_read(self, wlist)

 
Writes the specified bytes to the device, and reads equal no. of bytes from the device.
Parameters:
  • wlist (list) - the bytes to be written
Returns: list
the bytes read from the device
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted