From c1fcceee0a93d6b3793c72ca331b2aede3c98da2 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Fri, 10 Dec 2010 20:40:19 +0100 Subject: [PATCH 01/12] working on softtimer/display-oddity stuff --- firmware/Makefile | 2 +- firmware/display.c | 4 ---- firmware/display.h | 3 ++- firmware/main.c | 46 +++++++++++++++++++++++++--------------------- firmware/main.h | 3 +-- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/firmware/Makefile b/firmware/Makefile index bed7b54..6a7a846 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -1,6 +1,6 @@ DEFINES += -DF_CPU=16000000 CFLAGS += -save-temps -CFLAGS += -std=gnu99 # implements C99, for +CFLAGS += -std=gnu99 -Wall # implements C99, for # this removes dead code and does global linker optimization #CFLAGS += -ffunction-sections -Wl,--gc-sections -Wl,--relax diff --git a/firmware/display.c b/firmware/display.c index ec56c27..3b9b18e 100644 --- a/firmware/display.c +++ b/firmware/display.c @@ -255,10 +255,6 @@ void display_bar(int8_t value, int8_t min, int8_t max) { } } - - - - void updateTemperature() { if(newThermoData==1) { newThermoData = 0; diff --git a/firmware/display.h b/firmware/display.h index 6447319..f65a79b 100644 --- a/firmware/display.h +++ b/firmware/display.h @@ -5,6 +5,7 @@ #include "lcd/lcd.h" #include "main.h" + #define LCD_CHAR_HALFBAR 0x01 #define LCD_CHAR_BAR 0x02 #define LCD_CHAR_DEGREE 0x03 @@ -33,6 +34,6 @@ extern void display_puthex(uint8_t outbyte); extern void display_bar(int8_t value, int8_t min, int8_t max); extern void display_putint(int16_t number); -void updateTemperature(); +extern void updateTemperature(); #endif diff --git a/firmware/main.c b/firmware/main.c index 4e0dda3..5f8b085 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -1,10 +1,10 @@ #include "main.h" -#define SOFTTIMERNUMS 4 +volatile uint16_t timer1_acc; uint16_t softtimer_last[SOFTTIMERNUMS]; void softtimer_reset(uint8_t timernum){ - softtimer_last[SOFTTIMERNUMS] = timer1_acc; + softtimer_last[timernum] = timer1_acc; } uint8_t softtimer(uint8_t timernum, uint16_t interval){ @@ -16,6 +16,7 @@ uint8_t softtimer(uint8_t timernum, uint16_t interval){ return(0); } +// SOFTTIMER( , ); #define SOFTTIMER(n,a) if(softtimer((n),(a*4))) @@ -35,6 +36,9 @@ void hardinit() { OCR1A = 15; // contrast OCR1B = 50; // brightness + + // enable softtimer isr + TIMSK1 |= _BV(TOIE1); // init LCD: lcd_init(1); @@ -51,27 +55,25 @@ void softinit() { int __attribute__((noreturn)) main(void) { - int i=0; hardinit(); softinit(); usbInit(); - display_puts("Hallo, Welt!\n\n"); - display_update(); - - for(;;){ usbPoll(); - SOFTTIMER(1,100){ - updateTemperature(); + SOFTTIMER(2,500) { + thermoData[0]=thermoData[0]+5; + thermoData[1]=thermoData[1]+15; + thermoData[2]=thermoData[2]+7; + thermoData[3]=thermoData[3]+18; + newThermoData = 1; + } + + SOFTTIMER(1,100) { + updateTemperature(); } - thermoData[0]=thermoData[0]+5; - thermoData[1]=thermoData[1]+15; - thermoData[2]=thermoData[2]+7; - thermoData[3]=thermoData[3]+18; - i++; if(i%200 == 0) newThermoData = 1; } } @@ -82,16 +84,18 @@ int __attribute__((noreturn)) main(void) { asm volatile ("out %1, %0\n" : "=r" (sreg_store) : "I" (_SFR_IO_ADDR(SREG))); reti(); }*/ + ISR(TIMER1_OVF_vect,ISR_NOBLOCK){ - uint16_t temp; - temp=timer1_acc; - temp++; - ATOMIC_BLOCK(ATOMIC_FORCEON){ - timer1_acc=temp; - } + uint16_t tmp; + tmp=timer1_acc; + tmp++; + /* the ATOMIC is acutally only needed if timer1_acc is never read from an ISR, which * is probably the case. * ATOMIC_FORCEON: the ISR_NOBLOCK sets sei() a few cycles before. */ -} + ATOMIC_BLOCK(ATOMIC_FORCEON){ + timer1_acc=tmp; + } +} diff --git a/firmware/main.h b/firmware/main.h index 213c57f..5008b1c 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -26,11 +26,10 @@ #include "spi.h" #include "usb.h" - static uint8_t newThermoData = 1; static uint16_t thermoData[] = {1024, 814, 2475, 2243}; -volatile uint16_t timer1_acc; +#define SOFTTIMERNUMS 4 #define LED1PORT PORTC #define LED1APIN 0 From bd37b567a3786b88b34ece6e330fb236abaab2fe Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Fri, 10 Dec 2010 20:47:14 +0100 Subject: [PATCH 02/12] finally works again --- firmware/display.h | 4 ++++ firmware/main.c | 6 +++++- firmware/main.h | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/firmware/display.h b/firmware/display.h index f65a79b..c085f61 100644 --- a/firmware/display.h +++ b/firmware/display.h @@ -11,6 +11,10 @@ #define LCD_CHAR_DEGREE 0x03 #define LCD_CHAR_BLANK 0x20 +extern uint8_t newThermoData1; +extern uint16_t thermoData[]; + + extern const prog_uint8_t lcd_halfbar_char[]; extern const prog_uint8_t lcd_bar_char[]; extern const prog_uint8_t lcd_degree_char[]; diff --git a/firmware/main.c b/firmware/main.c index 5f8b085..df2ee59 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -1,5 +1,9 @@ #include "main.h" +uint8_t newThermoData = 1; +uint16_t thermoData[] = {1024, 814, 2475, 2243}; + + volatile uint16_t timer1_acc; uint16_t softtimer_last[SOFTTIMERNUMS]; @@ -70,7 +74,7 @@ int __attribute__((noreturn)) main(void) { newThermoData = 1; } - SOFTTIMER(1,100) { + SOFTTIMER(1,250) { updateTemperature(); } diff --git a/firmware/main.h b/firmware/main.h index 5008b1c..fc9bc6a 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -26,8 +26,8 @@ #include "spi.h" #include "usb.h" -static uint8_t newThermoData = 1; -static uint16_t thermoData[] = {1024, 814, 2475, 2243}; +extern uint8_t newThermoData; +extern uint16_t thermoData[]; #define SOFTTIMERNUMS 4 From c3503c6b7938d17c259738f435e87ac37a23a0f1 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Fri, 10 Dec 2010 20:47:52 +0100 Subject: [PATCH 03/12] finally works again --- firmware/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index df2ee59..e8f1835 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -3,7 +3,6 @@ uint8_t newThermoData = 1; uint16_t thermoData[] = {1024, 814, 2475, 2243}; - volatile uint16_t timer1_acc; uint16_t softtimer_last[SOFTTIMERNUMS]; @@ -21,7 +20,7 @@ uint8_t softtimer(uint8_t timernum, uint16_t interval){ } // SOFTTIMER( , ); -#define SOFTTIMER(n,a) if(softtimer((n),(a*4))) +#define SOFTTIMER(n,a) if(softtimer((n),(a*8))) void hardinit() { From 994bf4d7d8ec17903d8e53356634190c01e393b2 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Fri, 10 Dec 2010 21:04:28 +0100 Subject: [PATCH 04/12] updated todo --- TODO | 7 ++----- cmdline/read-temp.c | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index baa624c..7b6b24f 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,7 @@ TODO für ersten funktionierenden Stand: Hardware: -- Analogteil +# Analogteil Software: - I2C-Code @@ -11,10 +11,7 @@ Software: Später: -- USB-Protokoll auf AVR -- USB-Client am Rechner -- Display-Code - PT1000 - Digitalansteuerung für muxer/offsetkompensatoren - Gehäuse -- Thermocouple-Buchsen +# Thermocouple-Buchsen diff --git a/cmdline/read-temp.c b/cmdline/read-temp.c index 1f960bc..449a6d8 100644 --- a/cmdline/read-temp.c +++ b/cmdline/read-temp.c @@ -74,8 +74,8 @@ int cnt, vid, pid; } rxValue = ((int)buffer[1] & 0xff) | (((int)buffer[0] & 0xff) << 8); rxIndex = ((int)buffer[3] & 0xff) | (((int)buffer[2] & 0xff) << 8); - fprintf(stderr, "%3d.%02d*C||", rxValue/100, rxValue%100); - fprintf(stderr, "%3d.%02d*C\n", rxIndex/100, rxIndex%100); + fprintf(stderr, "%3d.%02d*C ", rxValue/100, rxValue%100); + fprintf(stderr, "%3d.%02d*C \n", rxIndex/100, rxIndex%100); cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 2, value, index, buffer, sizeof(buffer), 5000); if(cnt < 0){ @@ -83,8 +83,8 @@ int cnt, vid, pid; } rxValue = ((int)buffer[1] & 0xff) | (((int)buffer[0] & 0xff) << 8); rxIndex = ((int)buffer[3] & 0xff) | (((int)buffer[2] & 0xff) << 8); - fprintf(stderr, "%3d.%02d*C||", rxValue/100, rxValue%100); - fprintf(stderr, "%3d.%02d*C\n", rxIndex/100, rxIndex%100); + fprintf(stderr, "%3d.%02d*C ", rxValue/100, rxValue%100); + fprintf(stderr, "%3d.%02d*C \n", rxIndex/100, rxIndex%100); usb_close(handle); From 4200e69a339714f248fa5859a0c3b0d5a0ae6260 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Fri, 10 Dec 2010 21:46:40 +0100 Subject: [PATCH 05/12] added SPI protocol --- documentation/SPI-Proto | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 documentation/SPI-Proto diff --git a/documentation/SPI-Proto b/documentation/SPI-Proto new file mode 100644 index 0000000..bf19dd5 --- /dev/null +++ b/documentation/SPI-Proto @@ -0,0 +1,26 @@ + 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 + +-------------+ +-------------+ +-------------+ +-------------+ + | OpCode | | Address | | ValueH | | ValueL | + +-------------+ +-------------+ +-------------+ +-------------+ + + +Where following values are Valid: +|--------------------------------------------------------------------------------------------------------------------------| +| Binary Hex Name Address ValueL ValueH Reply Description| +|--------------------------------------------------------------------------------------------------------------------------| +| 0000001 0x01 Read-Temp Number of None/Rand None/Rand A 16Bit Value Reads the | +| Thermometer Representing Temperature| +| Starting with 0 the Temperature | +|--------------------------------------------------------------------------------------------------------------------------| +| 0000002 0x02 Read-Var8 Number of the None/Rand None/Rand A 8Bit Value Reads 8Bit | +| var-DEFINE read from VAR Variable | +|--------------------------------------------------------------------------------------------------------------------------| +| 0000003 0x03 Read-Var16 Number of the None/Rand None/Rand A 16Bit Value Reads 16Bit| +| var-DEFINE read from VAR Variable | +|--------------------------------------------------------------------------------------------------------------------------| +| 0000004 0x04 Write-Var8 Number of the Value of Var None/Rand None/Rand Writes 8Bit| +| var-DEFINE to write Variable | +|--------------------------------------------------------------------------------------------------------------------------| +| 0000005 0x05 Write-Var16 Number of the Value of Var Value of Var None/Rand Writes 16 | +| var-DEFINE to write (HIGH) to write (LOW) Bit Var | +|--------------------------------------------------------------------------------------------------------------------------| From 01fb4da199d922402180dfc31a3bdda24aac772d Mon Sep 17 00:00:00 2001 From: Matthias Merz Date: Fri, 10 Dec 2010 21:48:48 +0100 Subject: [PATCH 06/12] tree reorg for separate master/slave build-dirs * moved files * rudimentary Makefile-support --- firmware/Makefile | 10 +++- firmware/Makefile.inc | 13 ++++++ firmware/masterchip/Makefile | 67 +++++++++++++++++++++++++++ firmware/{ => masterchip}/display.c | 0 firmware/{ => masterchip}/display.h | 0 firmware/{ => masterchip}/lcd/COPYING | 0 firmware/{ => masterchip}/lcd/lcd.c | 0 firmware/{ => masterchip}/lcd/lcd.h | 0 firmware/{ => masterchip}/main.c | 0 firmware/{ => masterchip}/main.h | 0 firmware/masterchip/spi.c | 1 + firmware/masterchip/spi.h | 1 + firmware/{ => masterchip}/usb.c | 0 firmware/{ => masterchip}/usb.h | 0 firmware/masterchip/usbdrv | 1 + firmware/{ => shared}/spi.c | 0 firmware/{ => shared}/spi.h | 0 firmware/slavechip/Makefile | 66 ++++++++++++++++++++++++++ firmware/{ => slavechip}/i2c_simple.c | 0 firmware/{ => slavechip}/i2c_simple.h | 0 firmware/{ => slavechip}/mcp_adc.c | 0 firmware/{ => slavechip}/mcp_adc.h | 0 firmware/usbdrv | 1 - 23 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 firmware/Makefile.inc create mode 100644 firmware/masterchip/Makefile rename firmware/{ => masterchip}/display.c (100%) rename firmware/{ => masterchip}/display.h (100%) rename firmware/{ => masterchip}/lcd/COPYING (100%) rename firmware/{ => masterchip}/lcd/lcd.c (100%) rename firmware/{ => masterchip}/lcd/lcd.h (100%) rename firmware/{ => masterchip}/main.c (100%) rename firmware/{ => masterchip}/main.h (100%) create mode 120000 firmware/masterchip/spi.c create mode 120000 firmware/masterchip/spi.h rename firmware/{ => masterchip}/usb.c (100%) rename firmware/{ => masterchip}/usb.h (100%) create mode 120000 firmware/masterchip/usbdrv rename firmware/{ => shared}/spi.c (100%) rename firmware/{ => shared}/spi.h (100%) create mode 100644 firmware/slavechip/Makefile rename firmware/{ => slavechip}/i2c_simple.c (100%) rename firmware/{ => slavechip}/i2c_simple.h (100%) rename firmware/{ => slavechip}/mcp_adc.c (100%) rename firmware/{ => slavechip}/mcp_adc.h (100%) delete mode 120000 firmware/usbdrv diff --git a/firmware/Makefile b/firmware/Makefile index bed7b54..47ccb94 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -4,9 +4,15 @@ CFLAGS += -std=gnu99 # implements C99, for # this removes dead code and does global linker optimization #CFLAGS += -ffunction-sections -Wl,--gc-sections -Wl,--relax -OBJECTS = usbdrv/usbdrvasm.o usbdrv/usbdrv.o main.o display.o lcd/lcd.o mcp_adc.o i2c_simple.o usb.o +include Makefile.inc +# symbolic targets: +all: master -include avrbuild/Makefile.avrbuild +master: + cd masterchip; $(MAKE) $(MFLAGS) +clean: + cd masterchip; $(MAKE) $(MFLAGS) clean + cd slavechip; $(MAKE) $(MFLAGS) clean diff --git a/firmware/Makefile.inc b/firmware/Makefile.inc new file mode 100644 index 0000000..03314b8 --- /dev/null +++ b/firmware/Makefile.inc @@ -0,0 +1,13 @@ +DEFINES += -DF_CPU=16000000 +CFLAGS += -save-temps +CFLAGS += -std=gnu99 -Wall # implements C99, for +# this removes dead code and does global linker optimization +#CFLAGS += -ffunction-sections -Wl,--gc-sections -Wl,--relax +CFLAGS += -Wall -Os -I. -mmcu=atmega88 + +# further optimization: +#CFLAGS += --param inline-call-cost=2 +CFLAGS += -fno-move-loop-invariants # suggestions from from v-usb +CFLAGS += -fno-tree-scev-cprop +CFLAGS += -fno-inline-small-functions + diff --git a/firmware/masterchip/Makefile b/firmware/masterchip/Makefile new file mode 100644 index 0000000..7bcd805 --- /dev/null +++ b/firmware/masterchip/Makefile @@ -0,0 +1,67 @@ +# masterchip-makefile +include ../Makefile.inc + +COMPILE = avr-gcc $(CFLAGS) $(DEFINES) + +OBJECTS = usbdrv/usbdrvasm.o usbdrv/usbdrv.o main.o display.o lcd/lcd.o usb.o + +# symbolic targets: +all: firmware.hex + +.c.o: + $(COMPILE) -c $< -o $@ + +.S.o: + $(COMPILE) -x assembler-with-cpp -c $< -o $@ +# "-x assembler-with-cpp" should not be necessary since this is the default +# file type for the .S (with capital S) extension. However, upper case +# characters are not always preserved on Windows. To ensure WinAVR +# compatibility define the file type manually. + +.c.s: + $(COMPILE) -S $< -o $@ + +flash: all + avrdude -c usbasp -p m88 -U flash:w:firmware.hex + +fuses: + avrdude -c usbasp -p m88 -U lfuse:w:0xdf:m -U hfuse:w:0xde:m # external oscillator + + +## what are the source dependencies +%.d: %.c + @set -e; rm -f $@; \ + $(COMPILE) -MM $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@; +# line 1: exits if anything goes wrong +# line 2a: gcc -MM outputs dependencies +# line 2b: insert the %.d into dependency list + +#main.c: version.h + + +clean: + rm -f *.o *.hex *.obj *.i *.s *.d */*.i */*.s */*.o */*.d version.h + +# file targets: +firmware.bin: $(OBJECTS) + $(COMPILE) -o firmware.bin $(OBJECTS) + +firmware.hex: firmware.bin + rm -f firmware.hex firmware.eep.hex + avr-objcopy -j .text -j .data -O ihex firmware.bin firmware.hex + avr-size firmware.bin +# ./checksize firmware.bin 8192 960 +# do the checksize script as our last action to allow successful compilation +# on Windows with WinAVR where the Unix commands will fail. + +disasm: firmware.bin + avr-objdump -d firmware.bin >disasm + +functionsize: disasm + python avrbuild/functionsize.py + +countregs: disasm + python avrbuild/countregs.py + +# for depends: +-include $(OBJECTS:.o=.d) diff --git a/firmware/display.c b/firmware/masterchip/display.c similarity index 100% rename from firmware/display.c rename to firmware/masterchip/display.c diff --git a/firmware/display.h b/firmware/masterchip/display.h similarity index 100% rename from firmware/display.h rename to firmware/masterchip/display.h diff --git a/firmware/lcd/COPYING b/firmware/masterchip/lcd/COPYING similarity index 100% rename from firmware/lcd/COPYING rename to firmware/masterchip/lcd/COPYING diff --git a/firmware/lcd/lcd.c b/firmware/masterchip/lcd/lcd.c similarity index 100% rename from firmware/lcd/lcd.c rename to firmware/masterchip/lcd/lcd.c diff --git a/firmware/lcd/lcd.h b/firmware/masterchip/lcd/lcd.h similarity index 100% rename from firmware/lcd/lcd.h rename to firmware/masterchip/lcd/lcd.h diff --git a/firmware/main.c b/firmware/masterchip/main.c similarity index 100% rename from firmware/main.c rename to firmware/masterchip/main.c diff --git a/firmware/main.h b/firmware/masterchip/main.h similarity index 100% rename from firmware/main.h rename to firmware/masterchip/main.h diff --git a/firmware/masterchip/spi.c b/firmware/masterchip/spi.c new file mode 120000 index 0000000..688c0fb --- /dev/null +++ b/firmware/masterchip/spi.c @@ -0,0 +1 @@ +../shared/spi.c \ No newline at end of file diff --git a/firmware/masterchip/spi.h b/firmware/masterchip/spi.h new file mode 120000 index 0000000..ef58aea --- /dev/null +++ b/firmware/masterchip/spi.h @@ -0,0 +1 @@ +../shared/spi.h \ No newline at end of file diff --git a/firmware/usb.c b/firmware/masterchip/usb.c similarity index 100% rename from firmware/usb.c rename to firmware/masterchip/usb.c diff --git a/firmware/usb.h b/firmware/masterchip/usb.h similarity index 100% rename from firmware/usb.h rename to firmware/masterchip/usb.h diff --git a/firmware/masterchip/usbdrv b/firmware/masterchip/usbdrv new file mode 120000 index 0000000..fe38647 --- /dev/null +++ b/firmware/masterchip/usbdrv @@ -0,0 +1 @@ +../../vusb-20100715/usbdrv \ No newline at end of file diff --git a/firmware/spi.c b/firmware/shared/spi.c similarity index 100% rename from firmware/spi.c rename to firmware/shared/spi.c diff --git a/firmware/spi.h b/firmware/shared/spi.h similarity index 100% rename from firmware/spi.h rename to firmware/shared/spi.h diff --git a/firmware/slavechip/Makefile b/firmware/slavechip/Makefile new file mode 100644 index 0000000..beadcff --- /dev/null +++ b/firmware/slavechip/Makefile @@ -0,0 +1,66 @@ +include ../Makefile.inc + +COMPILE = avr-gcc $(CFLAGS) $(DEFINES) + +OBJECTS = mcp_adc.o i2c_simple.o + +# symbolic targets: +all: firmware.hex + +.c.o: + $(COMPILE) -c $< -o $@ + +.S.o: + $(COMPILE) -x assembler-with-cpp -c $< -o $@ +# "-x assembler-with-cpp" should not be necessary since this is the default +# file type for the .S (with capital S) extension. However, upper case +# characters are not always preserved on Windows. To ensure WinAVR +# compatibility define the file type manually. + +.c.s: + $(COMPILE) -S $< -o $@ + +flash: all + avrdude -c usbasp -p m88 -U flash:w:firmware.hex + +fuses: + avrdude -c usbasp -p m88 -U lfuse:w:0xdf:m -U hfuse:w:0xde:m # external oscillator + + +## what are the source dependencies +%.d: %.c + @set -e; rm -f $@; \ + $(COMPILE) -MM $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@; +# line 1: exits if anything goes wrong +# line 2a: gcc -MM outputs dependencies +# line 2b: insert the %.d into dependency list + +#main.c: version.h + + +clean: + rm -f *.o *.hex *.obj *.i *.s *.d */*.i */*.s */*.o */*.d version.h + +# file targets: +firmware.bin: $(OBJECTS) + $(COMPILE) -o firmware.bin $(OBJECTS) + +firmware.hex: firmware.bin + rm -f firmware.hex firmware.eep.hex + avr-objcopy -j .text -j .data -O ihex firmware.bin firmware.hex + avr-size firmware.bin +# ./checksize firmware.bin 8192 960 +# do the checksize script as our last action to allow successful compilation +# on Windows with WinAVR where the Unix commands will fail. + +disasm: firmware.bin + avr-objdump -d firmware.bin >disasm + +functionsize: disasm + python avrbuild/functionsize.py + +countregs: disasm + python avrbuild/countregs.py + +# for depends: +-include $(OBJECTS:.o=.d) diff --git a/firmware/i2c_simple.c b/firmware/slavechip/i2c_simple.c similarity index 100% rename from firmware/i2c_simple.c rename to firmware/slavechip/i2c_simple.c diff --git a/firmware/i2c_simple.h b/firmware/slavechip/i2c_simple.h similarity index 100% rename from firmware/i2c_simple.h rename to firmware/slavechip/i2c_simple.h diff --git a/firmware/mcp_adc.c b/firmware/slavechip/mcp_adc.c similarity index 100% rename from firmware/mcp_adc.c rename to firmware/slavechip/mcp_adc.c diff --git a/firmware/mcp_adc.h b/firmware/slavechip/mcp_adc.h similarity index 100% rename from firmware/mcp_adc.h rename to firmware/slavechip/mcp_adc.h diff --git a/firmware/usbdrv b/firmware/usbdrv deleted file mode 120000 index 421b6b4..0000000 --- a/firmware/usbdrv +++ /dev/null @@ -1 +0,0 @@ -../vusb-20100715/usbdrv/ \ No newline at end of file From 9e41d6e261f96f36a6c647301942aad8b9e2d498 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Fri, 10 Dec 2010 21:49:06 +0100 Subject: [PATCH 07/12] clearified --- documentation/SPI-Proto | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/documentation/SPI-Proto b/documentation/SPI-Proto index bf19dd5..980ee66 100644 --- a/documentation/SPI-Proto +++ b/documentation/SPI-Proto @@ -8,19 +8,19 @@ Where following values are Valid: |--------------------------------------------------------------------------------------------------------------------------| | Binary Hex Name Address ValueL ValueH Reply Description| |--------------------------------------------------------------------------------------------------------------------------| -| 0000001 0x01 Read-Temp Number of None/Rand None/Rand A 16Bit Value Reads the | +| 0000001 0x01 Read-Temp Number of zeroes/Rand zeroes/Rand A 16Bit Value Reads the | | Thermometer Representing Temperature| | Starting with 0 the Temperature | |--------------------------------------------------------------------------------------------------------------------------| -| 0000002 0x02 Read-Var8 Number of the None/Rand None/Rand A 8Bit Value Reads 8Bit | +| 0000002 0x02 Read-Var8 Number of the zeroes/Rand zeroes/Rand A 8Bit Value Reads 8Bit | | var-DEFINE read from VAR Variable | |--------------------------------------------------------------------------------------------------------------------------| -| 0000003 0x03 Read-Var16 Number of the None/Rand None/Rand A 16Bit Value Reads 16Bit| +| 0000003 0x03 Read-Var16 Number of the zeroes/Rand zeroes/Rand A 16Bit Value Reads 16Bit| | var-DEFINE read from VAR Variable | |--------------------------------------------------------------------------------------------------------------------------| -| 0000004 0x04 Write-Var8 Number of the Value of Var None/Rand None/Rand Writes 8Bit| +| 0000004 0x04 Write-Var8 Number of the Value of Var zeroes/Rand zeroes/Rand Writes 8Bit| | var-DEFINE to write Variable | |--------------------------------------------------------------------------------------------------------------------------| -| 0000005 0x05 Write-Var16 Number of the Value of Var Value of Var None/Rand Writes 16 | +| 0000005 0x05 Write-Var16 Number of the Value of Var Value of Var zeroes/Rand Writes 16 | | var-DEFINE to write (HIGH) to write (LOW) Bit Var | |--------------------------------------------------------------------------------------------------------------------------| From a874e4f099465ccce780de0c3834d8b5276bd5bb Mon Sep 17 00:00:00 2001 From: Matthias Merz Date: Fri, 10 Dec 2010 21:55:09 +0100 Subject: [PATCH 08/12] add make-targets for master/slave all, fuses, flash --- firmware/Makefile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/firmware/Makefile b/firmware/Makefile index b0f5ffc..e9403e6 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -13,6 +13,21 @@ all: master master: cd masterchip; $(MAKE) $(MFLAGS) +flash-master: + cd masterchip; $(MAKE) $(MFLAGS) flash + +fuses-master: + cd masterchip; $(MAKE) $(MFLAGS) fuses + +slave: + cd slavechip; $(MAKE) $(MFLAGS) + +flash-slave: + cd slavechip; $(MAKE) $(MFLAGS) flash + +fuses-slave: + cd slavechip; $(MAKE) $(MFLAGS) fuses + clean: cd masterchip; $(MAKE) $(MFLAGS) clean cd slavechip; $(MAKE) $(MFLAGS) clean From 57b81079eedef34913838e6a2d8980db03fc1393 Mon Sep 17 00:00:00 2001 From: Matthias Merz Date: Fri, 10 Dec 2010 22:05:28 +0100 Subject: [PATCH 09/12] symlink spi-routines to slave --- firmware/slavechip/spi.c | 78 ++++++++++++++++++++++++++++++++++++++++ firmware/slavechip/spi.h | 6 ++++ 2 files changed, 84 insertions(+) create mode 100644 firmware/slavechip/spi.c create mode 100644 firmware/slavechip/spi.h diff --git a/firmware/slavechip/spi.c b/firmware/slavechip/spi.c new file mode 100644 index 0000000..870a16d --- /dev/null +++ b/firmware/slavechip/spi.c @@ -0,0 +1,78 @@ +#include +#include +#include + + +#include + + +/* SPI framework. + * + * currently alpha, uses interrupts, single master/single slave operation + */ + + +uint8_t * volatile spi_writeptr; +uint8_t * volatile spi_readptr; +uint8_t volatile spi_writelen; +uint8_t volatile spi_readlen; +uint8_t spi_readbuf[SPI_READBUF_LEN]; + + +void spi_init(){ + uint8_t spcr, spsr, d; + + /* calculate clock divisor, + * gcc with optimize will do that calculation compile-time. */ + uint8_t spi_clock_divisor(){ + double d; + d = F_CPU / SPI_BAUDRATE; + d = ceil((log(d)/log(2))*0.95); // clock needs dividing by 2^d + // the 0.95 to avoid ceil issues + return d-1; // the -1 because minimum divisor is /2 + } + + d = spi_clock_divisor(); + if(d>7){ + #warning "spi baudrate too slow, cannot be set" + d=7; + } + + //TODO: DDRs setzen + spsr = 0; + spsr |= (d & 1) ? 0 : _BV(SPI2X); + spcr = 0 | _BV(SPIE) | _BV(SPE); + spcr |= (d & 2) ? _BV(SPR0) : 0; + spcr |= (d & 4) ? _BV(SPR1) : 0; + +#ifdef SPI_MASTER + spcr |= _BV(MSTR); +#endif + SPCR = spcr; + SPSR = spsr; + + // initialize interface for ISR: + spi_readptr = spi_readbuf; + spi_readlen = SPI_READBUF_LEN; + spi_writeptr = NULL; +} + +// return true on success, false on error +uint8_t spi_write(uint8_t *data, uint8_t len){ + if(spi_writeptr != NULL){ + return 0 + } + spi_writeptr = data; + spi_writelen = len; + //TODO: handle SS, write out first byte + return 1; +} + +#ifdef SPI_MASTER +ISR(SPI_vector){ + + + + +} +#endif //SPI_MASTER diff --git a/firmware/slavechip/spi.h b/firmware/slavechip/spi.h new file mode 100644 index 0000000..bc9969b --- /dev/null +++ b/firmware/slavechip/spi.h @@ -0,0 +1,6 @@ +#define SPI_BAUDRATE 1000000 +#define SPI_MASTER 1 +#define SPI_READBUF_LEN 32 + +uint8_t spi_write(uint8_t *data, uint8_t len); +void spi_init(); From 5f91679c073008c995bb94a4e00271a7ce811a61 Mon Sep 17 00:00:00 2001 From: Matthias Merz Date: Fri, 10 Dec 2010 22:06:03 +0100 Subject: [PATCH 10/12] add first main.c/.h to slave --- firmware/slavechip/main.c | 22 ++++++++++++++++++++++ firmware/slavechip/main.h | 14 ++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 firmware/slavechip/main.c create mode 100644 firmware/slavechip/main.h diff --git a/firmware/slavechip/main.c b/firmware/slavechip/main.c new file mode 100644 index 0000000..55bfe7c --- /dev/null +++ b/firmware/slavechip/main.c @@ -0,0 +1,22 @@ +#include "main.h" +#include "spi.h" + + +void hardinit() { + /* initializes the hardware */ + + sei(); +} + +void softinit() { +} + + +int __attribute__((noreturn)) main(void) { + hardinit(); + softinit(); + + for(;;){ + } +} + diff --git a/firmware/slavechip/main.h b/firmware/slavechip/main.h new file mode 100644 index 0000000..c816a95 --- /dev/null +++ b/firmware/slavechip/main.h @@ -0,0 +1,14 @@ +#ifndef __MAIN_H +#define __MAIN_H +#include +#include +#include +#include +#include +#include +#include +#include + +#define SOFTTIMERNUMS 4 + +#endif //__MAIN_H From 81670202176de90751b8ecca35a001fa6cb90aa3 Mon Sep 17 00:00:00 2001 From: Matthias Merz Date: Fri, 10 Dec 2010 22:06:25 +0100 Subject: [PATCH 11/12] build main for slavechip --- firmware/slavechip/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/slavechip/Makefile b/firmware/slavechip/Makefile index beadcff..fd75855 100644 --- a/firmware/slavechip/Makefile +++ b/firmware/slavechip/Makefile @@ -2,7 +2,7 @@ include ../Makefile.inc COMPILE = avr-gcc $(CFLAGS) $(DEFINES) -OBJECTS = mcp_adc.o i2c_simple.o +OBJECTS = main.o mcp_adc.o i2c_simple.o # symbolic targets: all: firmware.hex From c278296553cc0de9fe619c7565ff6fbae5516cb1 Mon Sep 17 00:00:00 2001 From: Matthias Merz Date: Fri, 10 Dec 2010 22:07:16 +0100 Subject: [PATCH 12/12] enable build of slavechip for global Makefile --- firmware/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/Makefile b/firmware/Makefile index e9403e6..875c3a4 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -8,7 +8,7 @@ CFLAGS += -std=gnu99 -Wall # implements C99, for include Makefile.inc # symbolic targets: -all: master +all: master slave master: cd masterchip; $(MAKE) $(MFLAGS)