Added database support to read real valued signals

This commit is contained in:
Eyck Jentzsch 2018-10-11 11:20:36 +02:00
parent 2f11d8ed7b
commit 8a89b21d34
11 changed files with 205 additions and 70 deletions

View File

@ -45,6 +45,7 @@ $var wire 1 aaabd s_gpio_29 $end
$var wire 1 aaabe s_gpio_30 $end
$var wire 1 aaabf s_gpio_31 $end
$var wire 1 aaabg s_rst_n $end
$var real 1 bbbbb a_real $end
$scope module i_platform $end
$var wire 1 aaabh erst_n $end
$var wire 64 aabdc s_tlclk [63:0] $end
@ -1621,6 +1622,7 @@ b1110100011010100101001010 aabdd
0aabdv
0aabdw
0aabdx
r0.0 bbbbb
$end
#10000
@ -1641,6 +1643,7 @@ $end
#1287121272
b1000000000100000000000000000100 aabcr
r1.0 bbbbb
#1288121272
b111111110100111110 aaabi
@ -1656,33 +1659,43 @@ b11000000000100000000000000000100 aabcr
b111111110100111110 aabcw
b101010 aabdb
b111111110100111110 aabdc
r2.0 bbbbb
#1303801016
b1000 aaacx
r3.0 bbbbb
#1311382718
b100000000 aabcu
r2.0 bbbbb
#1312689908
b1000000010111110001 aabct
r1.0 bbbbb
#1315304288
b10000000000000000000010111110001 aabct
r0.0 bbbbb
#1317395792
b101011 aabdb
r-1.0 bbbbb
#1345892534
b101100 aabdb
r-2.0 bbbbb
#1375173590
b101101 aabdb
r-3.0 bbbbb
#1404454646
b101110 aabdb
r-2.0 bbbbb
#1437918710
b101111 aabdb
r-1.0 bbbbb
#1443670346
b11111111010100 aaabi
@ -1697,6 +1710,7 @@ b11111111010100 aabac
b10000000000000010000010111110001 aabct
b11111111010100 aabcw
b11111111010100 aabdc
r0.0 bbbbb
#1444438324
1aaaar

View File

@ -92,7 +92,7 @@ public class DatabaseServicesTest {
assertTrue(f.exists());
waveformDb.load(f);
assertNotNull(waveformDb);
assertEquals(778, waveformDb.getAllWaves().size());
assertEquals(779, waveformDb.getAllWaves().size());
assertEquals(1, waveformDb.getChildNodes().size());
}

View File

@ -34,26 +34,44 @@ public interface IVCDDatabaseBuilder {
*
* @param netName the net name
* @param i the index of the net, -1 if a new one, otherwise the id if the referenced
* @param width the width
* @return the integer
* @param width the width, -1 equals real, 0... is a bit vector
* @return the net id
*/
public Integer newNet(String netName, int i, int width) ;
/**
* Gets the net width.
*
* @param intValue the int value
* @return the net width
* @param intValue the net id
* @return the net width, -1 means a real-valued net
*/
public int getNetWidth(int intValue);
public int getNetWidth(int netId);
/**
* Append transition.
*
* @param signalId the int value
* @param netId the int value
* @param currentTime the current time in ps
* @param decodedValues the decoded values
*/
public void appendTransition(int signalId, long currentTime, BitVector decodedValues);
public void appendTransition(int netId, long currentTime, char decodedValue);
/**
* Append transition.
*
* @param netId the int value
* @param currentTime the current time in ps
* @param decodedValues the decoded values
*/
public void appendTransition(int netId, long currentTime, BitVector decodedValue);
/**
* Append transition.
*
* @param netId the int value
* @param currentTime the current time in ps
* @param decodedValue the decoded values
*/
public void appendTransition(int netId, long currentTime, double decodedValue);
}

View File

