# HG changeset patch # User Malte Bayer # Date 1321614187 -3600 # Node ID 69c2a14086194f0d0dec5891c2bc9b5c14ec3fdb # Parent 6d6e982bbc416ede9d7f58248725a7084fa70ccf done code for sniffing the rails diff -r 6d6e982bbc41 -r 69c2a1408619 blackbox/main.c --- a/blackbox/main.c Fri Nov 18 08:42:24 2011 +0100 +++ b/blackbox/main.c Fri Nov 18 12:03:07 2011 +0100 @@ -325,9 +325,9 @@ } } else { // output idle command - //if (do_program(7, 19, 0)) packet_index++; // reset + if (do_program(7, 19, 0)) packet_index++; // reset //if (do_program(7, 20, 15)) packet_index++; // reset / pitstop detect - if (insert_queue(0, 0)) packet_index++; // null command + //if (insert_queue(0, 0)) packet_index++; // null command } break; case 2: diff -r 6d6e982bbc41 -r 69c2a1408619 receiver/main.c --- a/receiver/main.c Fri Nov 18 08:42:24 2011 +0100 +++ b/receiver/main.c Fri Nov 18 12:03:07 2011 +0100 @@ -9,20 +9,12 @@ #include "main.h" #include "driver/rs232.h" -//#include "driver/manchester.h" +#include "util/delay.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; @@ -57,172 +49,112 @@ } -#define PULSE_IN PIND -#define PULSE_BIT 2 +#define PULSE_PORT PORTD +#define PULSE_BIT PD2 -#define TIMER_DIVISOR 8 -#define VALUE_100US 0.47e-4 -#define TIMER_100US 0xff - (uint8_t)(VALUE_100US * F_CPU/TIMER_DIVISOR) +volatile uint16_t data = 0; +volatile uint8_t data_len = 0; +volatile uint8_t bitbuf_len = 0; +volatile uint16_t bitbuf = 0; 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 + writeBit(PORTD, 5, 1); + GICR &= ~_BV(INT0) ; // Disable INT0 + // Startsignal erkannt, ab hier den Timer2 starten, + // der liest dann alle 50µ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 uint16_t pulse_counter = 0; -volatile uint8_t measure_progress = 0; -volatile uint16_t car_id = 0; -ISR(TIMER2_OVF_vect) { - TCNT2 = 0xF5; - pulse_counter++; } -ISR (INT1_vect) { - // measure pulse width - //RS232_putc('x'); - if (measure_progress == 0) { - // start measuring - TCNT2 = 0xF5; - 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< 5) { + if (data_len == 13) { // sync to first packet + i = 1; + RS232_puts("\n"); + } else if (i!=0) i++; + if (i>0) { + itoa( data, s, 16); + data = 0; + RS232_puts("0x"); + RS232_puts( s ); + RS232_putc(' '); + } + } + //if (i==10) for (;;); } - /*cli(); - i = rc5_data; // read two bytes from interrupt ! - rc5_data = 0; - sei(); - if (i) { - itoa( i, s, 10); - RS232_puts( s ); - } */ -/* - if (p_len < 0xFF) p_len++; - if( (p_bit ^ PULSE_IN) & 1< 0xFF -> 0x00 - itoa( p_len, s, 10); - RS232_puts(s); - RS232_puts_p(PSTR("\n")); - p_len = 0; - } -*/ } // main loop end }; diff -r 6d6e982bbc41 -r 69c2a1408619 receiver/main.h --- a/receiver/main.h Fri Nov 18 08:42:24 2011 +0100 +++ b/receiver/main.h Fri Nov 18 12:03:07 2011 +0100 @@ -1,29 +1,1 @@ -#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 +../blackbox/main.h \ No newline at end of file