Merge branch 'debugger'

Conflicts:
	firmware/slavechip/main.c
master
Paul Goeser 15 years ago committed by Dario Ernst
commit bd68f6fc67

@ -24,11 +24,12 @@ 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 */
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 +118,56 @@ 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], "dbg") == 0) {
if(argc != 2) {
usage();
return 0;
}
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?
// 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);
// 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);
if(rxIndex != 0 && (rxIndex & 0xff) != 0xff){
fprintf(stderr, "%c", rxIndex);
}
}
usleep(1000);
}
} 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,38 @@
#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];
}
dbgStrFill--;
return ret;
} else {
return 0xFF;
}
}
void dbgAdvanceChar() {
dbgCurChar = dbgReadChar();
}

@ -0,0 +1,17 @@
#ifndef __DEBUG_H
#define __DEBUG_H
#include <stdint.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;
}

@ -4,6 +4,8 @@
#include "i2c_simple.h"
#include "mcp_adc.h"
#include "debug.h"
uint8_t foo;
uint16_t bar;
uint16_t timertmp;
@ -67,6 +69,7 @@ int __attribute__((noreturn)) main(void) {
muxer_set(MUXER_CHANNEL_0);
temperatures[2]=0;
dbgLog("Hallo, Welt!\n");
for(;;){

@ -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