suddenly there were drago^W^W was debug code

master
Dario Ernst 15 years ago
parent acd9c72eac
commit 609b8e836e

@ -28,7 +28,7 @@ respectively.
#include "../firmware/masterchip/usbdrv/usbconfig.h" /* device's VID/PID and names */
void usage() {
printf("Usage: read-temp [spi|temp] [opcode] [addr] [value]\n");
printf("Usage: read-temp [spi|temp|dbg] [[opcode] [addr] [value]]\n");
}
int main(int argc, char **argv)
@ -117,6 +117,28 @@ 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) {
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());
}
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();
}

@ -2,7 +2,7 @@ include ../Makefile.inc
COMPILE = avr-gcc $(CFLAGS) $(DEFINES)
OBJECTS = main.o mcp_adc.o i2c_simple.o softtimer.o spi_proto.o spi.o spi_pointers.o muxer.o
OBJECTS = main.o mcp_adc.o i2c_simple.o softtimer.o spi_proto.o spi.o spi_pointers.o muxer.o debug.o
# symbolic targets:
all: firmware.hex

@ -0,0 +1,8 @@
;; Object thermocouple
;; EDE project file.
(ede-proj-project "thermocouple"
:name "thermocouple"
:file "Project.ede"
:targets (list
)
)

@ -0,0 +1,37 @@
#include "debug.h"
#include <stdio.h>
char debugStr[DEBUGCHARS];
volatile char dbgCurChar;
volatile uint8_t dbgStrFill; // amount of available chars in debugStr
volatile uint8_t dbgHasNewSPI;
void dbgLog(const char* fmt, ...) {
uint8_t maxwrite = DEBUGCHARS - dbgStrFill;
va_list va;
va_start(va,fmt);
char* pos = debugStr + dbgStrFill;
dbgStrFill += vsnprintf(pos, maxwrite, fmt, va);
va_end(va);
}
uint8_t dbgHasNew() {
dbgHasNewSPI = (dbgStrFill > 0);
return (dbgStrFill > 0);
}
char dbgReadChar() {
if(dbgHasNew()) {
char ret = debugStr[0];
for(int i=0; i<dbgStrFill-1; i++) {
debugStr[i] = debugStr[i+1];
}
return ret;
} else {
return 0xFF;
}
}
void dbgAdvanceChar() {
dbgCurChar = dbgReadChar();
}

@ -0,0 +1,18 @@
#ifndef __DEBUG_H
#define __DEBUG_H
#include <stdint.h>
#include <stdio.h>
#define DEBUGCHARS 100
extern char debugStr[];
extern volatile uint8_t dbgStrFill; // amount of available chars in debugStr
extern volatile uint8_t dbgHasNewSPI;
extern volatile char dbgCurChar;
void dbgLog(const char* fmt, ...);
uint8_t dbgHasNew();
char dbgReadChar();
void dbgAdvanceChar();
#endif

@ -99,8 +99,13 @@ inline uint8_t i2c_write(uint8_t addr, uint8_t len, uint8_t *data)
return i2c_write_i(addr, len, data, 1);
}
uint8_t i2c_write_read(uint8_t addr, uint8_t writelen, uint8_t *writedata, uint8_t readlen, uint8_t *readdata)
{
if(writelen == i2c_write_i(addr, writelen, writedata, 0)) {return i2c_read(addr, readlen, readdata);}
if(writelen == i2c_write_i(addr, writelen, writedata, 0)) {
return i2c_read(addr, readlen, readdata);
}
return 0;
}

@ -12,6 +12,7 @@
#define SOFTTIMERNUMS 4
#include "softtimer.h"
#include "debug.h"
extern uint8_t foo;
extern uint16_t bar;

@ -1,34 +1,23 @@
#include "spi_pointers.h"
#include "main.h"
uint8_t *spi_proto_globals8[] = {
&foo,
&foo,
&foo,
&foo,
&foo,
&foo,
&foo
};
&dbgHasNewSPI,
&dbgCurChar
};
uint16_t *spi_proto_globals16[] = {
&timertmp,
&temperatures[0],
&temperatures[1],
&temperatures[2],
&temperatures[3],
&bar,
&bar,
&bar,
&bar,
&bar,
&bar,
&bar,
&bar
};
&timertmp,
&temperatures[0],
&temperatures[1],
&temperatures[2],
&temperatures[3],
};
funptr_t spi_proto_funcs[] = {
&baz
};
&dbgHasNew,
&dbgAdvanceChar
};

Loading…
Cancel
Save