- comment and logging updated

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@87 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
schlaepfer
2006-01-17 12:53:15 +00:00
parent b1a591a94f
commit 6a0271478d

View File

@@ -274,9 +274,6 @@ public class MC68332 {
// 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 (bit15 .. bit0)
// TODO check this:
// sendData[Dispatch.PACKET_DATA_OFFSET + offset] = (byte) (((data >>>
// 9) & 0x7F) | 0x80);
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);
@@ -396,7 +393,7 @@ public class MC68332 {
*/ */
public static void break_() throws USBException, DispatchException, public static void break_() throws USBException, DispatchException,
BDIException { BDIException {
// TODO: this may be wrong, but works // FIXME: this may be wrong, but works
// ignore the result of the first transaction // ignore the result of the first transaction
ignoreResult = true; ignoreResult = true;
transferAndParse17(NOP); transferAndParse17(NOP);
@@ -406,6 +403,13 @@ public class MC68332 {
targetInDebugMode = isFreezeAsserted(); targetInDebugMode = isFreezeAsserted();
} }
/**
* Resume from debug mode.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void go() throws USBException, DispatchException, public static void go() throws USBException, DispatchException,
BDIException { BDIException {
if (!targetInDebugMode) { if (!targetInDebugMode) {
@@ -415,6 +419,14 @@ public class MC68332 {
targetInDebugMode = isFreezeAsserted(); targetInDebugMode = isFreezeAsserted();
} }
/**
* Send a command to reset the microcontroller.<br>
* The reset is done electrically by the USB-controller.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
private static void hard_reset() throws USBException, DispatchException, private static void hard_reset() throws USBException, DispatchException,
BDIException { BDIException {
DataPacket data = transmit(STYPE_BDI_HARD_RESET_332, 0); DataPacket data = transmit(STYPE_BDI_HARD_RESET_332, 0);
@@ -441,6 +453,13 @@ public class MC68332 {
break_(); break_();
} }
/**
* Send the <b>RST</b> command (reset peripherals) to the microcontroller.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void reset_peripherals() throws USBException, public static void reset_peripherals() throws USBException,
DispatchException, BDIException { DispatchException, BDIException {
// hard reset // hard reset
@@ -456,7 +475,8 @@ public class MC68332 {
} }
/** /**
* Check if the freeze signal is asserted. * Check if the freeze signal is asserted.<br>
* The freeze siganl is asserted if the target is in debug mode.
* *
* @return * @return
* @throws USBException * @throws USBException
@@ -480,9 +500,9 @@ public class MC68332 {
} }
/** /**
* Fill is used in conjunction with the <code>writeMem</code> command to * Fill large blocks of memory.<br>
* fill large blocks of memory. <br> * Fill is used in conjunction with the <code>writeMem</code> command. The
* The maximal number of words is defined by * maximal number of words is defined by
* <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
@@ -504,7 +524,7 @@ public class MC68332 {
// check if data fits into USB-packet // check if data fits into USB-packet
int currentIndex = 0; int currentIndex = 0;
DataPacket data; DataPacket data;
logger.debug("dataLength: " + dataLength); logger.finer("dataLength: " + dataLength);
switch (writeMemSize) { switch (writeMemSize) {
case 1: case 1:
if (dataLength > MAX_NOF_BYTES_WORDS_FILL) { if (dataLength > MAX_NOF_BYTES_WORDS_FILL) {
@@ -589,12 +609,15 @@ public class MC68332 {
} }
/** /**
* Dump is used in conjunction with the <code>readMem(...)</code> command * Dump large blocks of memory. <br>
* to dump large blocks of memory. The size depends on the size set up with * Dump is used in conjunction with the <code>readMem(...)</code> command.
* <code>readMem(...)</code> and is internally stored. * The size depends on the size set up with <code>readMem(...)</code> and
* is internally stored.
* *
* @param nofData * @param nofData
* @return * number of bytes/words/longs to read (depends on the size set
* up with <code>readMem(...)</code>)
* @return read values
* @throws USBException * @throws USBException
* @throws DispatchException * @throws DispatchException
* @throws BDIException * @throws BDIException
@@ -695,15 +718,28 @@ public class MC68332 {
} }
} }
/**
* Write to a specified memory address.<br>
*
* @param addr
* address to write
* @param value
* value to write
* @param size
* number of bytes to read
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void writeMem(int addr, int value, int size) public static void writeMem(int addr, int value, int size)
throws USBException, DispatchException, BDIException { throws USBException, DispatchException, BDIException {
if (!targetInDebugMode) { if (!targetInDebugMode) {
throw new BDIException("target not in debug mode"); throw new BDIException("target not in debug mode");
} }
logger.info("writeMem: 0x" + Integer.toHexString(addr >>> 16) + " 0x" logger.info("addr: 0x" + Integer.toHexString(addr >>> 16) + " 0x"
+ Integer.toHexString(addr & 0xFFFF)); + Integer.toHexString(addr & 0xFFFF) + "\tvalue: 0x"
logger.info("writeMem: 0x" + Integer.toHexString(value >>> 16) + " 0x" + Integer.toHexString(value >>> 16) + " 0x"
+ Integer.toHexString(value & 0xFFFF)); + Integer.toHexString(value & 0xFFFF));
writeMemSize = size; writeMemSize = size;
@@ -751,6 +787,18 @@ public class MC68332 {
} }
} }
/**
* Read the value of a specified memory address.<br>
*
* @param addr
* address to read
* @param size
* number of bytes to read
* @return value of this memory address
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static int readMem(int addr, int size) throws USBException, public static int readMem(int addr, int size) throws USBException,
DispatchException, BDIException { DispatchException, BDIException {
@@ -758,7 +806,7 @@ public class MC68332 {
throw new BDIException("target not in debug mode"); throw new BDIException("target not in debug mode");
} }
logger.info("readMem: 0x" + Integer.toHexString(addr >>> 16) logger.info("addr: 0x" + Integer.toHexString(addr >>> 16) + " 0x"
+ Integer.toHexString(addr & 0xFFFF)); + Integer.toHexString(addr & 0xFFFF));
readMemSize = size; readMemSize = size;
@@ -799,6 +847,18 @@ public class MC68332 {
} }
} }
/**
* Read a specified value from a user register. <br>
* See the <b>registerDictionary.xml</b> file for valid registers. This
* file can be found in the <b>mc68332 resource</b>-section.
*
* @param reg
* register to read
* @return value of register
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static int readUserReg(int reg) throws USBException, public static int readUserReg(int reg) throws USBException,
DispatchException, BDIException { DispatchException, BDIException {
@@ -814,6 +874,19 @@ public class MC68332 {
return (valMS << 16) + transferAndParse17(NOP); return (valMS << 16) + transferAndParse17(NOP);
} }
/**
* Write a specified value to user register. <br>
* See the <b>registerDictionary.xml</b> file for valid registers. This
* file can be found in the <b>mc68332 resource</b>-section.
*
* @param reg
* register to write
* @param value
* value to write to register
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void writeUserReg(int reg, int value) throws USBException, public static void writeUserReg(int reg, int value) throws USBException,
DispatchException, BDIException { DispatchException, BDIException {
@@ -833,6 +906,18 @@ public class MC68332 {
} }
} }
/**
* Read a specified value from a system register. <br>
* See the <b>registerDictionary.xml</b> file for valid registers. This
* file can be found in the <b>mc68332 resource</b>-section.
*
* @param reg
* register to read
* @return value of register
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static int readSysReg(int reg) throws USBException, public static int readSysReg(int reg) throws USBException,
DispatchException, BDIException { DispatchException, BDIException {
@@ -848,16 +933,29 @@ public class MC68332 {
return (valMS << 16) + transferAndParse17(NOP); return (valMS << 16) + transferAndParse17(NOP);
} }
/**
* Write a specified value to system register. <br>
* See the <b>registerDictionary.xml</b> file for valid registers. This
* file can be found in the <b>mc68332 resource</b>-section.
*
* @param reg
* register to write
* @param value
* value to write to register
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void writeSysReg(int reg, int value) throws USBException, public static void writeSysReg(int reg, int value) throws USBException,
DispatchException, BDIException { DispatchException, BDIException {
if (!targetInDebugMode) { if (!targetInDebugMode) {
throw new BDIException("target not in debug mode"); throw new BDIException("target not in debug mode");
} }
logger.info("0x" + Integer.toHexString(reg) + " " + "0x" logger.info("register: 0x" + Integer.toHexString(reg) + ", value: "
+ Integer.toHexString(value)); + "0x" + Integer.toHexString(value) + "\tinstructions: 0x"
logger.info("0x" + Integer.toHexString(WSREG + (reg & 0xF)) + " 0x" + Integer.toHexString(WSREG + (reg & 0xF)) + " 0x"
+ Integer.toHexString(value >>> 16) + " 0x" + Integer.toHexString(value >>> 16) + ", 0x"
+ Integer.toHexString(value)); + Integer.toHexString(value));
// put instr. // put instr.
@@ -875,15 +973,17 @@ public class MC68332 {
// TODO: remove // TODO: remove
public static void nop() throws USBException, DispatchException, public static void nop() throws USBException, DispatchException,
BDIException { BDIException {
logger.info("0x" + Integer.toHexString(transferAndParse17(NOP))); logger
.info("result: 0x"
+ Integer.toHexString(transferAndParse17(NOP)));
} }
/** /**
* Return the last known state of the freeze signal. This value may not be * Return the last known state of the freeze signal.<br>
* up to date as the target state may have changed meanwhile. To get the up * This value may not be up to date as the target state may have changed
* to date value use <code>isFreezeAsserted</code> which will issue an USB * meanwhile. To get the up to date value use <code>isFreezeAsserted</code>
* request, read the freeze signal and update the internal value returned by * which will issue an USB request, read the freeze signal and update the
* this method. * internal value returned by this method.
* *
* @return the last known state of the freeze signal * @return the last known state of the freeze signal
*/ */