- ch.ntb.usb separated

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@142 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
schlaepfer
2006-05-05 08:41:03 +00:00
parent cd9a329a05
commit 9b4076866f
81 changed files with 0 additions and 23866 deletions

View File

@@ -1,52 +0,0 @@
EXPORTS
UART0_read = _Z10UART0_readPc @1
destroyJVM = _Z10destroyJVMv @2
UART0_write = _Z11UART0_writePci @3
BDI332_break_ = _Z13BDI332_break_v @4
BDI555_break_ = _Z13BDI555_break_v @5
BDI555_readCR = _Z13BDI555_readCRv @6
BDI332_dumpMem = _Z14BDI332_dumpMemiPi @7
BDI332_fillMem = _Z14BDI332_fillMemPii @8
BDI332_readMem = _Z14BDI332_readMemii @9
BDI555_readFPR = _Z14BDI555_readFPRii @10
BDI555_readGPR = _Z14BDI555_readGPRi @11
BDI555_readMSR = _Z14BDI555_readMSRv @12
BDI555_readMem = _Z14BDI555_readMemii @13
BDI555_readSPR = _Z14BDI555_readSPRi @14
BDI555_writeCR = _Z14BDI555_writeCRi @15
BDI332_writeMem = _Z15BDI332_writeMemiii @16
BDI555_setGpr31 = _Z15BDI555_setGpr31i @17
BDI555_writeFPR = _Z15BDI555_writeFPRiil @18
BDI555_writeGPR = _Z15BDI555_writeGPRii @19
BDI555_writeMSR = _Z15BDI555_writeMSRi @20
BDI555_writeMem = _Z15BDI555_writeMemiii @21
BDI555_writeSPR = _Z15BDI555_writeSPRii @22
USB_Device_open = _Z15USB_Device_openv @23
BDI555_readFPSCR = _Z16BDI555_readFPSCRv @24
USB_Device_close = _Z16USB_Device_closev @25
USB_Device_reset = _Z16USB_Device_resetv @26
getErrPipeHandle = _Z16getErrPipeHandlev @27
getOutPipeHandle = _Z16getOutPipeHandlev @28
BDI332_readSysReg = _Z17BDI332_readSysRegi @29
BDI555_readMemSeq = _Z17BDI555_readMemSeqi @30
BDI555_writeFPSCR = _Z17BDI555_writeFPSCRi @31
BDI332_readUserReg = _Z18BDI332_readUserRegi @32
BDI332_writeSysReg = _Z18BDI332_writeSysRegii @33
BDI555_writeMemSeq = _Z18BDI555_writeMemSeqii @34
checkForExceptions = _Z18checkForExceptionsv @35
BDI332_reset_target = _Z19BDI332_reset_targetv @36
BDI332_writeUserReg = _Z19BDI332_writeUserRegii @37
BDI555_fastDownload = _Z19BDI555_fastDownloadPii @38
BDI555_reset_target = _Z19BDI555_reset_targetv @39
BDI332_nopsToLegalCmd = _Z21BDI332_nopsToLegalCmdv @40
BDI332_isFreezeAsserted = _Z23BDI332_isFreezeAssertedv @41
BDI555_isFreezeAsserted = _Z23BDI555_isFreezeAssertedv @42
BDI555_stopFastDownload = _Z23BDI555_stopFastDownloadv @43
BDI332_reset_peripherals = _Z24BDI332_reset_peripheralsv @44
BDI555_startFastDownload = _Z24BDI555_startFastDownloadi @45
BDI332_isTargetInDebugMode = _Z26BDI332_isTargetInDebugModev @46
BDI555_isTargetInDebugMode = _Z26BDI555_isTargetInDebugModev @47
USB_Device_getMaxPacketSize = _Z27USB_Device_getMaxPacketSizev @48
BDI332_go = _Z9BDI332_gov @49
BDI555_go = _Z9BDI555_gov @50
createJVM = _Z9createJVMPc @51

Binary file not shown.

View File

@@ -1,849 +0,0 @@
#include <jni.h>
#include <windows.h>
#include <stdlib.h>
#include <stdarg.h>
#define EXPORT JNIEXPORT
#define NOF_VM_ARGS 4
#define PIPEBUFSIZE 4096
#define PIPE_TIMEOUT 500 //ms
// Classes
#define USB_Device_Class "ch/ntb/mcdp/usb/USBDevice"
#define BDI555_Class "ch/ntb/mcdp/bdi/blackbox/MPC555"
#define BDI332_Class "ch/ntb/mcdp/bdi/blackbox/MC68332"
#define Redirect_Class "ch/ntb/mcdp/utils/Redirect"
#define Uart0_Class "ch/ntb/mcdp/uart/blackbox/Uart0"
// JVM handles
JNIEnv *env = NULL;
JavaVM *jvm = NULL;
// Pipe names
char stdout_pipename[32] = "\\\\.\\pipe\\BDIDll_stdout";
char stderr_pipename[32] = "\\\\.\\pipe\\BDIDll_stderr";
// Pipe handles
HANDLE hStdout_pipe, hStderr_pipe;
// status flags
int stdOutErr_redirected = FALSE;
int jvm_created = FALSE, jvm_classPtrs_done = FALSE, \
jvm_mIDs_done = FALSE, jvm_redirection_done = FALSE;
// Java classes
jclass cls_USB_Device, cls_BDI555, cls_BDI332, cls_Redirect, cls_Uart0;
// USB_Device
jmethodID mid_USB_Dev_open, mid_USB_Dev_close, mid_USB_Dev_reset, \
mid_USB_Dev_getMaxPacketSize;
// BDI555
jmethodID mid_BDI555_break_, mid_BDI555_go, mid_BDI555_reset_target, \
mid_BDI555_isFreezeAsserted, mid_BDI555_startFastDownload, mid_BDI555_fastDownload, \
mid_BDI555_stopFastDownload, mid_BDI555_writeMem, mid_BDI555_readMem, \
mid_BDI555_writeMemSeq, mid_BDI555_readMemSeq, mid_BDI555_readGPR, \
mid_BDI555_writeGPR, mid_BDI555_readSPR, mid_BDI555_writeSPR, mid_BDI555_readMSR, \
mid_BDI555_writeMSR, mid_BDI555_readFPR, mid_BDI555_writeFPR, mid_BDI555_readCR, \
mid_BDI555_writeCR, mid_BDI555_readFPSCR, mid_BDI555_writeFPSCR, \
mid_BDI555_isTargetInDebugMode, mid_BDI555_setGpr31;
// BDI332
jmethodID mid_BDI332_nopsToLegalCmd, mid_BDI332_break_, mid_BDI332_go, \
mid_BDI332_reset_target, mid_BDI332_reset_peripherals, mid_BDI332_isFreezeAsserted, \
mid_BDI332_fillMem, mid_BDI332_dumpMem, mid_BDI332_writeMem, mid_BDI332_readMem, \
mid_BDI332_readUserReg, mid_BDI332_writeUserReg, mid_BDI332_readSysReg, \
mid_BDI332_writeSysReg, mid_BDI332_isTargetInDebugMode;
// Redirect
jmethodID mid_Redirect_redirect;
// Uart0
jmethodID mid_Uart0_write, mid_Uart0_read;
BOOL setupNamedPipes(){
hStdout_pipe = CreateNamedPipe(
stdout_pipename, // pipe name
PIPE_ACCESS_INBOUND,// server only writes and client only reads
PIPE_TYPE_BYTE | // message type pipe
PIPE_WAIT, // non blocking mode
1, // max. instances
PIPEBUFSIZE, // output buffer size
PIPEBUFSIZE, // input buffer size
PIPE_TIMEOUT, // client time-out
NULL); // default security attribute
if (hStdout_pipe == INVALID_HANDLE_VALUE)
{
fprintf(stderr, "CreateNamedPipe (stdout_pipe) failed\n");
return FALSE;
}
hStderr_pipe = CreateNamedPipe(
stderr_pipename, // pipe name
PIPE_ACCESS_INBOUND,// server only writes and client only reads
PIPE_TYPE_BYTE | // message type pipe
PIPE_WAIT, // non blocking mode
1, // max. instances
PIPEBUFSIZE, // output buffer size
PIPEBUFSIZE, // input buffer size
PIPE_TIMEOUT, // client time-out
NULL); // default security attribute
if (hStderr_pipe == INVALID_HANDLE_VALUE)
{
fprintf(stderr, "CreateNamedPipe (stderr_pipe) failed\n");
return FALSE;
}
// Connect the reading end of the hStdout_pipe and assign it to stdout
if (freopen(stdout_pipename, "w", stdout) == NULL) {
fprintf(stderr, "freopen(stdout_pipename, w, stdout) failed\n");
return FALSE;
}
// Connect the reading end of the hStderr_pipe and assign it to sterr
if (freopen(stderr_pipename, "w", stderr) == NULL) {
fprintf(stderr, "freopen(stderr_pipename, w, stderr) failed\n");
return FALSE;
}
return TRUE;
}
void flushAll()
{
fflush(stderr);
fflush(stdout);
}
void fprintf_flush(FILE* stream, const char *format, ...)
{
va_list argptr;
va_start(argptr, format);
vfprintf(stream, format, argptr);
fflush(stream);
}
EXPORT HANDLE getOutPipeHandle(){
return hStdout_pipe;
}
EXPORT HANDLE getErrPipeHandle(){
return hStderr_pipe;
}
EXPORT int destroyJVM()
{
jint result = -1;
if (env) {
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
}
}
if (jvm) {
result = jvm->DestroyJavaVM();
fprintf_flush(stderr, "JVM destroyed\n");
}
// reset flags
jvm_created = FALSE;
jvm_classPtrs_done = FALSE;
jvm_mIDs_done = FALSE;
jvm_redirection_done = FALSE;
return result;
}
jint JNICALL _vfprintf_(FILE *fp, const char *format, va_list args)
{
jint result = vfprintf(stderr, format, args);
return result;
}
EXPORT int createJVM(char *classpath)
{
char javaclasspath[1024];
jint res;
JavaVMInitArgs vm_args;
JavaVMOption options[NOF_VM_ARGS];
if (!stdOutErr_redirected) {
// writing to the stdout/stderr stream will write to pipes
// USE fprintf_flush INSTEAD OF printf/fprintf TO WRITE TO THE PIPES
if (!setupNamedPipes()) {
fprintf_flush(stderr, "setupNamedPipes() failed\n");
return FALSE;
}
stdOutErr_redirected = TRUE;
}
if (!jvm_created) {
fprintf_flush(stdout, "Starting JVM: classpath: %s\n", classpath);
sprintf(javaclasspath, "-Djava.class.path=%s", classpath);
options[0].optionString = "-Xmx20m"; // specify the maximum heap size that the JVM is allowed to grow to
options[1].optionString = javaclasspath;
options[2].optionString = "-verbose:class,jni";
options[3].optionString = "-Djava.compiler=NONE";
vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = NOF_VM_ARGS;
vm_args.ignoreUnrecognized = JNI_FALSE;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (res < 0) {
fprintf_flush(stderr, "Can't create Java VM\n");
return FALSE;
}
jvm_created = TRUE;
} else {
fprintf_flush(stdout, "JVM already created -> trying to redirect ouput streams\n");
}
if (!jvm_redirection_done) {
cls_Redirect = env->FindClass(Redirect_Class);
if (cls_Redirect == 0) {
fprintf_flush(stderr, "Can't find %s class\n", Redirect_Class);
return FALSE;
}
// Redirect Class
mid_Redirect_redirect = env->GetStaticMethodID(cls_Redirect, "redirect", "()V");
if (mid_Redirect_redirect == 0) {
fprintf_flush(stderr, "Can't find Redirect.redirect\n");
return FALSE;
}
// Call redirect
env->CallStaticVoidMethod(cls_Redirect, mid_Redirect_redirect);
jvm_redirection_done = TRUE;
} else {
fprintf_flush(stdout, "Redirection already done -> creating class pointers\n");
}
if (!jvm_classPtrs_done) {
/* create class pointers */
cls_USB_Device = env->FindClass(USB_Device_Class);
if (cls_USB_Device == 0) {
fprintf_flush(stderr, "Can't find %s class\n", USB_Device_Class);
return FALSE;
}
cls_BDI555 = env->FindClass(BDI555_Class);
if (cls_BDI555 == 0) {
fprintf_flush(stderr, "Can't find %s class\n", BDI555_Class);
return FALSE;
}
cls_BDI332 = env->FindClass(BDI332_Class);
if (cls_BDI332 == 0) {
fprintf_flush(stderr, "Can't find %s class\n", BDI332_Class);
return FALSE;
}
cls_Uart0 = env->FindClass(Uart0_Class);
if (cls_Uart0 == 0) {
fprintf_flush(stderr, "Can't find %s class\n", Uart0_Class);
return FALSE;
}
jvm_classPtrs_done = TRUE;
} else {
fprintf_flush(stdout, "Class Pointers already created -> creating method IDs\n");
}
if (!jvm_mIDs_done) {
/* create method pointers */
// USB_Device
mid_USB_Dev_open = env->GetStaticMethodID(cls_USB_Device, "open", "()V");
if (mid_USB_Dev_open == 0) {
fprintf_flush(stderr, "Can't find USB_Device.open\n");
return FALSE;
}
mid_USB_Dev_close = env->GetStaticMethodID(cls_USB_Device, "close", "()V");
if (mid_USB_Dev_close == 0) {
fprintf_flush(stderr, "Can't find USB_Device.close\n");
return FALSE;
}
mid_USB_Dev_reset = env->GetStaticMethodID(cls_USB_Device, "reset", "()V");
if (mid_USB_Dev_reset == 0) {
fprintf_flush(stderr, "Can't find USB_Device.reset\n");
return FALSE;
}
mid_USB_Dev_getMaxPacketSize = env->GetStaticMethodID(cls_USB_Device, "getMaxPacketSize", "()I");
if (mid_USB_Dev_getMaxPacketSize == 0) {
fprintf_flush(stderr, "Can't find USB_Device.getMaxPacketSize\n");
return FALSE;
}
// BDI555
mid_BDI555_break_ = env->GetStaticMethodID(cls_BDI555, "break_", "()V");
if (mid_BDI555_break_ == 0) {
fprintf_flush(stderr, "Can't find BDI555.break_\n");
return FALSE;
}
mid_BDI555_go = env->GetStaticMethodID(cls_BDI555, "go", "()V");
if (mid_BDI555_go == 0) {
fprintf_flush(stderr, "Can't find BDI555.go\n");
return FALSE;
}
mid_BDI555_reset_target = env->GetStaticMethodID(cls_BDI555, "reset_target", "()V");
if (mid_BDI555_reset_target == 0) {
fprintf_flush(stderr, "Can't find BDI555.reset_target\n");
return FALSE;
}
mid_BDI555_isFreezeAsserted = env->GetStaticMethodID(cls_BDI555, "isFreezeAsserted", "()Z");
if (mid_BDI555_isFreezeAsserted == 0) {
fprintf_flush(stderr, "Can't find BDI555.isFreezeAsserted\n");
return FALSE;
}
mid_BDI555_startFastDownload = env->GetStaticMethodID(cls_BDI555, "startFastDownload", "(I)V");
if (mid_BDI555_startFastDownload == 0) {
fprintf_flush(stderr, "Can't find BDI555.startFastDownload\n");
return FALSE;
}
mid_BDI555_fastDownload = env->GetStaticMethodID(cls_BDI555, "fastDownload", "([II)V");
if (mid_BDI555_fastDownload == 0) {
fprintf_flush(stderr, "Can't find BDI555.fastDownload\n");
return FALSE;
}
mid_BDI555_stopFastDownload = env->GetStaticMethodID(cls_BDI555, "stopFastDownload", "()V");
if (mid_BDI555_stopFastDownload == 0) {
fprintf_flush(stderr, "Can't find BDI555.stopFastDownload\n");
return FALSE;
}
mid_BDI555_writeMem = env->GetStaticMethodID(cls_BDI555, "writeMem", "(III)V");
if (mid_BDI555_writeMem == 0) {
fprintf_flush(stderr, "Can't find BDI555.writeMem\n");
return FALSE;
}
mid_BDI555_readMem = env->GetStaticMethodID(cls_BDI555, "readMem", "(II)I");
if (mid_BDI555_readMem == 0) {
fprintf_flush(stderr, "Can't find BDI555.readMem\n");
return FALSE;
}
mid_BDI555_writeMemSeq = env->GetStaticMethodID(cls_BDI555, "writeMemSeq", "(II)V");
if (mid_BDI555_writeMemSeq == 0) {
fprintf_flush(stderr, "Can't find BDI555.writeMemSeq\n");
return FALSE;
}
mid_BDI555_readMemSeq = env->GetStaticMethodID(cls_BDI555, "readMemSeq", "(I)I");
if (mid_BDI555_readMemSeq == 0) {
fprintf_flush(stderr, "Can't find BDI555.readMemSeq\n");
return FALSE;
}
mid_BDI555_readGPR = env->GetStaticMethodID(cls_BDI555, "readGPR", "(I)I");
if (mid_BDI555_readGPR == 0) {
fprintf_flush(stderr, "Can't find BDI555.readGPR\n");
return FALSE;
}
mid_BDI555_writeGPR = env->GetStaticMethodID(cls_BDI555, "writeGPR", "(II)V");
if (mid_BDI555_writeGPR == 0) {
fprintf_flush(stderr, "Can't find BDI555.writeGPR\n");
return FALSE;
}
mid_BDI555_readSPR = env->GetStaticMethodID(cls_BDI555, "readSPR", "(I)I");
if (mid_BDI555_readSPR == 0) {
fprintf_flush(stderr, "Can't find BDI555.readSPR\n");
return FALSE;
}
mid_BDI555_writeSPR = env->GetStaticMethodID(cls_BDI555, "writeSPR", "(II)V");
if (mid_BDI555_writeSPR == 0) {
fprintf_flush(stderr, "Can't find BDI555.writeSPR\n");
return FALSE;
}
mid_BDI555_readMSR = env->GetStaticMethodID(cls_BDI555, "readMSR", "()I");
if (mid_BDI555_readMSR == 0) {
fprintf_flush(stderr, "Can't find BDI555.readMSR\n");
return FALSE;
}
mid_BDI555_writeMSR = env->GetStaticMethodID(cls_BDI555, "writeMSR", "(I)V");
if (mid_BDI555_writeMSR == 0) {
fprintf_flush(stderr, "Can't find BDI555.writeMSR\n");
return FALSE;
}
mid_BDI555_readFPR = env->GetStaticMethodID(cls_BDI555, "readFPR", "(II)J");
if (mid_BDI555_readFPR == 0) {
fprintf_flush(stderr, "Can't find BDI555.readFPR\n");
return FALSE;
}
mid_BDI555_writeFPR = env->GetStaticMethodID(cls_BDI555, "writeFPR", "(IIJ)V");
if (mid_BDI555_writeFPR == 0) {
fprintf_flush(stderr, "Can't find BDI555.writeFPR\n");
return FALSE;
}
mid_BDI555_readCR = env->GetStaticMethodID(cls_BDI555, "readCR", "()I");
if (mid_BDI555_readCR == 0) {
fprintf_flush(stderr, "Can't find BDI555.readCR\n");
return FALSE;
}
mid_BDI555_writeCR = env->GetStaticMethodID(cls_BDI555, "writeCR", "(I)V");
if (mid_BDI555_writeCR == 0) {
fprintf_flush(stderr, "Can't find BDI555.writeCR\n");
return FALSE;
}
mid_BDI555_readFPSCR = env->GetStaticMethodID(cls_BDI555, "readFPSCR", "()I");
if (mid_BDI555_readFPSCR == 0) {
fprintf_flush(stderr, "Can't find BDI555.readFPSCR\n");
return FALSE;
}
mid_BDI555_writeFPSCR = env->GetStaticMethodID(cls_BDI555, "writeFPSCR", "(I)V");
if (mid_BDI555_writeFPSCR == 0) {
fprintf_flush(stderr, "Can't find BDI555.writeFPSCR\n");
return FALSE;
}
mid_BDI555_isTargetInDebugMode = env->GetStaticMethodID(cls_BDI555, "isTargetInDebugMode", "()Z");
if (mid_BDI555_isTargetInDebugMode == 0) {
fprintf_flush(stderr, "Can't find BDI555.isTargetInDebugMode\n");
return FALSE;
}
mid_BDI555_setGpr31 = env->GetStaticMethodID(cls_BDI555, "setGpr31", "(I)V");
if (mid_BDI555_setGpr31 == 0) {
fprintf_flush(stderr, "Can't find BDI555.setGpr31\n");
return FALSE;
}
// BDI332
mid_BDI332_nopsToLegalCmd = env->GetStaticMethodID(cls_BDI332, "nopsToLegalCmd", "()V");
if (mid_BDI332_nopsToLegalCmd == 0) {
fprintf_flush(stderr, "Can't find BDI332.nopsToLegalCmd\n");
return FALSE;
}
mid_BDI332_break_ = env->GetStaticMethodID(cls_BDI332, "break_", "()V");
if (mid_BDI332_break_ == 0) {
fprintf_flush(stderr, "Can't find BDI332.break_\n");
return FALSE;
}
mid_BDI332_go = env->GetStaticMethodID(cls_BDI332, "go", "()V");
if (mid_BDI332_go == 0) {
fprintf_flush(stderr, "Can't find BDI332.go\n");
return FALSE;
}
mid_BDI332_reset_target = env->GetStaticMethodID(cls_BDI332, "reset_target", "()V");
if (mid_BDI332_reset_target == 0) {
fprintf_flush(stderr, "Can't find BDI332.reset_target\n");
return FALSE;
}
mid_BDI332_reset_peripherals = env->GetStaticMethodID(cls_BDI332, "reset_peripherals", "()V");
if (mid_BDI332_reset_peripherals == 0) {
fprintf_flush(stderr, "Can't find BDI332.reset_peripherals\n");
return FALSE;
}
mid_BDI332_isFreezeAsserted = env->GetStaticMethodID(cls_BDI332, "isFreezeAsserted", "()Z");
if (mid_BDI332_isFreezeAsserted == 0) {
fprintf_flush(stderr, "Can't find BDI332.isFreezeAsserted\n");
return FALSE;
}
mid_BDI332_fillMem = env->GetStaticMethodID(cls_BDI332, "fillMem", "([II)V");
if (mid_BDI332_fillMem == 0) {
fprintf_flush(stderr, "Can't find BDI332.fillMem\n");
return FALSE;
}
mid_BDI332_dumpMem = env->GetStaticMethodID(cls_BDI332, "dumpMem", "(I)[I");
if (mid_BDI332_dumpMem == 0) {
fprintf_flush(stderr, "Can't find BDI332.dumpMem\n");
return FALSE;
}
mid_BDI332_writeMem = env->GetStaticMethodID(cls_BDI332, "writeMem", "(III)V");
if (mid_BDI332_writeMem == 0) {
fprintf_flush(stderr, "Can't find BDI332.writeMem\n");
return FALSE;
}
mid_BDI332_readMem = env->GetStaticMethodID(cls_BDI332, "readMem", "(II)I");
if (mid_BDI332_readMem == 0) {
fprintf_flush(stderr, "Can't find BDI332.readMem\n");
return FALSE;
}
mid_BDI332_readUserReg = env->GetStaticMethodID(cls_BDI332, "readUserReg", "(I)I");
if (mid_BDI332_readUserReg == 0) {
fprintf_flush(stderr, "Can't find BDI332.readUserReg\n");
return FALSE;
}
mid_BDI332_writeUserReg = env->GetStaticMethodID(cls_BDI332, "writeUserReg", "(II)V");
if (mid_BDI332_writeUserReg == 0) {
fprintf_flush(stderr, "Can't find BDI332.writeUserReg\n");
return FALSE;
}
mid_BDI332_readUserReg = env->GetStaticMethodID(cls_BDI332, "readUserReg", "(I)I");
if (mid_BDI332_readUserReg == 0) {
fprintf_flush(stderr, "Can't find BDI332.readUserReg\n");
return FALSE;
}
mid_BDI332_writeSysReg = env->GetStaticMethodID(cls_BDI332, "writeSysReg", "(II)V");
if (mid_BDI332_writeSysReg == 0) {
fprintf_flush(stderr, "Can't find BDI332.writeSysReg\n");
return FALSE;
}
mid_BDI332_readSysReg = env->GetStaticMethodID(cls_BDI332, "readSysReg", "(I)I");
if (mid_BDI332_readSysReg == 0) {
fprintf_flush(stderr, "Can't find BDI332.readSysReg\n");
return FALSE;
}
mid_BDI332_isTargetInDebugMode = env->GetStaticMethodID(cls_BDI332, "isTargetInDebugMode", "()Z");
if (mid_BDI332_isTargetInDebugMode == 0) {
fprintf_flush(stderr, "Can't find BDI332.isTargetInDebugMode\n");
return FALSE;
}
// Uart0 Class
mid_Uart0_write = env->GetStaticMethodID(cls_Uart0, "write", "([BI)Z");
if (mid_Uart0_write == 0) {
fprintf_flush(stderr, "Can't find Uart0.write\n");
return FALSE;
}
mid_Uart0_read = env->GetStaticMethodID(cls_Uart0, "read", "()[B");
if (mid_Uart0_read == 0) {
fprintf_flush(stderr, "Can't find Uart0.read\n");
return FALSE;
}
jvm_mIDs_done = TRUE;
} else {
fprintf_flush(stdout, "Method IDs already created -> everything successfully set up!\n");
}
return TRUE;
}
/* Exception Handling
* This function has to be called after every function (which may throw an exception)
* returns TRUE (0) if an exception occured, FALSE (#0) if not
*/
EXPORT int checkForExceptions() {
jthrowable exc;
exc = env->ExceptionOccurred();
if (exc) {
env->ExceptionDescribe();
env->ExceptionClear();
return TRUE;
}
return FALSE;
}
/* USB_Device methods
*
* For documentation see the java doc.
*/
EXPORT void USB_Device_open()
{
env->CallStaticVoidMethod(cls_USB_Device, mid_USB_Dev_open);
}
EXPORT void USB_Device_close()
{
env->CallStaticVoidMethod(cls_USB_Device, mid_USB_Dev_close);
}
EXPORT void USB_Device_reset()
{
env->CallStaticVoidMethod(cls_USB_Device, mid_USB_Dev_reset);
}
EXPORT int USB_Device_getMaxPacketSize()
{
return env->CallStaticIntMethod(cls_USB_Device, mid_USB_Dev_getMaxPacketSize);
}
/* BDI 555 methods
*
* For documentation see the java doc.
*/
EXPORT void BDI555_break_()
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_break_);
}
EXPORT void BDI555_go()
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_go);
}
EXPORT void BDI555_reset_target()
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_reset_target);
}
EXPORT BOOL BDI555_isFreezeAsserted()
{
jboolean isAsserted;
isAsserted = env->CallStaticBooleanMethod(cls_BDI555, mid_BDI555_isFreezeAsserted);
return (isAsserted != JNI_FALSE);
}
EXPORT void BDI555_startFastDownload(int startAddr)
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_startFastDownload, startAddr);
}
EXPORT void BDI555_fastDownload(int downloadData[], int dataLength)
{
jintArray jdata;
jdata = env->NewIntArray(dataLength);
if (jdata == NULL) {
jclass excCls;
excCls = env->FindClass("java/lang/OutOfMemoryError");
if (excCls == 0) {
return;
}
env->ThrowNew(excCls, "BDI555_fastDownload: not enough memory");
return;
}
// TODO: check type cast
env->SetIntArrayRegion(jdata, 0, dataLength, (jint*) downloadData);
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_fastDownload, jdata, dataLength);
env->DeleteLocalRef(jdata);
}
EXPORT void BDI555_stopFastDownload()
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_stopFastDownload);
}
EXPORT void BDI555_writeMem(int addr, int value, int size)
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_writeMem, addr, value, size);
}
EXPORT int BDI555_readMem(int addr, int size)
{
return env->CallStaticIntMethod(cls_BDI555, mid_BDI555_readMem, addr, size);
}
EXPORT void BDI555_writeMemSeq(int value, int size)
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_writeMemSeq, value, size);
}
EXPORT int BDI555_readMemSeq(int size)
{
return env->CallStaticIntMethod(cls_BDI555, mid_BDI555_readMemSeq, size);
}
EXPORT int BDI555_readGPR(int gpr)
{
return env->CallStaticIntMethod(cls_BDI555, mid_BDI555_readGPR, gpr);
}
EXPORT void BDI555_writeGPR(int gpr, int value)
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_writeGPR, gpr, value);
}
EXPORT int BDI555_readSPR(int spr)
{
return env->CallStaticIntMethod(cls_BDI555, mid_BDI555_readSPR, spr);
}
EXPORT void BDI555_writeSPR(int spr, int value)
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_writeSPR, spr, value);
}
EXPORT int BDI555_readMSR()
{
return env->CallStaticIntMethod(cls_BDI555, mid_BDI555_readMSR);
}
EXPORT void BDI555_writeMSR(int value)
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_writeMSR, value);
}
EXPORT long BDI555_readFPR(int fpr, int tmpMemAddr)
{
return env->CallStaticLongMethod(cls_BDI555, mid_BDI555_readFPR, fpr, tmpMemAddr);
}
EXPORT void BDI555_writeFPR(int fpr, int tmpMemAddr, long value)
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_writeSPR, fpr, tmpMemAddr, value);
}
EXPORT int BDI555_readCR()
{
return env->CallStaticIntMethod(cls_BDI555, mid_BDI555_readCR);
}
EXPORT void BDI555_writeCR(int value)
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_writeCR, value);
}
EXPORT int BDI555_readFPSCR()
{
return env->CallStaticIntMethod(cls_BDI555, mid_BDI555_readFPSCR);
}
EXPORT void BDI555_writeFPSCR(int value)
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_writeFPSCR, value);
}
EXPORT BOOL BDI555_isTargetInDebugMode()
{
jboolean inDebugMode;
inDebugMode = env->CallStaticBooleanMethod(cls_BDI555, mid_BDI555_isTargetInDebugMode);
return (inDebugMode != JNI_FALSE);
}
EXPORT void BDI555_setGpr31(int gpr31)
{
env->CallStaticVoidMethod(cls_BDI555, mid_BDI555_setGpr31, gpr31);
}
/* BDI 332 methods
*
* For documentation see the java doc.
*/
EXPORT void BDI332_nopsToLegalCmd()
{
env->CallStaticVoidMethod(cls_BDI332, mid_BDI332_nopsToLegalCmd);
}
EXPORT void BDI332_break_()
{
env->CallStaticVoidMethod(cls_BDI332, mid_BDI332_break_);
}
EXPORT void BDI332_go()
{
env->CallStaticVoidMethod(cls_BDI332, mid_BDI332_go);
}
EXPORT void BDI332_reset_target()
{
env->CallStaticVoidMethod(cls_BDI332, mid_BDI332_reset_target);
}
EXPORT void BDI332_reset_peripherals()
{
env->CallStaticVoidMethod(cls_BDI332, mid_BDI332_reset_peripherals);
}
EXPORT BOOL BDI332_isFreezeAsserted()
{
jboolean isAsserted;
isAsserted = env->CallStaticBooleanMethod(cls_BDI332, mid_BDI332_isFreezeAsserted);
return (isAsserted != JNI_FALSE);
}
EXPORT void BDI332_fillMem(int downloadData[], int dataLength)
{
jintArray jdata;
jdata = env->NewIntArray(dataLength);
if (jdata == NULL) {
jclass excCls;
excCls = env->FindClass("java/lang/OutOfMemoryError");
if (excCls == 0) {
return;
}
env->ThrowNew(excCls, "BDI332_fillMem: not enough memory");
return;
}
// for (int i = 0; i < dataLength; ++i) {
// fprintf_flush(stdout, ("data %d: %x\n", i, downloadData[i]);
// }
env->SetIntArrayRegion(jdata, 0, dataLength, (jint*) downloadData);
env->CallStaticVoidMethod(cls_BDI332, mid_BDI332_fillMem, jdata, dataLength);
env->DeleteLocalRef(jdata);
}
EXPORT int BDI332_dumpMem(int nofData, int result[])
{
jintArray intArray;
jsize size;
jint *intArrayElements;
intArray = (jintArray) env->CallStaticObjectMethod(cls_BDI332, mid_BDI332_dumpMem, nofData);
if (intArray == NULL)
return 0;
size = env->GetArrayLength(intArray);
intArrayElements = env->GetIntArrayElements(intArray, 0);
for (int i = 0; i < size; i++) {
result[i] = intArrayElements[i];
}
env->ReleaseIntArrayElements(intArray, intArrayElements, 0);
return size;
}
EXPORT void BDI332_writeMem(int addr, int value, int size)
{
env->CallStaticVoidMethod(cls_BDI332, mid_BDI332_writeMem, addr, value, size);
}
EXPORT int BDI332_readMem(int addr, int size)
{
return env->CallStaticIntMethod(cls_BDI332, mid_BDI332_readMem, addr, size);
}
EXPORT int BDI332_readUserReg(int reg)
{
return env->CallStaticIntMethod(cls_BDI332, mid_BDI332_readUserReg, reg);
}
EXPORT void BDI332_writeUserReg(int reg, int value)
{
env->CallStaticVoidMethod(cls_BDI332, mid_BDI332_writeUserReg, reg, value);
}
EXPORT int BDI332_readSysReg(int reg)
{
return env->CallStaticIntMethod(cls_BDI332, mid_BDI332_readSysReg, reg);
}
EXPORT void BDI332_writeSysReg(int reg, int value)
{
env->CallStaticVoidMethod(cls_BDI332, mid_BDI332_writeSysReg, reg, value);
}
EXPORT BOOL BDI332_isTargetInDebugMode()
{
jboolean isAsserted;
isAsserted = env->CallStaticBooleanMethod(cls_BDI332, mid_BDI332_isTargetInDebugMode);
return (isAsserted != JNI_FALSE);
}
/*
* UART functions
*
* For documentation see the java doc.
*/
EXPORT int UART0_read(char result[])
{
jbyteArray byteArray;
jsize size;
jbyte *byteArrayElements;
byteArray = (jbyteArray) env->CallStaticObjectMethod(cls_Uart0, mid_Uart0_read);
if (byteArray == NULL)
return 0;
size = env->GetArrayLength(byteArray);
byteArrayElements = env->GetByteArrayElements(byteArray, 0);
for (int i = 0; i < size; i++) {
result[i] = byteArrayElements[i];
}
env->ReleaseByteArrayElements(byteArray, byteArrayElements, 0);
return size;
}
EXPORT int UART0_write(char data[], int dataLength)
{
jbyteArray jdata;
jboolean result;
jdata = env->NewByteArray(dataLength);
if (jdata == NULL) {
jclass excCls;
excCls = env->FindClass("java/lang/OutOfMemoryError");
if (excCls == 0) {
return FALSE;
}
env->ThrowNew(excCls, "UART0_write: not enough memory");
return FALSE;
}
env->SetByteArrayRegion(jdata, 0, dataLength, (jbyte*) data);
result = env->CallStaticBooleanMethod(cls_Uart0, mid_Uart0_write, jdata, dataLength);
env->DeleteLocalRef(jdata);
return result;
}

