# HG changeset patch # User Malte Bayer # Date 1321459450 -3600 # Node ID 20dbe0546a36156b4a89222fba18eb32eb33929a # Parent 84249ab5d691563d3cca91fb8998a72e73ca4f82 added receiver testing stuff diff -r 84249ab5d691 -r 20dbe0546a36 receiver/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/receiver/Makefile Wed Nov 16 17:04:10 2011 +0100 @@ -0,0 +1,92 @@ +PRG=main + +MCU=atmega16 +FUSES=-U lfuse:w:0x2f:m -U hfuse:w:0xc8:m +BOOTFUSES=-U lfuse:w:0xff:m -U hfuse:w:0xce:m + +#F_CPU=4185600 +#F_CPU = 14318000 + +F_CPU = 8000000 + +BAUD=38400 +ISP_BAUD = 115200 + +#SRC = main.c seriald.c driver/ADC.c driver/clock.c driver/timer.c +#SRC = main.c driver/rs232.c driver/manchester.c +SRC = main.c driver/rs232.c + +################################################################### +# You possibly do not need to change settings below this marker +################################################################### + +# Binaries to be used +# You may add the path to them if they are not in the PATH variable. +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +AVRDUDE = avrdude +PERL = perl + +# Optional library search path +LIBS = + +# Compiler options for all c source files +CFLAGS += -g -Wall -mmcu=$(MCU) -DBAUD=$(BAUD) -DF_CPU=$(F_CPU)UL -std=gnu99 +CFLAGS += -funsigned-char +CFLAGS += -funsigned-bitfields +CFLAGS += -fpack-struct +CFLAGS += -fshort-enums +CFLAGS += -Wstrict-prototypes +CFLAGS += -Wundef +#CFLAGS += -save-temps + +# optimize for size +CFLAGS += -Os +# dont optimize +#CFLAGS += -O0 + +# Linker options +LDFLAGS = -Wl,-Map,$(PRG).map + +# Enable floating-point support in printf +#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm + +################################################################### +# TARGET DEFINITIONS: + + +all: code + +code: $(PRG).hex + +$(PRG).elf: $(SRC:.c=.o) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) + +%.lst: %.elf + $(OBJDUMP) -h -S $< > $@ + +%.hex: %.elf + $(OBJCOPY) -j .text -j .data -O ihex $< $@ + rm $(PRG).elf + rm $(PRG).map + +program: code + $(AVRDUDE) -c stk500v2 -b $(ISP_BAUD) -i 1 -p $(MCU) -V -U flash:w:$(PRG).hex:i + +fuse: + $(AVRDUDE) -c stk500 -p $(MCU) -V $(FUSES) + +clean: + rm -rf *.o *.elf *.elf.src *.s *.i + rm -rf driver/*.o + +upgrade: code + $(RESETCOMMAND) + ./bootloader -d $(NETDEV) -b $(UPGRADE_BAUD) -p $(PRG).hex + +bootloader: bootload.hex + $(AVRDUDE) -p $(MCU) -c stk500 -V -U flash:w:bootload.hex:i + +bootfuses: + $(AVRDUDE) -p $(MCU) -c stk500 $(BOOTFUSES) diff -r 84249ab5d691 -r 20dbe0546a36 receiver/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/receiver/README Wed Nov 16 17:04:10 2011 +0100 @@ -0,0 +1,1 @@ +Just for testing at the moment \ No newline at end of file diff -r 84249ab5d691 -r 20dbe0546a36 receiver/driver --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/receiver/driver Wed Nov 16 17:04:10 2011 +0100 @@ -0,0 +1,1 @@ +../blackbox/driver \ No newline at end of file diff -r 84249ab5d691 -r 20dbe0546a36 receiver/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/receiver/main.c Wed Nov 16 17:04:10 2011 +0100 @@ -0,0 +1,229 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "main.h" + +#include "driver/rs232.h" +//#include "driver/manchester.h" + +volatile uint8_t datalen = 0; +char data[10]; // 8 bytes data buffer + string termination + +static char buffer[RS232_BUFSIZE+1]; +static uint8_t buffer_len; + +volatile uint8_t bitbuf_len = 0; +volatile uint16_t bitbuf = 0; +volatile uint16_t bitbuf_out = 0; +volatile uint8_t bitbuf_out_len = 0; +volatile uint8_t timeout = 0; +volatile uint8_t lastbit = 0; + + + +// USART0 RX interrupt +ISR ( USART_RXC_vect ) { + char c = UDR; + + // check for buffer overflow + if (buffer_len==sizeof(buffer)) { + buffer_len=0; + if (c == 27) { + // escape sequence, store to empty buffer + buffer[buffer_len++] = c; + } + } else { + // collect characters until end of line + if (c == 27) { + // escape sequence, clear buffer + buffer_len = 0; + buffer[buffer_len++] = c; + } else if ( (c==0xff) && (buffer_len > 3) ) { + buffer[buffer_len]=0; + + // packet end received, parse the received packet + + // wait for the next packet + buffer_len=0; + } else { + buffer[buffer_len++]=c; + } + } +} + + +#define PULSE_IN PIND +#define PULSE_BIT 2 + +#define TIMER_DIVISOR 8 +#define VALUE_100US 0.47e-4 +#define TIMER_100US 0xff - (uint8_t)(VALUE_100US * F_CPU/TIMER_DIVISOR) + +ISR ( INT0_vect ) { + writeBit(GICR, INT0, 0); // disable INT0 interrupt + // Startsignal erkannt, ab hier den Timer0 starten, + // der liest dann alle 100µs den Zustand ein und schreibt das + // empfangene Bit in den Puffer + lastbit = 0b10000001; // initialize + + TCNT0 = TIMER_100US; + TIMSK |= 1< 0) { + bitbuf_out = bitbuf; + bitbuf_out_len = bitbuf_len; + } + bitbuf = 0; + bitbuf_len = 0; + GICR |= _BV(INT0); // Enable INT0 + } + + writeBit(PORTD, 4, 1); + SREG = sr; +} + +volatile uint8_t pulse_counter = 0; +volatile uint8_t measure_progress = 0; +volatile uint8_t car_id = 0; +ISR(TIMER2_OVF_vect) { + //TCNT2 = 0x90; + pulse_counter++; +} + +ISR (INT1_vect) { + // measure pulse width + //RS232_putc('x'); + if (measure_progress == 0) { + // start measuring + pulse_counter = 0; + measure_progress = 1; + // set INT1 to rising edge (stops current measurement) + //MCUCR |= _BV(ISC10); + writeBit(PORTD, 4, 1); + } else { + // stop measuring + car_id = pulse_counter; + measure_progress = 0; + // set INT1 to falling edge (initiates next measurement) + //MCUCR &= ~_BV(ISC10); + writeBit(PORTD, 4, 0); + } +} + + +int main(void) +{ + uint i; +char s[30]; + + TCCR0 = 0; //timer off + //TCCR0 = (1< 0xFF -> 0x00 + itoa( p_len, s, 10); + RS232_puts(s); + RS232_puts_p(PSTR("\n")); + p_len = 0; + } +*/ + } // main loop end +}; + diff -r 84249ab5d691 -r 20dbe0546a36 receiver/main.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/receiver/main.h Wed Nov 16 17:04:10 2011 +0100 @@ -0,0 +1,29 @@ +#ifndef MAIN_H +#define MAIN_H + +#include + +#define uchar unsigned char +#define uint unsigned int + +// Macro used to write to a single I/O pin +#define writeBit(port,bit,value) { if ((value)>0) (port) |= (1<> (bit)) & 1) + +// we have internal AREF... +// #define EXT_AREF 1 + +// RESET ROUTINE FOR DOING A SOFT-RESET: +#define soft_reset() \ +do \ +{ \ + wdt_enable(WDTO_15MS); \ + for(;;) \ + { \ + } \ +} while(0) + + +#endif