carrerashark/main.c

Sat, 03 Dec 2011 16:42:53 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Sat, 03 Dec 2011 16:42:53 +0100
changeset 37
136a79772098
parent 31
a8f082503782
child 38
ff76255904c4
permissions
-rw-r--r--

implemented race prepare phase, countdown and jumpstart detection

12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
1 #include <avr/interrupt.h>
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
2 #include <avr/io.h>
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
3 #include <avr/wdt.h>
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
4 #include <avr/eeprom.h>
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
5 #include <stdlib.h>
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
6 #include <stdint.h>
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
7 #include <avr/pgmspace.h>
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
8
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
9 #include "main.h"
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
10
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
11 #include "driver/rs232.h"
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
12 #include "util/delay.h"
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
13
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
14
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
15 static char buffer[RS232_BUFSIZE+1];
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
16 static uint8_t buffer_len;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
17
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
18
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
19
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
20
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
21 // USART0 RX interrupt
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
22 ISR ( USART_RXC_vect ) {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
23 char c = UDR;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
24
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
25 // check for buffer overflow
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
26 if (buffer_len==sizeof(buffer)) {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
27 buffer_len=0;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
28 if (c == 27) {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
29 // escape sequence, store to empty buffer
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
30 buffer[buffer_len++] = c;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
31 }
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
32 } else {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
33 // collect characters until end of line
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
34 if (c == 27) {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
35 // escape sequence, clear buffer
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
36 buffer_len = 0;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
37 buffer[buffer_len++] = c;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
38 } else if ( (c==0xff) && (buffer_len > 3) ) {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
39 buffer[buffer_len]=0;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
40
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
41 // packet end received, parse the received packet
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
42
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
43 // wait for the next packet
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
44 buffer_len=0;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
45 } else {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
46 buffer[buffer_len++]=c;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
47 }
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
48 }
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
49 }
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
50
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
51
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
52 #define PULSE_PORT PORTD
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
53 #define PULSE_BIT PD2
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
54
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
55 volatile uint16_t data = 0;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
56 volatile uint8_t data_len = 0;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
57 volatile uint8_t bitbuf_len = 0;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
58 volatile uint16_t bitbuf = 0;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
59
31
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
60 volatile uint16_t sysclock = 0;
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
61 ISR ( TIMER0_OVF_vect ) {
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
62 PORTD ^= _BV(PD6);
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
63 if (sysclock != 0xffff) sysclock++;
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
64 }
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
65
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
66 ISR ( INT0_vect ) {
28
d4235895fdbc shark: corrected debug pins
Malte Bayer <mbayer@neo-soft.org>
parents: 12
diff changeset
67 PORTD ^= _BV(PD3);
31
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
68 if (sysclock<10) {
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
69 // this is the answer slot start bit??
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
70 PORTD ^= _BV(PD7);
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
71 } else {
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
72 GICR &= ~_BV(INT0) ; // Disable INT0
31
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
73 // Startsignal erkannt, ab hier den Timer2 starten,
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
74 // der liest dann alle 50µs den Zustand ein und schreibt das
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
75 // empfangene Bit in den Puffer
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
76 bitbuf = 0; // init
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
77 bitbuf_len = 0b10000000; // init 1 pulse received
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
78 TCNT2 = 0;
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
79 TIMSK |= _BV(OCIE2); //enable timer2 interrupt
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
80 }
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
81 }
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
82
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
83
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
84 ISR ( TIMER2_COMP_vect ) {
28
d4235895fdbc shark: corrected debug pins
Malte Bayer <mbayer@neo-soft.org>
parents: 12
diff changeset
85 PORTD ^= _BV(PD4);
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
86 uint8_t clock;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
87 uint8_t state;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
88 uint8_t state2;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
89 if ((bitbuf_len & 0b10000000) == 0) clock = 0; else clock = 0xff;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
90 if ((bitbuf_len & 0b01000000) == 0) state = 0; else state = 0xff;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
91 if ((PIN(PULSE_PORT) & _BV(PULSE_BIT)) == 0) state2 = 0; else state2 = 0xff;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
92
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
93 if (clock) {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
94 // second pulse of bit
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
95 bitbuf_len &= ~_BV(7); // switch clock to low
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
96 if ((state==state2) & state2) {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
97 // two cycles high: packet end received
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
98 data_len = (bitbuf_len & 0b00111111);
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
99 if (data_len == 13) PORTD ^= _BV(6); // debug sync output on program packets
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
100 TIMSK &= ~_BV(OCIE2); //disable timer2 interrupt
31
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
101 GICR |= _BV(INT0); // Enable INT0
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
102 GIFR &= ~_BV(INTF0); // clear int0 irq flag
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
103 data = bitbuf; // output data
31
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
104 sysclock = 0; // reset system clock counter
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
105 } else {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
106 bitbuf_len++; // increment bit counter
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
107 bitbuf = bitbuf << 1; // shift bits
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
108 if (state2 == 0) bitbuf |= 1; // receive logic one
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
109 }
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
110 } else {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
111 // first pulse of bit
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
112 bitbuf_len |= _BV(7); // switch clock to high
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
113 if (state2) {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
114 bitbuf_len |= _BV(6); // store new state
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
115 } else {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
116 bitbuf_len &= ~_BV(6); // store new state
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
117 }
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
118 }
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
119 }
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
120
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
121
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
122
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
123 int main(void)
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
124 {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
125 uint8_t i;
29
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
126 unsigned char s[10];
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
127 uint16_t tmp;
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
128 uint16_t cycle[11];
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
129
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
130 // setup data bit timer
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
131 TCCR2 = (1<<CS21) | (1<<WGM21); //divide by 8, set compare match
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
132 OCR2 = TIMER2_50US;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
133 TIMSK |= 1<<OCIE2; //enable timer2 interrupt
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
134
31
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
135 // setup system timer
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
136 TCCR0 = (1<<CS21); //divide by 8
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
137 TIMSK |= 1<<TOIE0; //enable timer0 interrupt
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
138
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
139
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
140 MCUCR = _BV(ISC00); // falling edge
31
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
141 // MCUCR = _BV(ISC00) | _BV(ISC01); // rising edge
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
142 GICR = _BV(INT0) ; // Enable INT0
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
143
31
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
144 DDRD |= _BV(PD3) | _BV(PD4) | _BV(PD5) | _BV(PD6) | _BV(PD7);
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
145 PORTD |= _BV(PD7);
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
146
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
147 RS232_init(); // initialize RS232 interface
31
a8f082503782 carrerashark minor changes
Malte Bayer <mbayer@neo-soft.org>
parents: 30
diff changeset
148 RS232_puts_p(PSTR("CarreraShark 1.2\n"));
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
149
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
150 sei();
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
151 i = 0;
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
152 while (1) {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
153 // main loop
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
154
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
155 if (data != 0) {
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
156 if (data_len > 5) {
29
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
157 tmp = data;
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
158 data = 0;
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
159 if (data_len == 13) { // sync to first packet
28
d4235895fdbc shark: corrected debug pins
Malte Bayer <mbayer@neo-soft.org>
parents: 12
diff changeset
160 PORTD ^= _BV(PD5);
29
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
161 for (i=0; i<10;i++ ) {
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
162 // output previous cycle data
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
163 itoa( cycle[i], s, 16);
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
164 RS232_putc('0');
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
165 RS232_putc('x');
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
166 RS232_puts( s );
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
167 RS232_putc(' ');
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
168 }
30
10c78c097d18 shark: bugfix + added a complete trace of the old blackbox
Malte Bayer <mbayer@neo-soft.org>
parents: 29
diff changeset
169 RS232_putc('*');
29
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
170 i = 0;
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
171 PORTD ^= _BV(PD5);
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
172 }
29
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
173 cycle[i] = tmp;
ba4f69250592 shark: fixed uart bug
Malte Bayer <mbayer@neo-soft.org>
parents: 28
diff changeset
174 i++;
12
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
175 }
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
176 //if (i==10) for (;;);
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
177 }
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
178 } // main loop end
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
179 };
a399f9d5e672 added carrerashark project-part to separate subdirectory
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
180

mercurial