Binary file not shown.

View File

@@ -1,22 +0,0 @@
DLLSRC=BDI_dll.cpp
DLL=BDI.dll
DEF=BDI.def
JVMLIBA=libjvm.a
OBJ=$(SRC:.c=.o) # replaces the .c from SRC with .o
JAVA_HOME="C:/Program Files/Java/jdk1.5.0_04"
CC=gcc
RM=rm
dll: $(DLL)
$(CC) -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at, \
-I$(JAVAPATH)/include -I$(JAVAPATH)/include/win32 \
-shared $(DLLSRC) -o $(DLL) $(DEF) $(JVMLIBA)
dll_def: $(DLL)
$(CC) -Wall -D_JNI_IMPLEMENTATION_ -Wl,--output-def,$(DEF),--kill-at, \
-I$(JAVAPATH)/include -I$(JAVAPATH)/include/win32 \
-shared $(DLLSRC) -o $(DLL) $(JVMLIBA)
clean:
$(RM) $(DLL)

Binary file not shown.

View File

@@ -1,17 +0,0 @@
<EFBFBD><EFBFBD>CXdeCmdsDev.CompileThis
UsbBDIDll
UsbBDI
UsbBDI332
UsbBDI555
UsbTargLog
UsbUtils
<EFBFBD><EFBFBD>E
<EFBFBD><EFBFBD>CDevDebug.UnloadThis
UsbTargLog
UsbBDI555
UsbBDI332
UsbBDI
UsbBDIDll
UsbUtils
<09><>E

View File

