commit
95f5224d46
@ -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 zeroes/Rand zeroes/Rand A 16Bit Value Reads the |
|
||||
| Thermometer Representing Temperature|
|
||||
| Starting with 0 the Temperature |
|
||||
|--------------------------------------------------------------------------------------------------------------------------|
|
||||
| 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 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 zeroes/Rand zeroes/Rand Writes 8Bit|
|
||||
| var-DEFINE to write Variable |
|
||||
|--------------------------------------------------------------------------------------------------------------------------|
|
||||
| 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 |
|
||||
|--------------------------------------------------------------------------------------------------------------------------|
|
||||
@ -1,12 +1,33 @@
|
||||
DEFINES += -DF_CPU=16000000
|
||||
CFLAGS += -save-temps
|
||||
CFLAGS += -std=gnu99 # implements C99, for <util/atomic.h>
|
||||
CFLAGS += -std=gnu99 -Wall # implements C99, for <util/atomic.h>
|
||||
# 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 slave
|
||||
|
||||
include avrbuild/Makefile.avrbuild
|
||||
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
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
DEFINES += -DF_CPU=16000000
|
||||
CFLAGS += -save-temps
|
||||
CFLAGS += -std=gnu99 -Wall # implements C99, for <util/atomic.h>
|
||||
# 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
|
||||
|
||||
@ -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)
|
||||
@ -0,0 +1 @@
|
||||
../shared/spi.c
|
||||
@ -0,0 +1 @@
|
||||
../shared/spi.h
|
||||
@ -0,0 +1 @@
|
||||
../../vusb-20100715/usbdrv
|
||||
@ -0,0 +1,66 @@
|
||||
include ../Makefile.inc
|
||||
|
||||
COMPILE = avr-gcc $(CFLAGS) $(DEFINES)
|
||||
|
||||
OBJECTS = main.o 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)
|
||||
@ -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(;;){
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
#include <stdint.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/eeprom.h>
|
||||
#include <util/delay.h>
|
||||
#include <util/atomic.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define SOFTTIMERNUMS 4
|
||||
|
||||
#endif //__MAIN_H
|
||||
@ -0,0 +1,78 @@
|
||||
#include <avr/io.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#include <spi.h>
|
||||
|
||||
|
||||
/* 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
|
||||
@ -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();
|
||||
@ -1 +0,0 @@
|
||||
../vusb-20100715/usbdrv/
|
||||
Loading…
Reference in new issue