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

View File

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

View File

@ -34,26 +34,44 @@ public interface IVCDDatabaseBuilder {
* *
* @param netName the net name * @param netName the net name
* @param i the index of the net, -1 if a new one, otherwise the id if the referenced * @param i the index of the net, -1 if a new one, otherwise the id if the referenced
* @param width the width * @param width the width, -1 equals real, 0... is a bit vector
* @return the integer * @return the net id
*/ */
public Integer newNet(String netName, int i, int width) ; public Integer newNet(String netName, int i, int width) ;
/** /**
* Gets the net width. * Gets the net width.
* *
* @param intValue the int value * @param intValue the net id
* @return the net width * @return the net width, -1 means a real-valued net
*/ */
public int getNetWidth(int intValue); public int getNetWidth(int netId);
/** /**
* Append transition. * Append transition.
* *
* @param signalId the int value * @param netId the int value
* @param currentTime the current time in ps * @param currentTime the current time in ps
* @param decodedValues the decoded values * @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.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.NavigableMap;
import java.util.Stack; import java.util.Stack;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.Vector; import java.util.Vector;
@ -22,8 +23,9 @@ import java.util.Vector;
import com.minres.scviewer.database.BitVector; import com.minres.scviewer.database.BitVector;
import com.minres.scviewer.database.ISignal; import com.minres.scviewer.database.ISignal;
import com.minres.scviewer.database.ISignalChange; import com.minres.scviewer.database.ISignalChange;
import com.minres.scviewer.database.ISignalChangeMulti; import com.minres.scviewer.database.ISignalChangeBitVector;
import com.minres.scviewer.database.ISignalChangeSingle; import com.minres.scviewer.database.ISignalChangeReal;
import com.minres.scviewer.database.ISignalChangeBit;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbLoader; import com.minres.scviewer.database.IWaveformDbLoader;
@ -83,20 +85,25 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
moduleStack=null; moduleStack=null;
if(!res) throw new InputFormatException(); if(!res) throw new InputFormatException();
// calculate max time of database // calculate max time of database
for(IWaveform<? extends IWaveformEvent> waveform:signals) for(IWaveform<? extends IWaveformEvent> waveform:signals) {
maxTime= Math.max(maxTime, ((ISignal<? extends ISignalChange>)waveform).getEvents().lastKey()); 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 // extend signals to hav a last value set at max time
for(IWaveform<? extends IWaveformEvent> waveform:signals){ for(IWaveform<? extends IWaveformEvent> waveform:signals){
TreeMap<Long,? extends ISignalChange> events = ((VCDSignal<? extends ISignalChange>)waveform).values; 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(); ISignalChange x = events.lastEntry().getValue();
if(x instanceof ISignalChangeSingle) if(x instanceof ISignalChangeBit)
((VCDSignal<ISignalChangeSingle>)waveform).values.put(maxTime, ((VCDSignal<ISignalChangeBit>)waveform).values.put(maxTime,
new VCDSignalChangeSingle(maxTime, ((ISignalChangeSingle)x).getValue())); new VCDSignalChangeBit(maxTime, ((ISignalChangeBit)x).getValue()));
else else if(x instanceof ISignalChangeBitVector)
if(x instanceof ISignalChangeMulti) ((VCDSignal<ISignalChangeBitVector>)waveform).values.put(maxTime,
((VCDSignal<ISignalChangeMulti>)waveform).values.put(maxTime, new VCDSignalChangeBitVector(maxTime, ((ISignalChangeBitVector)x).getValue()));
new VCDSignalChangeMulti(maxTime, ((ISignalChangeMulti)x).getValue())); else if(x instanceof ISignalChangeReal)
((VCDSignal<ISignalChangeReal>)waveform).values.put(maxTime,
new VCDSignalChangeReal(maxTime, ((ISignalChangeReal)x).getValue()));
} }
} }
return true; return true;
@ -147,12 +154,15 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
String netName = moduleStack.empty()? name: moduleStack.lastElement()+"."+name; String netName = moduleStack.empty()? name: moduleStack.lastElement()+"."+name;
int id = signals.size(); int id = signals.size();
VCDSignal<? extends IWaveformEvent> signal; VCDSignal<? extends IWaveformEvent> signal;
if(width==1){ if(width<0) {
signal = i<0 ? new VCDSignal<ISignalChangeSingle>(db, id, netName) : signal = i<0 ? new VCDSignal<ISignalChangeReal>(db, id, netName, width) :
new VCDSignal<ISignalChangeSingle>((VCDSignal<ISignalChangeSingle>)signals.get(i), id, netName); 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 { } else {
signal = i<0 ? new VCDSignal<ISignalChangeMulti>(db, id, netName, width) : signal = i<0 ? new VCDSignal<ISignalChangeBitVector>(db, id, netName, width) :
new VCDSignal<ISignalChangeMulti>((VCDSignal<VCDSignalChangeMulti>)signals.get(i), id, netName); new VCDSignal<ISignalChangeBitVector>((VCDSignal<VCDSignalChangeBitVector>)signals.get(i), id, netName);
}; };
signals.add(signal); signals.add(signal);
return id; return id;
@ -172,13 +182,37 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @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); VCDSignal<? extends IWaveformEvent> signal = (VCDSignal<? extends IWaveformEvent>) signals.get(signalId);
Long time = currentTime* TIME_RES; Long time = currentTime* TIME_RES;
if(signal.getWidth()==1){ if(signal.getWidth()==1){
((VCDSignal<ISignalChangeSingle>)signal).values.put(time, new VCDSignalChangeSingle(time, decodedValues.getValue()[0])); ((VCDSignal<ISignalChangeBit>)signal).values.put(time, new VCDSignalChangeBit(time, decodedValues));
} else { }
((VCDSignal<VCDSignalChangeMulti>)signal).values.put(time, new VCDSignalChangeMulti(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 { private void parseVar() throws Exception {
nextToken(); // type nextToken(); // type
String type = tokenizer.sval;
nextToken(); // size nextToken(); // size
int width = Integer.parseInt(tokenizer.sval); int width = Integer.parseInt(tokenizer.sval);
if("real".equals(type))
width*=-1;
nextToken(); nextToken();
String id = tokenizer.sval; String id = tokenizer.sval;
nextToken(); nextToken();
@ -153,7 +155,8 @@ class VCDFileParser {
} while (!tokenizer.sval.equals("$end")); } while (!tokenizer.sval.equals("$end"));
return true; 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; String value, id;
if (tokenizer.sval.charAt(0) == 'b') { if (tokenizer.sval.charAt(0) == 'b') {
// Multiple value net. Value appears first, followed by space, // Multiple value net. Value appears first, followed by space,
@ -161,6 +164,12 @@ class VCDFileParser {
value = tokenizer.sval.substring(1); value = tokenizer.sval.substring(1);
nextToken(); nextToken();
id = tokenizer.sval; 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 { } else {
// Single value net. identifier first, then value, no space. // Single value net. identifier first, then value, no space.
value = tokenizer.sval.substring(0, 1); value = tokenizer.sval.substring(0, 1);
@ -174,39 +183,46 @@ class VCDFileParser {
} }
int netWidth = traceBuilder.getNetWidth(net); int netWidth = traceBuilder.getNetWidth(net);
BitVector decodedValues = new BitVector(netWidth); if(netWidth<0) {
if (value.equals("z") && netWidth > 1) { traceBuilder.appendTransition(net, currentTime, Double.parseDouble(value));
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 { } else {
int stringIndex = 0; BitVector decodedValues = new BitVector(netWidth);
for (int convertedIndex = netWidth - value.length(); convertedIndex < netWidth; convertedIndex++) { if (value.equals("z") && netWidth > 1) {
switch (value.charAt(stringIndex++)) { for (int i = 0; i < netWidth; i++)
case 'z': decodedValues.setValue(i, BitVector.VALUE_Z);
decodedValues.setValue(convertedIndex, BitVector.VALUE_Z); } else if (value.equals("x") && netWidth > 1) {
break; 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': case '1':
decodedValues.setValue(convertedIndex, BitVector.VALUE_1); decodedValues.setValue(convertedIndex, BitVector.VALUE_1);
break; break;
case '0': case '0':
decodedValues.setValue(convertedIndex, BitVector.VALUE_0); decodedValues.setValue(convertedIndex, BitVector.VALUE_0);
break; break;
case 'x': case 'x':
decodedValues.setValue(convertedIndex, BitVector.VALUE_X); decodedValues.setValue(convertedIndex, BitVector.VALUE_X);
break; break;
default: default:
decodedValues.setValue(convertedIndex, BitVector.VALUE_X); 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; return true;
} }

View File

@ -10,14 +10,14 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database.vcd; package com.minres.scviewer.database.vcd;
import com.minres.scviewer.database.ISignalChangeSingle; import com.minres.scviewer.database.ISignalChangeBit;
import com.minres.scviewer.database.SignalChange; 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; private char value;
public VCDSignalChangeSingle(Long time, char value) { public VCDSignalChangeBit(Long time, char value) {
super(time); super(time);
this.value=value; this.value=value;
} }

View File

@ -11,18 +11,18 @@
package com.minres.scviewer.database.vcd; package com.minres.scviewer.database.vcd;
import com.minres.scviewer.database.BitVector; import com.minres.scviewer.database.BitVector;
import com.minres.scviewer.database.ISignalChangeMulti; import com.minres.scviewer.database.ISignalChangeBitVector;
import com.minres.scviewer.database.SignalChange; 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; private BitVector value;
public VCDSignalChangeMulti(Long time) { public VCDSignalChangeBitVector(Long time) {
super(time); super(time);
} }
public VCDSignalChangeMulti(Long time, BitVector decodedValues) { public VCDSignalChangeBitVector(Long time, BitVector decodedValues) {
super(time); super(time);
this.value=decodedValues; 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; package com.minres.scviewer.database;
public interface ISignalChangeSingle extends ISignalChange{ public interface ISignalChangeBit extends ISignalChange{
public char getValue(); public char getValue();

View File

@ -10,8 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database; package com.minres.scviewer.database;
public interface ISignalChangeBitVector extends ISignalChange {
public interface ISignalChangeMulti extends ISignalChange {
public BitVector getValue(); 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();
}