@@ -1,469 +0,0 @@
MODULE UsbBDI;
IMPORT SYS := SYSTEM, BDI := UsbBDIDll, Log := StdLog, ComTools, WinApi, Services, TextModels, Ports,
Files, HostFiles;
CONST
ttDefaultPeriod = 500; (*500 ms*) ttPipeHandDisconnected = -1;
nul = 0X;
ascLf = 0AX; ascCr = 0DX;
CONST
FALSE_ = 0;
PATH_LENGTH* = 512;
CONST
JAVA_OUT_FILENAME = "JavaOut.txt";
JAVA_ERR_FILENAME = "JavaErr.txt";
INVALID_HANDLE_VALUE = -1;
STD_OUT_COLOR = Ports.green;
STD_ERR_COLOR = Ports.grey50;
JAVA_OUT_COLOR = Ports.blue;
JAVA_ERR_COLOR = Ports.red;
CONST
MAX_UART_DATA_LENGTH* = BDI.MAX_UART_DATA_LENGTH;
CONST
PATH_SEPARATOR = "\";
ARG_SEPARATOR = ";";
JAR_FILE_USB = "usb.jar";
JAR_FILE_BDI = "usbpdi.jar";
JAR_LOCATION = "Usb" + PATH_SEPARATOR + "Rsrc";
TYPE
StdReaderWriter = POINTER TO ABSTRACT RECORD (Services.Action)
stdIoText: TextModels.Model; stdIoTextPos: INTEGER;
time, endTime: LONGINT; period: INTEGER;
hStdOut, hStdErr: WinApi.HANDLE;
connected, running: BOOLEAN; prevChar: SHORTCHAR
END;
JvmReaderWriter = POINTER TO EXTENSIBLE RECORD (StdReaderWriter)
errText: TextModels.Model; stdIoWriter, stdErrWriter: TextModels.Writer;
hJavaOut, hJavaErr: WinApi.HANDLE;
END;
VAR
bool: BDI.BOOL;
Done-, deviceOpen, jvmCreated: BOOLEAN; (** previous operation successfully completed *)
readerWriter: JvmReaderWriter;
(* ----------- Standard-IO / Java ReaderWriter --------------- *)
PROCEDURE (task: StdReaderWriter) Clear, NEW, EXTENSIBLE;
BEGIN
task.stdIoText := NIL; task.stdIoTextPos := 0;
task.hStdOut := ttPipeHandDisconnected; task.hStdErr := ttPipeHandDisconnected;
task.time := 0; task.endTime := 0; task.period := 0;
task.connected := FALSE; task.running := FALSE;
task.prevChar := nul;
END Clear;
PROCEDURE (task: StdReaderWriter) Stop, NEW, EXTENSIBLE;
VAR done: WinApi.BOOL;
BEGIN
Services.RemoveAction(task); task.running := FALSE;
IF task.connected THEN
done := WinApi.CloseHandle(task.hStdOut);
done := WinApi.CloseHandle(task.hStdErr);
END;
task.Clear
END Stop;
PROCEDURE (task: StdReaderWriter) SetTime (startFromNow, period, timeOut: INTEGER), NEW;
BEGIN
task.time := Services.Ticks() + startFromNow;
IF timeOut <= 0 THEN timeOut := MAX(INTEGER) END;
task.endTime := task.time + LONG(timeOut) * Services.resolution DIV 1000;
task.period := period
END SetTime;
PROCEDURE (task: StdReaderWriter) ConnectStdOutPipe (hStdOut: WinApi.HANDLE), NEW;
VAR done: WinApi.BOOL;
BEGIN
IF task.connected & (task.hStdOut # hStdOut) THEN done := WinApi.CloseHandle(task.hStdOut) END;
task.hStdOut := hStdOut; task.connected := TRUE
END ConnectStdOutPipe;
PROCEDURE (task: StdReaderWriter) ConnectStdErrPipe (hStdErr: WinApi.HANDLE), NEW;
VAR done: WinApi.BOOL;
BEGIN
IF task.connected & (task.hStdErr # hStdErr) THEN done := WinApi.CloseHandle(task.hStdErr) END;
task.hStdErr := hStdErr; task.connected := TRUE
END ConnectStdErrPipe;
PROCEDURE (task: StdReaderWriter) Start, NEW, ABSTRACT;
PROCEDURE NewJvmReaderWriter ( ): JvmReaderWriter;
VAR rec: JvmReaderWriter;
BEGIN
NEW(rec); rec.Clear; RETURN rec
END NewJvmReaderWriter;
PROCEDURE (rec: JvmReaderWriter) Clear, EXTENSIBLE;
VAR done: WinApi.BOOL;
BEGIN
rec.Clear^;
rec.errText := NIL; rec.stdIoWriter := NIL; rec.stdErrWriter := NIL;
rec.hJavaOut := ttPipeHandDisconnected; rec.hJavaErr := ttPipeHandDisconnected;
END Clear;
PROCEDURE (rec: JvmReaderWriter) Stop, EXTENSIBLE;
VAR done: WinApi.BOOL;
BEGIN
IF rec.connected THEN
rec.Stop^; done := WinApi.CloseHandle(rec.hJavaErr); done := WinApi.CloseHandle(rec.hJavaOut)
END;
rec.Clear
END Stop;
PROCEDURE (rec: JvmReaderWriter) ConnectJavaOutPipe (hJavaOut: WinApi.HANDLE), NEW;
VAR done: WinApi.BOOL;
BEGIN
IF rec.connected & (rec.hJavaOut # hJavaOut) THEN done := WinApi.CloseHandle(rec.hJavaOut) END;
rec.hJavaOut := hJavaOut; rec.connected := TRUE
END ConnectJavaOutPipe;
PROCEDURE (rec: JvmReaderWriter) ConnectJavaErrPipe (hJavaErr: WinApi.HANDLE), NEW;
VAR done: WinApi.BOOL;
BEGIN
IF rec.connected & (rec.hJavaErr # hJavaErr) THEN done := WinApi.CloseHandle(rec.hJavaErr) END;
rec.hJavaErr := hJavaErr; rec.connected := TRUE
END ConnectJavaErrPipe;
PROCEDURE (rec: JvmReaderWriter) Start;
VAR handle, stdOutHandle, stdErrHandle: WinApi.HANDLE;
BEGIN
IF rec.running THEN rec.Stop END;
IF rec.stdIoText = NIL THEN rec.stdIoText := TextModels.dir.New(); END;
IF rec.stdIoWriter = NIL THEN rec.stdIoWriter := rec.stdIoText.NewWriter(NIL) END;
rec.stdIoWriter.SetPos(rec.stdIoTextPos);
IF rec.errText = NIL THEN rec.errText := TextModels.dir.New(); END;
IF rec.stdErrWriter = NIL THEN rec.stdErrWriter := rec.errText.NewWriter(NIL) END;
rec.stdErrWriter.SetPos(rec.errText.Length());
(* Connect Std pipes *)
rec.ConnectStdOutPipe(BDI.getOutPipeHandle());
rec.ConnectStdErrPipe(BDI.getErrPipeHandle());
(* Connect Java pipes *)
handle := WinApi.CreateFile(JAVA_OUT_FILENAME, WinApi.GENERIC_READ + WinApi.GENERIC_WRITE,
WinApi.FILE_SHARE_WRITE, NIL, WinApi.OPEN_EXISTING, {}, 0);
IF (handle = INVALID_HANDLE_VALUE) THEN
Log.String("Error opening JAVA_OUT_FILENAME"); Log.Ln;
ELSE
rec.ConnectJavaOutPipe(handle)
END;
handle := WinApi.CreateFile(JAVA_ERR_FILENAME, WinApi.GENERIC_READ + WinApi.GENERIC_WRITE,
WinApi.FILE_SHARE_WRITE, NIL, WinApi.OPEN_EXISTING, {}, 0);
IF (handle = INVALID_HANDLE_VALUE) THEN
Log.String("Error opening JAVA_ERR_FILENAME"); Log.Ln;
ELSE
rec.ConnectJavaErrPipe(handle)
END;
rec.running := TRUE; Services.DoLater(rec, rec.time)
END Start;
PROCEDURE (rec: JvmReaderWriter) Do;
VAR
outModel: TextModels.Model;
n, ioDone, errDone, nofBytesRead, ioBytesAvail, errBytesAvail, exitCode: INTEGER;
ch: SHORTCHAR;
strSC: ARRAY 512 OF SHORTCHAR;
success: WinApi.BOOL;
BEGIN
IF rec.running THEN
(* STD OUT *)
IF rec.hStdOut > 0 THEN
nofBytesRead := 0; ioBytesAvail := 0;
ioDone := WinApi.PeekNamedPipe(
rec.hStdOut, (*//handle to pipe to copy from *)
SYS.ADR(strSC), (*//pointer to data buffer*)
LEN(strSC), (*//size, in bytes, of data buffer*)
nofBytesRead, (*nofBytesRead,*) (*//pointer to number of bytes read*)
ioBytesAvail, (*//pointer to total number of bytes available*)
NIL (*//pointer to unread bytes in this message*)
);
IF (ioDone # 0) & (ioBytesAvail > 0) THEN
ioDone := WinApi.ReadFile(rec.hStdOut, SYS.ADR(strSC), LEN(strSC), nofBytesRead, NIL);
IF (ioDone # 0) & (nofBytesRead > 0) THEN
FOR n := 0 TO nofBytesRead - 1 DO
ch := strSC[n];
IF (ch = ascLf) & (rec.prevChar # ascCr) THEN ch := TextModels.line END;
rec.stdIoWriter.WriteChar(ch);
rec.prevChar := ch;
END
END;
rec.stdIoText.SetAttr(0, rec.stdIoText.Length(),
TextModels.NewColor(TextModels.dir.attr, STD_OUT_COLOR));
Log.text.Append(rec.stdIoText)
END;
END;
(* STD ERR *)
IF rec.hStdErr > 0 THEN
nofBytesRead := 0; errBytesAvail := 0;
ioDone := WinApi.PeekNamedPipe(
rec.hStdErr, (*//handle to pipe to copy from *)
SYS.ADR(strSC), (*//pointer to data buffer*)
LEN(strSC), (*//size, in bytes, of data buffer*)
nofBytesRead, (*nofBytesRead,*) (*//pointer to number of bytes read*)
errBytesAvail, (*//pointer to total number of bytes available*)
NIL (*//pointer to unread bytes in this message*)
);
IF (ioDone # 0) & (errBytesAvail > 0) THEN
errDone := WinApi.ReadFile(rec.hStdErr, SYS.ADR(strSC), LEN(strSC), nofBytesRead, NIL);
IF (errDone # 0) & (nofBytesRead > 0) THEN
FOR n := 0 TO nofBytesRead - 1 DO
ch := strSC[n];
IF (ch = ascLf) & (rec.prevChar # ascCr) THEN ch := TextModels.line END;
rec.stdErrWriter.WriteChar(ch); rec.prevChar := ch
END
END;
rec.errText.SetAttr(0, rec.errText.Length(),
TextModels.NewColor(TextModels.dir.attr, STD_ERR_COLOR));
Log.text.Append(rec.errText)
END
END;
(* JAVA OUT *)
IF rec.hJavaOut > 0 THEN
ioDone := WinApi.ReadFile(rec.hJavaOut, SYS.ADR(strSC), LEN(strSC), nofBytesRead, NIL);
IF (ioDone # 0) & (nofBytesRead > 0) THEN
FOR n := 0 TO nofBytesRead - 1 DO
ch := strSC[n];
IF (ch = ascLf) & (rec.prevChar # ascCr) THEN ch := TextModels.line END;
rec.stdIoWriter.WriteChar(ch);
rec.prevChar := ch;
END
END;
rec.stdIoText.SetAttr(0, rec.stdIoText.Length(),
TextModels.NewColor(TextModels.dir.attr, JAVA_OUT_COLOR));
Log.text.Append(rec.stdIoText)
END;
(* JAVA ERR *)
IF rec.hJavaErr > 0 THEN
errDone := WinApi.ReadFile(rec.hJavaErr, SYS.ADR(strSC), LEN(strSC), nofBytesRead, NIL);
IF (errDone # 0) & (nofBytesRead > 0) THEN
FOR n := 0 TO nofBytesRead - 1 DO
ch := strSC[n];
IF (ch = ascLf) & (rec.prevChar # ascCr) THEN ch := TextModels.line END;
rec.stdErrWriter.WriteChar(ch); rec.prevChar := ch
END
END;
rec.errText.SetAttr(0, rec.errText.Length(),
TextModels.NewColor(TextModels.dir.attr, JAVA_ERR_COLOR));
Log.text.Append(rec.errText)
END;
INC( rec.time, rec.period ); Services.DoLater(rec, rec.time )
END;
END Do;
(* ----------- JVM --------------- *)
PROCEDURE CreateJVM (classpath: ARRAY OF SHORTCHAR);
VAR string: WinApi.PtrSTR;
BEGIN
string := ComTools.NewSString(classpath);
bool := BDI.createJVM(string);
IF bool = FALSE_ THEN
Done := FALSE;
Log.String("creating JVM failed"); Log.Ln;
HALT(77);
ELSE
Done := TRUE;
Log.String("JVM successfully created"); Log.Ln;
jvmCreated := TRUE;
END;
(* We need to create the jvm before opening the ReaderWriter.
The javaout, javaerr can only be opened after creating the jvm! *)
IF readerWriter = NIL THEN
readerWriter := NewJvmReaderWriter();
readerWriter.Start();
END;
ComTools.FreeSString(string);
END CreateJVM;
PROCEDURE DestroyJVM ;
BEGIN
bool := BDI.destroyJVM();
IF bool = FALSE_ THEN
Done := FALSE;
Log.String("destroying JVM failed"); Log.Ln;
ELSE
Done := TRUE;
Log.String("JVM destroyed"); Log.Ln;
END;
jvmCreated := FALSE;
END DestroyJVM;
PROCEDURE CheckForExceptions * (): BOOLEAN;
BEGIN
RETURN (BDI.checkForExceptions() # FALSE_)
END CheckForExceptions;
(* ----------- USB --------------- *)
PROCEDURE USB_Device_open ;
BEGIN
BDI.USB_Device_open;
Done := ~CheckForExceptions();
IF Done THEN
deviceOpen := TRUE;
END
END USB_Device_open;
PROCEDURE USB_Device_close ;
BEGIN
BDI.USB_Device_close;
Done := ~CheckForExceptions();
deviceOpen := FALSE;
END USB_Device_close;
PROCEDURE USB_Device_reset * ;
BEGIN
BDI.USB_Device_reset;
Done := ~CheckForExceptions();
deviceOpen := FALSE;
END USB_Device_reset;
PROCEDURE USB_Device_getMaxPacketSize * (): INTEGER;
VAR val: INTEGER;
BEGIN
IF deviceOpen THEN
Done := TRUE;
RETURN BDI.USB_Device_getMaxPacketSize();
ELSE
Done := FALSE;
RETURN - 1
END
END USB_Device_getMaxPacketSize;
(* --------- UART0 ----------------- *)
PROCEDURE UART0_read * (VAR data: ARRAY OF SHORTCHAR; VAR length: INTEGER): BOOLEAN;
BEGIN
length := BDI.UART0_read(data);
RETURN length # FALSE_;
END UART0_read;
PROCEDURE UART0_write * (VAR data: ARRAY OF SHORTCHAR; length: INTEGER): BOOLEAN;
VAR
result: INTEGER;
BEGIN
RETURN BDI.UART0_write(SYS.ADR(data[0]), length) # FALSE_;
END UART0_write;
(* -------------- Helper Functions ------------------*)
PROCEDURE GetUserStartUpPath (VAR startupPath: ARRAY OF SHORTCHAR);
VAR
userStartUpLocator: Files.Locator; userStartUpHostLoc: HostFiles.Locator;
startupPathChar: ARRAY PATH_LENGTH OF CHAR;
i: INTEGER;
BEGIN
userStartUpLocator := Files.dir.This(""); userStartUpHostLoc := userStartUpLocator(HostFiles.Locator);
startupPathChar := userStartUpHostLoc.path$;
FOR i := 0 TO LEN(startupPathChar) - 1 DO
startupPath[i] := SYS.VAL(SHORTCHAR, startupPathChar[i]);
END
END GetUserStartUpPath;
PROCEDURE GetSystemStartUpPath (VAR startupPath: ARRAY OF SHORTCHAR);
VAR
cmdLinePtr: WinApi.PtrWSTR; args: WinApi.RetCommandLineToArgvW;
n, i, nofArgs: INTEGER;
sysStartUpLocator: Files.Locator; sysStartUpHostLoc: HostFiles.Locator;
BEGIN
cmdLinePtr := WinApi.GetCommandLineW();
args := WinApi.CommandLineToArgvW(cmdLinePtr, nofArgs);
n := LEN(args[0]$);
REPEAT DEC(n) UNTIL (args[0][n] = PATH_SEPARATOR) OR (n <= 0); args[0][n] := nul;
sysStartUpLocator := HostFiles.NewLocator(args[0]$); args[0][n] := PATH_SEPARATOR;
sysStartUpHostLoc := sysStartUpLocator(HostFiles.Locator);
FOR i := 0 TO LEN(sysStartUpHostLoc.path$) DO
startupPath[i] := SYS.VAL(SHORTCHAR, sysStartUpHostLoc.path[i]);
END;
END GetSystemStartUpPath;
PROCEDURE CheckIfFileExists (filePath: ARRAY OF CHAR; fileName: ARRAY OF CHAR): BOOLEAN;
VAR
i: INTEGER; done: BOOLEAN;
loc: Files.Locator; file: Files.File; name: Files.Name;
BEGIN
loc := Files.dir.This(filePath);
IF loc.res # 0 THEN (*RETURN FALSE*) END;
FOR i := 0 TO LEN(fileName$) DO
name[i] := fileName[i];
END;
file := Files.dir.Old(loc, name, Files.shared);
RETURN loc.res = 0
END CheckIfFileExists;
PROCEDURE ConnectDevice * ;
VAR
startupPath: ARRAY PATH_LENGTH OF SHORTCHAR;
BEGIN
IF ~deviceOpen THEN
IF ~jvmCreated THEN
(* Check for existence of jar-file (whether in user of system directory) *)
GetUserStartUpPath(startupPath);
IF ~CheckIfFileExists(startupPath + PATH_SEPARATOR + JAR_LOCATION, JAR_FILE_USB) OR
~CheckIfFileExists(startupPath + PATH_SEPARATOR + JAR_LOCATION, JAR_FILE_BDI) THEN
GetSystemStartUpPath(startupPath);
IF ~CheckIfFileExists(startupPath + PATH_SEPARATOR + JAR_LOCATION, JAR_FILE_USB) OR
~CheckIfFileExists(startupPath + PATH_SEPARATOR + JAR_LOCATION, JAR_FILE_BDI) THEN
Log.String(JAR_FILE_USB + " or " + JAR_FILE_BDI +
" not found in user or system path; expected in " + JAR_LOCATION); Log.Ln;
HALT(76);
END
END;
Log.String("Startup Path: " + startupPath); Log.Ln;
CreateJVM(startupPath + PATH_SEPARATOR + JAR_LOCATION + PATH_SEPARATOR + JAR_FILE_USB +
ARG_SEPARATOR + startupPath + PATH_SEPARATOR + JAR_LOCATION + PATH_SEPARATOR +
JAR_FILE_BDI);
(*
CreateJVM("D:\work\USB\eclipse\mcdp\jars\usb.jar;D:\work\USB\eclipse\mcdp\jars\usbpdi.jar");
*)
IF ~Done THEN HALT(78) END;
jvmCreated := TRUE;
END;
USB_Device_open;
IF ~Done THEN HALT(79) END;
deviceOpen := TRUE;
END
END ConnectDevice;
PROCEDURE DeviceOpen * (): BOOLEAN ;
BEGIN
RETURN deviceOpen
END DeviceOpen;
(* Close and reopen the device *)
PROCEDURE ReopenDevice * ;
BEGIN
ConnectDevice;
USB_Device_close;
USB_Device_open;
IF Done THEN
Log.String("Device opened successfully"); Log.Ln;
ELSE
Log.String("Error while opening Device"); Log.Ln;
END
END ReopenDevice;
BEGIN
deviceOpen := FALSE;
jvmCreated := FALSE;
CLOSE
IF readerWriter # NIL THEN
readerWriter.Stop;
END;
IF deviceOpen THEN
USB_Device_close;
END;
IF jvmCreated THEN
DestroyJVM
END
END UsbBDI.

View File

@@ -1,109 +0,0 @@
MODULE UsbBDI332;
IMPORT SYS := SYSTEM, BDI := UsbBDIDll, BDIMain := UsbBDI, WinApi;
CONST
FALSE_ = 0;
VAR
Done-: BOOLEAN;
(* --------- 332 ----------------- *)
PROCEDURE nopsToLegalCmd * ;
BEGIN
BDI.BDI332_nopsToLegalCmd;
Done := ~BDIMain.CheckForExceptions()
END nopsToLegalCmd;
PROCEDURE go * ;
BEGIN
BDI.BDI332_go;
Done := ~BDIMain.CheckForExceptions()
END go;
PROCEDURE break_ * ;
BEGIN
BDI.BDI332_break_;
Done := ~BDIMain.CheckForExceptions()
END break_;
PROCEDURE reset_target * ;
BEGIN
BDI.BDI332_reset_target;
Done := ~BDIMain.CheckForExceptions()
END reset_target;
PROCEDURE reset_peripherals * ;
BEGIN
BDI.BDI332_reset_peripherals;
Done := ~BDIMain.CheckForExceptions()
END reset_peripherals;
PROCEDURE isFreezeAsserted * (): BOOLEAN;
VAR result: WinApi.BOOL;
BEGIN
result := BDI.BDI332_isFreezeAsserted();
Done := ~BDIMain.CheckForExceptions();
RETURN result # FALSE_
END isFreezeAsserted;
PROCEDURE fillMem * (downloadData: ARRAY OF INTEGER; dataLength: INTEGER);
BEGIN
BDI.BDI332_fillMem(SYS.ADR(downloadData[0]), dataLength);
Done := ~BDIMain.CheckForExceptions()
END fillMem;
PROCEDURE dumpMem * (nofData: INTEGER; VAR result: ARRAY OF INTEGER; VAR length: INTEGER);
BEGIN
length := BDI.BDI332_dumpMem(nofData, result);
Done := ~BDIMain.CheckForExceptions()
END dumpMem;
PROCEDURE writeMem * (addr, value, size: INTEGER);
BEGIN
BDI.BDI332_writeMem(addr, value, size);
Done := ~BDIMain.CheckForExceptions()
END writeMem;
PROCEDURE readMem * (addr, size: INTEGER): INTEGER;
VAR result: INTEGER;
BEGIN
result := BDI.BDI332_readMem(addr, size);
Done := ~BDIMain.CheckForExceptions();
RETURN result
END readMem;
PROCEDURE readUserReg * (reg: INTEGER): INTEGER;
VAR result: INTEGER;
BEGIN
result := BDI.BDI332_readUserReg(reg);
Done := ~BDIMain.CheckForExceptions();
RETURN result
END readUserReg;
PROCEDURE writeUserReg * (reg, value: INTEGER);
BEGIN
BDI.BDI332_writeUserReg(reg, value);
Done := ~BDIMain.CheckForExceptions()
END writeUserReg;
PROCEDURE readSysReg * (reg: INTEGER): INTEGER;
VAR result: INTEGER;
BEGIN
result := BDI.BDI332_readSysReg(reg);
Done := ~BDIMain.CheckForExceptions();
RETURN result
END readSysReg;
PROCEDURE writeSysReg * (reg, value: INTEGER);
BEGIN
BDI.BDI332_writeSysReg(reg, value);
Done := ~BDIMain.CheckForExceptions()
END writeSysReg;
PROCEDURE isTargetInDebugMode * (): BOOLEAN;
BEGIN
RETURN BDI.BDI332_isTargetInDebugMode() # FALSE_;
END isTargetInDebugMode;
END UsbBDI332.

View File

@@ -1,189 +0,0 @@
MODULE UsbBDI555;
IMPORT SYS := SYSTEM, BDI := UsbBDIDll, BDIMain := UsbBDI, WinApi;
CONST
FALSE_ = 0;
CONST
MAX_NOF_LONGS_FILL* = BDI.MAX_NOF_LONGS_FILL;
VAR
Done-: BOOLEAN;
(* ----------- 555 --------------- *)
PROCEDURE go * ;
BEGIN
BDI.BDI555_go;
Done := ~BDIMain.CheckForExceptions()
END go;
PROCEDURE break_ * ;
BEGIN
BDI.BDI555_break_;
Done := ~BDIMain.CheckForExceptions()
END break_;
PROCEDURE reset_target * ;
BEGIN
BDI.BDI555_reset_target;
Done := ~BDIMain.CheckForExceptions()
END reset_target;
PROCEDURE isFreezeAsserted * (): BOOLEAN;
VAR result: WinApi.BOOL;
BEGIN
result := BDI.BDI555_isFreezeAsserted();
Done := ~BDIMain.CheckForExceptions();
RETURN result # FALSE_
END isFreezeAsserted;
PROCEDURE startFastDownload * (addr: INTEGER);
BEGIN
BDI.BDI555_startFastDownload(addr);
Done := ~BDIMain.CheckForExceptions()
END startFastDownload;
PROCEDURE fastDownload * (downloadData: ARRAY OF INTEGER; dataLength: INTEGER);
(*VAR i: INTEGER;*)
BEGIN
(*
Log.String("BDI555_fastDownload: length = "); Log.Int(dataLength); Log.Ln;
FOR i := 0 TO dataLength - 1 DO
Log.Int(downloadData[i]); Log.Tab;
END;
Log.Ln;
*)
BDI.BDI555_fastDownload(SYS.ADR(downloadData[0]), dataLength);
Done := ~BDIMain.CheckForExceptions()
END fastDownload;
PROCEDURE stopFastDownload * ;
BEGIN
BDI.BDI555_stopFastDownload;
Done := ~BDIMain.CheckForExceptions()
END stopFastDownload;
PROCEDURE writeMem * (addr, value, size: INTEGER);
BEGIN
BDI.BDI555_writeMem(addr, value, size);
Done := ~BDIMain.CheckForExceptions()
END writeMem;
PROCEDURE readMem * (addr, size: INTEGER): INTEGER;
VAR result: INTEGER;
BEGIN
result := BDI.BDI555_readMem(addr, size);
Done := ~BDIMain.CheckForExceptions();
RETURN result
END readMem;
PROCEDURE writeMemSeq * (value, size: INTEGER);
BEGIN
BDI.BDI555_writeMemSeq(value, size);
Done := ~BDIMain.CheckForExceptions()
END writeMemSeq;
PROCEDURE readMemSeq * (size: INTEGER): INTEGER;
VAR result: INTEGER;
BEGIN
result := BDI.BDI555_readMemSeq(size);
Done := ~BDIMain.CheckForExceptions();
RETURN result
END readMemSeq;
PROCEDURE readGPR * (gpr: INTEGER): INTEGER;
VAR result: INTEGER;
BEGIN
result := BDI.BDI555_readGPR(gpr);
Done := ~BDIMain.CheckForExceptions();
RETURN result
END readGPR;
PROCEDURE writeGPR * (gpr, value: INTEGER);
BEGIN
BDI.BDI555_writeGPR(gpr, value);
Done := ~BDIMain.CheckForExceptions()
END writeGPR;
PROCEDURE readSPR * (spr: INTEGER): INTEGER;
VAR result: INTEGER;
BEGIN
result := BDI.BDI555_readSPR(spr);
Done := ~BDIMain.CheckForExceptions();
RETURN result
END readSPR;
PROCEDURE writeSPR * (spr, value: INTEGER);
BEGIN
BDI.BDI555_writeSPR(spr, value);
Done := ~BDIMain.CheckForExceptions()
END writeSPR;
PROCEDURE readMSR * (): INTEGER;
VAR result: INTEGER;
BEGIN
result := BDI.BDI555_readMSR();
Done := ~BDIMain.CheckForExceptions();
RETURN result
END readMSR;
PROCEDURE writeMSR * (value: INTEGER);
BEGIN
BDI.BDI555_writeMSR(value);
Done := ~BDIMain.CheckForExceptions()
END writeMSR;
PROCEDURE readFPR * (fpr, tmpMemAddr: INTEGER): LONGINT;
VAR result: LONGINT;
BEGIN
result := BDI.BDI555_readFPR(fpr, tmpMemAddr);
Done := ~BDIMain.CheckForExceptions();
RETURN result
END readFPR;
PROCEDURE writeFPR * (fpr, tmpMemAddr: INTEGER; value: LONGINT);
BEGIN
BDI.BDI555_writeFPR(fpr, tmpMemAddr, value);
Done := ~BDIMain.CheckForExceptions()
END writeFPR;
PROCEDURE readCR * (): INTEGER;
VAR result: INTEGER;
BEGIN
result := BDI.BDI555_readCR();
Done := ~BDIMain.CheckForExceptions();
RETURN result
END readCR;
PROCEDURE writeCR * (value: INTEGER);
BEGIN
BDI.BDI555_writeCR(value);
Done := ~BDIMain.CheckForExceptions()
END writeCR;
PROCEDURE readFPSCR * (): INTEGER;
VAR result: INTEGER;
BEGIN
result := BDI.BDI555_readFPSCR();
Done := ~BDIMain.CheckForExceptions();
RETURN result
END readFPSCR;
PROCEDURE writeFPSCR * (value: INTEGER);
BEGIN
BDI.BDI555_writeFPSCR(value);
Done := ~BDIMain.CheckForExceptions()
END writeFPSCR;
PROCEDURE isTargetInDebugMode * (): BOOLEAN;
BEGIN
RETURN BDI.BDI555_isTargetInDebugMode() # FALSE_;
END isTargetInDebugMode;
PROCEDURE setGpr31 * (gpr31: INTEGER);
BEGIN
BDI.BDI555_setGpr31(gpr31);
END setGpr31;
END UsbBDI555.

View File

@@ -1,178 +0,0 @@
MODULE UsbBDIDll ["BDI.dll"];
IMPORT SYSTEM;
CONST
MAX_NOF_LONGS_FILL* = 84;
MAX_UART_DATA_LENGTH* = 256;
TYPE
PtrSTR* = POINTER TO ARRAY [untagged] OF SHORTCHAR;
BOOL* = INTEGER;
(* -------JVM--------- *)
PROCEDURE getErrPipeHandle* (): INTEGER;
(*END getErrPipeHandle; *)
PROCEDURE getOutPipeHandle* (): INTEGER;
(*END getOutPipeHandle; *)
PROCEDURE createJVM* (classpath: PtrSTR): BOOL;
(*END createJVM; *)
PROCEDURE destroyJVM* (): INTEGER;
(*END destroyJVM; *)
PROCEDURE checkForExceptions* (): BOOL;
(*END checkForExceptions; *)
(* -------USB--------- *)
PROCEDURE USB_Device_open*;
(*END USB_Device_open; *)
PROCEDURE USB_Device_close*;
(*END USB_Device_close; *)
PROCEDURE USB_Device_reset*;
(*END USB_Device_reset; *)
PROCEDURE USB_Device_getMaxPacketSize* (): INTEGER;
(*END USB_Device_reset; *)
(* -------555--------- *)
PROCEDURE BDI555_go*;
(*END BDI555_go; *)
PROCEDURE BDI555_break_*;
(*END BDI555_break_; *)
PROCEDURE BDI555_reset_target*;
(*END BDI555_reset_target; *)
PROCEDURE BDI555_isFreezeAsserted* (): BOOL;
(*END BDI555_isFreezeAsserted; *)
PROCEDURE BDI555_startFastDownload* (adr: INTEGER);
(*END BDI555_startFastDownload; *)
PROCEDURE BDI555_fastDownload* (downloadData: (* ARRAY OF *) INTEGER; dataLength: INTEGER);
(*END BDI555_fastDownload; *)
PROCEDURE BDI555_stopFastDownload*;
(*END BDI555_stopFastDownload; *)
PROCEDURE BDI555_writeMem* (addr, value, size: INTEGER);
(*END BDI555_writeMem; *)
PROCEDURE BDI555_readMem* (addr, size: INTEGER): INTEGER;
(*END BDI555_readMem; *)
PROCEDURE BDI555_writeMemSeq* (value, size: INTEGER);
(*END BDI555_writeMemSeq; *)
PROCEDURE BDI555_readMemSeq* (size: INTEGER): INTEGER;
(*END BDI555_readMemSeq; *)
PROCEDURE BDI555_readGPR* (gpr: INTEGER): INTEGER;
(*END BDI555_readGPR; *)
PROCEDURE BDI555_writeGPR* (gpr, value: INTEGER);
(*END BDI555_writeGPR; *)
PROCEDURE BDI555_readSPR* (spr: INTEGER): INTEGER;
(*END BDI555_readSPR; *)
PROCEDURE BDI555_writeSPR* (spr, value: INTEGER);
(*END BDI555_writeSPR; *)
PROCEDURE BDI555_readMSR* (): INTEGER;
(*END BDI555_readMSR; *)
PROCEDURE BDI555_writeMSR* (value: INTEGER);
(*END BDI555_writeMSR; *)
PROCEDURE BDI555_readFPR* (fpr, tmpMemAddr: INTEGER): LONGINT;
(*END BDI555_readFPR; *)
PROCEDURE BDI555_writeFPR* (fpr, tmpMemAddr: INTEGER; value: LONGINT);
(*END BDI555_writeFPR; *)
PROCEDURE BDI555_readCR* (): INTEGER;
(*END BDI555_readCR; *)
PROCEDURE BDI555_writeCR* (value: INTEGER);
(*END BDI555_writeCR; *)
PROCEDURE BDI555_readFPSCR* (): INTEGER;
(*END BDI555_readFPSCR; *)
PROCEDURE BDI555_writeFPSCR* (value: INTEGER);
(*END BDI555_writeFPSCR; *)
PROCEDURE BDI555_isTargetInDebugMode* (): BOOL;
(*END BDI555_isTargetInDebugMode; *)
PROCEDURE BDI555_setGpr31* (gpr31: INTEGER);
(*END BDI555_setGpr31; *)
(* -------332--------- *)
PROCEDURE BDI332_nopsToLegalCmd*;
(*END BDI332_nopsToLegalCmd; *)
PROCEDURE BDI332_go*;
(*END BDI332_go; *)
PROCEDURE BDI332_break_*;
(*END BDI332_break_; *)
PROCEDURE BDI332_reset_target*;
(*END BDI332_reset_target; *)
PROCEDURE BDI332_reset_peripherals*;
(*END BDI332_reset_peripherals; *)
PROCEDURE BDI332_isFreezeAsserted* (): BOOL;
(*END BDI332_isFreezeAsserted; *)
PROCEDURE BDI332_fillMem* (downloadData: (* ARRAY OF *) INTEGER; dataLength: INTEGER);
(*END BDI332_fillMem; *)
PROCEDURE BDI332_dumpMem* (nofData: INTEGER; VAR result: ARRAY OF INTEGER): INTEGER;
(*
PROCEDURE BDI332_dumpMem* (nofData: INTEGER; VAR result: ARRAY [untagged] MAX_NOF_LONGS_FILL OF INTEGER): INTEGER;
*)
(*END BDI332_dumpMem; *)
PROCEDURE BDI332_writeMem* (addr, value, size: INTEGER);
(*END BDI332_writeMem; *)
PROCEDURE BDI332_readMem* (addr, size: INTEGER): INTEGER;
(*END BDI332_readMem; *)
PROCEDURE BDI332_readUserReg* (reg: INTEGER): INTEGER;
(*END BDI332_readUserReg; *)
PROCEDURE BDI332_writeUserReg* (reg, value: INTEGER);
(*END BDI332_writeUserReg; *)
PROCEDURE BDI332_readSysReg* (reg: INTEGER): INTEGER;
(*END BDI332_readSysReg; *)
PROCEDURE BDI332_writeSysReg* (reg, value: INTEGER);
(*END BDI332_writeSysReg; *)
PROCEDURE BDI332_isTargetInDebugMode* (): BOOL;
(*END BDI332_isTargetInDebugMode; *)
(* ------ UART0 ------ *)
PROCEDURE UART0_read* (VAR data: ARRAY [untagged] OF SHORTCHAR): INTEGER;
(*END UART0_read; *)
PROCEDURE UART0_write* (data: (* ARRAY OF SHORTCHAR *) INTEGER; length: INTEGER): BOOL;
(*END UART0_write; *)
END UsbBDIDll.

View File

@@ -1,111 +0,0 @@
MODULE UsbTargLog;
(** <20> NTB/AS 12.01.2006 *)
(**
Changes:
*)
IMPORT
USB := UsbBDI, Log := StdLog, Services, TextModels, XUT := XdeUtilities;
CONST
logTitle = "USB Target Log";
PERIOD = 500;
TYPE
Receiver = POINTER TO RECORD (Services.Action)
time: LONGINT; period: INTEGER
END;
VAR
receiver: Receiver;
logTextModel: TextModels.Model; logWriter: TextModels.Writer;
PROCEDURE (receiver: Receiver) Do;
VAR
length, i: INTEGER; done: BOOLEAN;
data: ARRAY USB.MAX_UART_DATA_LENGTH OF SHORTCHAR;
BEGIN
done := USB.UART0_read(data, length);
IF done THEN
length := MIN(length, USB.MAX_UART_DATA_LENGTH );
FOR i := 0 TO length - 1 DO
logWriter.WriteChar(data[i])
END
END;
INC( receiver.time, receiver.period ); Services.DoLater(receiver, receiver.time )
END Do;
PROCEDURE Stop * ;
BEGIN
IF receiver # NIL THEN Services.RemoveAction(receiver ); receiver := NIL END;
logWriter := NIL; logTextModel := NIL
END Stop;
PROCEDURE StartReceiver;
BEGIN
IF receiver # NIL THEN Services.RemoveAction(receiver ); receiver := NIL END;
NEW(receiver);
receiver.time := Services.Ticks(); receiver.period := PERIOD;
Services.DoLater(receiver, receiver.time)
END StartReceiver;
PROCEDURE Start * ;
VAR beg, end: INTEGER;
BEGIN
IF ~USB.DeviceOpen() THEN
USB.ConnectDevice;
END;
Stop;
Log.String("opening USB target log"); Log.Ln;
XUT.GetTextModel("", logTextModel, beg, end); logWriter := logTextModel.NewWriter(NIL);
XUT.ShowTextView(logTextModel, logTitle);
StartReceiver;
END Start;
PROCEDURE SendSelToTarget * ;
(** send all visible char of the current selection to the target
*)
VAR
reader: TextModels.Reader; textModel: TextModels.Model; beg, end, currentLen: INTEGER; ch: CHAR;
data: ARRAY USB.MAX_UART_DATA_LENGTH OF SHORTCHAR; done, error: BOOLEAN;
BEGIN
XUT.GetTextModel("@", textModel, beg, end);
IF textModel # NIL THEN
reader := textModel.NewReader(NIL); reader.SetPos(beg);
currentLen := 0; error := FALSE;
WHILE reader.Pos() < end DO
reader.ReadChar(ch);
data[currentLen] := SHORT(ch);
INC(currentLen);
IF currentLen >= USB.MAX_UART_DATA_LENGTH THEN
done := USB.UART0_write(data, currentLen);
IF ~done THEN
error := TRUE;
Log.String("Sending data failed"); Log.Ln;
END;
currentLen := 0;
END
END;
IF currentLen > 0 THEN
done := USB.UART0_write(data, currentLen);
IF ~done THEN
error := TRUE;
Log.String("Sending data failed"); Log.Ln;
END
END;
IF ~error THEN
Log.String("Data sent successfully"); Log.Ln;
END
END
END SendSelToTarget;
PROCEDURE ClearText * ;
BEGIN
IF logTextModel # NIL THEN
logTextModel.Delete(0, logTextModel.Length()); logWriter.SetPos(0)
END
END ClearText;
CLOSE
Stop
END UsbTargLog .

View File

@@ -1,130 +0,0 @@
MODULE UsbUtils;
IMPORT SYSTEM, WinApi, Strings, ComTools, Log := StdLog;
CONST
HK_LM_JRE_Key = "SOFTWARE\javaSoft\Java Runtime Environment";
HK_LM_JRE_CurrentVersion_value = "CurrentVersion";
HK_LM_JRE_JavaHome_value = "JavaHome";
HK_LM_PATH_Key = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment";
HK_CU_PATH_Key = "Environment";
PATH_value = "PATH";
PROCEDURE RegLMQuery* (IN subKey, valueName: ARRAY OF SHORTCHAR;
OUT qValue: ARRAY OF SHORTCHAR): BOOLEAN;
VAR
res, length: INTEGER; hKey: WinApi.HKEY;
BEGIN
qValue := "";
res := WinApi.RegOpenKeyEx(WinApi.HKEY_LOCAL_MACHINE,
subKey, 0, WinApi.KEY_QUERY_VALUE, hKey);
IF res # WinApi.ERROR_SUCCESS THEN
RETURN FALSE
ELSE
length := LEN(qValue);
res := WinApi.RegQueryValueEx(hKey, valueName, NIL, NIL, qValue[0], length);
IF res # WinApi.ERROR_SUCCESS THEN
RETURN FALSE
END
END;
res := WinApi.RegCloseKey(hKey);
RETURN TRUE;
END RegLMQuery;
PROCEDURE RegCUQuery* (IN subKey, valueName: ARRAY OF SHORTCHAR;
OUT qValue: ARRAY OF SHORTCHAR): BOOLEAN;
VAR
res, length: INTEGER; hKey: WinApi.HKEY;
BEGIN
qValue := "";
res := WinApi.RegOpenKeyEx(WinApi.HKEY_CURRENT_USER,
subKey, 0, WinApi.KEY_QUERY_VALUE, hKey);
IF res # WinApi.ERROR_SUCCESS THEN
RETURN FALSE
ELSE
length := LEN(qValue);
res := WinApi.RegQueryValueEx(hKey, valueName, NIL, NIL, qValue[0], length);
IF res # WinApi.ERROR_SUCCESS THEN
RETURN FALSE
END
END;
res := WinApi.RegCloseKey(hKey);
RETURN TRUE;
END RegCUQuery;
PROCEDURE RegCUCreateKeyAndSetValue* (IN subKey, valueName: ARRAY OF SHORTCHAR;
newValue: ARRAY OF SHORTCHAR): BOOLEAN;
VAR
res, length, lpdwDisposition: INTEGER; hKey: WinApi.HKEY;
BEGIN
res := WinApi.RegCreateKeyEx(WinApi.HKEY_CURRENT_USER, subKey, 0, NIL,
WinApi.REG_OPTION_NON_VOLATILE, WinApi.KEY_ALL_ACCESS, NIL, hKey, lpdwDisposition);
IF res # WinApi.ERROR_SUCCESS THEN
RETURN FALSE
END;
res := WinApi.RegSetValueEx(hKey, valueName, 0, WinApi.REG_SZ,
newValue[0], LEN(newValue$));
IF res # WinApi.ERROR_SUCCESS THEN
RETURN FALSE
END;
res := WinApi.RegCloseKey(hKey);
RETURN TRUE
END RegCUCreateKeyAndSetValue;
PROCEDURE CheckAndSetPath*;
CONST
PATH_Pattern = "\bin\client";
SMTO_ABORTIFHUNG = {1} (* 2 in C *);
HWND_BROADCAST = 0FFFFH;
VAR
jreHome, regValue, tmpRegValue: ARRAY 2048 OF SHORTCHAR;
pos, result: INTEGER; noUserPathValue, success, found: BOOLEAN;
environment: WinApi.PtrSTR;
BEGIN
(* get jre home path *)
IF ~RegLMQuery(HK_LM_JRE_Key, HK_LM_JRE_CurrentVersion_value, tmpRegValue) (* e.g. "1.5" *) THEN
Log.String("UsbUtils: Error getting " + HK_LM_JRE_Key + "! Is Java installed?"); Log.Ln; RETURN
END;
IF ~RegLMQuery(HK_LM_JRE_Key + "\" + tmpRegValue, HK_LM_JRE_JavaHome_value, jreHome) THEN
Log.String("UsbUtils: Error getting " + HK_LM_JRE_Key + "\" + tmpRegValue + "! Is Java installed?"); Log.Ln; RETURN
END;
(* look for %javahome%\bin\client on system and user path*)
regValue := jreHome + PATH_Pattern;
found := RegLMQuery(HK_LM_PATH_Key, "Path", tmpRegValue);
Strings.Find(LONG(tmpRegValue), LONG(regValue), 0, pos);
found := pos >= 0;
IF found THEN
Log.String("the PATH system variable " + regValue + " is already set"); Log.Ln;
RETURN
END;
tmpRegValue := "";
noUserPathValue := ~RegCUQuery(HK_CU_PATH_Key, PATH_value, tmpRegValue);
Strings.Find(LONG(tmpRegValue), PATH_Pattern, 0, pos);
found := pos >= 0;
IF ~found THEN (* insert registry key into user PATH variable *)
IF tmpRegValue = "" THEN
tmpRegValue := regValue;
ELSE
tmpRegValue := tmpRegValue + ";" + regValue
END;
IF RegCUCreateKeyAndSetValue(HK_CU_PATH_Key, PATH_value, tmpRegValue) THEN
IF noUserPathValue THEN (* create user PATH value first *)
Log.String("user value PATH created"); Log.Ln;
END;
Log.String(regValue + " added to user PATH"); Log.Ln;
ELSE
Log.String("UsbUtils: Error on CreateKey with value " + tmpRegValue); Log.Ln;
END;
(* Notify windows about Environment Change (if this is not done, the changes will only take effect after reboot) *)
Log.String("Updating Environment - this may take some seconds..."); Log.Ln;
environment := ComTools.NewSString("Environment");
result := WinApi.SendMessageTimeout(HWND_BROADCAST, WinApi.WM_SETTINGCHANGE, 0,
SYSTEM.VAL(INTEGER, environment), SMTO_ABORTIFHUNG, 2000, result);
Log.String("Please restart Blackbox"); Log.Ln;
ELSE
Log.String("the PATH user variable " + regValue + " is already set"); Log.Ln;
END
END CheckAndSetPath;
END UsbUtils.

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +0,0 @@
Manufacturer string: NTB
Product string: USB Programming and Debugging Interface
VID: 0x8235
PDI: 0x0100

Binary file not shown.

Binary file not shown.

View File

@@ -1,3 +0,0 @@
This file will contain the digital signature of the files to be installed
on the system.
This file will be provided by Microsoft upon certification of your drivers.

View File

@@ -1,106 +0,0 @@
[Version]
Signature = "$Chicago$"
provider = %manufacturer%
DriverVer = 10/14/2005,0.1.10.2
CatalogFile = USBPDI.cat
Class = LibUsbDevices
ClassGUID = {EB781AAF-9C70-4523-A5DF-642A87ECA567}
[ClassInstall]
AddReg=ClassInstall.AddReg
[ClassInstall32]
AddReg=ClassInstall.AddReg
[ClassInstall.AddReg]
HKR,,,,"LibUSB-Win32 Devices"
HKR,,Icon,,"-20"
[Manufacturer]
%manufacturer%=Devices
;--------------------------------------------------------------------------
; Files
;--------------------------------------------------------------------------
[SourceDisksNames]
1 = "Libusb-Win32 Driver Installation Disk",,
[SourceDisksFiles]
libusb0.sys = 1,,
libusb0.dll = 1,,
LibusbWin.dll = 1,,
[DestinationDirs]
LIBUSB.Files.Sys = 10,System32\Drivers
LIBUSB.Files.Dll = 10,System32
LIBUSB.Files.Dll2 = 10,System32
[LIBUSB.Files.Sys]
libusb0.sys
[LIBUSB.Files.Dll]
libusb0.dll
[LIBUSB.Files.DllJNI]
LibusbWin.dll
;--------------------------------------------------------------------------
; Device driver
;--------------------------------------------------------------------------
[LIBUSB_DEV]
CopyFiles = LIBUSB.Files.Sys, LIBUSB.Files.Dll, LIBUSB.Files.DllJNI
AddReg = LIBUSB_DEV.AddReg
[LIBUSB_DEV.NT]
CopyFiles = LIBUSB.Files.Sys, LIBUSB.Files.Dll, LIBUSB.Files.DllJNI
[LIBUSB_DEV.HW]
DelReg = LIBUSB_DEV.DelReg.HW
AddReg = LIBUSB_DEV.AddReg.HW
[LIBUSB_DEV.NT.HW]
DelReg = LIBUSB_DEV.DelReg.HW
AddReg = LIBUSB_DEV.AddReg.HW
[LIBUSB_DEV.NT.Services]
AddService = libusb0, 0x00000002, LIBUSB.AddService
[LIBUSB_DEV.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,libusb0.sys
[LIBUSB_DEV.DelReg.HW]
HKR,,LowerFilters
HKR,,UpperFilters
[LIBUSB_DEV.AddReg.HW]
HKR,,libusb_is_device_driver, 0x00010001 ,1
;--------------------------------------------------------------------------
; Services
;--------------------------------------------------------------------------
[LIBUSB.AddService]
DisplayName = "LibUsb-Win32 - Kernel Driver 10/14/2005, 0.1.10.2"
ServiceType = 1
StartType = 3
ErrorControl = 0
ServiceBinary = %12%\libusb0.sys
;--------------------------------------------------------------------------
; Devices
;--------------------------------------------------------------------------
[Devices]
"USB Programming and Debugging Interface"=LIBUSB_DEV, USB\VID_8235&PID_0100
;--------------------------------------------------------------------------
; Strings
;--------------------------------------------------------------------------
[Strings]
manufacturer = "NTB"

View File

@@ -1,190 +0,0 @@
; This examples demonstrates how libusb's drivers
; can be installed automatically along with your application using an installer.
;
; Requirements: Inno Setup (http://www.jrsoftware.org/isdl.php)
;
; To use this script, do the following:
; - copy libusb's driver (libusb0.sys, libusb0.dll) to this folder
; - create an .inf and .cab file using libusb's 'inf-wiward.exe'
; and save the generated files in this folder.
; - in this script replace <your_inf_file.inf> with the name of your .inf file
; - customize other settings (strings)
; - open this scipt with Inno Setup
; - compile and run
[Setup]
AppName=USB Programming and Debugging Interface
AppVerName=USB Programming and Debugging Interface 0.0.2
AppPublisher=NTB
AppPublisherURL=http://inf.ntb.ch/
AppVersion=0.0.2
DefaultDirName={pf}\USB PD-Interface
DefaultGroupName=USB PD-Interface
Compression=lzma
SolidCompression=yes
ChangesEnvironment=yes
; WinMe or higher
MinVersion=4.9,5
PrivilegesRequired=admin
WizardImageFile=setupUSBPDI_2.bmp
WizardSmallImageFile=setupUSBPDI_2small.bmp
[Files]
; copy the file to the App folder
Source: "*.sys"; DestDir: "{app}\driver"
Source: "*.cat"; DestDir: "{app}\driver"
Source: "*.dll"; DestDir: "{app}\driver"
Source: "*.inf"; DestDir: "{app}\driver"
; also copy the DLL to the system folders so that rundll32.exe will find it
Source: "*.dll"; DestDir: "{win}\system32"; FLags: replacesameversion restartreplace uninsneveruninstall
[Icons]
Name: "{group}\Uninstall USB PD-Interface"; Filename: "{uninstallexe}"
[Run]
; invoke libusb's DLL to install the .inf file
Filename: "rundll32"; Parameters: "libusb0.dll,usb_install_driver_np_rundll {app}\driver\USBPDI.inf"; StatusMsg: "Installing Programming and Debugging Interface driver (this may take a few seconds) ..."
[Code]
const
WM_SETTINGCHANGE = $1A;
SMTO_ABORTIFHUNG = $2;
function SendMessageTimeout(hwnd :LongInt; msg :LongInt; wParam :LongInt;
lParam :String; fuFlags :LongInt; uTimeout :LongInt; var lpdwResult :LongInt): LongInt;
external 'SendMessageTimeoutA@user32.dll stdcall';
// NotifyWindows: The function will notify other running applications
// (notably Windows Explorer) that they should reload their environment
// variables from the registry.
// On Windows NT platforms, if the funtion is not called, the
// environment variable will not be seen by applications launched from
// Explorer until the user logs off or restarts the computer.
procedure NotifyWindows();
var
res :LOngInt;
begin
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,'Environment', SMTO_ABORTIFHUNG, 5000, res);
end;
{returns true if s1 contains s2, else false (Case insensitive)}
function ContainsString(const s1, s2 :String):Boolean;
var
s1Lower, s2Lower :String; i, j, s1Length, s2Length:Integer;
begin
s1Lower := Lowercase(s1);
s2Lower := Lowercase(s2);
s1Length := Length(s1);
s2Length := Length(s2);
if s1Length < s2Length then begin
Result := False;
Exit;
end;
j := 1;
for i := 1 TO s1Length do begin
if j > s2Length then begin
Result := True;
Exit
end;
if s1Lower[i] = s2Lower[j] then begin
j := j + 1;
end else begin
j := 1;
end
end;
Result := False;
end;
function InitializeSetup(): Boolean;
var
Rootkey, Res: Integer; SubKeyName, ResultStr, ValueName, messageStr, JREPath, JREBin, JREBinClient, EnvPath: String;
javaInstalled, continueOnError, writeRegistry: Boolean;
begin
javaInstalled := True;
continueOnError := False;
rootKey := HKLM;
SubKeyName := 'SOFTWARE\JavaSoft\Java Runtime Environment';
ValueName := 'CurrentVersion';
if not RegQueryStringValue(RootKey, SubKeyName, ValueName, ResultStr) then
javaInstalled := False;
if javaInstalled then begin
if not RegQueryStringValue(RootKey, SubKeyName, ValueName, ResultStr) then begin
javaInstalled := False;
end else begin
SubKeyName := SubKeyName + '\' + ResultStr;
ValueName := 'JavaHome';
if not RegQueryStringValue(RootKey, SubKeyName, ValueName, JREPath) then
javaInstalled := False;
end;
end;
if not javaInstalled then begin
messageStr := 'No Java Runtime Environment found!' #13#10;
messageStr := messageStr + 'The JRE is needed to run this program.' #13#13;
messageStr := messageStr + 'If you continue, you need to set your PATH environment variable manualy to' #13#10;
messageStr := messageStr + 'JRE\bin and JRE\bin\client after installing the JRE from java.sun.com.' #13#13;
messageStr := messageStr + 'Do you want to continue?';
if MsgBox(messageStr, mbError, MB_YESNO) = idYes then
continueOnError := True;
end;
if javaInstalled then begin
Result := True;
{JREPath contains the path to the JRE directory (e.g. C:\Program Files\Java\jre1.5.0_06)}
{get the USER Path variable}
RootKey := HKCU;
SubKeyName := 'Environment';
ValueName := 'PATH';
JREBin := JREPath + '\bin';
JREBinClient := JREPath + '\bin\client';
{check if PATH is already set}
if not RegValueExists(RootKey, SubKeyName, ValueName) then begin
{create new PATH entry}
messageStr := 'In order to run the program the path to your JRE\bin and JRE\bin\client must be added.' #13#10;
messageStr := messageStr + 'Setup will added this paths to your User PATH variable.' #13#13;
messageStr := messageStr + 'Do you want Setup to modify your PATH variable?';
if MsgBox(messageStr, mbConfirmation, MB_YESNO) = idYes then begin
RegWriteStringValue(RootKey, SubKeyName, ValueName, JREBin + ';' + JREBinClient);
NotifyWindows();
end
end else begin
if RegQueryStringValue(RootKey, SubKeyName, ValueName, EnvPath) then begin
writeRegistry := False;
{check if EnvPath contains the right paths}
if not ContainsString(EnvPath, JREBin) then begin
{add to Path}
Res := Length(EnvPath);
if EnvPath[Res] = ';' then begin
end else begin
EnvPath := EnvPath + ';';
end;
EnvPath := EnvPath + JREBin;
writeRegistry := True;
end
if not ContainsString(EnvPath, JREBinClient) then begin
{add to Path}
Res := Length(EnvPath);
if EnvPath[Res] = ';' then begin
end else begin
EnvPath := EnvPath + ';';
end;
EnvPath := EnvPath + JREBinClient;
writeRegistry := True;
end
if writeRegistry then begin
messageStr := 'In order to run the program the path to your JRE\bin and JRE\bin\client must be added.' #13#10;
messageStr := messageStr + 'Setup will added this paths to your User PATH variable.' #13#13;
messageStr := messageStr + 'Do you want Setup to modify your PATH variable?';
if MsgBox(messageStr, mbConfirmation, MB_YESNO) = idYes then begin
RegWriteStringValue(RootKey, SubKeyName, ValueName, EnvPath);
NotifyWindows();
end
end
end else
continueOnError := True;
end;
end else
Result := False;
if continueOnError then
Result := True;
end;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 151 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

View File

@@ -1,37 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- DTD for memory devices. -->
<!ELEMENT device (attributes, size?, segment+, init?)>
<!ATTLIST device
type CDATA #REQUIRED
width (1|2|4) #REQUIRED>
<!ELEMENT segment (attributes?, base, size, subsegment*, subsegmentList?)>
<!ATTLIST segment
name CDATA #REQUIRED>
<!ELEMENT subsegment (attributes?, base?, size?, subsegment*)>
<!ATTLIST subsegment
name CDATA #REQUIRED>
<!ELEMENT subsegmentList (attributes?, size)>
<!ATTLIST subsegmentList
name CDATA #REQUIRED
numberOfEntries CDATA #REQUIRED
startID CDATA #IMPLIED>
<!ELEMENT size (#PCDATA)>
<!ELEMENT base (#PCDATA)>
<!ELEMENT attributes EMPTY>
<!ATTLIST attributes
mode (replace | change) #IMPLIED
read (add | remove) #IMPLIED
write (add | remove) #IMPLIED
const (add | remove) #IMPLIED
code (add | remove) #IMPLIED
var (add | remove) #IMPLIED
sysconst (add | remove) #IMPLIED
heap (add | remove) #IMPLIED
stack (add | remove) #IMPLIED>
<!ELEMENT init (assignment+)>
<!ELEMENT assignment (#PCDATA)>
<!ATTLIST assignment
name CDATA #REQUIRED
type (value | uri) #REQUIRED>

View File

@@ -1,17 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- DTD for MPC555 memoryMap. -->
<!ELEMENT memorymap (xi:include+)>
<!ATTLIST memorymap
xmlns:xi CDATA #FIXED "http://www.w3.org/2001/XInclude">
<!ELEMENT xi:include EMPTY>
<!ATTLIST xi:include
xmlns:xi CDATA #FIXED "http://www.w3.org/2001/XInclude"
href CDATA #IMPLIED
parse (xml|text) "xml"
xpointer CDATA #IMPLIED
encoding CDATA #IMPLIED
accept CDATA #IMPLIED
accept-language CDATA #IMPLIED
>

View File

@@ -1,21 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- DTD template for a RegisterDictionary.
Note: the type values are microcontroller specific and need to be adapted
to the specific register used in this registerDict.
-->
<!ELEMENT registerDefinitions ((registerGroup* | register*)*)>
<!ELEMENT registerGroup (register+)>
<!ATTLIST registerGroup
baseAddress CDATA #REQUIRED>
<!ELEMENT register (description?)>
<!ATTLIST register
mnemonic CDATA #REQUIRED
altmnemonic CDATA #IMPLIED
type (type1|type2|type3) #REQUIRED
value CDATA #REQUIRED
size (1|2|4) #REQUIRED
accessmode (supervisor|user|test) #IMPLIED
accessattr (readonly|writeonly) #IMPLIED>
<!ELEMENT description (#PCDATA)>

View File

@@ -1,20 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- DTD for MC68332 RegisterDictionary.
Only the type values are MC68332 specific.
-->
<!ELEMENT registerDefinitions ((registerGroup* | register*)*)>
<!ELEMENT registerGroup (register+)>
<!ATTLIST registerGroup
baseAddress CDATA #REQUIRED>
<!ELEMENT register (description?)>
<!ATTLIST register
mnemonic CDATA #REQUIRED
altmnemonic CDATA #IMPLIED
type (CtrlReg|UserReg|SysReg) #REQUIRED
value CDATA #REQUIRED
size (1|2|4) #REQUIRED
accessmode (supervisor|user|test) #IMPLIED
accessattr (readonly|writeonly) #IMPLIED>
<!ELEMENT description (#PCDATA)>

View File

@@ -1,524 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- Register Definitions for the Motorola MC68332 Microcontroller -->
<!DOCTYPE registerDefinitions SYSTEM "registerDictionary.dtd">
<registerDefinitions>
<!-- data registers -->
<register mnemonic="D0" type="UserReg" value="0x0" size="4">
<description>data register 0</description>
</register>
<register mnemonic="D1" type="UserReg" value="0x1" size="4">
<description>data register 1</description>
</register>
<register mnemonic="D2" type="UserReg" value="0x2" size="4">
<description>data register 2</description>
</register>
<register mnemonic="D3" type="UserReg" value="3" size="4">
<description>data register 3</description>
</register>
<register mnemonic="D4" type="UserReg" value="4" size="4">
<description>data register 43</description>
</register>
<register mnemonic="D5" type="UserReg" value="5" size="4">
<description>data register 5</description>
</register>
<register mnemonic="D6" type="UserReg" value="6" size="4">
<description>data register 6</description>
</register>
<register mnemonic="D7" type="UserReg" value="7" size="4">
<description>data register 7</description>
</register>
<!-- address registers -->
<register mnemonic="A0" type="UserReg" value="0x8" size="4">
<description>address register 0</description>
</register>
<register mnemonic="A1" type="UserReg" value="0x9" size="4">
<description>address register 1</description>
</register>
<register mnemonic="A2" type="UserReg" value="0xA" size="4">
<description>address register 2</description>
</register>
<register mnemonic="A3" type="UserReg" value="0xB" size="4">
<description>address register 3</description>
</register>
<register mnemonic="A4" type="UserReg" value="0xC" size="4">
<description>address register 4</description>
</register>
<register mnemonic="A5" type="UserReg" value="0xD" size="4">
<description>address register 5</description>
</register>
<register mnemonic="A6" type="UserReg" value="0xE" size="4">
<description>address register 06</description>
</register>
<register mnemonic="A7" type="UserReg" value="0xF" size="4">
<description>address register 7</description>
</register>
<!-- system registers -->
<register mnemonic="RPC" type="SysReg" value="0x0" size="4">
<description>return program counter</description>
</register>
<register mnemonic="PCC" type="SysReg" value="0x1" size="4">
<description>current instruction program counter</description>
</register>
<register mnemonic="SR" type="SysReg" value="0xB" size="2">
<description>status register</description>
</register>
<register mnemonic="USP" type="SysReg" value="0xC" size="4">
<description>user stack pointer (A7)</description>
</register>
<register mnemonic="SSP" type="SysReg" value="0xD" size="4">
<description>supervisor stack pointer</description>
</register>
<register mnemonic="SFC" type="SysReg" value="0xE" size="4">
<description>source function code register</description>
</register>
<register mnemonic="DFC" type="SysReg" value="0xF" size="4">
<description>destination function code register</description>
</register>
<register mnemonic="ATEMP" type="SysReg" value="0x8" size="4">
<description>temporary register A</description>
</register>
<register mnemonic="FAR" type="SysReg" value="0x9" size="4">
<description>fault address register</description>
</register>
<register mnemonic="VBR" type="SysReg" value="0xA" size="4">
<description>vector base register</description>
</register>
<registerGroup baseAddress="0xFFFFF000">
<!-- control registers -->
<register mnemonic="SIMCR" type="CtrlReg" value="0x0A00"
size="2">
<description>sim module configuration register</description>
</register>
<register mnemonic="SYNCR" type="CtrlReg" value="0x0A04"
size="2">
<description>clock synthesizer control</description>
</register>
<register mnemonic="SYPCR" type="CtrlReg" value="0x0A20"
size="2">
<description>system protection control</description>
</register>
<register mnemonic="CSPAR0" type="CtrlReg" value="0x0A44"
size="2">
<description>
chip select pin assignment register 0
</description>
</register>
<register mnemonic="CSPAR1" type="CtrlReg" value="0x0A46"
size="2">
<description>
chip select pin assignment register 1
</description>
</register>
<register mnemonic="CSBARBT" type="CtrlReg" value="0x0A48"
size="2">
<description>CSBOOT base address register</description>
</register>
<register mnemonic="CSORBT" type="CtrlReg" value="0x0A4A"
size="2">
<description>CSBOOT option register</description>
</register>
<register mnemonic="CSBAR0" type="CtrlReg" value="0x0A4C"
size="2">
<description>
chip select 0 base address register
</description>
</register>
<register mnemonic="CSOR0" type="CtrlReg" value="0x0A4E"
size="2">
<description>chip select 0 option register</description>
</register>
<register mnemonic="CSBAR1" type="CtrlReg" value="0x0A50"
size="2">
<description>
chip select 1 base address register
</description>
</register>
<register mnemonic="CSOR1" type="CtrlReg" value="0x0A52"
size="2">
<description>chip select 1 option register</description>
</register>
<register mnemonic="CSBAR2" type="CtrlReg" value="0x0A54"
size="2">
<description>
chip select 2 base address register
</description>
</register>
<register mnemonic="CSOR2" type="CtrlReg" value="0x0A56"
size="2">
<description>chip select 2 option register</description>
</register>
<register mnemonic="CSBAR3" type="CtrlReg" value="0x0A58"
size="2">
<description>
chip select 3 base address register
</description>
</register>
<register mnemonic="CSOR3" type="CtrlReg" value="0x0A5A"
size="2">
<description>chip select 3 option register</description>
</register>
<register mnemonic="CSBAR4" type="CtrlReg" value="0x0A5C"
size="2">
<description>
chip select 4 base address register
</description>
</register>
<register mnemonic="CSOR4" type="CtrlReg" value="0x0A5E"
size="2">
<description>chip select 4 option register</description>
</register>
<register mnemonic="CSBAR5" type="CtrlReg" value="0x0A60"
size="2">
<description>
chip select 5 base address register
</description>
</register>
<register mnemonic="CSOR5" type="CtrlReg" value="0x0A62"
size="2">
<description>chip select 5 option register</description>
</register>
<register mnemonic="CSBAR6" type="CtrlReg" value="0x0A64"
size="2">
<description>
chip select 6 base address register
</description>
</register>
<register mnemonic="CSOR6" type="CtrlReg" value="0x0A66"
size="2">
<description>chip select 6 option register</description>
</register>
<register mnemonic="CSBAR7" type="CtrlReg" value="0x0A68"
size="2">
<description>
chip select 7 base address register
</description>
</register>
<register mnemonic="CSOR7" type="CtrlReg" value="0x0A6A"
size="2">
<description>chip select 7 option register</description>
</register>
<register mnemonic="CSBAR8" type="CtrlReg" value="0x0A6C"
size="2">
<description>
chip select 8 base address register
</description>
</register>
<register mnemonic="CSOR8" type="CtrlReg" value="0x0A6E"
size="2">
<description>chip select 8 option register</description>
</register>
<register mnemonic="CSBAR9" type="CtrlReg" value="0x0A70"
size="2">
<description>
chip select 9 base address register
</description>
</register>
<register mnemonic="CSOR9" type="CtrlReg" value="0x0A72"
size="2">
<description>chip select 9 option register</description>
</register>
<!-- TPU registers -->
<!-- adjust the setting of tpumcr to reflect modmap bit -->
<register mnemonic="TRAMMCR" type="CtrlReg" value="0x0B00"
size="2">
<description>
TPURAM module configuration register
</description>
</register>
<register mnemonic="TRAMBAR" type="CtrlReg" value="0x0B04"
size="2">
<description>
TPURAM base address and status register
</description>
</register>
<register mnemonic="TPUMCR" type="CtrlReg" value="0x0E00"
size="2">
<description>TPU module control register</description>
</register>
<register mnemonic="TPUCFG" type="CtrlReg" value="0x0E02"
size="2">
<description>TPU configuration register</description>
</register>
<register mnemonic="DSCR" type="CtrlReg" value="0x0E04"
size="2">
<description>
development support control register
</description>
</register>
<register mnemonic="DSSR" type="CtrlReg" value="0x0E06"
size="2">
<description>
development support status register
</description>
</register>
<register mnemonic="TPUICR" type="CtrlReg" value="0x0E08"
size="2">
<description>
TPU interrupt configuration register
</description>
</register>
<register mnemonic="TPUIER" type="CtrlReg" value="0x0E0A"
size="2">
<description>TPU interrupt enable register</description>
</register>
<register mnemonic="CFSR0" type="CtrlReg" value="0x0E0C"
size="2">
<description>
channel function select register 0
</description>
</register>
<register mnemonic="CFSR1" type="CtrlReg" value="0x0E0E"
size="2">
<description>
channel function select register 1
</description>
</register>
<register mnemonic="CFSR2" type="CtrlReg" value="0x0E10"
size="2">
<description>
channel function select register 2
</description>
</register>
<register mnemonic="CFSR3" type="CtrlReg" value="0x0E12"
size="2">
<description>
channel function select register 3
</description>
</register>
<register mnemonic="HSR0" type="CtrlReg" value="0x0E14"
size="2">
<description>host sequence register 0</description>
</register>
<register mnemonic="HSR1" type="CtrlReg" value="0x0E16"
size="2">
<description>host sequence register 1</description>
</register>
<register mnemonic="HSRR0" type="CtrlReg" value="0x0E18"
size="2">
<description>host service request register 0</description>
</register>
<register mnemonic="HSRR1" type="CtrlReg" value="0x0E1A"
size="2">
<description>host service request register 1</description>
</register>
<register mnemonic="CPR0" type="CtrlReg" value="0x0E1C"
size="2">
<description>channel priority register 0</description>
</register>
<register mnemonic="CPR1" type="CtrlReg" value="0x0E1E"
size="2">
<description>channel priority register 1</description>
</register>
<register mnemonic="TPUISR" type="CtrlReg" value="0x0E20"
size="2">
<description>TPU interrupt status register</description>
</register>
<register mnemonic="LINK" type="CtrlReg" value="0x0E22"
size="2">
<description>???</description>
</register>
<register mnemonic="SGLR" type="CtrlReg" value="0x0E24"
size="2">
<description>service grant latch register</description>
</register>
<register mnemonic="DCNR" type="CtrlReg" value="0x0E26"
size="2">
<description>decoded channel number register</description>
</register>
<!-- Port E Registers -->
<register mnemonic="PORTE0" type="CtrlReg" value="0x0A11"
size="1">
<description>Port E data register 0</description>
</register>
<register mnemonic="PORTE1" type="CtrlReg" value="0x0A13"
size="1">
<description>Port E data register 1</description>
</register>
<register mnemonic="DDRE" type="CtrlReg" value="0x0A15"
size="1">
<description>Port E data direction register</description>
</register>
<register mnemonic="PEPAR" type="CtrlReg" value="0x0A17"
size="1">
<description>Port E pin assignment register</description>
</register>
<!-- Port F Registers -->
<register mnemonic="PORTF0" type="CtrlReg" value="0x0A19"
size="1">
<description>Port F data register 0</description>
</register>
<register mnemonic="PORTF1" type="CtrlReg" value="0x0A1B"
size="1">
<description>Port F data register 1</description>
</register>
<register mnemonic="DDRF" type="CtrlReg" value="0x0A1D"
size="1">
<description>Port F data direction register</description>
</register>
<register mnemonic="PFPAR" type="CtrlReg" value="0x0A1F"
size="1">
<description>Port F pin assignment register</description>
</register>
<!-- TPU parameter ram start addresses -->
<register mnemonic="CH0" type="CtrlReg" value="0x0F00"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH1" type="CtrlReg" value="0x0F10"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH2" type="CtrlReg" value="0x0F20"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH3" type="CtrlReg" value="0x0F30"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH4" type="CtrlReg" value="0x0F40"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH5" type="CtrlReg" value="0x0F50"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH6" type="CtrlReg" value="0x0F60"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH7" type="CtrlReg" value="0x0F70"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH8" type="CtrlReg" value="0x0F80"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH9" type="CtrlReg" value="0x0F90"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH10" type="CtrlReg" value="0x0FA0"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH11" type="CtrlReg" value="0x0FB0"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH12" type="CtrlReg" value="0x0FC0"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH13" type="CtrlReg" value="0x0FD0"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH14" type="CtrlReg" value="0x0FE0"
size="2">
<description>TPU parameter ram start address</description>
</register>
<register mnemonic="CH15" type="CtrlReg" value="0x0FF0"
size="2">
<description>TPU parameter ram start address</description>
</register>
<!-- queued serial module -->
<register mnemonic="QMCR" type="CtrlReg" value="0x0C00"
size="2">
<description>QSM configuration register</description>
</register>
<register mnemonic="QTEST" type="CtrlReg" value="0x0C02"
size="2">
<description>QSM test register</description>
</register>
<register mnemonic="QILR" type="CtrlReg" value="0x0C04"
size="1">
<description>QSM interrupt level register</description>
</register>
<register mnemonic="QIVR" type="CtrlReg" value="0x0C05"
size="1">
<description>QSM interrupt vector register</description>
</register>
<register mnemonic="SCCR0" type="CtrlReg" value="0x0C08"
size="2">
<description>SCI control register 0</description>
</register>
<register mnemonic="SCCR1" type="CtrlReg" value="0x0C0A"
size="2">
<description>SCI control register 1</description>
</register>
<register mnemonic="SCSR" type="CtrlReg" value="0x0C0C"
size="2">
<description>SCI status register</description>
</register>
<register mnemonic="SCDR" type="CtrlReg" value="0x0C0E"
size="2">
<description>SCI data register</description>
</register>
<register mnemonic="QPDR" type="CtrlReg" value="0x0C15"
size="2">
<description>QSM port data register</description>
</register>
<register mnemonic="QPAR" type="CtrlReg" value="0x0C16"
size="2">
<description>QSM pin assignment register</description>
</register>
<register mnemonic="QDDR" type="CtrlReg" value="0x0C17"
size="2">
<description>QSM data direction register</description>
</register>
<register mnemonic="SPCR0" type="CtrlReg" value="0x0C18"
size="2">
<description>QSPI control register 0</description>
</register>
<register mnemonic="SPCR1" type="CtrlReg" value="0x0C1A"
size="2">
<description>QSPI control register 1</description>
</register>
<register mnemonic="SPCR2" type="CtrlReg" value="0x0C1C"
size="2">
<description>QSPI control register 2</description>
</register>
<register mnemonic="SPCR3" type="CtrlReg" value="0x0C1E"
size="1">
<description>QSPI control register 3</description>
</register>
<register mnemonic="SPSR" type="CtrlReg" value="0x0C1F"
size="1">
<description>QSPI status register</description>
</register>
<register mnemonic="QRXD" type="CtrlReg" value="0x0D00"
size="2">
<description>QSPI receive data</description>
</register>
<register mnemonic="QTXD" type="CtrlReg" value="0x0D20"
size="2">
<description>QSPI transmit data</description>
</register>
<register mnemonic="QCMD" type="CtrlReg" value="0x0D40"
size="2">
<description>QSPI command control</description>
</register>
</registerGroup>
</registerDefinitions>

View File

@@ -1,38 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- External Flash Description for the Motorola MPC555 Microcontroller -->
<!DOCTYPE device SYSTEM "../../general/device.dtd">
<device type="Am29LV160D" width="2">
<attributes mode="change" read="add"></attributes>
<size>0x200000</size>
<segment name="ExternalFlash">
<base>ToppcKernel.CextRomBase</base>
<size>ToppcKernel.CextRomSize</size>
<subsegment name="ExcCode">
<attributes code="add"></attributes>
<size>ToppcKernel.excpCodeSize</size>
</subsegment>
<subsegment name="SysTab">
<attributes sysconst="add"></attributes>
<size>0x6000</size>
</subsegment>
<subsegment name="S1">
<attributes const="add" code="add"></attributes>
<size>0x4000</size>
</subsegment>
<subsegment name="S2">
<size>0x4000</size>
</subsegment>
<subsegment name="S3">
<size>0x10000</size>
</subsegment>
<subsegmentList name="S" numberOfEntries="30" startID="4">
<size>0x20000</size>
</subsegmentList>
</segment>
<init>
<assignment name="BR0" type="uri">ToppcKernel.pBR0</assignment>
<assignment name="OR0" type="uri">ToppcKernel.pOR0</assignment>
</init>
</device>

View File

@@ -1,16 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- Internal Flash description for the Motorola MPC555 Microcontroller -->
<!DOCTYPE device SYSTEM "../../general/device.dtd">
<device type="Ppc555Flash" width="4">
<attributes mode="replace" read="add"></attributes>
<segment name="InternalFlashA">
<base>0x2000</base>
<size>0x3E000</size>
</segment>
<segment name="InternalFlashB">
<base>0x40000</base>
<size>0x30000</size>
</segment>
</device>

View File

@@ -1,64 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- RAM description of the Motorola MPC555 Microcontroller -->
<!DOCTYPE device SYSTEM "../../general/device.dtd">
<device type="RAM" width="4">
<attributes mode="change" read="add" write="add"></attributes>
<segment name="InternalFlashAblock0">
<attributes code="add"></attributes>
<base>0</base>
<size>0x2000</size>
<subsegment name="ExcCode">
<base>0</base>
</subsegment>
</segment>
<segment name="InternalRAM">
<base>ToppcKernel.CintRamBase</base>
<size>ToppcKernel.CintRamSize</size>
<subsegment name="SysTab">
<attributes sysconst="add"></attributes>
<base>ToppcKernel.sysTabAdr</base>
</subsegment>
<subsegment name="SegConst">
<attributes const="add"></attributes>
</subsegment>
<subsegment name="SegCode">
<attributes code="add"></attributes>
</subsegment>
<subsegment name="SegVars">
<attributes var="add"></attributes>
</subsegment>
<subsegment name="Stack">
<attributes stack="add"></attributes>
<size>ToppcKernel.stackSize</size>
</subsegment>
</segment>
<segment name="ExternalRAM">
<attributes mode="change"></attributes>
<base>ToppcKernel.CextRamBase</base>
<size>ToppcKernel.CextRamSize</size>
<subsegment name="Heap">
<attributes heap="add"></attributes>
</subsegment>
</segment>
<init>
<assignment name="BR0" type="uri">ToppcKernel.pBR0</assignment>
<assignment name="OR0" type="uri">ToppcKernel.pOR0</assignment>
<assignment name="BR1" type="uri">ToppcKernel.pBR1</assignment>
<assignment name="OR1" type="uri">ToppcKernel.pOR1</assignment>
<assignment name="DMBR" type="uri">
ToppcKernel.pDMBR
</assignment>
<assignment name="DMOR" type="uri">
ToppcKernel.pDMOR
</assignment>
<assignment name="ICTRL" type="value">7</assignment>
<!-- reset RSR -->
<assignment name="RSR" type="value">-1</assignment>
<!-- cause to enter debug mode -->
<assignment name="DER" type="value">0x31C7400F</assignment>
<!-- MSR -->
<assignment name="SRR1" type="value">0x03802</assignment>
</init>
</device>

View File

@@ -1,21 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- Memory Assignment for the Motorola MPC555 Microcontroller -->
<!DOCTYPE sysclasses SYSTEM "memoryAssignment.dtd">
<sysclasses>
<systable>InternalRam.SysTab</systable>
<classes>
<general>
<code>InternalRam</code>
<const>InternalRam</const>
<var>InternalRam</var>
</general>
<class name="ToppcHeap">
<attributes>only_link_if_referenced</attributes>
</class>
<class name="ToppcExceptions">
<code>InternalFlashAblock0.ExcCode</code>
</class>
</classes>
</sysclasses>

View File

@@ -1,10 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- Memory Map for the Motorola MPC555 Microcontroller -->
<!DOCTYPE memorymap SYSTEM "../general/memoryMap.dtd">
<memorymap xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="devices/deviceRAM.xml"></xi:include>
<xi:include href="devices/deviceMPC555Flash.xml"></xi:include>
<xi:include href="devices/deviceAm29LV160D.xml"></xi:include>
</memorymap>

View File

@@ -1,20 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- DTD for MPC555 RegisterDictionary.
Only the type values are MPC555 specific.
-->
<!ELEMENT registerDefinitions ((registerGroup* | register*)*)>
<!ELEMENT registerGroup (register+)>
<!ATTLIST registerGroup
baseAddress CDATA #REQUIRED>
<!ELEMENT register (description?)>
<!ATTLIST register
mnemonic CDATA #REQUIRED
altmnemonic CDATA #IMPLIED
type (CtrlReg|GPR|FPR|SPR|MSR|CR|FPSCR) #REQUIRED
value CDATA #REQUIRED
size (1|2|4) #REQUIRED
accessmode (supervisor|user|test) #IMPLIED
accessattr (readonly|writeonly) #IMPLIED>
<!ELEMENT description (#PCDATA)>

File diff suppressed because it is too large Load Diff

View File

@@ -1,115 +0,0 @@
short i = (short) 0x8613;
return i;(short) -31213
++++++
int i = -15;
System.out.println(i & 0xFF);
++++++
int x;
for (int i = -10000; i < 10000; i++) {
x = (i & 0xFF);
if (x < 0){
System.out.println(i & 0xFF);
}
}
++++++
int b = -15;
int c = (b & 0xFF);
System.out.println(c);
++++++
byte b = (byte) 0x80;
b |= 0x40;
b |= 0x20;
System.out.println(b);
++++++
int word = -1; // 0x00010000;
int shift = 27;
byte b = (byte) ((word >>> 21) & 0x0FF);
int i = (word >>> shift);
System.out.println(word + "\t" + shift);
System.out.println(b);
System.out.println(i);
++++++
int word = 0xFF3;
byte b = (byte) ((word & 0x07) << 5);
System.out.println(b);
++++++
System.out.println(64 >>> 1);
++++++
int word = 0xFF0F0F0F;
boolean lengthBit = false, controlBit = true;
byte b = (byte) 0x80;
if (lengthBit) {
b |= 0x40;
}
if (controlBit) {
b |= 0x20;
}
b |= (byte) (word >>> 27); System.out.print(b + "\t");
b = (byte) ((word >>> 19) & 0xFF); System.out.print(b + "\t");
b = (byte) ((word >>> 11) & 0xFF); System.out.print(b + "\t");
b = (byte) ((word >>> 3) & 0xFF); System.out.print(b + "\t");
b = (byte) ((word & 0x07) << 5); System.out.println(b);
++++++
byte[] data = new byte[5];
data[0] = 0x00; data[1] = 0x00; data[2] = 0x00; data[3] = 0x29; data[4] = (byte) 0x80;
int retValue = ((data[0] << 3) + ((data[1] & 0xFF) >>> 5)) << 24;
System.out.println("0x" + Integer.toHexString(retValue));
// second byte
retValue += (((data[1] << 3) & 0xFF) + ((data[2] & 0xFF) >>> 5)) << 16;
System.out.println("0x" + Integer.toHexString(retValue));
// third byte
retValue += (((data[2] << 3) & 0xFF) + ((data[3] & 0xFF) >>> 5)) << 8;
System.out.println("0x" + Integer.toHexString(retValue));
// fourth byte
retValue += ((data[3] << 3) & 0xFF) + ((data[4] & 0xFF) >>> 5);
System.out.println("0x" + Integer.toHexString(retValue));
++++++
byte b = 0x7D;
System.out.println((b & 0x80));
++++++
int i1 = 0x12345678, i2 = 0x56789012;
long l = ((long) i1 << 32) + i2;
System.out.println(Long.toHexString(l));
++++++
int val = 5;
for (int i = 0; i <= 7; i++) {
int cmd = 0xFC00010C + (7 - i) * 0x800000 + ((val >>> i*4) & 0xF)*0x1000;
System.out.println(i + "\t0x" + Integer.toHexString(cmd));
}
++++++
System.out.println("0x" + Integer.toHexString((0x20 << 3) & 0xFF));
++++++
int data = 0x1111;
byte b;
b = (byte) ((data >>> 9) & 0xFF);
System.out.println("0x" + Integer.toHexString(b));
b = (byte) ((data >>> 1) & 0xFF);
System.out.println("0x" + Integer.toHexString(b));
b = (byte) ((data & 0x01) << 7);
System.out.println("0x" + Integer.toHexString(b));
++++++
byte[] data = new byte[3];
data[0] = (byte) 0xFF; data[1] = 0x01; data[2] = 0x00;
byte b = 0;
for (int bit = 0; bit <= 7; bit++) {
if ((data[1] & (1 << bit)) > 0) {
b += 1 << (7 - bit);
}
}
int retValue = (b & 0xFF) << 8;
// turn LSB
b = 0;
for (int bit = 0; bit <= 7; bit++) {
if ((data[0] & (1 << bit)) > 0) {
b += 1 << (7 - bit);
}
}
retValue += (b & 0xFF);
System.out.println("0x" + Integer.toHexString(retValue));
++++++
System.out.println(((512 - 6) / 2) & 0xFFFC);
++++++
int MR30TSPR = 0x7FC003A6;
int spr = 158;
System.out.println(((spr & 0x1F) * 0x20 + (spr >>> 5)) * 0x800 + MR30TSPR);
+++++++

View File

@@ -1,14 +0,0 @@
package ch.ntb.mcdp.bdi;
public class BDIException extends Exception {
public BDIException(String string) {
super(string);
}
/**
*
*/
private static final long serialVersionUID = -3800838568826846479L;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,255 +0,0 @@
package ch.ntb.mcdp.bdi.blackbox;
import ch.ntb.mcdp.bdi.BDIException;
import ch.ntb.mcdp.usb.DispatchException;
import ch.ntb.mcdp.usb.USBDevice;
import ch.ntb.usb.USBException;
public class MC68332 {
private static ch.ntb.mcdp.bdi.MC68332 bdi;
/**
* Create a new BDI instance.
*/
static {
bdi = new ch.ntb.mcdp.bdi.MC68332(USBDevice.getDevice());
}
/**
* Sends NOPs to the target until a <code>STATUS_OK</code> result is
* received.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void nopsToLegalCmd() throws USBException, DispatchException,
BDIException {
bdi.nopsToLegalCmd();
}
/**
* Signals a breakpoint and enters debug mode.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void break_() throws USBException, DispatchException,
BDIException {
bdi.break_();
}
/**
* Resume from debug mode.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void go() throws USBException, DispatchException,
BDIException {
bdi.go();
}
/**
* Reset the target and put it into debug mode.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void reset_target() throws USBException, DispatchException,
BDIException {
bdi.reset_target();
}
/**
* Send the <b>RST</b> command (reset peripherals) to the microcontroller.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void reset_peripherals() throws USBException,
DispatchException, BDIException {
bdi.reset_peripherals();
}
/**
* Check if the freeze signal is asserted.<br>
* The freeze siganl is asserted if the target is in debug mode.
*
* @return
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static boolean isFreezeAsserted() throws USBException,
DispatchException, BDIException {
return bdi.isFreezeAsserted();
}
/**
* Fill large blocks of memory.<br>
* Fill is used in conjunction with the <code>writeMem</code> command. The
* maximal number of words is defined by
* <code>MAX_NOF_WORDS_FAST_DOWNLOAD</code> for 1 and 2 byte (word) data.
* For 4 byte (long) data, only half the size 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>
* Befor using <code>fillMem</code>, <code>writeMem</code> has to be
* called to set up the start address and size.
*
* @param downloadData
* Data to be downloaded (size depending on size set up with
* <code>writeMem</code>)
* @param dataLength
* Number of bytes, words or longs (1, 2, 4 bytes)
* @throws BDIException
* @throws DispatchException
* @throws USBException
*/
public static void fillMem(int[] downloadData, int dataLength)
throws BDIException, USBException, DispatchException {
bdi.fillMem(downloadData, dataLength);
}
/**
* Dump large blocks of memory. <br>
* Dump is used in conjunction with the <code>readMem(...)</code> command.
* The size depends on the size set up with <code>readMem(...)</code> and
* is internally stored.
*
* @param nofData
* number of bytes/words/longs to read (depends on the size set
* up with <code>readMem(...)</code>)
* @return read values
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static int[] dumpMem(int nofData) throws USBException,
DispatchException, BDIException {
return bdi.dumpMem(nofData);
}
/**
* 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)
throws USBException, DispatchException, BDIException {
bdi.writeMem(addr, value, size);
}
/**
* 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,
DispatchException, BDIException {
return bdi.readMem(addr, size);
}
/**
* 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,
DispatchException, BDIException {
return bdi.readUserReg(reg);
}
/**
* 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,
DispatchException, BDIException {
bdi.writeUserReg(reg, value);
}
/**
* 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,
DispatchException, BDIException {
return bdi.readSysReg(reg);
}
/**
* 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,
DispatchException, BDIException {
bdi.writeSysReg(reg, value);
}
/**
* Return the last known state of the freeze signal.<br>
* This value may not be up to date as the target state may have changed
* meanwhile. To get the up to date value use <code>isFreezeAsserted</code>
* which will issue an USB request, read the freeze signal and update the
* internal value returned by this method.
*
* @return the last known state of the freeze signal
*/
public static boolean isTargetInDebugMode() {
return bdi.isTargetInDebugMode();
}
}

View File

@@ -1,252 +0,0 @@
package ch.ntb.mcdp.bdi.blackbox;
import ch.ntb.mcdp.bdi.BDIException;
import ch.ntb.mcdp.usb.DispatchException;
import ch.ntb.mcdp.usb.USBDevice;
import ch.ntb.usb.USBException;
public class MPC555 {
private static ch.ntb.mcdp.bdi.MPC555 bdi;
/**
* Create a new BDI instance.
*/
static {
bdi = new ch.ntb.mcdp.bdi.MPC555(USBDevice.getDevice());
}
/**
* Signals a breakpoint and enters debug mode.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void break_() throws USBException, DispatchException,
BDIException {
bdi.break_();
}
/**
* Resume from debug mode.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void go() throws USBException, DispatchException,
BDIException {
bdi.go();
}
/**
* Reset the target and put it into debug mode.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void reset_target() throws USBException, DispatchException,
BDIException {
bdi.reset_target();
}
/**
* Check if the freeze signal is asserted.<br>
* The freeze siganl is asserted if the target is in debug mode.
*
* @return
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static boolean isFreezeAsserted() throws USBException,
DispatchException, BDIException {
return bdi.isFreezeAsserted();
}
/**
* Called to start the fast download procedure.
*
* @param startAddr
* Address to which the data will be downloaded.
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void startFastDownload(int startAddr) throws USBException,
DispatchException, BDIException {
bdi.startFastDownload(startAddr);
}
/**
* Fill one USB-Packet with data to download. The maximal number of words is
* defined by <code>MAX_NOF_WORDS_FAST_DOWNLOAD</code><br>
* <code>startFastDownload</code> has to be called before to set up the
* start address.
*
* @param downloadData
* Data to be downloaded (32 bit wide)
* @param dataLength
* Length of the data to download (words)
* @throws BDIException
* @throws DispatchException
* @throws USBException
*/
public static void fastDownload(int[] downloadData, int dataLength)
throws BDIException, USBException, DispatchException {
bdi.fastDownload(downloadData, dataLength);
}
/**
* Stop the fast download procedure.<br>
* Use this command after <code>startFastDownload(...)</code> and
* <code>fastDownload(...)</code>.
*
* @throws USBException
* @throws DispatchException
* @throws BDIException
*/
public static void stopFastDownload() throws USBException,
DispatchException, BDIException {
bdi.stopFastDownload();
}
public static void writeMem(int addr, int value, int size)
throws USBException, DispatchException, BDIException {
bdi.writeMem(addr, value, size);
}
public static int readMem(int addr, int size) throws USBException,
DispatchException, BDIException {
return bdi.readMem(addr, size);
}
public static void writeMemSeq(int value, int size) throws USBException,
DispatchException, BDIException {
bdi.writeMemSeq(value, size);
}
public static int readMemSeq(int size) throws USBException,
DispatchException, BDIException {
return bdi.readMemSeq(size);
}
public static int readGPR(int gpr) throws USBException, DispatchException,
BDIException {
return bdi.readGPR(gpr);
}
public static void writeGPR(int gpr, int value) throws USBException,
DispatchException, BDIException {
bdi.writeGPR(gpr, value);
}
public static int readSPR(int spr) throws USBException, DispatchException,
BDIException {
return bdi.readSPR(spr);
}
public static void writeSPR(int spr, int value) throws USBException,
DispatchException, BDIException {
bdi.writeSPR(spr, value);
}
public static int readMSR() throws USBException, DispatchException,
BDIException {
return bdi.readMSR();
}
public static void writeMSR(int value) throws USBException,
DispatchException, BDIException {
bdi.writeMSR(value);
}
public static long readFPR(int fpr, int tmpMemAddr) throws USBException,
DispatchException, BDIException {
return bdi.readFPR(fpr, tmpMemAddr);
}
public static void writeFPR(int fpr, int tmpMemAddr, long value)
throws USBException, DispatchException, BDIException {
bdi.writeFPR(fpr, tmpMemAddr, value);
}
public static int readCR() throws USBException, DispatchException,
BDIException {
return bdi.readCR();
}
public static void writeCR(int value) throws USBException,
DispatchException, BDIException {
bdi.writeCR(value);
}
public static int readFPSCR() throws USBException, DispatchException,
BDIException {
return bdi.readFPSCR();
}
public static void writeFPSCR(int value) throws USBException,
DispatchException, BDIException {
bdi.writeFPSCR(value);
}
/**
* Return the last known state of the freeze signal. This value may not be
* up to date as the target state may have changed meanwhile. To get the up
* to date value use <code>isFreezeAsserted</code> which will issue an USB
* request, read the freeze signal and update the internal value returned by
* this method.
*
* @return the last known state of the freeze signal
*/
public static boolean isTargetInDebugMode() {
return bdi.isTargetInDebugMode();
}
/**
* Read the currently stored value of the GPR 30 register.<br>
* This value is updated when entering debug mode (break -> prologue).
*
* @return the store value of this register
*/
public static int getGpr30() {
return bdi.getGpr30();
}
/**
* Set the value of the GPR 30 register.<br>
* This value is written to the GPR30 register when the microcontroller
* resumes from debug mode (go -> epilogue).
*
* @param value
* value to write to the register
*/
public static void setGpr30(int value) {
bdi.setGpr30(value);
}
/**
* Read the currently stored value of the GPR 31 register.<br>
* This value is updated when entering debug mode (break -> prologue).
*
* @return the store value of this register
*/
public static int getGpr31() {
return bdi.getGpr31();
}
/**
* Set the value of the GPR 31 register.<br>
* This value is written to the GPR31 register when the microcontroller
* resumes from debug mode (go -> epilogue).
*
* @param value
* value to write to the register
*/
public static void setGpr31(int value) {
bdi.setGpr31(value);
}
}

View File

@@ -1,279 +0,0 @@
package ch.ntb.mcdp.bdi.test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import ch.ntb.mcdp.bdi.MC68332;
import ch.ntb.mcdp.usb.USBDevice;
import ch.ntb.usb.USBException;
public class BDI332App {
private Shell sShell = null; // @jve:decl-index=0:visual-constraint="10,10"
private Button button1 = null;
private Button button2 = null;
private Button button3 = null;
private Button button4 = null;
private Button button5 = null;
private Button button6 = null;
private Button button7 = null;
private Button button8 = null;
private Button button9 = null;
private Button button10 = null;
private Button button15 = null;
private Button button11 = null;
private Button button12 = null;
private Button button13 = null;
private Button button14 = null;
private Button button20 = null;
private Button button16 = null;
private Button button17 = null;
private Button button18 = null;
private Button button19 = null;
/**
* This method initializes sShell
*/
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setLayout(new RowLayout());
sShell.setSize(new org.eclipse.swt.graphics.Point(320, 134));
button1 = new Button(sShell, SWT.NONE);
button1.setText("testBdiTransaction");
button1
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button1();
}
});
button2 = new Button(sShell, SWT.NONE);
button2.setText("reset_target");
button2
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button2();
}
});
button3 = new Button(sShell, SWT.NONE);
button3.setText("go");
button3
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button3();
}
});
button4 = new Button(sShell, SWT.NONE);
button4.setText("break_");
button4
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button4();
}
});
button5 = new Button(sShell, SWT.NONE);
button5.setText("freeze");
button6 = new Button(sShell, SWT.NONE);
button6.setText("writeMem");
button6
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button6();
}
});
button7 = new Button(sShell, SWT.NONE);
button7.setText("readMem");
button8 = new Button(sShell, SWT.NONE);
button8.setText("dumpMem");
button8
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button8();
}
});
button9 = new Button(sShell, SWT.NONE);
button9.setText("NOP");
button10 = new Button(sShell, SWT.NONE);
button10.setText("fillMem");
button11 = new Button(sShell, SWT.NONE);
button11.setText("initTarget");
button11
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button11();
}
});
button12 = new Button(sShell, SWT.NONE);
button12.setText("replaceA");
button12
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button12();
}
});
button13 = new Button(sShell, SWT.NONE);
button13.setText("compare1");
button13
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button13();
}
});
button14 = new Button(sShell, SWT.NONE);
button14.setText("compare2");
button14
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button14();
}
});
button15 = new Button(sShell, SWT.NONE);
button15.setText("resetUSB");
button16 = new Button(sShell, SWT.NONE);
button16.setText("replaceE");
button16
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button16();
}
});
button17 = new Button(sShell, SWT.NONE);
button17.setText("-");
button17
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button17();
}
});
button18 = new Button(sShell, SWT.NONE);
button18.setText("-");
button18
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button18();
}
});
button19 = new Button(sShell, SWT.NONE);
button19.setText("-");
button19
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
Dump332.dumpToBin();
}
});
button20 = new Button(sShell, SWT.NONE);
button20.setText("-");
button20
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
Dump332.dumpToHex();
}
});
button15
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button15();
}
});
button10
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button10();
}
});
button9
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button9();
}
});
button7
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button7();
}
});
button5
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI332test.button5();
}
});
}
public static void main(String[] args) {
BDI332App app = new BDI332App();
app.createSShell();
app.sShell.open();
Display display = app.sShell.getDisplay();
try {
USBDevice.open();
MC68332 bdi = new MC68332(USBDevice.getDevice());
BDI332test.bdi = bdi;
Dump332.bdi = bdi;
System.out.println("open device...");
} catch (USBException e) {
e.printStackTrace();
return;
}
while (!app.sShell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
try {
USBDevice.close();
System.out.println("closing device...");
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@@ -1,718 +0,0 @@
package ch.ntb.mcdp.bdi.test;
import ch.ntb.mcdp.bdi.BDIException;
import ch.ntb.mcdp.bdi.MC68332;
import ch.ntb.mcdp.mc68332.IMCBTargetBoard;
import ch.ntb.mcdp.usb.DataPacket;
import ch.ntb.mcdp.usb.DispatchException;
import ch.ntb.mcdp.usb.USBDevice;
import ch.ntb.mcdp.utils.logger.LogUtil;
import ch.ntb.mcdp.utils.logger.McdpLogger;
import ch.ntb.usb.USBException;
public class BDI332test {
private static McdpLogger logger = LogUtil.ch_ntb_mcdp_bdi_test;
public static MC68332 bdi;
private static void testBdiTransaction() {
// test bdi transaction
DataPacket result = null;
try {
result = bdi.transfer(0xaaaa);
} catch (USBException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (DispatchException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (result != null) {
logger.info(result.toString());
}
}
private static void reset_target() {
try {
bdi.reset_target();
} catch (USBException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (DispatchException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void freeze() {
try {
logger.info("isFreezeAsserted: " + bdi.isFreezeAsserted());
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void break_() {
try {
bdi.break_();
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void go() {
try {
bdi.go();
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void writeMem() {
final int BASE_ADDR = 0x105624;
try {
bdi.writeMem(BASE_ADDR, 0x123456, 4);
bdi.writeMem(BASE_ADDR + 4, 0x123457, 4);
bdi.writeMem(BASE_ADDR + 8, 0x123458, 4);
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void readMem() {
final int BASE_ADDR = 0x105624;
try {
StringBuffer sb = new StringBuffer("0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 4)) + "\n");
sb.append("0x" + Integer.toHexString(bdi.readMem(BASE_ADDR + 4, 4))
+ "\n");
sb.append("0x" + Integer.toHexString(bdi.readMem(BASE_ADDR + 8, 4))
+ "\n");
logger.info(sb.toString());
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// private static void fastDownload() {
// int[] testData = new int[120];
// for (int i = 0; i < testData.length; i++) {
// testData[i] = i;
// }
// try {
// BDI332.startFastDownload(0x800000);
// BDI332.fastDownload(testData, BDI332.MAX_NOF_WORDS_FAST_DOWNLOAD);
// BDI332.stopFastDownload();
// } catch (USBException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (DispatchException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (BDIException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// private static void readMemSeq() {
// int startAddr = 0x800000;
// try {
// StringBuffer sb = new StringBuffer(0 + "\tData: 0x"
// + Integer.toHexString(BDI332.readMem(startAddr, 4)) + "\n");
// for (int i = 1; i < 120; i++) {
// sb.append(i + "\tData: 0x"
// + Integer.toHexString(BDI332.readMemSeq(4)) + "\n");
// }
// System.out.println(sb.toString());
// } catch (USBException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (DispatchException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (BDIException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
public static void button1() {
logger.info("testBdiTransaction()");
testBdiTransaction();
}
public static void button2() {
logger.info("reset_target()");
reset_target();
}
public static void button3() {
logger.info("go()");
go();
}
public static void button4() {
logger.info("break_()");
break_();
}
public static void button5() {
logger.info("freeze()");
freeze();
}
public static void button6() {
logger.info("writeMem()");
writeMem();
}
public static void button7() {
logger.info("readMem()");
readMem();
}
public static void button8() {
final int BASE_ADDR = 0x105624;
int[] result;
logger.info("dump()");
try {
logger.info("Data: 0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 4)) + " ");
result = bdi.dumpMem(bdi.getMaxNofLongsDump());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
sb.append("0x" + Integer.toHexString(result[i]) + " ");
}
logger.info(sb.toString());
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void button9() {
logger.info("nop");
// test bdi transaction
DataPacket result = null;
try {
result = bdi.transfer(0x0000);
} catch (USBException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (DispatchException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (result != null) {
logger.info(result.toString());
}
}
public static void button10() {
final int BASE_ADDR = 0x105624;
logger.info("fill");
try {
bdi.writeMem(BASE_ADDR, 0, 4);
int[] data = new int[bdi.getMaxNofLongsFill()];
for (int i = 0; i < data.length; i++) {
data[i] = i;
}
bdi.fillMem(data, data.length);
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void button11() {
logger.info("initTarget()");
try {
IMCBTargetBoard imcb = new IMCBTargetBoard(bdi);
imcb.init();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void button12() {
final int BASE_ADDR = 0x105624;
final int DATA = 0x00ff00ff;
final int OFFSET = 0x06 * 4;
final int LENGTH = 0x04;
try {
logger.info("Fill (1 to data.length)");
bdi.writeMem(BASE_ADDR, 0, 4);
int[] data = new int[bdi.getMaxNofLongsFill()];
for (int i = 0; i < data.length; i++) {
data[i] = i + 1;
}
bdi.fillMem(data, data.length);
logger.info("writing byte " + (OFFSET / 4) + " to "
+ ((OFFSET / 4) + LENGTH) + " with 0x"
+ Integer.toHexString(DATA));
bdi.writeMem(BASE_ADDR + OFFSET, DATA, 4);
for (int i = 0; i < LENGTH; i++) {
data[i] = DATA;
}
bdi.fillMem(data, LENGTH);
logger.info((LENGTH + 1) + " bytes written");
logger.info("dump data");
int firstInt = bdi.readMem(BASE_ADDR, 4);
int[] result = bdi.dumpMem(bdi.getMaxNofLongsDump());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
sb.append("0x" + Integer.toHexString(result[i]) + " ");
}
logger.info("Data: 0x" + Integer.toHexString(firstInt) + " "
+ sb.toString());
logger.info("Done");
} catch (BDIException e) {
e.printStackTrace();
} catch (USBException e) {
e.printStackTrace();
} catch (DispatchException e) {
e.printStackTrace();
}
}
public static void button13() {
final int BASE_ADDR = 0x105624;
final int FIRST_VAL = 0xFF;
try {
logger.info("initialize data");
bdi.writeMem(BASE_ADDR, FIRST_VAL, 4);
int[] data = new int[bdi.getMaxNofLongsFill()];
for (int i = 0; i < data.length; i++) {
data[i] = 5;
}
bdi.fillMem(data, data.length);
logger.info("write data");
bdi.writeMem(BASE_ADDR, FIRST_VAL, 4);
data = new int[10];
for (int i = 0; i < data.length; i++) {
data[i] = i;
}
bdi.fillMem(data, data.length);
logger.info("Fill done");
logger.info("read back data");
int firstResult = bdi.readMem(BASE_ADDR, 4);
if (firstResult != FIRST_VAL) {
logger.warning("Error at 0: 0x"
+ Integer.toHexString(firstResult) + " instead of 0x"
+ Integer.toHexString(FIRST_VAL));
}
logger.fine("Compare first 0x" + Integer.toHexString(firstResult)
+ " == 0x" + Integer.toHexString(FIRST_VAL));
int[] result = bdi.dumpMem(bdi.getMaxNofLongsDump());
for (int i = 0; i < result.length; i++) {
logger.fine("Compare " + i + ": 0x"
+ Integer.toHexString(result[i]));
}
logger.info("Dump done");
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void button14() {
final int BASE_ADDR = 0x105624;
final int FIRST_VAL = 0xFF;
logger.info("write data");
try {
bdi.writeMem(BASE_ADDR, FIRST_VAL, 4);
int[] data = new int[bdi.getMaxNofLongsFill()];
for (int i = 0; i < data.length; i++) {
data[i] = i;
}
bdi.fillMem(data, data.length);
logger.info("Fill done");
logger.info("read back data");
int firstResult = bdi.readMem(BASE_ADDR, 4);
if (firstResult != FIRST_VAL) {
logger.warning("Error at 0: 0x"
+ Integer.toHexString(firstResult) + " instead of 0x"
+ Integer.toHexString(FIRST_VAL));
}
logger.fine("Compare first 0x" + Integer.toHexString(firstResult)
+ " == 0x" + Integer.toHexString(FIRST_VAL));
int[] result = bdi.dumpMem(bdi.getMaxNofLongsFill());
for (int i = 0; i < result.length; i++) {
if (data[i] != result[i]) {
logger.warning("Error at " + i + ": 0x"
+ Integer.toHexString(result[i]) + " instead of 0x"
+ Integer.toHexString(data[i]));
}
logger.fine("Compare " + i + ": 0x"
+ Integer.toHexString(result[i]) + " == 0x"
+ Integer.toHexString(data[i]));
}
logger.info("Dump done");
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void button15() {
logger.info("resetUSB()");
try {
USBDevice.reset();
Thread.sleep(500);
USBDevice.open();
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void button16() {
final int BASE_ADDR = 0x105624;
final int DATA = 0x00ff00ff;
final int OFFSET = (bdi.getMaxNofLongsFill() - 2) * 4;
final int LENGTH = 0x04;
final int DUMP_BASE = BASE_ADDR + (bdi.getMaxNofLongsFill() / 2) * 4;
try {
logger.info("REPLACE at the end");
logger.info("Fill first");
bdi.writeMem(BASE_ADDR, 0, 4);
int[] data = new int[bdi.getMaxNofLongsFill()];
for (int i = 0; i < data.length; i++) {
data[i] = i + 1;
}
bdi.fillMem(data, data.length);
logger.info("Fill second");
bdi.writeMem(BASE_ADDR + (bdi.getMaxNofLongsFill() + 1) * 4, 0, 4);
for (int i = 0; i < data.length; i++) {
data[i] = bdi.getMaxNofLongsFill() + i + 2;
}
bdi.fillMem(data, data.length);
logger.info("Dump from base: 0x" + Integer.toHexString(DUMP_BASE));
int firstInt = bdi.readMem(DUMP_BASE, 4);
int[] result = bdi.dumpMem(bdi.getMaxNofLongsFill());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
sb.append("0x" + Integer.toHexString(result[i]) + " ");
}
logger.info("Data: 0x" + Integer.toHexString(firstInt) + " "
+ sb.toString());
logger.info("writing byte " + (OFFSET / 4) + " to "
+ ((OFFSET / 4) + LENGTH) + " with 0x"
+ Integer.toHexString(DATA));
bdi.writeMem(BASE_ADDR + OFFSET, DATA, 4);
for (int i = 0; i < LENGTH; i++) {
data[i] = DATA;
}
bdi.fillMem(data, LENGTH);
logger.info((LENGTH + 1) + " bytes written");
logger.info("dump data from base: 0x"
+ Integer.toHexString(DUMP_BASE));
firstInt = bdi.readMem(DUMP_BASE, 4);
result = bdi.dumpMem(bdi.getMaxNofLongsFill());
sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
sb.append("0x" + Integer.toHexString(result[i]) + " ");
}
logger.info("Data: 0x" + Integer.toHexString(firstInt) + " "
+ sb.toString());
logger.info("Done");
} catch (BDIException e) {
e.printStackTrace();
} catch (USBException e) {
e.printStackTrace();
} catch (DispatchException e) {
e.printStackTrace();
}
}
public static void button17() {
logger.info("test read/write mem byte/word");
final int BASE_ADDR = 0x105624;
final int DATA = 0x12345678;
try {
logger.info("read 4 bytes at: 0x" + Integer.toHexString(BASE_ADDR)
+ ", value: 0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 4)));
logger.info("read 2 bytes at: 0x" + Integer.toHexString(BASE_ADDR)
+ ", value: 0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 2)));
logger.info("read 1 byte at: 0x" + Integer.toHexString(BASE_ADDR)
+ ", value: 0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 1)));
logger.info("write 1 byte at: 0x" + Integer.toHexString(BASE_ADDR)
+ ", value: 0x" + Integer.toHexString(DATA));
bdi.writeMem(BASE_ADDR, DATA, 1);
logger.info("read 4 bytes at: 0x" + Integer.toHexString(BASE_ADDR)
+ ", value: 0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 4)));
logger.info("write 2 byte at: 0x" + Integer.toHexString(BASE_ADDR)
+ ", value: 0x" + Integer.toHexString(DATA));
bdi.writeMem(BASE_ADDR, DATA, 2);
logger.info("read 4 bytes at: 0x" + Integer.toHexString(BASE_ADDR)
+ ", value: 0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 4)));
logger.info("write 4 byte at: 0x" + Integer.toHexString(BASE_ADDR)
+ ", value: 0x" + Integer.toHexString(DATA));
bdi.writeMem(BASE_ADDR, DATA, 4);
logger.info("read 4 bytes at: 0x" + Integer.toHexString(BASE_ADDR)
+ ", value: 0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 4)));
} catch (USBException e) {
e.printStackTrace();
} catch (DispatchException e) {
e.printStackTrace();
} catch (BDIException e) {
e.printStackTrace();
}
logger.info("test done");
}
private static void dump(int baseAddr, int size) throws USBException,
DispatchException, BDIException {
int dumpSize = 0;
if (size > 2) {
dumpSize = bdi.getMaxNofLongsFill();
} else {
dumpSize = bdi.getMaxNofBytesWordsFill();
}
logger.info("read " + size + " byte(s) at 0x"
+ Integer.toHexString(baseAddr) + ", value: "
+ Integer.toHexString(bdi.readMem(baseAddr, size)));
int[] result = bdi.dumpMem(dumpSize);
StringBuffer sb = new StringBuffer("data: ");
for (int i = 0; i < result.length; i++) {
sb.append("0x" + Integer.toHexString(result[i]) + " ");
}
logger.info(sb.toString());
}
private static void fill(int baseAddr, int size) throws USBException,
DispatchException, BDIException {
int fillSize = 0;
if (size > 2) {
fillSize = bdi.getMaxNofLongsFill();
} else {
fillSize = bdi.getMaxNofBytesWordsFill();
}
int[] data = new int[fillSize];
for (int i = 0; i < data.length; i++) {
data[i] = i;
}
logger.info("fill " + data.length + " integers with size " + size
+ " byte(s)");
bdi.writeMem(baseAddr, 0, size);
bdi.fillMem(data, data.length);
}
public static void button18() {
final int BASE_ADDR = 0x105624;
int[] data = new int[bdi.getMaxNofBytesWordsFill()];
for (int i = 0; i < data.length; i++) {
data[i] = i;
}
try {
IMCBTargetBoard imcb = new IMCBTargetBoard(bdi);
imcb.init();
fill(BASE_ADDR, 4);
// TODO: this does produce an error why???
imcb.init();
dump(BASE_ADDR, 4);
imcb.init();
fill(BASE_ADDR, 2);
imcb.init();
dump(BASE_ADDR, 2);
imcb.init();
fill(BASE_ADDR, 1);
imcb.init();
dump(BASE_ADDR, 1);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void button19() {
logger.info("test read/write register");
try {
int REG = 0x8;
int VALUE = 0x12345;
logger.info("test SysReg (ATEMP)");
bdi.writeSysReg(REG, VALUE);
int result = bdi.readSysReg(REG);
checkResult(VALUE, result);
REG = 0x5;
logger.info("test UserReg (D5)");
bdi.writeUserReg(REG, VALUE);
result = bdi.readUserReg(REG);
checkResult(VALUE, result);
REG = 0xD;
logger.info("test UserReg (A5)");
bdi.writeUserReg(REG, VALUE);
result = bdi.readUserReg(REG);
checkResult(VALUE, result);
// Does only work after LoadRam!
//
// REG = 0xFFFFFA00;
// logger.info("test ctrlReg (SIMCR)");
// bdi.writeMem(REG, VALUE, 4);
// result = bdi.readMem(REG, 4);
// checkResult(VALUE, result);
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void checkResult(int value, int result) {
if (value != result) {
logger.severe("value: 0x" + Integer.toHexString(value)
+ ", result: 0x" + Integer.toHexString(result));
} else {
logger.info("test ok: result: 0x" + Integer.toHexString(result));
}
}
public static void button20() {
final int BASE_ADDR = 0x01004E0;
try {
StringBuffer sb = new StringBuffer("0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 4)) + "\n");
sb.append("0x" + Integer.toHexString(bdi.readMem(BASE_ADDR + 4, 4))
+ "\n");
sb.append("0x" + Integer.toHexString(bdi.readMem(BASE_ADDR + 8, 4))
+ "\n");
logger.info(sb.toString());
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// public static void main(String[] args) {
// boolean testRunning = true;
//
// while (testRunning) {
// // testBdiTransaction();
// // reset_target();
// // freeze();
// // go();
// // System.out.println();
//
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
//
// }
}

View File

@@ -1,221 +0,0 @@
package ch.ntb.mcdp.bdi.test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import ch.ntb.mcdp.bdi.MPC555;
import ch.ntb.mcdp.usb.USBDevice;
import ch.ntb.usb.USBException;
public class BDI555App {
private Shell sShell = null; // @jve:decl-index=0:visual-constraint="10,10"
private Button button1 = null;
private Button button2 = null;
private Button button3 = null;
private Button button4 = null;
private Button button5 = null;
private Button button6 = null;
private Button button7 = null;
private Button button8 = null;
private Button button9 = null;
private Button button10 = null;
private Button button11 = null;
private Button button12 = null;
private Button button13 = null;
private Button button14 = null;
private Button button15 = null;
/**
* This method initializes sShell
*/
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setLayout(new RowLayout());
sShell.setSize(new org.eclipse.swt.graphics.Point(361, 108));
button1 = new Button(sShell, SWT.NONE);
button1.setText("testBdiTransaction");
button1
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button1();
}
});
button2 = new Button(sShell, SWT.NONE);
button2.setText("reset_target");
button2
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button2();
}
});
button3 = new Button(sShell, SWT.NONE);
button3.setText("go");
button3
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button3();
}
});
button4 = new Button(sShell, SWT.NONE);
button4.setText("break_");
button4
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button4();
}
});
button5 = new Button(sShell, SWT.NONE);
button5.setText("freeze");
button6 = new Button(sShell, SWT.NONE);
button6.setText("writeMem");
button6
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button6();
}
});
button7 = new Button(sShell, SWT.NONE);
button7.setText("readMem");
button8 = new Button(sShell, SWT.NONE);
button8.setText("readMemSeq");
button8
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button8();
}
});
button9 = new Button(sShell, SWT.NONE);
button9.setText("Button9");
button10 = new Button(sShell, SWT.NONE);
button10.setText("fastDownload");
button11 = new Button(sShell, SWT.NONE);
button11.setText("read/write Registers");
button12 = new Button(sShell, SWT.NONE);
button12.setText("Button12");
button12
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button12();
}
});
button13 = new Button(sShell, SWT.NONE);
button13.setText("Button13");
button13
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button13();
}
});
button14 = new Button(sShell, SWT.NONE);
button14.setText("Button14");
button14
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button14();
}
});
button15 = new Button(sShell, SWT.NONE);
button15.setText("Button15");
button15
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button15();
}
});
button11
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button11();
}
});
button10
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button10();
}
});
button9
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button9();
}
});
button7
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button7();
}
});
button5
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
BDI555test.button5();
}
});
}
public static void main(String[] args) {
BDI555App app = new BDI555App();
app.createSShell();
app.sShell.open();
Display display = app.sShell.getDisplay();
try {
USBDevice.open();
BDI555test.bdi = new MPC555(USBDevice.getDevice());
} catch (USBException e) {
e.printStackTrace();
return;
}
while (!app.sShell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
try {
USBDevice.close();
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@@ -1,648 +0,0 @@
package ch.ntb.mcdp.bdi.test;
import java.util.logging.Level;
import ch.ntb.mcdp.bdi.BDIException;
import ch.ntb.mcdp.bdi.MPC555;
import ch.ntb.mcdp.usb.DispatchException;
import ch.ntb.mcdp.utils.logger.LogUtil;
import ch.ntb.mcdp.utils.logger.McdpLogger;
import ch.ntb.usb.USBException;
public class BDI555test {
private static McdpLogger logger = LogUtil.ch_ntb_mcdp_bdi_test;
public static MPC555 bdi;
private static void testBdiTransaction() {
/*
// test bdi transaction
DataPacket result = null;
try {
// result = bdi.transfer(false, false, 0x00000000);
result = bdi.transfer(false, false, 0x7FD69BA6);
// result = bdi.transfer(false, false, 0x60000000);
} catch (USBException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (DispatchException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (result != null) {
System.out.println(result.toString());
}
*/
}
private static void reset_target() {
try {
bdi.reset_target();
// assign pin to Freeze output
bdi.writeMem(0x02FC000, 0x40000, 4);
// enable bus monitor, disable watchdog timer
bdi.writeMem(0x02FC004, 0x0FFFFFF83, 4);
// SCCR, switch off EECLK for download
bdi.writeMem(0x02FC280, 0x08121C100, 4);
logger.info("Is freeze asserted: " + bdi.isFreezeAsserted());
} catch (USBException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (DispatchException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void freeze() {
try {
logger.info("isFreezeAsserted: " + bdi.isFreezeAsserted());
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void break_() {
try {
bdi.break_();
logger.info("break");
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void go() {
try {
bdi.go();
logger.info("go");
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void writeMem() {
final int BASE_ADDR = 0x800000, VALUE = 0x123456;
try {
bdi.writeMem(BASE_ADDR, VALUE, 4);
logger.info("writeMem: BASE_ADDR = 0x"
+ Integer.toHexString(BASE_ADDR) + ", value = 0x"
+ Integer.toHexString(VALUE));
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void readMem() {
final int BASE_ADDR = 0x800000;
try {
StringBuffer sb = new StringBuffer("readMem: BASE_ADDR = 0x"
+ Integer.toHexString(BASE_ADDR) + ", value = ");
for (int i = 0; i < 10; i++) {
sb.append("0x"
+ Integer
.toHexString(bdi.readMem(BASE_ADDR + i * 4, 4))
+ "\n");
}
logger.info(sb.toString());
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void fastDownload() {
final int BASE_ADDR = 0x800000;
int[] testData = new int[bdi.getMaxNofWordsFastDownload()];
for (int i = 0; i < testData.length; i++) {
testData[i] = i;
}
try {
logger.info("fastDownload at BASE_ADDR = 0x"
+ Integer.toHexString(BASE_ADDR) + ", length = "
+ bdi.getMaxNofWordsFastDownload());
bdi.startFastDownload(BASE_ADDR);
bdi.fastDownload(testData, bdi.getMaxNofWordsFastDownload());
bdi.stopFastDownload();
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void readMemSeq() {
final int BASE_ADDR = 0x800000;
try {
StringBuffer sb = new StringBuffer("readMemSeq: BASE_ADDR = 0x"
+ Integer.toHexString(BASE_ADDR) + "\n" + 0 + "\tData: 0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 4)) + "\n");
for (int i = 1; i < 120; i++) {
sb.append(i + "\tData: 0x"
+ Integer.toHexString(bdi.readMemSeq(4)) + "\n");
}
logger.info(sb.toString());
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void nop() throws USBException, DispatchException,
BDIException {
// nop
System.out.println("nop");
//int data = bdi.transferAndParse35(true, true, 0x00000000);
//System.out.println("0x" + Integer.toHexString(data));
}
public static void button1() {
System.out.println("testBdiTransaction()");
testBdiTransaction();
}
public static void button2() {
reset_target();
}
public static void button3() {
go();
}
public static void button4() {
break_();
}
public static void button5() {
freeze();
}
public static void button6() {
writeMem();
}
public static void button7() {
readMem();
}
public static void button8() {
readMemSeq();
}
public static void button9() {
final int SPR = 158;
final int VALUE = 0x12345;
try {
int result = bdi.readSPR(SPR);
logger.info("readSPR(" + SPR + ") = 0x"
+ Integer.toHexString(result));
bdi.writeSPR(SPR, VALUE);
logger.info("writeSPR(" + SPR + ", 0x" + Integer.toHexString(VALUE)
+ ")");
result = bdi.readSPR(SPR);
logger.info("readSPR(" + SPR + ") = 0x"
+ Integer.toHexString(result));
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// logger.info("not implemented!");
// logger.info("hard_reset()");
// try {
// bdi.hard_reset();
// } catch (USBException e) {
// e.printStackTrace();
// } catch (DispatchException e) {
// e.printStackTrace();
// } catch (BDIException e) {
// e.printStackTrace();
// }
}
public static void button10() {
// fastDownload();
button12();
}
public static void button11() {
Level oldLevel = LogUtil.ch_ntb_mcdp_bdi.getLevel();
LogUtil.setLevel(LogUtil.ch_ntb_mcdp_bdi, Level.ALL);
try {
logger.info("test SPR");
// valid spr registers:
// CMPA<50>CMPD SPR 144 <20> SPR 147
// CMPE<50>CMPF SPR 152, 153
// CMPG<50>CMPH SPR 154, 155
// ICTRL SPR 158
// LCTRL1 SPR 156
// LCTRL2 SPR 157
// COUNTA SPR 150
// COUNTB SPR 151
// ECR SPR 148
// DER SPR 149
int REG = 152;
int VALUE = 0x12345;
bdi.writeSPR(REG, VALUE);
int result = bdi.readSPR(REG);
checkResult(VALUE, result);
logger.info("test GPR");
REG = 5;
bdi.writeGPR(REG, VALUE);
result = bdi.readGPR(REG);
checkResult(VALUE, result);
logger.info("test FPR");
int TMP_MEM_ADDR = 0x800000;
long LONG_VAL = 0x12345012345L;
bdi.writeFPR(REG, TMP_MEM_ADDR, LONG_VAL);
long fprResult = bdi.readFPR(REG, TMP_MEM_ADDR);
if (fprResult != LONG_VAL) {
logger.severe("value: 0x" + Long.toHexString(LONG_VAL)
+ ", result: 0x" + Long.toHexString(fprResult));
} else {
logger
.info("test ok: result: 0x"
+ Long.toHexString(fprResult));
}
logger.info("test MSR");
bdi.writeMSR(VALUE);
result = bdi.readMSR();
checkResult(VALUE, result);
logger.info("test CR");
bdi.writeCR(VALUE);
result = bdi.readCR();
checkResult(VALUE, result);
logger.info("test CtrlReg");
int MEM_ADDR = 0x2FC100;
bdi.writeMem(MEM_ADDR, VALUE, 4);
result = bdi.readMem(MEM_ADDR, 4);
checkResult(VALUE, result);
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LogUtil.setLevel(LogUtil.ch_ntb_mcdp_bdi, oldLevel);
}
private static void checkResult(int value, int result) {
if (value != result) {
logger.severe("value: 0x" + Integer.toHexString(value)
+ ", result: 0x" + Integer.toHexString(result));
} else {
logger.info("test ok: result: 0x" + Integer.toHexString(result));
}
}
public static void button12() {
final int BASE_ADDR = 0x3f9bf0;
int[] data = new int[bdi.getMaxNofWordsFastDownload()];
data[0] = 0x9421ffb0;
data[1] = 0xbf810040;
data[2] = 0x3be10038;
data[3] = 0x3bc30000;
data[4] = 0x3ba40000;
data[5] = 0x3c600030;
data[6] = 0x38836102;
data[7] = 0x38a08000;
data[8] = 0xb0a40000;
data[9] = 0x2c9e0000;
data[10] = 0x4085004c;
data[11] = 0x3cc00030;
data[12] = 0x38e66100;
data[13] = 0x39000000;
data[14] = 0xb1070000;
data[15] = 0x1f9d2710;
data[16] = 0x339cffff;
data[17] = 0x2f1c0000;
data[18] = 0x4199fff8;
data[19] = 0x3d200030;
data[20] = 0x39496100;
data[21] = 0x39608000;
data[22] = 0xb16a0000;
data[23] = 0x1f9d2710;
data[24] = 0x339cffff;
data[25] = 0x2f9c0000;
data[26] = 0x419dfff8;
data[27] = 0x33deffff;
data[28] = 0x4280ffb4;
data[29] = 0x383fffc8;
data[30] = 0xbb810040;
data[31] = 0x38210050;
data[32] = 0x4e800020;
data[33] = 0x9421ffb0;
data[34] = 0x7c0802a6;
data[35] = 0x9001004c;
data[36] = 0xbfc10044;
data[37] = 0x3be10038;
data[38] = 0x90410014;
data[39] = 0x7fcc42e6;
data[40] = 0x387e0000;
data[41] = 0x42800008;
data[42] = 0x7fe00008;
data[43] = 0x383fffc8;
data[44] = 0xbbc10044;
data[45] = 0x8001004c;
data[46] = 0x7c0803a6;
data[47] = 0x38210050;
data[48] = 0x4e800020;
data[49] = 0x9421ffb8;
data[50] = 0x7c0802a6;
data[51] = 0x90010044;
data[52] = 0xbfa10038;
data[53] = 0x3be10038;
data[54] = 0x90410014;
data[55] = 0x3bc30000;
data[56] = 0x3ba40000;
data[57] = 0x4bffffa1;
data[58] = 0x90620018;
data[59] = 0x81820018;
data[60] = 0x3c60000f;
data[61] = 0x38834240;
data[62] = 0x7cac23d7;
data[63] = 0x40800008;
data[64] = 0x30a5ffff;
data[65] = 0x90be0000;
data[66] = 0x80c20018;
data[67] = 0x38e003e8;
data[68] = 0x7d063bd7;
data[69] = 0x40800008;
data[70] = 0x3108ffff;
data[71] = 0x392003e8;
data[72] = 0x7d484bd6;
data[73] = 0x7d4a49d6;
data[74] = 0x7d4a4011;
data[75] = 0x40800008;
data[76] = 0x314a03e8;
data[77] = 0xb15d0000;
data[78] = 0x383fffc8;
data[79] = 0xbba10038;
data[80] = 0x80010044;
data[81] = 0x7c0803a6;
data[82] = 0x38210048;
data[83] = 0x4e800020;
data[84] = 0x9421ff98;
data[85] = 0xbf21004c;
data[86] = 0x3be10038;
data[87] = 0x3bc30000;
data[88] = 0x3ba40000;
data[89] = 0x3b7e0000;
data[90] = 0x3b800000;
data[91] = 0x7c9be800;
data[92] = 0x40840070;
data[93] = 0xa33b0000;
data[94] = 0x7f9ccb78;
data[95] = 0x3b40000f;
data[96] = 0x578b0001;
data[97] = 0x4182000c;
data[98] = 0x6b8c8000;
data[99] = 0x6d9c0810;
data[100] = 0x57830801;
try {
StringBuffer sb = new StringBuffer("dumpData: BASE_ADDR = 0x"
+ Integer.toHexString(BASE_ADDR) + "\n" + 0 + "\tData: 0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 4)) + "\n");
for (int i = 1; i < 120; i++) {
sb.append(i + "\tData: 0x"
+ Integer.toHexString(bdi.readMemSeq(4)) + "\n");
}
logger.info(sb.toString());
logger.info("fastDownload at BASE_ADDR = 0x"
+ Integer.toHexString(BASE_ADDR) + ", length = "
+ bdi.getMaxNofWordsFastDownload());
bdi.startFastDownload(BASE_ADDR);
bdi.fastDownload(data, bdi.getMaxNofWordsFastDownload());
bdi.stopFastDownload();
sb = new StringBuffer("dumpData: BASE_ADDR = 0x"
+ Integer.toHexString(BASE_ADDR) + "\n" + 0 + "\tData: 0x"
+ Integer.toHexString(bdi.readMem(BASE_ADDR, 4)) + "\n");
for (int i = 1; i < 120; i++) {
sb.append(i + "\tData: 0x"
+ Integer.toHexString(bdi.readMemSeq(4)) + "\n");
}
logger.info(sb.toString());
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static int[] getSampleData(int length) {
int[] data = new int[length];
for (int i = 0; i < data.length; i++) {
data[i] = (int) (Math.random() * Integer.MAX_VALUE);
}
return data;
}
private static void testFill(int baseAddr) throws USBException,
DispatchException, BDIException {
// int length = (int) (1 + Math.random()
// * (bdi.getMaxNofWordsFastDownload() - 1));
int length = 101;
int[] data = getSampleData(length);
logger.info("BaseAddr: 0x" + Integer.toHexString(baseAddr)
+ ", dataLength: " + data.length);
// download data
bdi.startFastDownload(baseAddr);
bdi.fastDownload(data, data.length);
bdi.stopFastDownload();
// read back data
int[] compare = new int[data.length];
compare[0] = bdi.readMem(baseAddr, 4);
for (int i = 1; i < compare.length; i++) {
compare[i] = bdi.readMemSeq(4);
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < compare.length; i++) {
if (compare[i] != data[i]) {
sb.append("Error at " + i + ", addr: 0x"
+ Integer.toHexString(baseAddr + i * 4)
+ ", expected: 0x" + Integer.toHexString(data[i])
+ ", read: " + Integer.toHexString(compare[i]) + "\n");
}
}
if (sb.length() > 0) {
logger.warning(sb.toString());
}
}
public static void runFillTests(int nofRuns) {
try {
// BR0 = 01000003H(* 16777219*)
// OR0 = 0FFC00020H(* -4194272*)
// BR1 = 0800003H(* 8388611*)
// OR1 = 0FFE00020H(* -2097120*)
// DMBR = 03H(* 3*)
// DMOR = 07E000000H(* 2113929216*)
// ICTRL = 07H(* 7*)
// RSR = 00H(* 0*)
// DER = 031C7400FH(* 835141647*)
// SRR1 = 03802H(* 14338*)
bdi.writeMem(0x2FC100, 0x01000003, 4);
bdi.writeMem(0x2FC104, 0x0FFC00020, 4);
bdi.writeMem(0x2FC108, 0x0800003, 4);
bdi.writeMem(0x2FC10C, 0x0FFE00020, 4);
bdi.writeMem(0x2FC140, 3, 4);
bdi.writeMem(0x2FC144, 0x7E000000, 4);
bdi.writeSPR(158, 0x07);
bdi.writeMem(0x2FC288, -1, 4);
bdi.writeSPR(149, 0x031C7400F);
bdi.writeSPR(27, 0x03802);
for (int i = 0; i < nofRuns; i++) {
testFill(0x03F9800);
testFill(0x03F9BF0);
testFill(0x03F9D84);
testFill(0x03F9AA8);
testFill(0x03F9AE0);
testFill(0x0);
testFill(0x0594);
testFill(0x0D94);
testFill(0x01EA4);
testFill(0x0802000);
testFill(0x0802C10);
testFill(0x0803480);
}
} catch (USBException e) {
e.printStackTrace();
} catch (DispatchException e) {
e.printStackTrace();
} catch (BDIException e) {
e.printStackTrace();
}
}
public static void button13() {
logger.info("extensive fill test");
runFillTests(100);
logger.info("test done");
}
public static void button14() {
try {
logger.info("start FillTest");
FillTest.doFill();
logger.info("start compare");
FillTest.doCompare();
logger.info("FillTest done");
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void button15() {
try {
logger.info("start FillShort");
FillTest.doFill2();
logger.info("start compare");
FillTest.doCompare();
logger.info("FillShort done");
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@@ -1,135 +0,0 @@
package ch.ntb.mcdp.bdi.test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import ch.ntb.mcdp.utils.intelHex.IntelHex;
import ch.ntb.mcdp.bdi.BDIException;
import ch.ntb.mcdp.bdi.MC68332;
import ch.ntb.mcdp.usb.DispatchException;
import ch.ntb.mcdp.utils.logger.LogUtil;
import ch.ntb.mcdp.utils.logger.McdpLogger;
import ch.ntb.usb.USBException;
public class Dump332 {
private static final String pathHex = "D:\\temp\\332dump.ihx",
pathBin = "D:\\temp\\332dump.bin";
private static McdpLogger logger = LogUtil.ch_ntb_mcdp_bdi_test;
public static MC68332 bdi;
// CromBase = 0H;
// CromSize = 100000H (* 1 MByte kByte *);
// CromCSBAR = CromBase DIV 256 + 7;
//
// CramBase = 100000H;
// CramSize = 040000H; (* 256 kByte *)
// CramCSBAR = CramBase DIV 256 + 5;
public static void dumpToHex() {
// IntelHex.setFileName(fileName);
IntelHex.openWrite(pathHex);
// Read Ram
final int BASE_ADDR = 0x100000;
final int MEMORY_SIZE = 0x04000;
int currentAddress = BASE_ADDR, firstResult;
int[] result;
int hexDataLength = 2 * bdi.getMaxNofLongsFill() + 2, hexDataIndex = 0;
short[] hexData = new short[hexDataLength];
logger.info("dumpToHex: memory from BASE_ADDR: 0x"
+ Integer.toHexString(BASE_ADDR) + ", size = 0x"
+ Integer.toHexString(MEMORY_SIZE));
try {
// setup base address
firstResult = bdi.readMem(currentAddress, 4);
hexData[hexDataIndex++] = (short) (firstResult / 0x10000);
hexData[hexDataIndex++] = (short) firstResult;
currentAddress += 4;
while (currentAddress < BASE_ADDR + MEMORY_SIZE) {
result = bdi.dumpMem(bdi.getMaxNofLongsFill());
int i;
for (i = 0; i < result.length; i++) {
hexData[hexDataIndex + i * 2] = (short) (result[i] / 0x10000);
hexData[hexDataIndex + i * 2 + 1] = (short) result[i];
}
IntelHex.writeDataBlock(currentAddress, hexDataIndex + i * 2,
hexData);
currentAddress += hexDataIndex + i * 2;
hexDataIndex = 0;
}
IntelHex.close();
logger.info("Dump finished");
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void write(OutputStream os, int data) throws IOException {
os.write((byte) ((data / 0x1000000) & 0xFF));
os.write((byte) ((data / 0x10000) & 0xFF));
os.write((byte) ((data / 0x100) & 0xFF));
os.write((byte) ((data) & 0xFF));
}
public static void dumpToBin() {
// Read Ram
final int BASE_ADDR = 0x100000;
final int MEMORY_SIZE = 0x04000;
int currentAddress = BASE_ADDR, firstResult;
int[] result;
logger.info("dumpToBin: memory from BASE_ADDR: 0x"
+ Integer.toHexString(BASE_ADDR) + ", size = 0x"
+ Integer.toHexString(MEMORY_SIZE));
try {
String path = pathBin.substring(0, pathBin.lastIndexOf('\\'));
File pathFile = new File(path);
pathFile.mkdirs();
File f = new File(pathBin);
f.createNewFile();
OutputStream os = new FileOutputStream(f);
// setup base address
firstResult = bdi.readMem(currentAddress, 4);
write(os, firstResult);
currentAddress += 4;
while (currentAddress < BASE_ADDR + MEMORY_SIZE) {
result = bdi.dumpMem(bdi.getMaxNofLongsFill());
for (int i = 0; i < result.length; i++) {
write(os, result[i]);
}
currentAddress += result.length * 4;
}
logger.info("Dump finished");
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DispatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BDIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,232 +0,0 @@
package ch.ntb.mcdp.dict;
/**
* Representation of a register.
*
* @author schlaepfer
*/
/**
* @author schlaepfer
*
*/
public abstract class Register {
public enum Accessmode {
none, supervisor, user, test
};
public enum Accessattr {
none, readonly, writeonly
};
private static final String INIT_STRING = "***";
/**
* Register specific type values. <br>
* The index of each type in the types array represents its numeric value.
* When the register is read from an xml file, its type is converted from a
* string (xml file) to an integer (index of types field). Therefore each
* type in the corresponding xml file must be included in the type array.<br>
* The type field must be initialised in the <code>static { }</code>
* section of the subclass.
*/
protected static String[] types = null;
/**
* Menemoic of the register. Registers are identified by this value.
*/
private String mnemonic = INIT_STRING;
/**
* Alternative mnemonic of the register
*/
private String altmnemonic = INIT_STRING;
/**
* Register specific type
*/
private int type;
/**
* Address or a register specific value (e.g. BDI-identifier)
*/
private int value;
/**
* Size in bytes (width)
*/
private int size;
/**
* A string description of the register
*/
private String description = "";
/**
* The register access mode
*/
private Accessmode accessmode = Accessmode.none;
/**
* The register access attribute
*/
private Accessattr accessattr = Accessattr.none;
/**
* @return the mnemonic of this register
*/
public String getMnemonic() {
return mnemonic;
}
/**
* Set the mnemonic of this register
*
* @param name
*/
public void setMnemonic(String name) {
this.mnemonic = name;
}
/**
* @return alternative mnemonic of the register
*/
public String getAltmnemonic() {
return altmnemonic;
}
/**
* Set the alternative name of the register.
*
* @param altname
*/
public void setAltmnemonic(String altname) {
this.altmnemonic = altname;
}
/**
* @return the register description
*/
public String getDescription() {
return description;
}
/**
* Set the register description.
*
* @param description
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return the size in bytes (width)
*/
public int getSize() {
return size;
}
/**
* Set the size in bytes (width)
*
* @param size
*/
public void setSize(int size) {
this.size = size;
}
/**
* @return the type of the register. This is the index of the static
* <code>types</code> String array.
*/
public int getType() {
return type;
}
/**
* Set the type of the register. This is the index of the static
* <code>types</code> String array.
*
* @param type
*/
public void setType(int type) {
this.type = type;
}
/**
* @return the address or a register specific value (e.g. BDI-identifier)
*/
public int getValue() {
return value;
}
/**
* Set the address or a register specific value (e.g. BDI-identifier).
*
* @param value
*/
public void setValue(int value) {
this.value = value;
}
/**
* @return true if a mnemonic was set and the size is valid (size > 0), else
* false
*/
public boolean isValid() {
if ((mnemonic == INIT_STRING) || (size <= 0))
return false;
return true;
}
@Override
public String toString() {
return new String(mnemonic + "\t" + altmnemonic + "\t" + types[type]
+ "\t0x" + Integer.toHexString(value) + "\t" + size + "\t"
+ description);
}
/**
* Get the register specific type strings. This value has to be initialised
* in the <code>static</code> section of the derived Register class as
* this is Register specific.
*
* @return types strings
*/
public static String[] getTypes() {
return types;
}
/**
* @return the access attributes of the register
*/
public Accessattr getAccessattr() {
return accessattr;
}
/**
* Set the access attribute of the register
*
* @param accessattr
*/
public void setAccessattr(Accessattr accessattr) {
this.accessattr = accessattr;
}
/**
* @return the access mode of this register
*/
public Accessmode getAccessmode() {
return accessmode;
}
/**
* Set the access mode of this register
*
* @param accessmode
*/
public void setAccessmode(Accessmode accessmode) {
this.accessmode = accessmode;
}
}

View File

@@ -1,260 +0,0 @@
package ch.ntb.mcdp.dict;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.LinkedList;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
public abstract class RegisterDict extends DefaultHandler {
private static final long serialVersionUID = -582382284126896830L;
private Class<? extends Register> regClass;
private Method regClassGetTypesMethod;
private static final String GetTypes_METHOD_NAME = "getTypes";
private LinkedList registers;
private String[] types;
private static final String ELEMENT_REGISTER = "register";
private static final String ELEMENT_DESCRIPTION = "description";
private static final String ATTR_MNEMONIC = "mnemonic";
private static final String ATTR_ALTMNEMONIC = "altmnemonic";
private static final String ATTR_TYPE = "type";
private static final String ATTR_VALUE = "value";
private static final String ATTR_SIZE = "size";
private static final String ATTR_ACCESSMODE = "accessmode";
private static final String ATTR_ACCESSATTR = "accessattr";
private Register reg;
private StringBuffer cdata;
/**
* Default constructor which takes the Class object from a
* <code>Register</code> subclass as argument. The registerDict will be of
* this Register-type.<br>
* An example:<br>
* MPC555Register extends Register -> use <code>MPC555Register.class</code>
* as parameter.
*
* @param registerClass
* subclass of Register
*/
protected RegisterDict(Class<? extends Register> registerClass) {
this.regClass = registerClass;
try {
this.regClassGetTypesMethod = regClass.getMethod(
GetTypes_METHOD_NAME, (Class[]) null);
this.regClass.newInstance();
this.types = (String[]) regClassGetTypesMethod.invoke(
(Object[]) null, (Object[]) null);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
this.registers = new LinkedList();
}
private int convertType(String typeStr) throws SAXException {
for (int index = 0; index < types.length; index++) {
if (typeStr.equals(types[index])) {
return index;
}
}
throw new SAXException("invalid register definition: " + typeStr);
}
private int parseInt(String s) {
if (s == "")
return 0;
if (s.indexOf('x') > 0) {
// is hex number
if (s.length() <= 2) { // exception for "0x"
throw new NumberFormatException("string too short: " + s);
}
if ((s.length() > 10)) { // exception for e.g. 0x112345678
throw new NumberFormatException("number too large: " + s);
}
// check if string too long (max
return (int) Long.parseLong(s.substring(s.indexOf('x') + 1, s
.length()), 16);
} else {
// is decimal number
return Integer.parseInt(s);
}
}
/**
* Adds the registers from the specified xml-file to the register
* dictionary. <br>
* The xml-file must be structured according to
* <code>registerDictionary.dtd</code>. The dtd-file must be adapted to
* the type values specific to this register. Include
* <code><!DOCTYPE registerDefinitions SYSTEM "registerDictionary.dtd"></code>
* in your xml file.
*
* @param xmlPathname
* path to the xml file
* @throws IOException
* throws an IOException if the file is not found
* @throws SAXException
* @throws ParserConfigurationException
* @throws ParserConfigurationException
* throws an ParserConfigurationException if the SAX parser
* can't be configured
* @throws SAXException
* throws an SAXException if the file could not be successfully
* parsed
*/
public void addRegistersFromFile(String xmlPathname) throws IOException,
ParserConfigurationException, SAXException {
// reset temporary register variable
reg = null;
// Use the default (non-validating) parser
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(new File(xmlPathname), this);
}
/**
* Print a list of Registers to standard out.
*/
public void printRegisters() {
System.out
.println("******************** register dictionary *********************");
System.out
.println("Mnemonic\tAltmnemonic\tType\tAddress\tSize\tDescription");
System.out
.println("**************************************************************");
for (Iterator i = registers.iterator(); i.hasNext();) {
Register r = (Register) i.next();
System.out.println(r.toString());
}
System.out
.println("**************************************************************");
}
/**
* Get a register by its name.
*
* @param name
* the register name
* @return register on null if no register is found
*/
public Register getRegister(String name) {
for (Iterator i = registers.iterator(); i.hasNext();) {
Register r = (Register) i.next();
if (r.getMnemonic().equals(name) || r.getAltmnemonic().equals(name)) {
return r;
}
}
return null;
}
// ===========================================================
// SAX DocumentHandler methods
// ===========================================================
public void startDocument() throws SAXException {
}
public void endDocument() throws SAXException {
}
public void startElement(String namespaceURI, String lName, // local name
String qName, // qualified name
Attributes attrs) throws SAXException {
if (qName.equals(ELEMENT_REGISTER)) {
if (attrs != null) {
// instantiate new register
try {
reg = (Register) regClass.newInstance();
} catch (Exception e) {
throw new SAXException(e.getMessage());
}
for (int i = 0; i < attrs.getLength(); i++) {
String attr_qName = attrs.getQName(i);
String attr_value = attrs.getValue(i);
if (attr_qName.equals(ATTR_MNEMONIC)) {
reg.setMnemonic(attr_value);
} else if (attr_qName.equals(ATTR_ALTMNEMONIC)) {
reg.setAltmnemonic(attr_value);
} else if (attr_qName.equals(ATTR_TYPE)) {
reg.setType(convertType(attr_value));
} else if (attr_qName.equals(ATTR_SIZE)) {
reg.setSize(parseInt(attr_value));
} else if (attr_qName.equals(ATTR_VALUE)) {
reg.setValue(parseInt(attr_value));
} else if (attr_qName.equals(ATTR_ACCESSMODE)) {
reg.setAccessmode(Register.Accessmode
.valueOf(attr_value));
} else if (attr_qName.equals(ATTR_ACCESSATTR)) {
reg.setAccessattr(Register.Accessattr
.valueOf(attr_value));
}
}
} else {
throw new SAXException("attributes expected");
}
} else if (qName.equals(ELEMENT_DESCRIPTION)) {
// reset the cdata for descriptions
cdata = new StringBuffer();
}
}
@SuppressWarnings("unchecked")
public void endElement(String namespaceURI, String sName, // simple
// name
String qName // qualified name
) throws SAXException {
if (qName.equals(ELEMENT_DESCRIPTION)) {
reg.setDescription(cdata.toString().trim());
}
if (reg != null) {
registers.add(reg);
reg = null;
}
}
public void characters(char buf[], int offset, int len) throws SAXException {
int startOffset = offset;
while ((offset < startOffset + len) && (buf[offset] <= ' ')) {
offset++;
}
len -= offset - startOffset;
while ((len > 0) && (buf[offset + len - 1] <= ' ')) {
len--;
}
cdata.append(buf, offset, len);
}
// ===========================================================
// SAX ErrorHandler methods
// ===========================================================
// treat validation errors as fatal
public void error(SAXParseException e) throws SAXParseException {
throw e;
}
// dump warnings too
public void warning(SAXParseException err) throws SAXParseException {
System.out.println("** Warning" + ", line " + err.getLineNumber()
+ ", uri " + err.getSystemId());
System.out.println(" " + err.getMessage());
}
}

View File

@@ -1,32 +0,0 @@
package ch.ntb.mcdp.dict.test;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import ch.ntb.mcdp.mc68332.MC68332RegisterDict;
public class Test332Dict {
private static final String PATH_TO_REGISTER_FILE = "resources/targets/mc68332/registerDictionary.xml";
public static void main(String[] args) {
MC68332RegisterDict regdict = new MC68332RegisterDict();
try {
regdict.addRegistersFromFile(PATH_TO_REGISTER_FILE);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
regdict.printRegisters();
}
}

View File

@@ -1,29 +0,0 @@
package ch.ntb.mcdp.dict.test;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import ch.ntb.mcdp.mpc555.MPC555RegisterDict;
public class Test555Dict {
private static final String PATH_TO_REGISTER_FILE = "resources/targets/mpc555/registerDictionary.xml";
public static void main(String[] args) {
MPC555RegisterDict regdict = new MPC555RegisterDict();
try {
regdict.addRegistersFromFile(PATH_TO_REGISTER_FILE);
} catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
regdict.printRegisters();
}
}

View File

@@ -1,94 +0,0 @@
package ch.ntb.mcdp.mc68332;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import ch.ntb.mcdp.bdi.BDIException;
import ch.ntb.mcdp.bdi.MC68332;
import ch.ntb.mcdp.usb.DispatchException;
import ch.ntb.mcdp.utils.logger.LogUtil;
import ch.ntb.mcdp.utils.logger.McdpLogger;
import ch.ntb.usb.USBException;
public class IMCBTargetBoard {
private static final McdpLogger logger = LogUtil.ch_ntb_mcdp_mc68332;
private final static String dictionaryPath = "resources/targets/mc68332/registerDictionary.xml";
private static MC68332RegisterDict regDict = new MC68332RegisterDict();
private MC68332 bdi;
public IMCBTargetBoard(MC68332 bdi) {
this.bdi = bdi;
}
public void writeRegister(String name, int value) throws USBException,
DispatchException, BDIException {
logger.info("writeRegister: " + name + ", value: 0x"
+ Integer.toHexString(value));
MC68332Register r = (MC68332Register) regDict.getRegister(name);
switch (r.getType()) {
case MC68332Register.CtrlReg:
bdi.writeMem(r.getValue(), value, r.getSize());
break;
case MC68332Register.SysReg:
bdi.writeSysReg(r.getValue(), value);
break;
case MC68332Register.UserReg:
bdi.writeUserReg(r.getValue(), value);
break;
}
}
public int readRegister(String name) throws USBException,
DispatchException, BDIException {
logger.info("readRegister: " + name);
MC68332Register r = (MC68332Register) regDict.getRegister(name);
switch (r.getType()) {
case MC68332Register.CtrlReg:
return bdi.readMem(r.getValue(), r.getSize());
case MC68332Register.SysReg:
return bdi.readSysReg(r.getValue());
case MC68332Register.UserReg:
return bdi.readUserReg(r.getValue());
}
return -1;
}
public void init() throws USBException, DispatchException, BDIException,
IOException, ParserConfigurationException, SAXException {
logger.info("reading dictionary file from " + dictionaryPath);
regDict.addRegistersFromFile(dictionaryPath);
bdi.reset_target();
// regDict.printRegisters();
writeRegister("SR", 0x2700);
writeRegister("SFC", 0x05);
writeRegister("DFC", 0x05);
writeRegister("VBR", 0x100000);
writeRegister("SIMCR", 0x0404F);
writeRegister("SYNCR", 0x7F80);
writeRegister("SYPCR", 0x04);
writeRegister("CSPAR0", 0x03FF);
writeRegister("CSPAR1", 0x01);
writeRegister("CSBARBT", 0x07);
writeRegister("CSORBT", 0x06830);
writeRegister("CSBAR0", 0x07);
writeRegister("CSOR0", 0x07430);
writeRegister("CSBAR1", 0x01005);
writeRegister("CSOR1", 0x06C30);
writeRegister("CSBAR2", 0x01005);
writeRegister("CSOR2", 0x05030);
writeRegister("CSBAR3", 0x01005);
writeRegister("CSOR3", 0x03030);
}
}

View File

@@ -1,28 +0,0 @@
package ch.ntb.mcdp.mc68332;
import ch.ntb.mcdp.dict.Register;
/**
* Representation of a MC68332 Register
*
* For system and user registers the <code>value</code> value is used as BDI
* specific identifier (code specific to each register from the Technical
* Reference Manual).
*
* @author schlaepfer
*
*/
public class MC68332Register extends Register {
// Register Types
static {
types = new String[] { "UserReg", "SysReg", "CtrlReg" };
}
static final int UserReg = 0;
static final int SysReg = 1;
static final int CtrlReg = 2;
}

View File

@@ -1,10 +0,0 @@
package ch.ntb.mcdp.mc68332;
import ch.ntb.mcdp.dict.RegisterDict;
public class MC68332RegisterDict extends RegisterDict {
public MC68332RegisterDict() {
super(MC68332Register.class);
}
}

View File

@@ -1,33 +0,0 @@
package ch.ntb.mcdp.mpc555;
import ch.ntb.mcdp.dict.Register;
/**
* Representation of a MPC555 Register
*
* @author schlaepfer
*
*/
public class MPC555Register extends Register {
// Register Types
static {
types = new String[] { "GPR", "FPR", "SPR", "MSR", "CR", "FPSCR",
"CtrlReg" };
}
static final int GPR = 0;
static final int FPR = 1;
static final int SPR = 2;
static final int MSR = 3;
static final int CR = 4;
static final int FPSCR = 5;
static final int CtrlReg = 6;
}

View File

@@ -1,10 +0,0 @@
package ch.ntb.mcdp.mpc555;
import ch.ntb.mcdp.dict.RegisterDict;
public class MPC555RegisterDict extends RegisterDict {
public MPC555RegisterDict() {
super(MPC555Register.class);
}
}

View File

@@ -1,45 +0,0 @@
package ch.ntb.mcdp.system.memMap;
import java.util.LinkedList;
public class Device {
private String type;
private int width;
private int size = -1;
private MemAttributes attr;
LinkedList<Segment> segments;
Device(String type, int width) {
this.type = type;
this.width = width;
this.attr = new MemAttributes();
this.size = -1;
segments = new LinkedList<Segment>();
}
public String getType() {
return type;
}
public int getWidth() {
return width;
}
public MemAttributes getAttributes() {
return attr;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
}

View File

@@ -1,82 +0,0 @@
package ch.ntb.mcdp.system.memMap;
/**
* Attributes for <code>Device</code> and <code>Segment</code> objects.<br>
* Use the predefined constants to set or unset an attribute.
*
* @author schlaepfer
*
*/
public class MemAttributes {
public static int NOF_ATTRIBUTES = 8;
public static int read = 0, write = 1, const_ = 2, code = 3, var = 4,
sysconst = 5, heap = 6, stack = 7;
private boolean[] values = new boolean[NOF_ATTRIBUTES];
MemAttributes() {
for (int i = 0; i < values.length; i++) {
values[i] = false;
}
}
public void set(int index) {
values[index] = true;
}
public void unset(int index) {
values[index] = false;
}
public boolean isSet(int index) {
return values[index];
}
public boolean isReadSet() {
return values[read];
}
public boolean isWriteSet() {
return values[write];
}
public boolean isConstSet() {
return values[const_];
}
public boolean isCodeSet() {
return values[code];
}
public boolean isVarSet() {
return values[var];
}
public boolean isSysconstSet() {
return values[sysconst];
}
public boolean isHeapSet() {
return values[heap];
}
public boolean isStackSet() {
return values[stack];
}
public void reset() {
for (int i = 0; i < values.length; i++) {
values[i] = false;
}
}
public MemAttributes clone() {
MemAttributes at = new MemAttributes();
for (int i = 0; i < NOF_ATTRIBUTES; i++) {
at.values[i] = values[i];
}
return at;
}
}

View File

@@ -1,407 +0,0 @@
package ch.ntb.mcdp.system.memMap;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.TreeMap;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class MemoryMap {
private TreeMap<String, Device> devices;
// Elements
private static final String E_MEMORY_MAP = "memorymap";
private static final String E_DEVICE = "device";
private static final String A_DEVICE_TYPE = "type";
private static final String A_DEVICE_WIDTH = "width";
private static final String E_ATTRIBUTES = "attributes";
private static final String E_SIZE = "size";
private static final String E_SEGMENT = "segment";
private static final String E_INIT = "init";
private static final String E_ASSIGNMENT = "assignment";
private static final String A_NAME = "name";
private static final String A_TYPE = "type";
private static final String A_TYPE_VALUE = "value";
private static final String A_TYPE_URI = "uri";
private static final String A_MODE = "mode";
private static final String V_MODE_REPLACE = "replace";
private static final String A_READ = "read";
private static final String A_WRITE = "write";
private static final String A_CONST = "const";
private static final String A_CODE = "code";
private static final String A_VAR = "var";
private static final String A_SYSCONST = "sysconst";
private static final String A_HEAP = "heap";
private static final String A_STACK = "stack";
private static final String V_ADD = "add";
private static final String V_REMOVE = "remove";
private static final String E_BASE = "base";
private static final String E_SUBSEGMENT = "subsegment";
private static final String E_SUBSEGMENTLIST = "subsegmentList";
private static final String A_START_ID = "startID";
private static final String A_NUMBER_OF_ENTRIES = "numberOfEntries";
private int parseInt(String s) {
if (s == "")
return 0;
if (s.indexOf('x') > 0) {
// is hex number
if (s.length() <= 2) { // exception for "0x"
throw new NumberFormatException("string too short: " + s);
}
if ((s.length() > 10)) { // exception for e.g. 0x112345678
throw new NumberFormatException("number too large: " + s);
}
// check if string too long (max
return (int) Long.parseLong(s.substring(s.indexOf('x') + 1, s
.length()), 16);
} else {
// is decimal number
return Integer.parseInt(s);
}
}
public MemoryMap(String pathToMemFile) throws ParserConfigurationException,
SAXException, IOException {
devices = new TreeMap<String, Device>();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
factory.setXIncludeAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new ErrorHandler() {
// ignore fatal errors (an exception is guaranteed)
public void fatalError(SAXParseException exception)
throws SAXException {
}
// treat validation errors as fatal error
public void error(SAXParseException e) throws SAXParseException {
throw e;
}
// treat warnings as fatal error
public void warning(SAXParseException e) throws SAXParseException {
throw e;
}
});
Document document = builder.parse(new File(pathToMemFile));
NodeList list = document.getElementsByTagName(E_MEMORY_MAP);
if (list == null) {
throw new SAXParseException("<" + E_MEMORY_MAP
+ "> element not found", null);
}
list = list.item(0).getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
// Device (REQUIRED+)
System.out.println(list.item(i).getNodeName());
if (list.item(i).getNodeName().equals(E_DEVICE)) {
Device d = parseDevice(list.item(i));
devices.put(d.getType(), d);
}
}
}
private Device parseDevice(Node node) {
NamedNodeMap attributes = node.getAttributes();
String type = null;
int width = 0;
for (int j = 0; j < attributes.getLength(); j++) {
if (attributes.item(j).getNodeName().equals(A_DEVICE_TYPE)) {
type = attributes.item(j).getNodeValue();
System.out.println("\tType: " + type);
} else if (attributes.item(j).getNodeName().equals(A_DEVICE_WIDTH)) {
width = parseInt(attributes.item(j).getNodeValue());
System.out.println("\tWidth: " + width);
}
}
Device d = new Device(type, width);
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
System.out.println("\t\t" + children.item(i).getNodeName());
// ELEMENT attributes (REQUIRED)
// ELEMENT size (OPTIONAL?)
// ELEMENT segment (REQUIRED+)
// ELEMENT init (OPTIONAL)
if (children.item(i).getNodeName().equals(E_ATTRIBUTES)) {
parseAttributes(children.item(i), d.getAttributes());
} else if (children.item(i).getNodeName().equals(E_SIZE)) {
d.setSize(parseInt(children.item(i).getTextContent()));
} else if (children.item(i).getNodeName().equals(E_SEGMENT)) {
d.segments
.add(parseSegment(children.item(i), d.getAttributes()));
} else if (children.item(i).getNodeName().equals(E_INIT)) {
parseInit(children.item(i));
}
}
return d;
}
private void setAttributes(String nodeValue, MemAttributes attributes,
int index) {
if (nodeValue.equals(V_ADD)) {
attributes.set(index);
System.out.println("setAttribute (" + index + "): set: "
+ attributes.isSet(index));
} else if (nodeValue.equals(V_REMOVE)) {
attributes.unset(index);
System.out.println("setAttribute (" + index + "): unset: "
+ attributes.isSet(index));
}
}
private void parseAttributes(Node node, MemAttributes attributes) {
NamedNodeMap attr = node.getAttributes();
for (int i = 0; i < attr.getLength(); i++) {
String nodeName = attr.item(i).getNodeName();
String nodeValue = attr.item(i).getNodeValue();
System.out.println(nodeName);
if (nodeName.equals(A_MODE)) {
if (nodeValue.equals(V_MODE_REPLACE)) {
// clear all attributes
attributes.reset();
}
} else if (nodeName.equals(A_READ)) {
setAttributes(nodeValue, attributes, MemAttributes.read);
} else if (nodeName.equals(A_WRITE)) {
setAttributes(nodeValue, attributes, MemAttributes.write);
} else if (nodeName.equals(A_CONST)) {
setAttributes(nodeValue, attributes, MemAttributes.const_);
} else if (nodeName.equals(A_CODE)) {
setAttributes(nodeValue, attributes, MemAttributes.code);
} else if (nodeName.equals(A_VAR)) {
setAttributes(nodeValue, attributes, MemAttributes.var);
} else if (nodeName.equals(A_SYSCONST)) {
setAttributes(nodeValue, attributes, MemAttributes.sysconst);
} else if (nodeName.equals(A_HEAP)) {
setAttributes(nodeValue, attributes, MemAttributes.heap);
} else if (nodeName.equals(A_STACK)) {
setAttributes(nodeValue, attributes, MemAttributes.stack);
}
}
}
private int convertToNumber(String constant) {
int result = -1;
try {
return parseInt(constant);
} catch (NumberFormatException e) {
// TODO: convert constant to number
System.out.println("setBase: Kernel Constant: " + constant);
}
return result;
}
private Segment parseSegment(Node node, MemAttributes attributes) {
// ATTRIBUTE name (REQUIRED) TODO
// ELEMENT attributes (OPTIONAL?)
// ELEMENT base (REQUIRED)
// ELEMENT size (REQUIRED)
// ELEMENT subsegment (OPTIONAL*)
// ELEMENT subsegmentList (OPTIONAL?)
NamedNodeMap attrMap = node.getAttributes();
String name = "";
for (int i = 0; i < attrMap.getLength(); i++) {
if (attrMap.item(i).getNodeName().equals(A_NAME)) {
name = attrMap.item(i).getNodeValue();
// TODO remove
System.out.println("-> Segment: name: " + name);
}
}
MemAttributes attr = attributes.clone();
Segment s = new Segment(name, attr);
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeName().equals(E_ATTRIBUTES)) {
parseAttributes(children.item(i), attr);
} else if (children.item(i).getNodeName().equals(E_BASE)) {
s.setBase(convertToNumber(children.item(i).getTextContent()));
} else if (children.item(i).getNodeName().equals(E_SIZE)) {
s.setSize(convertToNumber(children.item(i).getTextContent()));
} else if (children.item(i).getNodeName().equals(E_SUBSEGMENT)) {
s.add(parseSegment(children.item(i), attr));
} else if (children.item(i).getNodeName().equals(E_SUBSEGMENTLIST)) {
parseSegmentList(s, children.item(i), attr);
}
}
return s;
}
private void parseSegmentList(Segment rootSegment, Node segmentList,
MemAttributes attributes) {
String name = "";
int nofEntries = 0, startID = 0, size = 0;
MemAttributes attr = rootSegment.getMemAttributes().clone();
NamedNodeMap attrMap = segmentList.getAttributes();
for (int i = 0; i < attrMap.getLength(); i++) {
if (attrMap.item(i).getNodeName().equals(A_NAME)) {
name = attrMap.item(i).getNodeValue();
} else if (attrMap.item(i).getNodeName()
.equals(A_NUMBER_OF_ENTRIES)) {
nofEntries = parseInt(attrMap.item(i).getNodeValue());
} else if (attrMap.item(i).getNodeName().equals(A_START_ID)) {
startID = parseInt(attrMap.item(i).getNodeValue());
}
}
NodeList children = segmentList.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeName().equals(E_ATTRIBUTES)) {
parseAttributes(children.item(i), attr);
} else if (children.item(i).getNodeName().equals(E_SIZE)) {
size = parseInt(children.item(i).getTextContent());
}
}
for (int i = 0; i < nofEntries; i++) {
Segment s = new Segment(new String(name
+ Integer.toString(startID + i)), attr);
s.setSize(size);
rootSegment.add(s);
}
}
private void parseInit(Node node) {
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeName().equals(E_ASSIGNMENT)) {
NamedNodeMap attr = children.item(i).getAttributes();
String name = null, type = null, value = null;
for (int j = 0; j < attr.getLength(); j++) {
if (attr.item(j).getNodeName().equals(A_NAME)) {
name = attr.item(j).getNodeValue();
} else if (attr.item(j).getNodeName().equals(A_TYPE)) {
type = attr.item(j).getNodeValue();
}
}
value = children.item(i).getTextContent();
System.out.print("\t\t\t assignment: type = " + type
+ ", name = " + name + ", value = ");
if (type.equals(A_TYPE_VALUE)) {
System.out.println("0x"
+ Integer.toHexString(parseInt(value)));
} else if (type.equals(A_TYPE_URI)) {
System.out.println(value);
}
}
}
}
public void printMemMap() {
Collection coll = devices.values();
System.out.println("*** *** Memory Map *** ***");
for (Iterator iter = coll.iterator(); iter.hasNext();) {
Device element = (Device) iter.next();
printTab(0);
System.out.println("Device: " + element.getType() + ", size: 0x"
+ Integer.toHexString(element.getSize()) + ", width: "
+ element.getWidth());
for (Iterator segIter = element.segments.iterator(); segIter
.hasNext();) {
Segment seg = (Segment) segIter.next();
printSegment(1, seg);
}
}
System.out.println("*** *** *** *** *** *** *** ***");
}
private void printTab(int count) {
for (int i = 0; i < count; i++) {
System.out.print('\t');
}
}
private void printSegment(int indent, Segment seg) {
printTab(indent);
System.out.println("Segment: " + seg.getName() + ", base: 0x"
+ Integer.toHexString(seg.getBase()) + ", size: 0x"
+ Integer.toHexString(seg.getSize()));
printMemAttributes(indent + 1, seg.getMemAttributes());
for (Iterator subSegIter = seg.getSegments().iterator(); subSegIter
.hasNext();) {
Segment subseg = (Segment) subSegIter.next();
printSegment(2, subseg);
}
}
private void printMemAttributes(int indent, MemAttributes attr) {
printTab(indent);
System.out.print("MemAttributes: ");
for (int i = 0; i < MemAttributes.NOF_ATTRIBUTES; i++) {
if (attr.isSet(i)) {
if (i > 0) {
System.out.print(", ");
}
String type = null;
switch (i) {
case 0:
type = "read";
break;
case 1:
type = "write";
break;
case 2:
type = "const";
break;
case 3:
type = "code";
break;
case 4:
type = "var";
break;
case 5:
type = "sysconst";
break;
case 6:
type = "heap";
break;
case 7:
type = "stack";
break;
}
System.out.print(type);
}
}
System.out.println();
}
}

View File

@@ -1,60 +0,0 @@
package ch.ntb.mcdp.system.memMap;
import java.util.LinkedList;
public class Segment {
private LinkedList<Segment> subsegments;
private String name;
private MemAttributes attr;
private int base = 0;
private int size = 0;
Segment(String name) {
this.name = name;
subsegments = new LinkedList<Segment>();
attr = new MemAttributes();
}
Segment(String name, MemAttributes attr) {
this.name = name;
subsegments = new LinkedList<Segment>();
this.attr = attr;
}
public MemAttributes getMemAttributes() {
return attr;
}
public void add(Segment s) {
subsegments.add(s);
}
public LinkedList<Segment> getSegments() {
return subsegments;
}
public int getBase() {
return base;
}
public void setBase(int base) {
this.base = base;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getName() {
return name;
}
}

View File

@@ -1,33 +0,0 @@
package ch.ntb.mcdp.system.memMap.test;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import ch.ntb.mcdp.system.memMap.MemoryMap;
public class MemoryMapTest {
private static String filePath = "resources/targets/mpc555/memoryMap.xml";
public static void main(String[] args) {
MemoryMap map = null;
try {
map = new MemoryMap(filePath);
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("done");
map.printMemMap();
}
}

View File

@@ -1,58 +0,0 @@
package ch.ntb.mcdp.uart;
import java.io.InputStream;
import java.io.OutputStream;
public abstract class Uart {
private UartOutputStream out;
UartInputStream in;
Uart() {
UartDispatch.getUartList().add(this);
out = new UartOutputStream(getSTYPE_IN());
in = new UartInputStream();
// if the read-Thread is already started, this statement has no effect
UartDispatch.start();
}
/**
* Get the stream to write to the target device.
*
* @return OutputStream to write to target device
*/
public OutputStream getOutputStream() {
return out;
}
/**
* Get the stream to read from the target device.
*
* @return InputStream to read from target device
*/
public InputStream getInputStream() {
return in;
}
/**
* The packet subtype specified for this UART packet (from target to PC).
* This constant is defined in <code>Dispatch.h</code>.<br>
* Note: This direction is different from the input/output direction of the
* streams.
*
* @return packet subtype
*/
abstract byte getSTYPE_OUT();
/**
* The packet subtype specified for this UART packet (from PC to target).
* This constant is defined in <code>Dispatch.h</code>.<br>
* Note: This direction is different from the input/output direction of the
* streams.
*
* @return packet subtype
*/
abstract byte getSTYPE_IN();
}

View File

@@ -1,26 +0,0 @@
package ch.ntb.mcdp.uart;
public class Uart0 extends Uart {
// UART 0 Subtypes
/**
* Data to UART 0
*/
private static final byte STYPE_UART_0_IN = 0x11;
/**
* Data from UART 0
*/
private static final byte STYPE_UART_0_OUT = 0x22;
@Override
protected byte getSTYPE_OUT() {
return STYPE_UART_0_OUT;
}
@Override
protected byte getSTYPE_IN() {
return STYPE_UART_0_IN;
}
}

View File

@@ -1,137 +0,0 @@
package ch.ntb.mcdp.uart;
import java.util.Iterator;
import java.util.LinkedList;
import ch.ntb.mcdp.usb.DataPacket;
import ch.ntb.mcdp.usb.Dispatch;
import ch.ntb.mcdp.usb.DispatchException;
import ch.ntb.mcdp.usb.USBDevice;
import ch.ntb.usb.USBException;
import ch.ntb.usb.USBTimeoutException;
public class UartDispatch {
/**
* Size of the UART buffer on the USB controller. <br>
* This value is specified in <code>UART_BUF_LEN</code> in the file
* <code>uart.h</code>.
*/
public static final int UART_BUF_LEN = 256;
private static boolean running = false;
private static Thread dispatchThread;
private static LinkedList<Uart> uarts = new LinkedList<Uart>();
/**
* Starts the read thread for all Uarts. If the thread is already running,
* no action is taken.
*/
public static void start() {
if (dispatchThread == null) {
dispatchThread = new Thread() {
@Override
public void run() {
while (running) {
DataPacket data;
try {
data = Dispatch.readUART();
if (data != null) {
Iterator iterator = uarts.iterator();
while (iterator.hasNext()) {
Uart uartObj = (Uart) iterator.next();
if (uartObj.getSTYPE_OUT() == data.subtype) {
uartObj.in.bufferList.add(data);
}
}
}
// TODO: remove
sleep(200);
} catch (USBTimeoutException e) {
// ignore TimeoutExceptions
} catch (USBException e) {
// TODO: Exceptionhandling
e.printStackTrace();
try {
sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
} catch (DispatchException e) {
// TODO: Exceptionhandling
e.printStackTrace();
try {
sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
} catch (InterruptedException e) {
// TODO Exceptionhandling
e.printStackTrace();
}
}
}
};
}
if (!running) {
running = true;
dispatchThread.start();
}
}
/**
* Stops the Uart read-Thread.
*/
public static void stop() {
running = false;
}
/**
* Check whether the read-Thread is still running.
*
* @return state of the read-Thread
*/
public static boolean isRunning() {
return running;
}
/**
* Get the LinkedList which contains all Uart-objects.
*
* @return The LinkedList containing all Uart-objects.
*/
public static LinkedList<Uart> getUartList() {
return uarts;
}
/**
* Write a Uart data-packet to the target. The maximal number of bytes is
* specified by <code>MAX_UART_PAYLOAD</code>. If more data is sent in
* one packet, only <code>MAX_UART_PAYLOAD</code> bytes are forwarded to
* the uart.
*
* @param packetSubType
* The Subtype specified in <code>Dispatch.h</code>.
* @param data
* The data to be sent.
* @param len
* Length of the data to be sent.
* @throws USBException
*/
protected static void write(byte packetSubType, byte[] data, int len)
throws USBException {
byte[] usbData = new byte[len + DataPacket.PACKET_MIN_LENGTH];
usbData[0] = DataPacket.PACKET_HEADER;
usbData[1] = Dispatch.MTYPE_UART;
usbData[2] = packetSubType;
usbData[3] = (byte) (len / 0x100);
usbData[4] = (byte) (len & 0xFF);
for (int i = 0; i < len; i++) {
usbData[DataPacket.PACKET_DATA_OFFSET + i] = data[i];
}
usbData[DataPacket.PACKET_DATA_OFFSET + len] = DataPacket.PACKET_END;
USBDevice.write_BDI(usbData, usbData.length);
}
}

View File

@@ -1,75 +0,0 @@
package ch.ntb.mcdp.uart;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import ch.ntb.mcdp.usb.DataPacket;
public class UartInputStream extends InputStream {
private int bufferPos = 0;
LinkedList<DataPacket> bufferList = new LinkedList<DataPacket>();
@Override
public int read() throws IOException {
while (!bufferList.isEmpty()) {
if (bufferPos >= bufferList.element().data.length) {
// remove element, reset bufferPos
bufferList.remove();
bufferPos = 0;
} else {
return bufferList.element().data[bufferPos++];
}
}
return -1;
}
@Override
public int read(byte b[]) throws IOException {
return read(b, 0, b.length);
}
@Override
public int read(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0)
|| ((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
// TODO: optimize
int c = read();
if (c == -1) {
return -1;
}
b[off] = (byte) c;
int i = 1;
try {
for (; i < len; i++) {
c = read();
if (c == -1) {
break;
}
if (b != null) {
b[off + i] = (byte) c;
}
}
} catch (IOException ee) {
}
return i;
}
@Override
public int available() throws IOException {
if (bufferList.isEmpty())
return 0;
return bufferList.element().data.length;
}
}

View File

@@ -1,52 +0,0 @@
package ch.ntb.mcdp.uart;
import java.io.IOException;
import java.io.OutputStream;
import ch.ntb.usb.USBException;
public class UartOutputStream extends OutputStream {
private byte packetSubType;
UartOutputStream(byte packetSubType) {
this.packetSubType = packetSubType;
}
@Override
public void write(int b) throws IOException {
byte[] data = new byte[1];
data[0] = (byte) b;
try {
UartDispatch.write(packetSubType, data, 1);
} catch (USBException e) {
throw new IOException(e.getMessage());
}
}
@Override
public void write(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0)
|| ((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
int newLen = 0;
do {
newLen = Math.min(len, UartDispatch.UART_BUF_LEN);
byte[] data = new byte[newLen];
for (int i = 0; i < newLen; i++) {
data[i] = b[off + i];
}
try {
UartDispatch.write(packetSubType, data, newLen);
} catch (USBException e) {
throw new IOException(e.getMessage());
}
len -= newLen;
} while (len > UartDispatch.UART_BUF_LEN);
}
}

View File

@@ -1,72 +0,0 @@
package ch.ntb.mcdp.uart.blackbox;
import ch.ntb.mcdp.uart.UartDispatch;
import ch.ntb.mcdp.usb.DataPacket;
import ch.ntb.mcdp.usb.Dispatch;
import ch.ntb.mcdp.usb.USBDevice;
import ch.ntb.usb.USBException;
public class Uart0 {
// UART 0 Subtypes
/**
* Data to UART 0
*/
private static final byte STYPE_UART_0_IN = 0x11;
public static final int MAX_UART_PAYLOAD = UartDispatch.UART_BUF_LEN;
private static void write(byte packetSubType, byte[] data, int len)
throws USBException {
byte[] usbData = new byte[len + DataPacket.PACKET_MIN_LENGTH];
usbData[0] = DataPacket.PACKET_HEADER;
usbData[1] = Dispatch.MTYPE_UART;
usbData[2] = packetSubType;
usbData[3] = (byte) (len / 0x100);
usbData[4] = (byte) (len & 0xFF);
for (int i = 0; i < len; i++) {
usbData[DataPacket.PACKET_DATA_OFFSET + i] = data[i];
}
usbData[DataPacket.PACKET_DATA_OFFSET + len] = DataPacket.PACKET_END;
USBDevice.write_BDI(usbData, usbData.length);
}
/**
* Write a Uart data-packet to the target. The maximal number of bytes is
* specified by <code>MAX_UART_PAYLOAD</code>. If more data is sent in
* one packet, only <code>MAX_UART_PAYLOAD</code> bytes are forwarded to
* the uart.
*
* @param data
* The data to be sent.
* @param len
* Length of the data to be sent.
* @return true if the data has been sent successfully
*/
public static boolean write(byte[] data, int len) {
try {
write(STYPE_UART_0_IN, data, len);
} catch (USBException e) {
return false;
}
return true;
}
/**
* Try to read uart data from the device.
*
* @return uart data or null if no data is available or an exception occured
*/
public static byte[] read() {
DataPacket packet;
try {
packet = Dispatch.readUART();
if (packet == null) {
return null;
}
return packet.data;
} catch (Exception e) {
return null;
}
}
}

View File

@@ -1,100 +0,0 @@
package ch.ntb.mcdp.uart.blackbox.test;
import ch.ntb.mcdp.uart.UartDispatch;
import ch.ntb.mcdp.uart.blackbox.Uart0;
public class UartTest {
static Thread reader;
public static void init() {
reader = new Thread() {
public void run() {
while (true) {
try {
byte[] result = Uart0.read();
if (result != null) {
for (int i = 0; i < result.length; i++) {
System.out.print((char) result[i]);
}
}
sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
reader.start();
}
static public void button1() {
byte[] buffer = new byte[UartDispatch.UART_BUF_LEN];
for (int i = 0; i < buffer.length; i++) {
buffer[i] = (byte) ('0' + (i % ('z' - '0')));
}
boolean done = Uart0.write(buffer, buffer.length);
if (done) {
System.out.println("success");
} else {
System.out.println("failed");
}
}
static public void button2() {
}
static public void button3() {
}
static public void button4() {
}
static public void button5() {
}
static public void button6() {
}
static public void button7() {
}
static public void button8() {
}
static public void button9() {
}
static public void button10() {
}
static public void button11() {
}
static public void button12() {
}
static public void button13() {
}
static public void button14() {
}
static public void button15() {
}
}

View File

@@ -1,215 +0,0 @@
package ch.ntb.mcdp.uart.blackbox.test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import ch.ntb.mcdp.uart.UartDispatch;
import ch.ntb.mcdp.usb.USBDevice;
import ch.ntb.usb.USBException;
public class UartTestApp {
private Shell sShell = null; // @jve:decl-index=0:visual-constraint="10,10"
private Button button1 = null;
private Button button2 = null;
private Button button3 = null;
private Button button4 = null;
private Button button5 = null;
private Button button6 = null;
private Button button7 = null;
private Button button8 = null;
private Button button9 = null;
private Button button10 = null;
private Button button15 = null;
private Button button11 = null;
private Button button12 = null;
private Button button13 = null;
private Button button14 = null;
/**
* This method initializes sShell
*/
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setLayout(new RowLayout());
sShell.setSize(new org.eclipse.swt.graphics.Point(312,110));
button1 = new Button(sShell, SWT.NONE);
button1.setText("writeData");
button1
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button1();
}
});
button2 = new Button(sShell, SWT.NONE);
button2.setText("not assigned");
button2
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button2();
}
});
button3 = new Button(sShell, SWT.NONE);
button3.setText("not assigned");
button3
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button3();
}
});
button4 = new Button(sShell, SWT.NONE);
button4.setText("not assigned");
button4
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button4();
}
});
button5 = new Button(sShell, SWT.NONE);
button5.setText("not assigned");
button6 = new Button(sShell, SWT.NONE);
button6.setText("not assigned");
button6
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button6();
}
});
button7 = new Button(sShell, SWT.NONE);
button7.setText("not assigned");
button8 = new Button(sShell, SWT.NONE);
button8.setText("not assigned");
button8
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button8();
}
});
button9 = new Button(sShell, SWT.NONE);
button9.setText("not assigned");
button10 = new Button(sShell, SWT.NONE);
button10.setText("not assigned");
button11 = new Button(sShell, SWT.NONE);
button11.setText("not assigned");
button11.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
UartTest.button11();
}
});
button12 = new Button(sShell, SWT.NONE);
button12.setText("not assigned");
button12.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
UartTest.button12();
}
});
button13 = new Button(sShell, SWT.NONE);
button13.setText("not assigned");
button13.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
UartTest.button13();
}
});
button14 = new Button(sShell, SWT.NONE);
button14.setText("not assigned");
button14.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
UartTest.button14();
}
});
button15 = new Button(sShell, SWT.NONE);
button15.setText("not assigned");
button15.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
UartTest.button15();
}
});
button10
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button10();
}
});
button9
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button9();
}
});
button7
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button7();
}
});
button5
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button5();
}
});
}
public static void main(String[] args) {
UartTestApp app = new UartTestApp();
app.createSShell();
app.sShell.open();
Display display = app.sShell.getDisplay();
try {
USBDevice.open();
System.out.println("open device...");
} catch (USBException e) {
e.printStackTrace();
return;
}
UartTest.init();
while (!app.sShell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
UartDispatch.stop();
try {
USBDevice.close();
System.out.println("closing device...");
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.exit(0);
}
}

View File

@@ -1,118 +0,0 @@
package ch.ntb.mcdp.uart.test;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import ch.ntb.mcdp.uart.Uart0;
import ch.ntb.mcdp.uart.UartDispatch;
public class UartTest {
static Thread reader;
static OutputStream out;
static InputStream in;
static byte[] buffer = new byte[UartDispatch.UART_BUF_LEN];
public static void init() {
// create an uart object
Uart0 uart = new Uart0();
// get the streams
out = uart.getOutputStream();
in = uart.getInputStream();
reader = new Thread() {
public void run() {
int readLen = 0;
while (true) {
try {
readLen = in.read(buffer);
if (readLen > 0) {
for (int i = 0; i < readLen; i++) {
System.out.print((char) buffer[i]);
}
}
Thread.sleep(50);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
reader.start();
}
static public void button1() {
byte[] buffer = new byte[UartDispatch.UART_BUF_LEN];
for (int i = 0; i < buffer.length; i++) {
buffer[i] = (byte) ('0' + (i % ('z' - '0')));
}
try {
out.write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
}
static public void button2() {
}
static public void button3() {
}
static public void button4() {
}
static public void button5() {
}
static public void button6() {
}
static public void button7() {
}
static public void button8() {
}
static public void button9() {
}
static public void button10() {
}
static public void button11() {
}
static public void button12() {
}
static public void button13() {
}
static public void button14() {
}
static public void button15() {
}
}

View File

@@ -1,216 +0,0 @@
package ch.ntb.mcdp.uart.test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import ch.ntb.mcdp.uart.UartDispatch;
import ch.ntb.mcdp.usb.USBDevice;
import ch.ntb.usb.USBException;
public class UartTestApp {
private Shell sShell = null; // @jve:decl-index=0:visual-constraint="10,10"
private Button button1 = null;
private Button button2 = null;
private Button button3 = null;
private Button button4 = null;
private Button button5 = null;
private Button button6 = null;
private Button button7 = null;
private Button button8 = null;
private Button button9 = null;
private Button button10 = null;
private Button button15 = null;
private Button button11 = null;
private Button button12 = null;
private Button button13 = null;
private Button button14 = null;
/**
* This method initializes sShell
*/
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setLayout(new RowLayout());
sShell.setSize(new org.eclipse.swt.graphics.Point(312,110));
button1 = new Button(sShell, SWT.NONE);
button1.setText("writeData");
button1
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button1();
}
});
button2 = new Button(sShell, SWT.NONE);
button2.setText("not assigned");
button2
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button2();
}
});
button3 = new Button(sShell, SWT.NONE);
button3.setText("not assigned");
button3
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button3();
}
});
button4 = new Button(sShell, SWT.NONE);
button4.setText("not assigned");
button4
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button4();
}
});
button5 = new Button(sShell, SWT.NONE);
button5.setText("not assigned");
button6 = new Button(sShell, SWT.NONE);
button6.setText("not assigned");
button6
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button6();
}
});
button7 = new Button(sShell, SWT.NONE);
button7.setText("not assigned");
button8 = new Button(sShell, SWT.NONE);
button8.setText("not assigned");
button8
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button8();
}
});
button9 = new Button(sShell, SWT.NONE);
button9.setText("not assigned");
button10 = new Button(sShell, SWT.NONE);
button10.setText("not assigned");
button11 = new Button(sShell, SWT.NONE);
button11.setText("not assigned");
button11.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
UartTest.button11();
}
});
button12 = new Button(sShell, SWT.NONE);
button12.setText("not assigned");
button12.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
UartTest.button12();
}
});
button13 = new Button(sShell, SWT.NONE);
button13.setText("not assigned");
button13.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
UartTest.button13();
}
});
button14 = new Button(sShell, SWT.NONE);
button14.setText("not assigned");
button14.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
UartTest.button14();
}
});
button15 = new Button(sShell, SWT.NONE);
button15.setText("not assigned");
button15.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
UartTest.button15();
}
});
button10
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button10();
}
});
button9
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button9();
}
});
button7
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button7();
}
});
button5
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
UartTest.button5();
}
});
}
public static void main(String[] args) {
UartTestApp app = new UartTestApp();
app.createSShell();
app.sShell.open();
Display display = app.sShell.getDisplay();
try {
USBDevice.open();
System.out.println("open device...");
} catch (USBException e) {
e.printStackTrace();
return;
}
UartDispatch.start();
UartTest.init();
while (!app.sShell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
UartDispatch.stop();
try {
USBDevice.close();
System.out.println("closing device...");
} catch (USBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.exit(0);
}
}

View File

@@ -1,45 +0,0 @@
package ch.ntb.mcdp.usb;
public class DataPacket {
/**
* minimal Length of a packet (no payload)
*/
public static final int PACKET_MIN_LENGTH = 6;
public int subtype;
public byte[] data;
/**
* offset to the first byte of data
*/
public static final byte PACKET_DATA_OFFSET = 5;
/**
* last byte of packet
*/
public static final byte PACKET_END = 0x1F;
// Packet Constants
/**
* first byte of header
*/
public static final byte PACKET_HEADER = 0x5B;
DataPacket(int subtype, byte[] data) {
this.subtype = subtype;
this.data = data;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer("Subtype: 0x"
+ String.format("%1$02X", subtype) + "\t");
sb.append("Data: ");
for (int i = 0; i < data.length; i++) {
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
}
return sb.toString();
}
}

View File

@@ -1,138 +0,0 @@
package ch.ntb.mcdp.usb;
import java.util.LinkedList;
import java.util.logging.Logger;
import ch.ntb.mcdp.utils.logger.LogUtil;
import ch.ntb.usb.USB;
import ch.ntb.usb.USBException;
public class Dispatch {
private static Logger logger = LogUtil.ch_ntb_mcdp_usb;
// Main Types
/**
* general errors
*/
public static final byte MTYPE_ERROR = 0x01;
/**
* BDI specific packets
*/
public static final byte MTYPE_BDI = 0x02;
/**
* UART specific packets
*/
public static final byte MTYPE_UART = 0x03;
// Sub Types
// ERRORS
/**
* Unknown MTYPE
*/
public static final byte STYPE_ERROR_UNKNOWN_MTYPE = 0x70;
/**
* Header of packet wrong
*/
public static final byte STYPE_ERROR_HEADER = 0x71;
/**
* Packet end wrong
*/
public static final byte STYPE_ERROR_PACKET_END = 0x72;
private static byte[] usbData = new byte[USB.HIGHSPEED_MAX_BULK_PACKET_SIZE];
private static LinkedList<DataPacket> bdiData, uartData;
static {
bdiData = new LinkedList<DataPacket>();
uartData = new LinkedList<DataPacket>();
}
public static void emptyBuffers() {
bdiData.clear();
uartData.clear();
}
private static void dispatch(byte[] data, int size)
throws DispatchException {
int index = 0, mainType, subtype;
byte[] packetData;
while (index < size) {
if (data[index++] != DataPacket.PACKET_HEADER) {
throw new DispatchException("PACKET_HEADER wrong: "
+ data[index - 1]);
}
mainType = data[index++];
subtype = data[index++];
int dataLen = (data[index++] & 0xFF) * 0x100
+ (data[index++] & 0xFF);
if (data[index + dataLen] != DataPacket.PACKET_END) {
throw new DispatchException("PACKET_END or packetLen ("
+ dataLen + " bytes) wrong");
}
switch (mainType) {
case MTYPE_ERROR:
switch (subtype) {
case STYPE_ERROR_HEADER:
throw new DispatchException(
"MTYPE_ERROR: STYPE_ERROR_HEADER");
case STYPE_ERROR_PACKET_END:
throw new DispatchException(
"MTYPE_ERROR: STYPE_ERROR_PACKET_END");
case STYPE_ERROR_UNKNOWN_MTYPE:
throw new DispatchException(
"MTYPE_ERROR: STYPE_ERROR_UNKNOWN_MTYPE");
default:
throw new DispatchException("MTYPE_ERROR: Unknown S_TYPE: "
+ subtype);
}
case MTYPE_BDI:
packetData = new byte[dataLen];
// copy data to bdiData
for (int i = 0; i < dataLen; i++) {
packetData[i] = data[index + i];
}
bdiData.add(new DataPacket(subtype, packetData));
break;
case MTYPE_UART:
packetData = new byte[dataLen];
// copy data to uartData
for (int i = 0; i < dataLen; i++) {
packetData[i] = data[index + i];
}
uartData.add(new DataPacket(subtype, packetData));
break;
default:
throw new DispatchException("Unknown MTYPE: " + mainType);
}
index += dataLen + 1;
}
}
public static DataPacket readBDI() throws USBException, DispatchException {
if (!bdiData.isEmpty()) {
return bdiData.poll();
}
int dataLength = USBDevice.read_BDI(usbData, USBDevice
.getMaxPacketSize());
dispatch(usbData, dataLength);
return bdiData.poll();
}
public static DataPacket readUART() throws USBException, DispatchException {
if (!uartData.isEmpty()) {
logger.info("buffer not empty");
return uartData.poll();
}
int dataLength = USBDevice.read_UART(usbData, USBDevice
.getMaxPacketSize());
dispatch(usbData, dataLength);
return uartData.poll();
}
}

View File

@@ -1,14 +0,0 @@
package ch.ntb.mcdp.usb;
public class DispatchException extends Exception{
public DispatchException(String string) {
super(string);
}
/**
*
*/
private static final long serialVersionUID = -3507511795478700742L;
}

View File

@@ -1,73 +0,0 @@
package ch.ntb.mcdp.usb;
import ch.ntb.usb.Device;
import ch.ntb.usb.USB;
import ch.ntb.usb.USBException;
public class USBDevice {
private final static short IdVendor = (short) 0x8235;
private final static short IdProduct = 0x0100;
private final static int Configuration = 1;
private final static int Interface = 0;
private final static int Altinterface = 0;
private static final int OUT_Endpoint_BDI = 0x02;
private static final int IN_Endpoint_BDI = 0x86;
private static final int OUT_Endpoint_UART = 0x04;
private static final int IN_Endpoint_UART = 0x88;
private static final int BDI_Timeout = 1000;
private static final int UART_Timeout = 1;
private static Device dev;
static {
dev = USB.getDevice(IdVendor, IdProduct);
dev.setResetOnFirstOpen(true);
}
public static void open() throws USBException {
dev.open(Configuration, Interface, Altinterface);
}
public static void close() throws USBException {
dev.close();
}
public static void reset() throws USBException {
dev.reset();
}
public static void write_BDI(byte[] data, int length) throws USBException {
dev.bulkwrite(OUT_Endpoint_BDI, data, length, BDI_Timeout, true);
}
public static int read_BDI(byte[] data, int size) throws USBException {
return dev.bulkread(IN_Endpoint_BDI, data, size, BDI_Timeout, true);
}
public static void write_UART(byte[] data, int length) throws USBException {
dev.bulkwrite(OUT_Endpoint_UART, data, length, UART_Timeout, false);
}
public static int read_UART(byte[] data, int size) throws USBException {
return dev.bulkread(IN_Endpoint_UART, data, size, UART_Timeout, false);
}
public static int getMaxPacketSize() {
return dev.getMaxPacketSize();
}
public static Device getDevice() {
return dev;
}
}

View File

@@ -1,17 +0,0 @@
package ch.ntb.mcdp.utils;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class Redirect {
public static void redirect(){
try {
System.setOut(new PrintStream(new FileOutputStream("JavaOut.txt")));
System.setErr(new PrintStream(new FileOutputStream("JavaErr.txt")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}

View File

@@ -1,13 +0,0 @@
package ch.ntb.mcdp.utils.logger;
import java.util.logging.Level;
public class LogLevel extends Level {
public static final Level DEBUG = new LogLevel("DEBUG", 750);
protected LogLevel(String name, int value) {
super(name, value);
}
}

View File

@@ -1,48 +0,0 @@
package ch.ntb.mcdp.utils.logger;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
public class LogUtil {
public static McdpLogger ch_ntb_mcdp_bdi, ch_ntb_mcdp_bdi_test,
ch_ntb_mcdp_mc68332, ch_ntb_mcdp_usb;
static {
// set all loglevels here
ch_ntb_mcdp_usb = getLogger("ch.ntb.mcdp.usb", LogLevel.OFF);
ch_ntb_mcdp_bdi = getLogger("ch.ntb.mcdp.bdi", LogLevel.OFF);
ch_ntb_mcdp_bdi_test = getLogger("ch.ntb.mcdp.bdi.test", LogLevel.ALL);
ch_ntb_mcdp_mc68332 = getLogger("ch.ntb.mcdp.mc68332", LogLevel.OFF);
}
public static void setLevel(McdpLogger logger, Level loglevel) {
Handler[] h = logger.getHandlers();
for (int i = 0; i < h.length; i++) {
h[i].setLevel(loglevel);
}
logger.setLevel(loglevel);
}
private static void initLevel(McdpLogger logger, Level loglevel) {
Handler[] h = logger.getHandlers();
for (int i = 0; i < h.length; i++) {
logger.removeHandler(h[i]);
}
Handler console = new ConsoleHandler();
console.setLevel(loglevel);
logger.addHandler(console);
logger.setLevel(loglevel);
logger.setUseParentHandlers(false);
}
private static McdpLogger getLogger(String name, Level loglevel) {
McdpLogger logger = McdpLogger.getLogger(name);
initLevel(logger, loglevel);
return logger;
}
}

View File

@@ -1,26 +0,0 @@
package ch.ntb.mcdp.utils.logger;
import java.util.logging.Logger;
import java.util.logging.LogManager;
public class McdpLogger extends Logger {
protected McdpLogger(String name, String resourceBundleName) {
super(name, resourceBundleName);
}
public void debug(String msg) {
log(LogLevel.DEBUG, msg);
}
public static synchronized McdpLogger getLogger(String name) {
LogManager manager = LogManager.getLogManager();
McdpLogger result = (McdpLogger) manager.getLogger(name);
if (result == null) {
result = new McdpLogger(name, null);
manager.addLogger(result);
result = (McdpLogger) manager.getLogger(name);
}
return result;
}
}