cleanyp code and remove inital debug
This commit is contained in:
parent
b443d3df2f
commit
d65a17184f
@ -9,8 +9,7 @@ extern FILE uart_stdout;
|
|||||||
|
|
||||||
void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
|
void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
|
||||||
{
|
{
|
||||||
uint16_t i,
|
uint16_t i,j;
|
||||||
j;
|
|
||||||
uint16_t sum = 0;
|
uint16_t sum = 0;
|
||||||
uint8_t clear = 0;
|
uint8_t clear = 0;
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include "usbdrv.h"
|
#include "usbdrv.h"
|
||||||
#include "oddebug.h" /* This is also an example for using debug
|
#include "oddebug.h" /* This is also an example for using debug
|
||||||
* macros */
|
* macros */
|
||||||
|
#include "config.h"
|
||||||
#include "requests.h" /* The custom request numbers we use */
|
#include "requests.h" /* The custom request numbers we use */
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "sram.h"
|
#include "sram.h"
|
||||||
@ -15,11 +16,6 @@
|
|||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
|
|
||||||
|
|
||||||
#define REQ_IDLE 0
|
|
||||||
#define REQ_UPLOAD 1
|
|
||||||
#define RES_CRC 2
|
|
||||||
#define BUFFER_SIZE 256
|
|
||||||
|
|
||||||
extern FILE uart_stdout;
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
uint8_t read_buffer[BUFFER_SIZE];
|
uint8_t read_buffer[BUFFER_SIZE];
|
||||||
@ -64,7 +60,9 @@ void crc_check_memory_range(uint32_t start_addr, uint32_t size)
|
|||||||
}
|
}
|
||||||
tx_buffer[0] = crc & 0xff;
|
tx_buffer[0] = crc & 0xff;
|
||||||
tx_buffer[1] = (crc >> 8) & 0xff;
|
tx_buffer[1] = (crc >> 8) & 0xff;
|
||||||
|
#if DEBUG_USB
|
||||||
printf("crc_check_memory_range: Addr: 0x%lx CRC: %x\n", addr, crc);
|
printf("crc_check_memory_range: Addr: 0x%lx CRC: %x\n", addr, crc);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -78,7 +76,9 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
rx_remaining = 0;
|
rx_remaining = 0;
|
||||||
req_bank_size = 1 << rq->wValue.word;
|
req_bank_size = 1 << rq->wValue.word;
|
||||||
sync_errors = 0;
|
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
|
||||||
} else if (rq->bRequest == USB_UPLOAD_ADDR) { /* echo -- used for
|
} else if (rq->bRequest == USB_UPLOAD_ADDR) { /* echo -- used for
|
||||||
* reliability tests */
|
* reliability tests */
|
||||||
req_state = REQ_UPLOAD;
|
req_state = REQ_UPLOAD;
|
||||||
@ -88,27 +88,35 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
if (rx_remaining) {
|
if (rx_remaining) {
|
||||||
sync_errors++;
|
sync_errors++;
|
||||||
printf
|
printf
|
||||||
|
#if DEBUG_USB
|
||||||
("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);
|
req_addr, rx_remaining, rq->wLength.word, sync_errors);
|
||||||
|
#endif
|
||||||
ret_len = 0;
|
ret_len = 0;
|
||||||
}
|
}
|
||||||
rx_remaining = rq->wLength.word;
|
rx_remaining = rq->wLength.word;
|
||||||
ret_len = 0xff;
|
ret_len = 0xff;
|
||||||
if (req_addr && req_addr % req_bank_size == 0) {
|
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%x Addr: 0x%08lx \n",
|
||||||
|
#endif
|
||||||
req_bank, req_addr);
|
req_bank, req_addr);
|
||||||
req_bank++;
|
req_bank++;
|
||||||
}
|
}
|
||||||
ret_len = 0xff;
|
ret_len = 0xff;
|
||||||
} else if (rq->bRequest == USB_DOWNLOAD_INIT) {
|
} else if (rq->bRequest == USB_DOWNLOAD_INIT) {
|
||||||
|
#if DEBUG_USB
|
||||||
printf("USB_DOWNLOAD_INIT\n");
|
printf("USB_DOWNLOAD_INIT\n");
|
||||||
|
#endif
|
||||||
} else if (rq->bRequest == USB_DOWNLOAD_ADDR) {
|
} else if (rq->bRequest == USB_DOWNLOAD_ADDR) {
|
||||||
printf("USB_DOWNLOAD_ADDR\n");
|
printf("USB_DOWNLOAD_ADDR\n");
|
||||||
} else if (rq->bRequest == USB_CRC) {
|
} else if (rq->bRequest == USB_CRC) {
|
||||||
req_addr = rq->wValue.word;
|
req_addr = rq->wValue.word;
|
||||||
req_addr = req_addr << 16;
|
req_addr = req_addr << 16;
|
||||||
req_addr = req_addr | rq->wIndex.word;
|
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
|
||||||
cli();
|
cli();
|
||||||
crc_check_memory(req_addr);
|
crc_check_memory(req_addr);
|
||||||
sei();
|
sei();
|
||||||
@ -116,12 +124,16 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
req_addr = rq->wValue.word;
|
req_addr = rq->wValue.word;
|
||||||
req_addr = req_addr << 16;
|
req_addr = req_addr << 16;
|
||||||
req_addr = req_addr | rq->wIndex.word;
|
req_addr = req_addr | rq->wIndex.word;
|
||||||
|
#if DEBUG_USB
|
||||||
printf("USB_CRC_ADDR: Addr: 0x%lx Size: %i\n", req_addr,
|
printf("USB_CRC_ADDR: Addr: 0x%lx Size: %i\n", req_addr,
|
||||||
|
#endif
|
||||||
rq->wLength.word);
|
rq->wLength.word);
|
||||||
req_size = rq->wLength.word;
|
req_size = rq->wLength.word;
|
||||||
req_size = req_size << 2;
|
req_size = req_size << 2;
|
||||||
tx_remaining = 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();
|
cli();
|
||||||
// crc_check_memory_range(req_addr,req_size);
|
// crc_check_memory_range(req_addr,req_size);
|
||||||
sei();
|
sei();
|
||||||
@ -144,7 +156,7 @@ uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
|
|||||||
if (req_state == REQ_UPLOAD) {
|
if (req_state == REQ_UPLOAD) {
|
||||||
|
|
||||||
rx_remaining -= len;
|
rx_remaining -= len;
|
||||||
#if 1
|
#if DEBUG_USB_RAW
|
||||||
printf("usbFunctionWrite addr: 0x%08lx len: %i rx_remaining=%i\n",
|
printf("usbFunctionWrite addr: 0x%08lx len: %i rx_remaining=%i\n",
|
||||||
req_addr, len, rx_remaining);
|
req_addr, len, rx_remaining);
|
||||||
#endif
|
#endif
|
||||||
@ -162,7 +174,7 @@ uint8_t usbFunctionRead(uint8_t * data, uint8_t len)
|
|||||||
if (len > tx_remaining)
|
if (len > tx_remaining)
|
||||||
len = tx_remaining;
|
len = tx_remaining;
|
||||||
tx_remaining -= len;
|
tx_remaining -= len;
|
||||||
#if 1
|
#if DEBUG_USB_RAW
|
||||||
printf("usbFunctionRead len=%i tx_remaining=%i \n", len, tx_remaining);
|
printf("usbFunctionRead len=%i tx_remaining=%i \n", len, tx_remaining);
|
||||||
#endif
|
#endif
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
@ -180,62 +192,25 @@ int main(void)
|
|||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
|
|
||||||
wdt_enable(WDTO_8S);
|
|
||||||
uart_init();
|
uart_init();
|
||||||
stdout = &uart_stdout;
|
stdout = &uart_stdout;
|
||||||
|
|
||||||
system_init();
|
system_init();
|
||||||
|
|
||||||
printf("Sytem Init\n");
|
printf("Sytem Init\n");
|
||||||
avr_bus_active();
|
|
||||||
|
|
||||||
|
|
||||||
DDRB|= (1 << PB1);
|
|
||||||
PORTB|= (1 << PB1);
|
|
||||||
while(1)
|
|
||||||
wdt_reset();
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
avr_bus_active();
|
avr_bus_active();
|
||||||
printf("set sreg 0xff55aa\n");
|
|
||||||
sreg_set(0xff55aa);
|
|
||||||
counter_load();
|
|
||||||
sram_write(0xff55aa,0x55);
|
|
||||||
while(1)
|
|
||||||
wdt_reset();
|
|
||||||
addr = 0x3fffff;
|
|
||||||
sreg_set(0x00000);
|
|
||||||
counter_load();
|
|
||||||
wdt_reset();
|
|
||||||
|
|
||||||
while(addr--){
|
addr = 0x000000;
|
||||||
counter_up();
|
|
||||||
}
|
|
||||||
printf("done\n");
|
|
||||||
|
|
||||||
while(1){
|
|
||||||
wdt_reset();
|
|
||||||
i = 10;
|
|
||||||
while(i--)
|
|
||||||
_delay_ms(100);
|
|
||||||
//printf("counter up\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
avr_bus_active();
|
|
||||||
#if 1
|
|
||||||
addr = 0x00;
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (addr++ <= 0xff){
|
while (addr++ <= 0x00ffff){
|
||||||
sram_write(addr,i++);
|
sram_write(addr,i++);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
addr = 0x00;
|
addr = 0x000000;
|
||||||
while (addr++ <= 0xff){
|
while (addr++ <= 0x00ffff){
|
||||||
printf("read addr=0x%08lx %x\n",addr,sram_read(addr));
|
printf("read addr=0x%08lx %x\n",addr,sram_read(addr));
|
||||||
}
|
}
|
||||||
while(1);
|
|
||||||
|
|
||||||
usbInit();
|
usbInit();
|
||||||
printf("USB Init\n");
|
printf("USB Init\n");
|
||||||
@ -253,14 +228,11 @@ int main(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
led_on();
|
led_on();
|
||||||
|
|
||||||
|
|
||||||
usbDeviceConnect();
|
usbDeviceConnect();
|
||||||
printf("USB connect\n");
|
printf("USB connect\n");
|
||||||
sei();
|
sei();
|
||||||
printf("USB poll\n");
|
printf("USB poll\n");
|
||||||
for (;;) { /* main event loop */
|
for (;;) { /* main event loop */
|
||||||
wdt_reset();
|
|
||||||
usbPoll();
|
usbPoll();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -5,11 +5,11 @@
|
|||||||
#include <util/delay.h> /* for _delay_ms() */
|
#include <util/delay.h> /* for _delay_ms() */
|
||||||
|
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "sram.h"
|
#include "sram.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
void system_init(void)
|
void system_init(void)
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*/
|
/*-------------------------------------------------*/
|
||||||
@ -67,20 +67,28 @@ void system_init(void)
|
|||||||
void sreg_set(uint32_t addr)
|
void sreg_set(uint32_t addr)
|
||||||
{
|
{
|
||||||
uint8_t i = 24;
|
uint8_t i = 24;
|
||||||
printf("sreg addr=0x%08lx ",addr);
|
#ifdef DEBUG_SREG
|
||||||
|
printf("sreg_set: addr=0x%08lx",addr);
|
||||||
|
#endif
|
||||||
while(i--) {
|
while(i--) {
|
||||||
if ((addr & ( 1L << i))){
|
if ((addr & ( 1L << i))){
|
||||||
|
#ifdef DEBUG_SREG
|
||||||
printf("1");
|
printf("1");
|
||||||
|
#endif
|
||||||
AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN);
|
AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN);
|
||||||
} else {
|
} else {
|
||||||
AVR_ADDR_SER_PORT &= ~( 1 << AVR_ADDR_SER_PIN);
|
AVR_ADDR_SER_PORT &= ~( 1 << AVR_ADDR_SER_PIN);
|
||||||
|
#ifdef DEBUG_SREG
|
||||||
printf("0");
|
printf("0");
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN);
|
AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN);
|
||||||
AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN);
|
AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN);
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG_SREG
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
#endif
|
||||||
AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN);
|
AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN);
|
||||||
AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN);
|
AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN);
|
||||||
|
|
||||||
@ -99,7 +107,6 @@ uint8_t sram_read(uint32_t addr)
|
|||||||
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||||
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
||||||
AVR_CS_PORT &= ~(1 << AVR_CS_PIN);
|
AVR_CS_PORT &= ~(1 << AVR_CS_PIN);
|
||||||
_delay_ms(1);
|
|
||||||
|
|
||||||
sreg_set(addr);
|
sreg_set(addr);
|
||||||
|
|
||||||
@ -115,13 +122,8 @@ uint8_t sram_read(uint32_t addr)
|
|||||||
asm volatile ("nop");
|
asm volatile ("nop");
|
||||||
|
|
||||||
byte = AVR_DATA_PIN;
|
byte = AVR_DATA_PIN;
|
||||||
#if 0
|
|
||||||
printf("read %x\n",byte);
|
|
||||||
while(1)
|
|
||||||
wdt_reset();
|
|
||||||
#endif
|
|
||||||
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
||||||
|
|
||||||
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
||||||
|
|
||||||
avr_data_in();
|
avr_data_in();
|
||||||
@ -155,7 +157,7 @@ void sram_clear(uint32_t addr, uint32_t len)
|
|||||||
uint32_t i;
|
uint32_t i;
|
||||||
for (i = addr; i < (addr + len); i++) {
|
for (i = addr; i < (addr + len); i++) {
|
||||||
if (0 == i % 0xfff)
|
if (0 == i % 0xfff)
|
||||||
printf("sram_clear %lx\n\r", i);
|
printf("sram_clear: addr=0x%08lx\n\r", i);
|
||||||
sram_write(i, 0x00);
|
sram_write(i, 0x00);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user