maybe cmdline works for debug now?

master
Dario Ernst 15 years ago
parent c7f69049c9
commit d3fcd7304d

@ -24,6 +24,7 @@ respectively.
#include <usb.h> /* this is libusb */
#include "opendevice.h" /* common code moved to separate module */
#include <arpa/inet.h> //for htons()
#include <unistd.h>
#include "../firmware/masterchip/usbdrv/usbconfig.h" /* device's VID/PID and names */
@ -117,28 +118,54 @@ int cnt, vid, pid;
fprintf(stderr, "answer: value=0x%04x (%i)\n", rxIndex,rxIndex);
// fprintf(stderr, "rxValue = 0x%04x value = 0x%04x\n", rxValue, addr);
// fprintf(stderr, "rxIndex = 0x%04x index = 0x%04x\n", rxIndex, value);
} else if(strcasecmp(argv[1], "spi") == 0) {
if(argc != 5) {
} else if(strcasecmp(argv[1], "dbg") == 0) {
if(argc != 2) {
usage();
return 0;
}
int opcode, addr, value;
int i=0;
opcode = atoi(argv[2]);
addr = atoi(argv[3]);
value = atoi(argv[4]);
// x86 is little-endian, avr is big-endian
value = htons(value);
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, opcode, addr, value, buffer, sizeof(buffer), 5000);
if(cnt < 0){
fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror());
int rqRefreshHasNew[] = {6, 0, 0};
int rqHasNew[] = {2, 0, 0};
int rqGetNew[] = {2, 1, 0};
int rqAdvance[] = {6, 1, 0};
int *rq;
while(1) {
// refresh "hasNew" variable
rq = rqRefreshHasNew;
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, rq[0], rq[1], rq[2], buffer, sizeof(buffer), 5000);
if(cnt < 0){
fprintf(stderr, "\nUSB error in iteration ?!?: %s\n", usb_strerror());
}
// check whether we have new
rq = rqHasNew;
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, rq[0], rq[1], rq[2], buffer, sizeof(buffer), 5000);
if(cnt < 0){
fprintf(stderr, "\nUSB error in iteration ?!?: %s\n", usb_strerror());
}
rxIndex = ((int)buffer[1] & 0xff) | (((int)buffer[0] & 0xff) << 8);
if(rxIndex) { // if we have new data?
// get the new char and print it
rq = rqGetNew;
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, rq[0], rq[1], rq[2], buffer, sizeof(buffer), 5000);
if(cnt < 0){
fprintf(stderr, "\nUSB error in iteration ?!?: %s\n", usb_strerror());
}
rxIndex = ((int)buffer[1] & 0xff) | (((int)buffer[0] & 0xff) << 8);
fprintf(stderr, "%c", rxIndex);
// advance the new char pointer...
rq = rqAdvance;
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, rq[0], rq[1], rq[2], buffer, sizeof(buffer), 5000);
if(cnt < 0){
fprintf(stderr, "\nUSB error in iteration ?!?: %s\n", usb_strerror());
}
rxIndex = ((int)buffer[1] & 0xff) | (((int)buffer[0] & 0xff) << 8);
}
usleep(10000);
}
rxIndex = ((int)buffer[1] & 0xff) | (((int)buffer[0] & 0xff) << 8);
fprintf(stderr, "request = 0x%04x\n", opcode);
fprintf(stderr, "answer: value=0x%04x (%i)\n", rxIndex,rxIndex);
} else {
usage();
}

Loading…
Cancel
Save