E02 Adding logic signals

The previous article was about creating a simple reader. This article explains how to handle logic signals. It uses the ExampleLogicReader class in the Extension Toolkit.

Logic Signals

Logic signals can have up to 16 states:

	public final int STATE_0_BITS = 0x0;// L2
	public final int STATE_1_BITS = 0x1;// L2
	public final int STATE_Z_BITS = 0x2;// L4
	public final int STATE_X_BITS = 0x3;// L4
	public final int STATE_L_BITS = 0x4;// L16
	public final int STATE_H_BITS = 0x5;// L16
	public final int STATE_U_BITS = 0x6;// L16
	public final int STATE_W_BITS = 0x7;// L16
	public final int STATE_D_BITS = 0x8;// L16

	public final int STATE_J_BITS = 0x9;// L16
	public final int STATE_K_BITS = 0xa;// L16
	public final int STATE_M_BITS = 0xb;// L16
	public final int STATE_N_BITS = 0xc;// L16
	public final int STATE_O_BITS = 0xd;// L16
	public final int STATE_P_BITS = 0xe;// L16
	public final int STATE_Q_BITS = 0xf;// L16 

The first 9 states are verilog standard. The additional 7 states are free to use. The text representation (upper case and lower case) is:

	public final char[] STATE_LC_DIGITS = 
{ '0', '1', 'z', 'x', 'l', 'h', 'u', 'w', '-', 'j', 'k', 'm', 'n', 'o', 'p', 'q' }; public final char[] STATE_UC_DIGITS =
{ '0', '1', 'Z', 'X', 'L', 'H', 'U', 'W', '-', 'J', 'K', 'M', 'N', 'O', 'P', 'Q' };

Impulse can pack logic signals as single bits, pairs of 2 bits, or groups of 4 bits (nibbles), depending of the logic states used. These modes are called state levels and required to use in the writer interface:

	public final int STATE_LEVEL_2 = 0x1;// 1 Bit
	public final int STATE_LEVEL_4 = 0x2;// 2 Bits
	public final int STATE_LEVEL_16 = 0x3;// 4 Bits

Interface

Now lets get to the writer interface:

public interface ILogicSamplesWriter extends ISamplesWriter{
   
    // auto statelevel and reduction of states (preceding)
    boolean write(long units, boolean conflict, byte states);
    boolean write(long units, boolean conflict, byte precedingStates, byte[] states, 
    		int start, int length); 
    boolean write(long units, boolean conflict, byte precedingStates, String states);
    
    // manual statelevel and reduction of states (preceding)
    boolean write(long units, boolean conflict, int stateLevel, byte states);
    boolean write(long units, boolean conflict, int stateLevel, byte precedingStates, byte state);
    boolean write(long units, boolean conflict, int stateLevel, byte precedingStates, byte[] states, 
    		int start, int length);   
    
    boolean write(long units, Logic logic);
    int getBitWidth(); 
}	

The parameters have the following meaning:

units
No of domain units (e.g. ns)
conflict
Define this sample as a conflict one.
stateLevel
State packing - see above.
precedingStates
Fills all states preceding the given ones with this value (e.g. the value 0001 shall be given in the form preceidingStates:0 state:1.
states
The given states (without preceding) in different forms (array of states, string)

Creating

Now we take a look at some examples (out of de.toem.impulse.serializer.ExampleLogicReader):

        addSignal(signals, "Logic1", "l1", ProcessType.Discrete, 
SignalType.Logic, SignalDescriptor.BitWidth(1)); addSignal(signals, "Logic2", "l2", ProcessType.Discrete,
SignalType.Logic, SignalDescriptor.BitWidth(8)); addSignal(signals, "Logic3", "l3l", ProcessType.Discrete,
SignalType.Logic, SignalDescriptor.BitWidth(2048));

To create a logic signal, you need to give the signal type SignalType.Logic and the signal descriptor with the bit width (SignalDescriptor.BitWidth(2048)).

Here some examples how to add samples.

        logicWriter = (ILogicSamplesWriter) getWriter(logic2);
        logicWriter.write(0, false, STATE_LEVEL_16,STATE_U_BITS);
        logicWriter.write(10000, false, STATE_LEVEL_2,STATE_0_BITS);
        logicWriter.write(20000, false, STATE_LEVEL_2,STATE_0_BITS,
                new byte[]{STATE_1_BITS,STATE_1_BITS,STATE_0_BITS,STATE_1_BITS},0,4);
        logicWriter.write(30000, false, STATE_LEVEL_4,STATE_0_BITS,"11XX");
        
        logicWriter = (ILogicSamplesWriter) getWriter(logic3);
        logicWriter.write(20000, false, STATE_1_BITS);
        logicWriter.write(50000, false, STATE_0_BITS);
        logicWriter.write(70000, false, STATE_U_BITS,
                "111100001111000011110000");
        logicWriter.write(80000, false, STATE_U_BITS,
                "000011110000111100001111");
        
        logicWriter = (ILogicSamplesWriter) getWriter(logic4);
        Logic logic = new Logic("11XXZZUU00");
        logicWriter.write(0, logic);
        new Logic("uuXXZZUU00").write(logicWriter, 20000);
        new Logic("xxuuXXZZUU00").write(logicWriter, 40000);

Result