def ps2_synth(frames, clock_freq, idle_start=0.0, word_interval=0.0): '''Generate synthesized PS/2 waveform This function simulates a transmission of data over PS/2. This is a generator function that can be used in a pipeline of waveform procesing operations. frames (sequence of PS2Frame) A sequence of PS2Frame objects that will be transmitted serially clock_freq (float) The PS/2 clock frequency. 10kHz - 13KHz typ. idle_start (float) The amount of idle time before the transmission of data begins word_interval (float) The amount of time between data bytes Yields a set of pairs representing the two edge streams for clk and data respectively. Each edge stream pair is in (time, value) format representing the time and logic value (0 or 1) for each edge transition. The first set of pairs yielded is the initial state of the waveforms. ''' # This is a wrapper around the actual synthesis code in _ps2_synth() # It unzips the yielded tuple and removes unwanted artifact edges clk, data = itertools.izip(*_ps2_synth(frames, clock_freq, idle_start, word_interval)) clk = remove_excess_edges(clk) data = remove_excess_edges(data) return clk, data
def can_synth(frames, bit_rate, idle_start=0.0, idle_end=0.0): '''Generate synthesized CAN data streams frames (sequence of CANFrame compatible objects) Frames to be synthesized. bit_rate (number) The frequency of the clock generator idle_start (float) The amount of idle time before the transmission of frames begins. idle_end (float) The amount of idle time after the last frame. Yields an edge stream of (float, int) pairs. The first element in the iterator is the initial state of the stream. ''' # This is a wrapper around the actual synthesis code in _can_synth() # It unzips the yielded tuple and removes unwanted artifact edges ch, cl = itertools.izip(*_can_synth(frames, bit_rate, idle_start, idle_end)) ch = sigp.remove_excess_edges(ch) cl = sigp.remove_excess_edges(cl) return ch, cl
def i2c_synth(transfers, clock_freq, idle_start=0.0, transfer_interval=0.0, idle_end=0.0): '''Generate synthesized I2C waveforms This function simulates I2C transfers on the SCL and SDA signals. transfers (sequence of I2CTransfer objects) Data to be synthesized. clock_freq (float) Clock frequency for the I2C bus. Standard rates are 100kHz (100.0e3) and 400kHz (400.0e3) but any frequency can be specified. idle_start (float) The amount of idle time before the transmission of transfers begins transfer_interval (float) The amount of time between transfers idle_end (float) The amount of idle time after the last transfer Returns a pair of iterators representing the two edge streams for scl, and sda respectively. Each edge stream pair is in (time, value) format representing the time and logic value (0 or 1) for each edge transition. The first elements in the iterators are the initial state of the waveforms. ''' # This is a wrapper around the actual synthesis code in _i2c_synth() # It unzips the yielded tuple and removes unwanted artifact edges scl, sda = itertools.izip(*_i2c_synth(transfers, clock_freq, idle_start, transfer_interval, idle_end)) scl = remove_excess_edges(scl) sda = remove_excess_edges(sda) return scl, sda
def spi_synth(data, word_size, clock_freq, cpol=0, cpha=0, lsb_first=True, idle_start=0.0, word_interval=0.0, idle_end=0.0): '''Generate synthesized SPI waveform This function simulates a transmission of data over SPI. This is a generator function that can be used in a pipeline of waveform procesing operations. data (sequence of int) A sequence of words that will be transmitted serially word_size (int) The number of bits in each word clock_freq (float) The SPI clock frequency cpol (int) Clock polarity: 0 or 1 cpha (int) Clock phase: 0 or 1 lsb_first (bool) Flag indicating whether the Least Significant Bit is transmitted first. idle_start (float) The amount of idle time before the transmission of data begins word_interval (float) The amount of time between data words idle_end (float) The amount of idle time after the last transmission Yields a triplet of pairs representing the three edge streams for clk, data_io, and cs respectively. Each edge stream pair is in (time, value) format representing the time and logic value (0 or 1) for each edge transition. The first set of pairs yielded is the initial state of the waveforms. ''' # This is a wrapper around the actual synthesis code in _spi_synth() # It unzips the yielded tuple and removes unwanted artifact edges clk, data_io, cs = itertools.izip(*_spi_synth(data, word_size, clock_freq, cpol, cpha, \ lsb_first, idle_start, word_interval, idle_end)) clk = remove_excess_edges(clk) data_io = remove_excess_edges(data_io) cs = remove_excess_edges(cs) return clk, data_io, cs
def single_to_diff(signal): '''Convert a single-ended edge stream to a differential pair signal (edge stream) The edges to convert to differential Returns a pair of edge streams p and m representing the + and - differential pair. ''' p, m = itertools.izip(*_single_to_diff(signal)) p = sigp.remove_excess_edges(p) m = sigp.remove_excess_edges(m) return p, m
def i2s_synth(data, word_size, frame_size, sample_rate, cpol=0, wspol=0, msb_justified=True, channels=2, i2s_variant=I2SVariant.Standard, data_offset=1, idle_start=0.0, idle_end=0.0): # This is a wrapper around the actual synthesis code in _i2s_synth() # It unzips the yielded tuple and removes unwanted artifact edges sck, sd, ws = itertools.izip(*_i2s_synth(data, word_size, frame_size, sample_rate, cpol, \ wspol, msb_justified, channels, i2s_variant, data_offset, idle_start, idle_end)) sck = remove_excess_edges(sck) sd = remove_excess_edges(sd) ws = remove_excess_edges(ws) return sck, sd, ws
def lin_synth(frames, baud, idle_start=0.0, frame_interval=8.0e-3, idle_end=0.0, byte_interval=1.0e-3): '''Generate synthesized LIN data streams frames (sequence of LINFrame) Frames to be synthesized. baud (int) The baud rate. idle_start (float) The amount of idle time before the transmission of messages begins. frame_interval (float) The amount of time between frames. idle_end (float) The amount of idle time after the last message. byte_interval (float) The amount of time between message bytes. Yields an edge stream of (float, int) pairs. The first element in the iterator is the initial state of the stream. ''' return sigp.remove_excess_edges(_lin_synth(frames, baud, idle_start, frame_interval, idle_end, byte_interval))