- support for TP3564

- ignoreResult fix removed
- maximal values separated for fill/dump
- javadoc updated

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@130 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
schlaepfer
2006-04-10 07:11:25 +00:00
parent 81e14c81e8
commit d4c4fc0bc3
2 changed files with 201 additions and 164 deletions

View File

@@ -10,6 +10,12 @@ import ch.ntb.usb.Device;
import ch.ntb.usb.USB; import ch.ntb.usb.USB;
import ch.ntb.usb.USBException; import ch.ntb.usb.USBException;
/**
* Represents the Background Debugging Interface of the MC68332 microcontroller.
*
* @author schlaepfer
*
*/
public class MC68332 { public class MC68332 {
private static McdpLogger logger = LogUtil.ch_ntb_mcdp_bdi; private static McdpLogger logger = LogUtil.ch_ntb_mcdp_bdi;
@@ -197,36 +203,53 @@ public class MC68332 {
/** /**
* Maximal number of words or bytes (1 or 2 bytes) for one usb-packet to * Maximal number of words or bytes (1 or 2 bytes) for one usb-packet to
* download (fill) or read (dump). <br> * download (fill).
* Note that no status bit is used. Therefore one data entity is only 16
* bits wide (not 17 bits like normal commands). <br>
* <code>maxNofWordsFastDownload</code> is a multiple of 4 (FILLB/W +
* data).
*/ */
private int maxNofBytesWords; private int maxNofBytesWordsFill;
/** /**
* Maximal number of longs (4 bytes) for one usb-packet to download (fill) * Maximal number of longs (4 bytes) for one usb-packet to download (fill).<br>
* or read (dump).<br>
* Note that no status bit is used. Therefore one data entity is only 16
* bits wide (not 17 bits like normal commands). <br>
* <code>maxNofLongs</code> is a multiple of 6 (FILLW + MS data + LS
* data).
*/ */
private int maxNofLongs; private int maxNofLongsFill;
/**
* Maximal number of words or bytes (1 or 2 bytes) to dump in one
* usb-packet.
*/
private int maxNofBytesWordsDump;
/**
* Maximal number of longs (4 bytes) to dump in one usb-packet.
*/
private int maxNofLongsDump;
/**
* The last known state on the freeze signal.
*/
private boolean targetInDebugMode = false; private boolean targetInDebugMode = false;
/**
* Temporary buffer of the data to send.
*/
private byte[] sendData; private byte[] sendData;
/**
* Sizes which are setup up when writing or reading memory data. This values
* are used in <code>fillMem</code> and <code>dumpMem</code>.
*/
private int readMemSize, writeMemSize; private int readMemSize, writeMemSize;
private boolean ignoreResult; /**
* The USB device to connect to.
*/
private Device device; private Device device;
/**
* @param device
* The USB device to connect to. Before using any methods which
* communicate with the device, the device must be connected.
*/
public MC68332(Device device) { public MC68332(Device device) {
ignoreResult = false;
readMemSize = 0; readMemSize = 0;
writeMemSize = 0; writeMemSize = 0;
sendData = new byte[USB.HIGHSPEED_MAX_BULK_PACKET_SIZE]; sendData = new byte[USB.HIGHSPEED_MAX_BULK_PACKET_SIZE];
@@ -279,7 +302,7 @@ public class MC68332 {
private void fillPacket(int data, int offset) { private void fillPacket(int data, int offset) {
// refer to CPU32 Reference Manual, Section 7.2.7 // refer to CPU32 Reference Manual, Section 7.2.7
// bit16 = 0 + 16 bits of data (bit15 .. bit0) // bit16 = 0 + 16 bits of data (MSB .. LSB)
sendData[DataPacket.PACKET_DATA_OFFSET + offset] = (byte) ((data >>> 9) & 0x7F); sendData[DataPacket.PACKET_DATA_OFFSET + offset] = (byte) ((data >>> 9) & 0x7F);
sendData[DataPacket.PACKET_DATA_OFFSET + offset + 1] = (byte) ((data >>> 1) & 0xFF); sendData[DataPacket.PACKET_DATA_OFFSET + offset + 1] = (byte) ((data >>> 1) & 0xFF);
sendData[DataPacket.PACKET_DATA_OFFSET + offset + 2] = (byte) ((data & 0x01) << 7); sendData[DataPacket.PACKET_DATA_OFFSET + offset + 2] = (byte) ((data & 0x01) << 7);
@@ -314,22 +337,16 @@ public class MC68332 {
* @throws USBException * @throws USBException
* @throws DispatchException * @throws DispatchException
*/ */
private int parseResult17(DataPacket data) throws BDIException, private int parseResult17(DataPacket data, int offset) throws BDIException,
USBException, DispatchException { USBException, DispatchException {
if (data.subtype != STYPE_BDI_17OUT) { if ((data.subtype != STYPE_BDI_17OUT)
&& (data.subtype != STYPE_BDI_DUMP_DATA)) {
throw new BDIException("wrong subtype: " + data.subtype); throw new BDIException("wrong subtype: " + data.subtype);
} }
// 16 data bits boolean statusControlBit = (data.data[0 + offset] & 0x80) > 0;
// fist bit is status control bit int retValue = (((data.data[0 + offset] << 1) & 0xFF) + ((data.data[1 + offset] & 0x80) >>> 7)) << 8;
if (ignoreResult) { retValue += ((data.data[1 + offset] << 1) & 0xFF)
ignoreResult = false; + ((data.data[2 + offset] & 0x80) >>> 7);
return 0xFFFF;
}
boolean statusControlBit = (data.data[0] & 0x80) > 0;
int retValue = (((data.data[0] << 1) & 0xFF) + ((data.data[1] & 0x80) >>> 7)) << 8;
retValue += ((data.data[1] << 1) & 0xFF)
+ ((data.data[2] & 0x80) >>> 7);
if (statusControlBit) { if (statusControlBit) {
switch (retValue) { switch (retValue) {
@@ -367,7 +384,7 @@ public class MC68332 {
*/ */
private int transferAndParse17(int data) throws USBException, private int transferAndParse17(int data) throws USBException,
DispatchException, BDIException { DispatchException, BDIException {
return parseResult17(transfer(data)); return parseResult17(transfer(data), 0);
} }
/** /**
@@ -398,10 +415,6 @@ public class MC68332 {
* @throws BDIException * @throws BDIException
*/ */
public void break_() throws USBException, DispatchException, BDIException { public void break_() throws USBException, DispatchException, BDIException {
// FIXME: this may be wrong, but works
// ignore the result of the first transaction
ignoreResult = true;
transferAndParse17(NOP);
if (transferAndParse17(NOP) != STATUS_OK) { if (transferAndParse17(NOP) != STATUS_OK) {
throw new BDIException("no STATUS_OK received"); throw new BDIException("no STATUS_OK received");
} }
@@ -503,15 +516,23 @@ public class MC68332 {
return targetInDebugMode; return targetInDebugMode;
} }
/**
* Update the internal maximal values for the <code>fill</code> and
* <code>dump</code> commands.
*/
private void updateMaxValues() { private void updateMaxValues() {
// update the values (now the device should be connected) // update the values (now the device should be connected)
if ((maxNofLongs <= 0) | (maxNofBytesWords <= 0)) { if ((maxNofLongsFill <= 0) | (maxNofBytesWordsFill <= 0)
maxNofLongs = (device.getMaxPacketSize() | (maxNofBytesWordsDump <= 0) | (maxNofLongsDump <= 0)) {
- DataPacket.PACKET_MIN_LENGTH - 2) / 6; maxNofBytesWordsDump = (device.getMaxPacketSize()
maxNofBytesWords = (device.getMaxPacketSize() - DataPacket.PACKET_MIN_LENGTH - 3/* NOP */) / 3;
- DataPacket.PACKET_MIN_LENGTH - 2) / 4; maxNofBytesWordsFill = (device.getMaxPacketSize()
logger.finer("update maxNofLongs: " + maxNofLongs - DataPacket.PACKET_MIN_LENGTH - 3) / 6;
+ ", maxNofBytesWords: " + maxNofBytesWords); maxNofLongsDump = maxNofBytesWordsFill;
maxNofLongsFill = (device.getMaxPacketSize()
- DataPacket.PACKET_MIN_LENGTH - 3) / 9;
logger.finer("update maxNofLongs: " + maxNofLongsFill
+ ", maxNofBytesWords: " + maxNofBytesWordsFill);
} }
} }
@@ -522,7 +543,7 @@ public class MC68332 {
* <code>MAX_NOF_WORDS_FAST_DOWNLOAD</code> for 1 and 2 byte (word) data. * <code>MAX_NOF_WORDS_FAST_DOWNLOAD</code> for 1 and 2 byte (word) data.
* For 4 byte (long) data, only half the size of * For 4 byte (long) data, only half the size of
* <code>MAX_NOF_WORDS_FAST_DOWNLOAD</code> is available as 4 bytes of * <code>MAX_NOF_WORDS_FAST_DOWNLOAD</code> is available as 4 bytes of
* data has to be split in two packets (2 x 2 bytes).<br> * data has to be split in two packets (2 x 3 bytes).<br>
* Befor using <code>fillMem</code>, <code>writeMem</code> has to be * Befor using <code>fillMem</code>, <code>writeMem</code> has to be
* called to set up the start address and size. * called to set up the start address and size.
* *
@@ -544,67 +565,59 @@ public class MC68332 {
updateMaxValues(); updateMaxValues();
switch (writeMemSize) { switch (writeMemSize) {
case 1: case 1:
if (dataLength > maxNofBytesWords) { if (dataLength > maxNofBytesWordsFill) {
throw new BDIException("data length (" + dataLength throw new BDIException("data length (" + dataLength
+ ") larger than maxNofBytesWords (" + maxNofBytesWords + ") larger than maxNofBytesWords ("
+ ")"); + maxNofBytesWordsFill + ")");
} }
while (currentIndex < dataLength) { while (currentIndex < dataLength) {
// FILLB // FILLB
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4] = (byte) ((FILLB >>> 8) & 0xFF); fillPacket(FILLB, currentIndex * 6);
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4 + 1] = (byte) (FILLB & 0xFF); // DATA
// DATA (address) fillPacket(downloadData[currentIndex] & 0xFF,
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4 + 2] = 0; currentIndex * 6 + 3);
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4 + 3] = (byte) (downloadData[currentIndex] & 0xFF);
currentIndex++; currentIndex++;
} }
// send NOP to get result of last write // send NOP to get result of last write
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4] = NOP; fillPacket(NOP, currentIndex * 6);
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4 + 1] = NOP; data = transmit(STYPE_BDI_17FILL_BYTE_WORD, dataLength * 6 + 3);
data = transmit(STYPE_BDI_17FILL_BYTE_WORD, dataLength * 4 + 2);
break; break;
case 2: case 2:
if (dataLength > maxNofBytesWords) { if (dataLength > maxNofBytesWordsFill) {
throw new BDIException("data length (" + dataLength throw new BDIException("data length (" + dataLength
+ ") larger than maxNofBytesWords (" + maxNofBytesWords + ") larger than maxNofBytesWords ("
+ ")"); + maxNofBytesWordsFill + ")");
} }
while (currentIndex < dataLength) { while (currentIndex < dataLength) {
// FILLW // FILLW
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4] = (byte) ((FILLW >>> 8) & 0xFF); fillPacket(FILLW, currentIndex * 6);
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4 + 1] = (byte) (FILLW & 0xFF); // DATA
// DATA (address) fillPacket(downloadData[currentIndex], currentIndex * 6 + 3);
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4 + 2] = (byte) ((downloadData[currentIndex] >>> 8) & 0xFF);
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4 + 3] = (byte) (downloadData[currentIndex] & 0xFF);
currentIndex++; currentIndex++;
} }
// send NOP to get result of last write // send NOP to get result of last write
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4] = NOP; fillPacket(NOP, currentIndex * 6);
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 4 + 1] = NOP; data = transmit(STYPE_BDI_17FILL_BYTE_WORD, dataLength * 6 + 3);
data = transmit(STYPE_BDI_17FILL_BYTE_WORD, dataLength * 4 + 2);
break; break;
case 4: case 4:
if (dataLength > (maxNofLongs)) { if (dataLength > (maxNofLongsFill)) {
throw new BDIException("data length (" + dataLength throw new BDIException("data length (" + dataLength
+ ") larger than maxNofLongs (" + maxNofLongs + ")"); + ") larger than maxNofLongs (" + maxNofLongsFill + ")");
} }
while (currentIndex < dataLength) { while (currentIndex < dataLength) {
// FILL // FILLL
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 6] = (byte) ((FILLL >>> 8) & 0xFF); fillPacket(FILLL, currentIndex * 9);
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 6 + 1] = (byte) (FILLL & 0xFF);
// MS data // MS data
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 6 + 2] = (byte) ((downloadData[currentIndex] >>> 24) & 0xFF); fillPacket((downloadData[currentIndex] >>> 16),
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 6 + 3] = (byte) ((downloadData[currentIndex] >>> 16) & 0xFF); currentIndex * 9 + 3);
// LS data // LS data
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 6 + 4] = (byte) ((downloadData[currentIndex] >>> 8) & 0xFF); fillPacket(downloadData[currentIndex], currentIndex * 9 + 6);
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 6 + 5] = (byte) (downloadData[currentIndex] & 0xFF);
currentIndex++; currentIndex++;
} }
// send NOP to get result of last write // send NOP to get result of last write
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 6] = NOP; fillPacket(NOP, currentIndex * 9);
sendData[DataPacket.PACKET_DATA_OFFSET + currentIndex * 6 + 1] = NOP; data = transmit(STYPE_BDI_17FILL_LONG, dataLength * 9 + 3);
data = transmit(STYPE_BDI_17FILL_LONG, dataLength * 6 + 2); logger.fine("FILL: Transmit: " + (dataLength * 9 + 3));
logger.info("FILL: Transmit: " + (dataLength * 6 + 2));
break; break;
default: default:
throw new BDIException("invalid writeMemSize: " + writeMemSize); throw new BDIException("invalid writeMemSize: " + writeMemSize);
@@ -616,11 +629,16 @@ public class MC68332 {
switch (data.subtype) { switch (data.subtype) {
case STYPE_BDI_SUCCESS_FD: case STYPE_BDI_SUCCESS_FD:
break; break;
case STYPE_BDI_ERROR_FD_LENGTH: case STYPE_BDI_ERROR_FD_LENGTH:
System.out.println("0x"
+ Integer.toHexString(((data.data[0] & 0xff) << 8)
+ (data.data[1] & 0xff)));
throw new BDIException("length smaller than BDI_DATA17_LENGTH"); throw new BDIException("length smaller than BDI_DATA17_LENGTH");
case STYPE_BDI_ERROR_FD_GENERAL: case STYPE_BDI_ERROR_FD_GENERAL:
System.out.println("0x"
+ Integer.toHexString(((data.data[0] & 0xff) << 8)
+ (data.data[1] & 0xff)));
throw new BDIException("general fast download error"); throw new BDIException("general fast download error");
default: default:
throw new BDIException("wrong subtype: " + data.subtype); throw new BDIException("wrong subtype: " + data.subtype);
@@ -644,48 +662,40 @@ public class MC68332 {
public int[] dumpMem(int nofData) throws USBException, DispatchException, public int[] dumpMem(int nofData) throws USBException, DispatchException,
BDIException { BDIException {
// TODO: adjust MAX_NOF_XX_DUMP
updateMaxValues(); updateMaxValues();
int dataSize; int dataSize;
switch (readMemSize) { switch (readMemSize) {
case 1: case 1:
if (nofData > maxNofBytesWords) if (nofData > maxNofBytesWordsFill)
nofData = maxNofBytesWords; nofData = maxNofBytesWordsFill;
// fill the packet with {DUMPB} + 1 NOP at the end // fill the packet with {DUMPB} + 1 NOP at the end
int i; int i;
for (i = 0; i < nofData; i++) { for (i = 0; i < nofData; i++) {
sendData[DataPacket.PACKET_DATA_OFFSET + i * 2] = (byte) ((DUMPB >>> 8) & 0xFF); fillPacket(DUMPB, i * 3);
sendData[DataPacket.PACKET_DATA_OFFSET + i * 2 + 1] = (byte) (DUMPB & 0xFF);
} }
sendData[DataPacket.PACKET_DATA_OFFSET + i * 2] = (byte) ((NOP >>> 8) & 0xFF); fillPacket(NOP, i * 3);
sendData[DataPacket.PACKET_DATA_OFFSET + i * 2 + 1] = (byte) (NOP & 0xFF); dataSize = i * 3 + 3;
dataSize = i * 2 + 2;
break; break;
case 2: case 2:
if (nofData > maxNofBytesWords) if (nofData > maxNofBytesWordsFill)
nofData = maxNofBytesWords; nofData = maxNofBytesWordsFill;
// fill the packet with {DUMPW} + 1 NOP at the end // fill the packet with {DUMPW} + 1 NOP at the end
for (i = 0; i < nofData; i++) { for (i = 0; i < nofData; i++) {
sendData[DataPacket.PACKET_DATA_OFFSET + i * 2] = (byte) ((DUMPW >>> 8) & 0xFF); fillPacket(DUMPW, i * 3);
sendData[DataPacket.PACKET_DATA_OFFSET + i * 2 + 1] = (byte) (DUMPW & 0xFF);
} }
sendData[DataPacket.PACKET_DATA_OFFSET + i * 2] = (byte) ((NOP >>> 8) & 0xFF); fillPacket(NOP, i * 3);
sendData[DataPacket.PACKET_DATA_OFFSET + i * 2 + 1] = (byte) (NOP & 0xFF); dataSize = i * 3 + 3;
dataSize = i * 2 + 2;
break; break;
case 4: case 4:
if (nofData > maxNofLongs) if (nofData > maxNofLongsFill)
nofData = maxNofLongs; nofData = maxNofLongsFill;
// fill the packet with {DUMPL + NOP} + 1 NOP at the end // fill the packet with {DUMPL + NOP} + 1 NOP at the end
for (i = 0; i < nofData; i++) { for (i = 0; i < nofData; i++) {
sendData[DataPacket.PACKET_DATA_OFFSET + i * 4] = (byte) ((DUMPL >>> 8) & 0xFF); fillPacket(DUMPL, i * 6);
sendData[DataPacket.PACKET_DATA_OFFSET + i * 4 + 1] = (byte) (DUMPL & 0xFF); fillPacket(NOP, i * 6 + 3);
sendData[DataPacket.PACKET_DATA_OFFSET + i * 4 + 2] = (byte) ((NOP >>> 8) & 0xFF);
sendData[DataPacket.PACKET_DATA_OFFSET + i * 4 + 3] = (byte) (NOP & 0xFF);
} }
sendData[DataPacket.PACKET_DATA_OFFSET + i * 4] = (byte) ((NOP >>> 8) & 0xFF); fillPacket(NOP, i * 6);
sendData[DataPacket.PACKET_DATA_OFFSET + i * 4 + 1] = (byte) (NOP & 0xFF); dataSize = i * 6 + 3;
dataSize = i * 4 + 2;
break; break;
default: default:
throw new BDIException("invalid readMemSize: " + readMemSize); throw new BDIException("invalid readMemSize: " + readMemSize);
@@ -693,9 +703,8 @@ public class MC68332 {
DataPacket res = transmit(STYPE_BDI_17DUMP, dataSize); DataPacket res = transmit(STYPE_BDI_17DUMP, dataSize);
/* /*
* The resulting data is not 17 bits wide, but only 16 bits. The status * The status of each transfer is checked on the USB-Controller. If an
* bit is checked on the USB-Controller. If an error occurs, a * error occurs, a STYPE_BDI_DUMP_ERROR packet is returned.
* STYPE_BDI_DUMP_ERROR packet is returned.
*/ */
if (res == null) { if (res == null) {
throw new BDIException("no data from device"); throw new BDIException("no data from device");
@@ -707,31 +716,30 @@ public class MC68332 {
switch (readMemSize) { switch (readMemSize) {
case 1: case 1:
case 2: case 2:
result = new int[(res.data.length) / 2]; result = new int[(res.data.length) / 3];
// MS Result before LS Result // MS Result before LS Result
int resIndex = 0; int resIndex = 0;
while (resIndex * 2 < res.data.length) { while (resIndex * 3 + 3 < res.data.length) {
result[resIndex] = ((res.data[resIndex * 2] << 8) & 0xFFFF) result[resIndex] = parseResult17(res, resIndex * 3);
+ (res.data[resIndex * 2 + 1] & 0xFF);
resIndex++; resIndex++;
} }
return result; return result;
case 4: case 4:
result = new int[(res.data.length) / 4]; result = new int[(res.data.length) / 6];
// MS Result before LS Result // MS Result before LS Result
resIndex = 0; resIndex = 0;
while (resIndex * 4 < res.data.length) { while (resIndex * 6 + 6 < res.data.length) {
result[resIndex] = (res.data[resIndex * 4] << 24) // MS Result
+ ((res.data[resIndex * 4 + 1] << 16) & 0xFFFFFF) result[resIndex] = parseResult17(res, resIndex * 6) << 16;
+ ((res.data[resIndex * 4 + 2] << 8) & 0xFFFF) // LS Result
+ (res.data[resIndex * 4 + 3] & 0xFF); result[resIndex] += parseResult17(res, resIndex * 6 + 3);
resIndex++; resIndex++;
} }
return result; return result;
// the default case is handled above // the default case is handled above
} }
case STYPE_BDI_DUMP_ERROR: case STYPE_BDI_DUMP_ERROR:
// thows BDI exceptions, but not for "Not Ready" // throws BDI exceptions, but not for "Not Ready"
throw new BDIException("STYPE_BDI_DUMP_ERROR"); throw new BDIException("STYPE_BDI_DUMP_ERROR");
default: default:
throw new BDIException("wrong subtype: " + res.subtype); throw new BDIException("wrong subtype: " + res.subtype);
@@ -1005,29 +1013,53 @@ public class MC68332 {
/** /**
* Maximal number of words or bytes (1 or 2 bytes) for one usb-packet to * Maximal number of words or bytes (1 or 2 bytes) for one usb-packet to
* download (fill) or read (dump). <br> * download (fill).<br>
* Note that no status bit is used. Therefore one data entity is only 16 * This method will only return a valid result, if the USB device is
* bits wide (not 17 bits like normal commands). <br> * connected.
* <code>maxNofWordsFastDownload</code> is a multiple of 4 (FILLB/W +
* data).
* *
* @return * @return
*/ */
public int getMaxNofBytesWords() { public int getMaxNofBytesWordsFill() {
return maxNofBytesWords; updateMaxValues();
return maxNofBytesWordsFill;
} }
/** /**
* Maximal number of longs (4 bytes) for one usb-packet to download (fill) * Maximal number of longs (4 bytes) for one usb-packet to download (fill)
* or read (dump).<br> * or read (dump).<br>
* Note that no status bit is used. Therefore one data entity is only 16 * This method will only return a valid result, if the USB device is
* bits wide (not 17 bits like normal commands). <br> * connected.
* <code>maxNofLongs</code> is a multiple of 6 (FILLW + MS data + LS
* data).
* *
* @return * @return
*/ */
public int getMaxNofLongs() { public int getMaxNofLongsFill() {
return maxNofLongs; updateMaxValues();
return maxNofLongsFill;
}
/**
* Maximal number of words or bytes (1 or 2 bytes) to dump in one
* usb-packet.<br>
* This method will only return a valid result, if the USB device is
* connected.
*
* @return
*/
public int getMaxNofBytesWordsDump() {
updateMaxValues();
return maxNofBytesWordsDump;
}
/**
* Maximal number of longs (4 bytes) for one usb-packet to download (fill)
* or read (dump).<br>
* This method will only return a valid result, if the USB device is
* connected.
*
* @return
*/
public int getMaxNofLongsDump() {
updateMaxValues();
return maxNofLongsDump;
} }
} }

View File

@@ -20,7 +20,7 @@ public class BDI332test {
// test bdi transaction // test bdi transaction
DataPacket result = null; DataPacket result = null;
try { try {
result = bdi.transfer(0x0C00); result = bdi.transfer(0xaaaa);
} catch (USBException e1) { } catch (USBException e1) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e1.printStackTrace(); e1.printStackTrace();
@@ -224,7 +224,7 @@ public class BDI332test {
try { try {
logger.info("Data: 0x" logger.info("Data: 0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 4)) + " "); + Integer.toHexString(bdi.readMem(BASE_ADDR, 4)) + " ");
result = bdi.dumpMem(bdi.getMaxNofLongs()); result = bdi.dumpMem(bdi.getMaxNofLongsDump());
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
sb.append("0x" + Integer.toHexString(result[i]) + " "); sb.append("0x" + Integer.toHexString(result[i]) + " ");
@@ -244,19 +244,24 @@ public class BDI332test {
} }
public static void button9() { public static void button9() {
logger.info("not implemented"); logger.info("nop");
// try { // test bdi transaction
// bdi.nop(); DataPacket result = null;
// } catch (USBException e) { try {
// // TODO Auto-generated catch block result = bdi.transfer(0x0000);
// e.printStackTrace(); } catch (USBException e1) {
// } catch (DispatchException e) { // TODO Auto-generated catch block
// // TODO Auto-generated catch block e1.printStackTrace();
// e.printStackTrace(); } catch (DispatchException e1) {
// } catch (BDIException e) { // TODO Auto-generated catch block
// // TODO Auto-generated catch block e1.printStackTrace();
// e.printStackTrace(); } catch (BDIException e) {
// } // TODO Auto-generated catch block
e.printStackTrace();
}
if (result != null) {
logger.info(result.toString());
}
} }
public static void button10() { public static void button10() {
@@ -266,7 +271,7 @@ public class BDI332test {
logger.info("fill"); logger.info("fill");
try { try {
bdi.writeMem(BASE_ADDR, 0, 4); bdi.writeMem(BASE_ADDR, 0, 4);
int[] data = new int[bdi.getMaxNofLongs()]; int[] data = new int[bdi.getMaxNofLongsFill()];
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = i; data[i] = i;
} }
@@ -303,7 +308,7 @@ public class BDI332test {
try { try {
logger.info("Fill (1 to data.length)"); logger.info("Fill (1 to data.length)");
bdi.writeMem(BASE_ADDR, 0, 4); bdi.writeMem(BASE_ADDR, 0, 4);
int[] data = new int[bdi.getMaxNofLongs()]; int[] data = new int[bdi.getMaxNofLongsFill()];
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = i + 1; data[i] = i + 1;
} }
@@ -319,7 +324,7 @@ public class BDI332test {
logger.info((LENGTH + 1) + " bytes written"); logger.info((LENGTH + 1) + " bytes written");
logger.info("dump data"); logger.info("dump data");
int firstInt = bdi.readMem(BASE_ADDR, 4); int firstInt = bdi.readMem(BASE_ADDR, 4);
int[] result = bdi.dumpMem(bdi.getMaxNofLongs()); int[] result = bdi.dumpMem(bdi.getMaxNofLongsDump());
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
sb.append("0x" + Integer.toHexString(result[i]) + " "); sb.append("0x" + Integer.toHexString(result[i]) + " ");
@@ -343,7 +348,7 @@ public class BDI332test {
try { try {
logger.info("initialize data"); logger.info("initialize data");
bdi.writeMem(BASE_ADDR, FIRST_VAL, 4); bdi.writeMem(BASE_ADDR, FIRST_VAL, 4);
int[] data = new int[bdi.getMaxNofLongs()]; int[] data = new int[bdi.getMaxNofLongsFill()];
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = 5; data[i] = 5;
} }
@@ -366,7 +371,7 @@ public class BDI332test {
} }
logger.fine("Compare first 0x" + Integer.toHexString(firstResult) logger.fine("Compare first 0x" + Integer.toHexString(firstResult)
+ " == 0x" + Integer.toHexString(FIRST_VAL)); + " == 0x" + Integer.toHexString(FIRST_VAL));
int[] result = bdi.dumpMem(bdi.getMaxNofLongs()); int[] result = bdi.dumpMem(bdi.getMaxNofLongsDump());
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
logger.fine("Compare " + i + ": 0x" logger.fine("Compare " + i + ": 0x"
+ Integer.toHexString(result[i])); + Integer.toHexString(result[i]));
@@ -392,7 +397,7 @@ public class BDI332test {
logger.info("write data"); logger.info("write data");
try { try {
bdi.writeMem(BASE_ADDR, FIRST_VAL, 4); bdi.writeMem(BASE_ADDR, FIRST_VAL, 4);
int[] data = new int[bdi.getMaxNofLongs()]; int[] data = new int[bdi.getMaxNofLongsFill()];
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = i; data[i] = i;
} }
@@ -407,7 +412,7 @@ public class BDI332test {
} }
logger.fine("Compare first 0x" + Integer.toHexString(firstResult) logger.fine("Compare first 0x" + Integer.toHexString(firstResult)
+ " == 0x" + Integer.toHexString(FIRST_VAL)); + " == 0x" + Integer.toHexString(FIRST_VAL));
int[] result = bdi.dumpMem(bdi.getMaxNofLongs()); int[] result = bdi.dumpMem(bdi.getMaxNofLongsFill());
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
if (data[i] != result[i]) { if (data[i] != result[i]) {
logger.warning("Error at " + i + ": 0x" logger.warning("Error at " + i + ": 0x"
@@ -450,28 +455,28 @@ public class BDI332test {
public static void button16() { public static void button16() {
final int BASE_ADDR = 0x105624; final int BASE_ADDR = 0x105624;
final int DATA = 0x00ff00ff; final int DATA = 0x00ff00ff;
final int OFFSET = (bdi.getMaxNofLongs() - 2) * 4; final int OFFSET = (bdi.getMaxNofLongsFill() - 2) * 4;
final int LENGTH = 0x04; final int LENGTH = 0x04;
final int DUMP_BASE = BASE_ADDR + (bdi.getMaxNofLongs() / 2) * 4; final int DUMP_BASE = BASE_ADDR + (bdi.getMaxNofLongsFill() / 2) * 4;
try { try {
logger.info("REPLACE at the end"); logger.info("REPLACE at the end");
logger.info("Fill first"); logger.info("Fill first");
bdi.writeMem(BASE_ADDR, 0, 4); bdi.writeMem(BASE_ADDR, 0, 4);
int[] data = new int[bdi.getMaxNofLongs()]; int[] data = new int[bdi.getMaxNofLongsFill()];
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = i + 1; data[i] = i + 1;
} }
bdi.fillMem(data, data.length); bdi.fillMem(data, data.length);
logger.info("Fill second"); logger.info("Fill second");
bdi.writeMem(BASE_ADDR + (bdi.getMaxNofLongs() + 1) * 4, 0, 4); bdi.writeMem(BASE_ADDR + (bdi.getMaxNofLongsFill() + 1) * 4, 0, 4);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = bdi.getMaxNofLongs() + i + 2; data[i] = bdi.getMaxNofLongsFill() + i + 2;
} }
bdi.fillMem(data, data.length); bdi.fillMem(data, data.length);
logger.info("Dump from base: 0x" + Integer.toHexString(DUMP_BASE)); logger.info("Dump from base: 0x" + Integer.toHexString(DUMP_BASE));
int firstInt = bdi.readMem(DUMP_BASE, 4); int firstInt = bdi.readMem(DUMP_BASE, 4);
int[] result = bdi.dumpMem(bdi.getMaxNofLongs()); int[] result = bdi.dumpMem(bdi.getMaxNofLongsFill());
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
sb.append("0x" + Integer.toHexString(result[i]) + " "); sb.append("0x" + Integer.toHexString(result[i]) + " ");
@@ -491,7 +496,7 @@ public class BDI332test {
logger.info("dump data from base: 0x" logger.info("dump data from base: 0x"
+ Integer.toHexString(DUMP_BASE)); + Integer.toHexString(DUMP_BASE));
firstInt = bdi.readMem(DUMP_BASE, 4); firstInt = bdi.readMem(DUMP_BASE, 4);
result = bdi.dumpMem(bdi.getMaxNofLongs()); result = bdi.dumpMem(bdi.getMaxNofLongsFill());
sb = new StringBuffer(); sb = new StringBuffer();
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
sb.append("0x" + Integer.toHexString(result[i]) + " "); sb.append("0x" + Integer.toHexString(result[i]) + " ");
@@ -556,9 +561,9 @@ public class BDI332test {
DispatchException, BDIException { DispatchException, BDIException {
int dumpSize = 0; int dumpSize = 0;
if (size > 2) { if (size > 2) {
dumpSize = bdi.getMaxNofLongs(); dumpSize = bdi.getMaxNofLongsFill();
} else { } else {
dumpSize = bdi.getMaxNofBytesWords(); dumpSize = bdi.getMaxNofBytesWordsFill();
} }
logger.info("read " + size + " byte(s) at 0x" logger.info("read " + size + " byte(s) at 0x"
+ Integer.toHexString(baseAddr) + ", value: " + Integer.toHexString(baseAddr) + ", value: "
@@ -575,9 +580,9 @@ public class BDI332test {
DispatchException, BDIException { DispatchException, BDIException {
int fillSize = 0; int fillSize = 0;
if (size > 2) { if (size > 2) {
fillSize = bdi.getMaxNofLongs(); fillSize = bdi.getMaxNofLongsFill();
} else { } else {
fillSize = bdi.getMaxNofBytesWords(); fillSize = bdi.getMaxNofBytesWordsFill();
} }
int[] data = new int[fillSize]; int[] data = new int[fillSize];
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
@@ -592,7 +597,7 @@ public class BDI332test {
public static void button18() { public static void button18() {
final int BASE_ADDR = 0x105624; final int BASE_ADDR = 0x105624;
int[] data = new int[bdi.getMaxNofBytesWords()]; int[] data = new int[bdi.getMaxNofBytesWordsFill()];
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = i; data[i] = i;
} }