add dump functions
This commit is contained in:
parent
e4e4beac3a
commit
0b12206f1d
@ -8,7 +8,7 @@ AVRDUDE = avrdude -c usbasp -p $(DEVICE)
|
||||
|
||||
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
|
||||
#-std=gnu99
|
||||
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o
|
||||
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o dump.o
|
||||
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
||||
|
||||
|
||||
|
||||
@ -2,13 +2,12 @@
|
||||
#ifndef __config_h__
|
||||
#define __config_h__
|
||||
|
||||
#define DEBUG_USB 1
|
||||
#define DEBUG_USB_RAW 1
|
||||
#define DEBUG_SRAM 0
|
||||
#define DEBUG_SRAM_RAW 0
|
||||
#define DEBUG_SREG 0
|
||||
#define DEBUG 1
|
||||
|
||||
#define DEBUG_USB 2
|
||||
#define DEBUG_USB_RAW 4
|
||||
#define DEBUG_SRAM 8
|
||||
#define DEBUG_SRAM_RAW 16
|
||||
#define DEBUG_SREG 32
|
||||
|
||||
#define REQ_STATUS_IDLE 0x01
|
||||
#define REQ_STATUS_UPLOAD 0x02
|
||||
|
||||
@ -7,38 +7,23 @@
|
||||
|
||||
extern FILE uart_stdout;
|
||||
|
||||
void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
|
||||
{
|
||||
uint16_t i,j;
|
||||
uint16_t sum = 0;
|
||||
uint8_t clear = 0;
|
||||
extern int debug_level; /* the higher, the more messages... */
|
||||
|
||||
for (i = 0; i < len; i += 16) {
|
||||
|
||||
sum = 0;
|
||||
for (j = 0; j < 16; j++) {
|
||||
sum += packet[i + j];
|
||||
}
|
||||
if (!sum) {
|
||||
clear = 1;
|
||||
continue;
|
||||
}
|
||||
if (clear) {
|
||||
printf("*\n");
|
||||
clear = 0;
|
||||
}
|
||||
printf("%08lx:", addr + i);
|
||||
for (j = 0; j < 16; j++) {
|
||||
printf(" %02x", packet[i + j]);
|
||||
}
|
||||
printf(" |");
|
||||
for (j = 0; j < 16; j++) {
|
||||
if (packet[i + j] >= 33 && packet[i + j] <= 126)
|
||||
printf("%c", packet[i + j]);
|
||||
else
|
||||
printf(".");
|
||||
}
|
||||
printf("|\n");
|
||||
}
|
||||
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||
/* Nothing. debug has been "defined away" in debug.h already. */
|
||||
#else
|
||||
void debug(int level, char* format, ...) {
|
||||
#ifdef NDEBUG
|
||||
/* Empty body, so a good compiler will optimise calls
|
||||
to pmesg away */
|
||||
#else
|
||||
va_list args;
|
||||
if (!(debug_level & level))
|
||||
return;
|
||||
va_start(args, format);
|
||||
printf(format, args);
|
||||
va_end(args);
|
||||
#endif /* NDEBUG */
|
||||
#endif /* NDEBUG && __GNUC__ */
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,22 @@
|
||||
#ifndef DEBUG_H
|
||||
#define DEBUG_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||
arguments. We use this extension here to preprocess pmesg away. */
|
||||
#define debug(level, format, args...) ((void)0)
|
||||
#else
|
||||
void debug(int level, char *format, ...);
|
||||
/* print a message, if it is considered significant enough.
|
||||
Adapted from [K&R2], p. 174 */
|
||||
#endif
|
||||
|
||||
void dump_packet(uint32_t addr,uint32_t len,uint8_t *packet);
|
||||
|
||||
#endif /* DEBUG_H */
|
||||
|
||||
60
avr/usbload/dump.c
Normal file
60
avr/usbload/dump.c
Normal file
@ -0,0 +1,60 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "uart.h"
|
||||
#include "sram.h"
|
||||
|
||||
|
||||
extern FILE uart_stdout;
|
||||
|
||||
void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
|
||||
{
|
||||
uint16_t i,j;
|
||||
uint16_t sum = 0;
|
||||
uint8_t clear = 0;
|
||||
|
||||
for (i = 0; i < len; i += 16) {
|
||||
|
||||
sum = 0;
|
||||
for (j = 0; j < 16; j++) {
|
||||
sum += packet[i + j];
|
||||
}
|
||||
if (!sum) {
|
||||
clear = 1;
|
||||
continue;
|
||||
}
|
||||
if (clear) {
|
||||
printf("*\n");
|
||||
clear = 0;
|
||||
}
|
||||
printf("%08lx:", addr + i);
|
||||
for (j = 0; j < 16; j++) {
|
||||
printf(" %02x", packet[i + j]);
|
||||
}
|
||||
printf(" |");
|
||||
for (j = 0; j < 16; j++) {
|
||||
if (packet[i + j] >= 33 && packet[i + j] <= 126)
|
||||
printf("%c", packet[i + j]);
|
||||
else
|
||||
printf(".");
|
||||
}
|
||||
printf("|\n");
|
||||
}
|
||||
}
|
||||
|
||||
void dump_memoryt(uint32_t bottom_addr, uint32_t top_addr)
|
||||
{
|
||||
uint32_t addr;
|
||||
uint8_t byte;
|
||||
sram_bulk_read_start(bottom_addr);
|
||||
printf("%08lx:", bottom_addr);
|
||||
for ( addr = bottom_addr; addr < top_addr; addr++) {
|
||||
if (addr%0x16 == 0)
|
||||
printf("\n%08lx:", bottom_addr);
|
||||
byte = sram_bulk_read();
|
||||
sram_bulk_read_next();
|
||||
printf(" %02x", byte);
|
||||
}
|
||||
sram_bulk_read_end();
|
||||
}
|
||||
12
avr/usbload/dump.h
Normal file
12
avr/usbload/dump.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef DUMP_H
|
||||
#define DUMP_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
void dump_packet(uint32_t addr,uint32_t len,uint8_t *packet);
|
||||
void dump_memoryt(uint32_t bottom_addr, uint32_t top_addr);
|
||||
|
||||
#endif
|
||||
|
||||
@ -17,6 +17,8 @@
|
||||
|
||||
extern FILE uart_stdout;
|
||||
|
||||
uint8_t debug_level = ( DEBUG | DEBUG_USB );
|
||||
|
||||
uint8_t read_buffer[TRANSFER_BUFFER_SIZE];
|
||||
uint32_t req_addr = 0;
|
||||
uint32_t req_size;
|
||||
|
||||
@ -285,13 +285,13 @@ void sram_bulk_read_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
|
||||
void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value){
|
||||
uint32_t i;
|
||||
#if DEBUG_SRAM
|
||||
printf("sram_bulk_clear: addr=0x%08lx len=%li\n\r", addr,len);
|
||||
printf("sram_bulk_set: addr=0x%08lx len=%li\n\r", addr,len);
|
||||
#endif
|
||||
sram_bulk_write_start(addr);
|
||||
for (i = addr; i < (addr + len); i++) {
|
||||
if (0 == i % 0xfff)
|
||||
#if DEBUG_SRAM
|
||||
printf("sram_bulk_clear: addr=0x%08lx\n\r", i);
|
||||
printf("sram_bulk_set: addr=0x%08lx\n\r", i);
|
||||
#endif
|
||||
sram_bulk_write(value);
|
||||
sram_bulk_write_next();
|
||||
@ -299,7 +299,7 @@ void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value){
|
||||
sram_bulk_write_end();
|
||||
}
|
||||
|
||||
void sram_clear(uint32_t addr, uint32_t len)
|
||||
void sram_setr(uint32_t addr, uint32_t len,uint8_t value)
|
||||
{
|
||||
uint32_t i;
|
||||
#if DEBUG_SRAM
|
||||
@ -310,7 +310,7 @@ void sram_clear(uint32_t addr, uint32_t len)
|
||||
#if DEBUG_SRAM
|
||||
printf("sram_clear: addr=0x%08lx\n\r", i);
|
||||
#endif
|
||||
sram_write(i, 0x00);
|
||||
sram_write(i, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -145,7 +145,7 @@ void sreg_set(uint32_t addr);
|
||||
|
||||
uint8_t sram_read(uint32_t addr);
|
||||
void sram_write(uint32_t addr, uint8_t data);
|
||||
void sram_clear(uint32_t addr, uint32_t len);
|
||||
void sram_set(uint32_t addr, uint32_t len, uint8_t value);
|
||||
void sram_copy(uint32_t addr,uint8_t *src, uint32_t len);
|
||||
void sram_read_buffer(uint32_t addr,uint8_t *dst, uint32_t len);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user