- getGPR/setGPR added

- ecr Exception corrected
- some cleanup

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@45 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
schlaepfer
2005-11-17 10:12:24 +00:00
parent e4247ece42
commit 6580800d3c

View File

@@ -20,16 +20,6 @@ public class MPC555 {
*/ */
private static final byte STYPE_BDI_35OUT = 0x02; private static final byte STYPE_BDI_35OUT = 0x02;
/**
* 10 Bit Packet to BDI
*/
private static final byte STYPE_BDI_10IN = 0x03;
/**
* 10 Bit Packet from BDI
*/
private static final byte STYPE_BDI_10OUT = 0x04;
/** /**
* Fast Download Data * Fast Download Data
*/ */
@@ -159,12 +149,12 @@ public class MPC555 {
return data; return data;
} }
private static void fillPacket(boolean lengthBit, boolean controlBit, private static void fillPacket(boolean modeBit, boolean controlBit,
int data, int offset) { int data, int offset) {
// startBit = 1 | lengthBit | controlBit | 32 bits of data // startBit = 1 | modeBit | controlBit | 32 bits of data
byte b = (byte) 0x80; byte b = (byte) 0x80;
if (lengthBit) { if (modeBit) {
b |= 0x40; b |= 0x40;
} }
if (controlBit) { if (controlBit) {
@@ -178,12 +168,12 @@ public class MPC555 {
sendData[Dispatch.PACKET_DATA_OFFSET + offset + 4] = (byte) ((data & 0x07) << 5); sendData[Dispatch.PACKET_DATA_OFFSET + offset + 4] = (byte) ((data & 0x07) << 5);
} }
private static DataPacket transfer(boolean lengthBit, boolean controlBit, private static DataPacket transfer(boolean modeBit, boolean controlBit,
int data) throws USBException, DispatchException, BDIException { int data) throws USBException, DispatchException, BDIException {
initPacket(STYPE_BDI_35IN, BDI_DATA35_LENGTH); initPacket(STYPE_BDI_35IN, BDI_DATA35_LENGTH);
fillPacket(lengthBit, controlBit, data, 0); fillPacket(modeBit, controlBit, data, 0);
return transmit(BDI_DATA35_LENGTH); return transmit(BDI_DATA35_LENGTH);
} }
@@ -222,10 +212,10 @@ public class MPC555 {
} }
} }
private static int transferAndParse35(boolean lengthBit, private static int transferAndParse35(boolean modeBit,
boolean controlBit, int data) throws USBException, boolean controlBit, int data) throws USBException,
DispatchException, BDIException { DispatchException, BDIException {
return parseResult35(transfer(lengthBit, controlBit, data)); return parseResult35(transfer(modeBit, controlBit, data));
} }
private static void epilogue() throws USBException, DispatchException, private static void epilogue() throws USBException, DispatchException,
@@ -270,9 +260,9 @@ public class MPC555 {
// nop // nop
gpr31 = transferAndParse35(false, false, NOP); gpr31 = transferAndParse35(false, false, NOP);
if ((ecr & EBRK_bit * 2) > 0) { if ((ecr & (EBRK_bit * 2)) > 0) {
// TODO: change exception string // TODO: change exception string
System.out.println("Exception Cause Register = " + "0x" System.err.println("Exception Cause Register = " + "0x"
+ Integer.toHexString(ecr)); + Integer.toHexString(ecr));
} }
} }
@@ -325,10 +315,12 @@ public class MPC555 {
transferAndParse35(false, false, 0x7FD69BA6); transferAndParse35(false, false, 0x7FD69BA6);
// nop // nop
ecr = transferAndParse35(false, false, NOP); ecr = transferAndParse35(false, false, NOP);
// if (ecr != 0x01) { // TODO: change exception string // check if entry into debug mode was because of DPI
// throw new BDIException("ecr != 0x01: ecr = " if (ecr != 0x01) {
// + Integer.toHexString(ecr)); throw new BDIException(
// } "Wrong debug enable cause (not due to DPI): Exception Cause Register = 0x"
+ Integer.toHexString(ecr));
}
} }
public static boolean isFreezeAsserted() throws USBException, public static boolean isFreezeAsserted() throws USBException,
@@ -349,8 +341,7 @@ public class MPC555 {
} }
/** /**
* Called to start the fast download procedure. If a prior download * Called to start the fast download procedure.
* procedure is still running, a BDIException will be thrown.
* *
* @param startAddr * @param startAddr
* Address to which the data will be downloaded. * Address to which the data will be downloaded.
@@ -363,11 +354,11 @@ public class MPC555 {
if (!targetInDebugMode) { if (!targetInDebugMode) {
throw new BDIException("target not in debug mode"); throw new BDIException("target not in debug mode");
} }
// put instr. mfspr GPR30, DPDR
transferAndParse35(false, false, 0x7FD69AA6); transferAndParse35(false, false, 0x7FD69AA6);
// put adr into DPDR
transferAndParse35(false, true, startAddr - 4); transferAndParse35(false, true, startAddr - 4);
// start fast download
transferAndParse35(true, true, 0xC6000000); transferAndParse35(true, true, 0xC6000000);
fastDownloadStarted = true; fastDownloadStarted = true;
} }
@@ -429,13 +420,16 @@ public class MPC555 {
// stop fast download // stop fast download
int result = transferAndParse35(true, true, 0x86000000); int result = transferAndParse35(true, true, 0x86000000);
System.out.println("stopFastDownload: result: 0x" + Integer.toHexString(result)); System.out.println("stopFastDownload: result: 0x"
+ Integer.toHexString(result));
// if (result != 0x5F) { // if (result != 0x5F) {
// // TODO: change exception string // // TODO: change exception string
// throw new BDIException("result != 0x5F: " + result); // throw new BDIException("result != 0x5F: " + result);
// } // }
// terminate gracefully // terminate gracefully (DATA transaction)
transferAndParse35(false, true, 0); result = transferAndParse35(false, true, 0x0);
System.out.println("stopFastDownload: result 2: 0x"
+ Integer.toHexString(result));
} }
public static void writeMem(int addr, int value, int size) public static void writeMem(int addr, int value, int size)
@@ -790,4 +784,20 @@ public class MPC555 {
public static boolean isTargetInDebugMode() { public static boolean isTargetInDebugMode() {
return targetInDebugMode; return targetInDebugMode;
} }
public static int getGpr30() {
return gpr30;
}
public static void setGpr30(int gpr30) {
MPC555.gpr30 = gpr30;
}
public static int getGpr31() {
return gpr31;
}
public static void setGpr31(int gpr31) {
MPC555.gpr31 = gpr31;
}
} }