@ -15,6 +15,7 @@ import java.io.FileInputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.NavigableMap;
import java.util.Stack;
import java.util.TreeMap;
import java.util.Vector;
@ -22,8 +23,9 @@ import java.util.Vector;
import com.minres.scviewer.database.BitVector;
import com.minres.scviewer.database.ISignal;
import com.minres.scviewer.database.ISignalChange;
import com.minres.scviewer.database.ISignalChangeMulti;
import com.minres.scviewer.database.ISignalChangeSingle;
import com.minres.scviewer.database.ISignalChangeBitVector;
import com.minres.scviewer.database.ISignalChangeReal;
import com.minres.scviewer.database.ISignalChangeBit;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbLoader;
@ -83,20 +85,25 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
moduleStack=null;
if(!res) throw new InputFormatException();
// calculate max time of database
for(IWaveform<? extends IWaveformEvent> waveform:signals)
maxTime= Math.max(maxTime, ((ISignal<? extends ISignalChange>)waveform).getEvents().lastKey());
for(IWaveform<? extends IWaveformEvent> waveform:signals) {
NavigableMap<Long, ? extends ISignalChange> events =((ISignal<? extends ISignalChange>)waveform).getEvents();
if(events.size()>0)
maxTime= Math.max(maxTime, events.lastKey());
}
// extend signals to hav a last value set at max time
for(IWaveform<? extends IWaveformEvent> waveform:signals){
TreeMap<Long,? extends ISignalChange> events = ((VCDSignal<? extends ISignalChange>)waveform).values;
if(events.lastKey()<maxTime){
if(events.size()>0 && events.lastKey()<maxTime){
ISignalChange x = events.lastEntry().getValue();
if(x instanceof ISignalChangeSingle)
((VCDSignal<ISignalChangeSingle>)waveform).values.put(maxTime,
new VCDSignalChangeSingle(maxTime, ((ISignalChangeSingle)x).getValue()));
else
if(x instanceof ISignalChangeMulti)
((VCDSignal<ISignalChangeMulti>)waveform).values.put(maxTime,
new VCDSignalChangeMulti(maxTime, ((ISignalChangeMulti)x).getValue()));
if(x instanceof ISignalChangeBit)
((VCDSignal<ISignalChangeBit>)waveform).values.put(maxTime,
new VCDSignalChangeBit(maxTime, ((ISignalChangeBit)x).getValue()));
else if(x instanceof ISignalChangeBitVector)
((VCDSignal<ISignalChangeBitVector>)waveform).values.put(maxTime,
new VCDSignalChangeBitVector(maxTime, ((ISignalChangeBitVector)x).getValue()));
else if(x instanceof ISignalChangeReal)
((VCDSignal<ISignalChangeReal>)waveform).values.put(maxTime,
new VCDSignalChangeReal(maxTime, ((ISignalChangeReal)x).getValue()));
}
}
return true;
@ -147,12 +154,15 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
String netName = moduleStack.empty()? name: moduleStack.lastElement()+"."+name;
int id = signals.size();
VCDSignal<? extends IWaveformEvent> signal;
if(width==1){
signal = i<0 ? new VCDSignal<ISignalChangeSingle>(db, id, netName) :
new VCDSignal<ISignalChangeSingle>((VCDSignal<ISignalChangeSingle>)signals.get(i), id, netName);
if(width<0) {
signal = i<0 ? new VCDSignal<ISignalChangeReal>(db, id, netName, width) :
new VCDSignal<ISignalChangeReal>((VCDSignal<ISignalChangeReal>)signals.get(i), id, netName);
} else if(width==1){
signal = i<0 ? new VCDSignal<ISignalChangeBit>(db, id, netName) :
new VCDSignal<ISignalChangeBit>((VCDSignal<ISignalChangeBit>)signals.get(i), id, netName);
} else {
signal = i<0 ? new VCDSignal<ISignalChangeMulti>(db, id, netName, width) :
new VCDSignal<ISignalChangeMulti>((VCDSignal<VCDSignalChangeMulti>)signals.get(i), id, netName);
signal = i<0 ? new VCDSignal<ISignalChangeBitVector>(db, id, netName, width) :
new VCDSignal<ISignalChangeBitVector>((VCDSignal<VCDSignalChangeBitVector>)signals.get(i), id, netName);
};
signals.add(signal);
return id;
@ -172,13 +182,37 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
*/
@SuppressWarnings("unchecked")
@Override
public void appendTransition(int signalId, long currentTime, BitVector decodedValues) {
public void appendTransition(int signalId, long currentTime, char decodedValues) {
VCDSignal<? extends IWaveformEvent> signal = (VCDSignal<? extends IWaveformEvent>) signals.get(signalId);
Long time = currentTime* TIME_RES;
if(signal.getWidth()==1){
((VCDSignal<ISignalChangeSingle>)signal).values.put(time, new VCDSignalChangeSingle(time, decodedValues.getValue()[0]));
} else {
((VCDSignal<VCDSignalChangeMulti>)signal).values.put(time, new VCDSignalChangeMulti(time, decodedValues));
((VCDSignal<ISignalChangeBit>)signal).values.put(time, new VCDSignalChangeBit(time, decodedValues));
}
}
/* (non-Javadoc)
* @see com.minres.scviewer.database.vcd.ITraceBuilder#appendTransition(int, long, com.minres.scviewer.database.vcd.BitVector)
*/
@SuppressWarnings("unchecked")
@Override
public void appendTransition(int signalId, long currentTime, BitVector decodedValues) {
VCDSignal<? extends IWaveformEvent> signal = (VCDSignal<? extends IWaveformEvent>) signals.get(signalId);
Long time = currentTime* TIME_RES;
if(signal.getWidth()>1){
((VCDSignal<VCDSignalChangeBitVector>)signal).values.put(time, new VCDSignalChangeBitVector(time, decodedValues));
}
}
/* (non-Javadoc)
* @see com.minres.scviewer.database.vcd.ITraceBuilder#appendTransition(int, long, com.minres.scviewer.database.vcd.BitVector)
*/
@SuppressWarnings("unchecked")
@Override
public void appendTransition(int signalId, long currentTime, double decodedValue) {
VCDSignal<? extends IWaveformEvent> signal = (VCDSignal<? extends IWaveformEvent>) signals.get(signalId);
Long time = currentTime* TIME_RES;
if(signal.getWidth()<0){
((VCDSignal<ISignalChangeReal>)signal).values.put(time, new VCDSignalChangeReal(time, decodedValue));
}
}

View File

@ -61,9 +61,11 @@ class VCDFileParser {
private void parseVar() throws Exception {
nextToken(); // type
String type = tokenizer.sval;
nextToken(); // size
int width = Integer.parseInt(tokenizer.sval);
if("real".equals(type))
width*=-1;
nextToken();
String id = tokenizer.sval;
nextToken();
@ -153,7 +155,8 @@ class VCDFileParser {
} while (!tokenizer.sval.equals("$end"));
return true;
}
if (tokenizer.sval.equals("$dumpvars") || tokenizer.sval.equals("$end")) return true;
if (tokenizer.sval.equals("$dumpvars") || tokenizer.sval.equals("$end"))
return true;
String value, id;
if (tokenizer.sval.charAt(0) == 'b') {
// Multiple value net. Value appears first, followed by space,
@ -161,6 +164,12 @@ class VCDFileParser {
value = tokenizer.sval.substring(1);
nextToken();
id = tokenizer.sval;
}else if (tokenizer.sval.charAt(0) == 'r') {
// Multiple value net. Value appears first, followed by space,
// then identifier
value = tokenizer.sval.substring(1);
nextToken();
id = tokenizer.sval;
} else {
// Single value net. identifier first, then value, no space.
value = tokenizer.sval.substring(0, 1);
@ -174,39 +183,46 @@ class VCDFileParser {
}
int netWidth = traceBuilder.getNetWidth(net);
BitVector decodedValues = new BitVector(netWidth);
if (value.equals("z") && netWidth > 1) {
for (int i = 0; i < netWidth; i++)
decodedValues.setValue(i, BitVector.VALUE_Z);
} else if (value.equals("x") && netWidth > 1) {
for (int i = 0; i < netWidth; i++)
decodedValues.setValue(i, BitVector.VALUE_X);
if(netWidth<0) {
traceBuilder.appendTransition(net, currentTime, Double.parseDouble(value));
} else {
int stringIndex = 0;
for (int convertedIndex = netWidth - value.length(); convertedIndex < netWidth; convertedIndex++) {
switch (value.charAt(stringIndex++)) {
case 'z':
decodedValues.setValue(convertedIndex, BitVector.VALUE_Z);
break;
case '1':
decodedValues.setValue(convertedIndex, BitVector.VALUE_1);
break;
case '0':
decodedValues.setValue(convertedIndex, BitVector.VALUE_0);
break;
case 'x':
decodedValues.setValue(convertedIndex, BitVector.VALUE_X);
break;
default:
decodedValues.setValue(convertedIndex, BitVector.VALUE_X);
BitVector decodedValues = new BitVector(netWidth);
if (value.equals("z") && netWidth > 1) {
for (int i = 0; i < netWidth; i++)
decodedValues.setValue(i, BitVector.VALUE_Z);
} else if (value.equals("x") && netWidth > 1) {
for (int i = 0; i < netWidth; i++)
decodedValues.setValue(i, BitVector.VALUE_X);
} else {
int stringIndex = 0;
for (int convertedIndex = netWidth - value.length(); convertedIndex < netWidth; convertedIndex++) {
switch (value.charAt(stringIndex++)) {
case 'z':
decodedValues.setValue(convertedIndex, BitVector.VALUE_Z);
break;
case '1':
decodedValues.setValue(convertedIndex, BitVector.VALUE_1);
break;
case '0':
decodedValues.setValue(convertedIndex, BitVector.VALUE_0);
break;
case 'x':
decodedValues.setValue(convertedIndex, BitVector.VALUE_X);
break;
default:
decodedValues.setValue(convertedIndex, BitVector.VALUE_X);
}
}
}
if(netWidth==1)
traceBuilder.appendTransition(net, currentTime, decodedValues.getValue()[0]);
else
traceBuilder.appendTransition(net, currentTime, decodedValues);
}
traceBuilder.appendTransition(net, currentTime, decodedValues);
}
return true;
}

View File

@ -10,14 +10,14 @@
*******************************************************************************/
package com.minres.scviewer.database.vcd;
import com.minres.scviewer.database.ISignalChangeSingle;
import com.minres.scviewer.database.ISignalChangeBit;
import com.minres.scviewer.database.SignalChange;
public class VCDSignalChangeSingle extends SignalChange implements ISignalChangeSingle, Cloneable {
public class VCDSignalChangeBit extends SignalChange implements ISignalChangeBit, Cloneable {
private char value;
public VCDSignalChangeSingle(Long time, char value) {
public VCDSignalChangeBit(Long time, char value) {
super(time);
this.value=value;
}

View File

@ -11,18 +11,18 @@
package com.minres.scviewer.database.vcd;
import com.minres.scviewer.database.BitVector;
import com.minres.scviewer.database.ISignalChangeMulti;
import com.minres.scviewer.database.ISignalChangeBitVector;
import com.minres.scviewer.database.SignalChange;
public class VCDSignalChangeMulti extends SignalChange implements ISignalChangeMulti, Cloneable {
public class VCDSignalChangeBitVector extends SignalChange implements ISignalChangeBitVector, Cloneable {
private BitVector value;
public VCDSignalChangeMulti(Long time) {
public VCDSignalChangeBitVector(Long time) {
super(time);
}
public VCDSignalChangeMulti(Long time, BitVector decodedValues) {
public VCDSignalChangeBitVector(Long time, BitVector decodedValues) {
super(time);
this.value=decodedValues;
}

View File

@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.database.vcd;
import com.minres.scviewer.database.ISignalChangeReal;
import com.minres.scviewer.database.SignalChange;
public class VCDSignalChangeReal extends SignalChange implements ISignalChangeReal, Cloneable {
private double value;
public VCDSignalChangeReal(Long time, double value) {
super(time);
this.value=value;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
@Override
public String toString() {
return value+"@"+getTime();
}
}

View File

@ -10,7 +10,7 @@
*******************************************************************************/
package com.minres.scviewer.database;
public interface ISignalChangeSingle extends ISignalChange{
public interface ISignalChangeBit extends ISignalChange{
public char getValue();

View File

@ -10,8 +10,7 @@
*******************************************************************************/
package com.minres.scviewer.database;
public interface ISignalChangeMulti extends ISignalChange {
public interface ISignalChangeBitVector extends ISignalChange {
public BitVector getValue();

View File

@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.database;
public interface ISignalChangeReal extends ISignalChange{
public double getValue();
}