cleanup printfs

This commit is contained in:
david 2009-06-24 15:11:10 +02:00
parent 08e6710321
commit 128c27d441
4 changed files with 95 additions and 13 deletions

View File

@ -9,12 +9,14 @@
#define DEBUG 1
#define REQ_STATUS_IDLE 0
#define REQ_STATUS_UPLOAD 1
#define REQ_STATUS_CRC 2
#define REQ_STATUS_IDLE 0x01
#define REQ_STATUS_UPLOAD 0x02
#define REQ_STATUS_BULK_UPLOAD 0x03
#define REQ_STATUS_BULK_NEXT 0x04
#define REQ_STATUS_CRC 0x05
#define USB_MAX_TRANS 0xff
#define USB_CRC_CHECK 1
#define USB_CRC_CHECK 0x01
#define TRANSFER_BUFFER_SIZE 0xff

View File

@ -46,7 +46,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
req_bank_size = 1 << rq->wValue.word;
sync_errors = 0;
#if DEBUG_USB
printf("USB_UPLOAD_INIT: bank size %li\n", req_bank_size);
printf("USB_UPLOAD_INIT: bank_size=%li\n", req_bank_size);
#endif
/*
* -------------------------------------------------------------------------
@ -61,7 +61,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
sync_errors++;
#if DEBUG_USB
printf
("USB_UPLOAD_ADDR: Out of sync Addr=0x%lx remain=%i packet=%i sync_error=%i\n",
("USB_UPLOAD_ADDR: Out of sync addr=0x%lx remain=%i packet=%i sync_error=%i\n",
req_addr, rx_remaining, rq->wLength.word, sync_errors);
#endif
ret_len = 0;
@ -70,16 +70,22 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
ret_len = USB_MAX_TRANS;
if (req_addr && req_addr % req_bank_size == 0) {
#if DEBUG_USB
printf("USB_UPLOAD_ADDR: req_bank: 0x%x Addr: 0x%08lx \n",
printf("USB_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx \n",
#endif
req_bank, req_addr);
req_bank++;
}
ret_len = USB_MAX_TRANS;
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_DOWNLOAD_INIT) {
#if DEBUG_USB
printf("USB_DOWNLOAD_INIT\n");
#endif
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_DOWNLOAD_ADDR) {
printf("USB_DOWNLOAD_ADDR\n");
} else if (rq->bRequest == USB_CRC) {
@ -87,7 +93,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
req_addr = req_addr << 16;
req_addr = req_addr | rq->wIndex.word;
#if DEBUG_USB
printf("USB_CRC: Addr 0x%lx \n", req_addr);
printf("USB_CRC: addr=0x%lx \n", req_addr);
#endif
#if USB_CRC_CHECK
@ -95,24 +101,74 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
crc_check_memory(req_addr,read_buffer);
sei();
#endif
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_BULK_UPLOAD_INIT) {
req_bank = 0;
rx_remaining = 0;
req_bank_size = 1 << rq->wValue.word;
sync_errors = 0;
#if DEBUG_USB
printf("USB_BULK_UPLOAD_INIT: bank_size=%li\n", req_bank_size);
#endif
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_BULK_UPLOAD_ADDR) {
req_state = REQ_STATUS_BULK_UPLOAD;
req_addr = rq->wValue.word;
req_addr = req_addr << 16;
req_addr = req_addr | rq->wIndex.word;
#if DEBUG_USB
printf("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx \n",req_bank,req_addr);
#endif
ret_len = 0;
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_BULK_UPLOAD_NEXT) {
if (rx_remaining) {
sync_errors++;
#if DEBUG_USB
printf
("USB_BULK_UPLOAD_NEXT: Out of sync addr=0x%lx remain=%i packet=%i sync_error=%i\n",
req_addr, rx_remaining, rq->wLength.word, sync_errors);
#endif
ret_len = 0;
}
rx_remaining = rq->wLength.word;
ret_len = USB_MAX_TRANS;
if (req_addr && req_addr % req_bank_size == 0) {
#if DEBUG_USB
printf("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr= 0x%08lx \n",
#endif
req_bank, req_addr);
req_bank++;
}
ret_len = USB_MAX_TRANS;
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_CRC_ADDR) {
req_state = REQ_STATUS_CRC;
req_addr = rq->wValue.word;
req_addr = req_addr << 16;
req_addr = req_addr | rq->wIndex.word;
#if DEBUG_USB
printf("USB_CRC_ADDR: Addr: 0x%lx Size: %i\n", req_addr,
#endif
printf("USB_CRC_ADDR: addr=0x%lx size=%i\n", req_addr,
rq->wLength.word);
#endif
req_size = rq->wLength.word;
req_size = req_size << 2;
tx_remaining = 2;
#if DEBUG_USB
printf("USB_CRC_ADDR: Addr: 0x%lx Size: %li\n", req_addr, req_size);
printf("USB_CRC_ADDR: addr=0x%lx size=%li\n", req_addr, req_size);
#endif
cli();

View File

@ -18,9 +18,16 @@
#define USB_UPLOAD_INIT 0
#define USB_UPLOAD_ADDR 1
#define USB_DOWNLOAD_INIT 2
#define USB_DOWNLOAD_ADDR 3
#define USB_CRC 4
#define USB_CRC_ADDR 5
#define USB_BULK_UPLOAD_INIT 6
#define USB_BULK_UPLOAD_ADDR 7
#define USB_BULK_UPLOAD_NEXT 8
#define USB_BULK_UPLOAD_END 9
#endif /* __REQUESTS_H_INCLUDED__ */

View File

@ -29,6 +29,8 @@ extern uint8_t tx_buffer[32];
uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
{
uint8_t *ptr;
uint8_t i;
if (len > rx_remaining) {
printf("usbFunctionWrite more data than expected remain: %i len: %i\n",
rx_remaining, len);
@ -38,13 +40,28 @@ uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
rx_remaining -= len;
#if DEBUG_USB_RAW
printf("usbFunctionWrite addr: 0x%08lx len: %i rx_remaining=%i\n",
printf("usbFunctionWrite REQ_STATUS_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n",
req_addr, len, rx_remaining);
#endif
cli();
sram_copy(req_addr, data, len);
sei();
req_addr += len;
} else if (req_state == REQ_STATUS_BULK_UPLOAD) {
rx_remaining -= len;
#if DEBUG_USB_RAW
printf("usbFunctionWrite REQ_STATUS_BULK_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n",
req_addr, len, rx_remaining);
#endif
ptr = data;
i = len;
cli();
while(i--){
sram_bulk_write(*ptr++);
counter_up();
}
sei();
}
return len;
}