blackbox/main.c

Mon, 14 Nov 2011 20:32:30 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Mon, 14 Nov 2011 20:32:30 +0100
changeset 1
91246416e201
parent 0
9b7de464f0ea
child 2
6c59b4293fa9
permissions
-rw-r--r--

added hg ignorefile

0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
1 #include <avr/interrupt.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
2 #include <avr/io.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
3 #include <avr/wdt.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
4 #include <avr/eeprom.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
5 #include <stdlib.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
6 #include <stdint.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
7 #include <avr/pgmspace.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
8 #include <util/delay.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
9
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
10 #include "main.h"
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
11
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
12 #include "driver/rs232.h"
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
13 #include "driver/adc.h"
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
14
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
15 #include "lowlevel.h"
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
16
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
17 //#include "driver/manchester.h"
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
18
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
19 /*
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
20 // Hardware config
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
21 #define LAP_COUNTER_PORT PORTB
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
22 #define LAP_COUNTER PB2
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
23
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
24 #define MODUL_PORT PORTD
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
25 #define MODUL_ST4 PD5
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
26 #define MODUL_ST6 PD6
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
27
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
28 #define I2C_PORT PORTC
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
29 #define I2C_SDA PC0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
30 #define I2C_SCL PC1
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
31
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
32
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
33 #define SW_PACECAR_PORT PORTC
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
34 #define SW_START_PORT PORTB
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
35 #define SW_TANK_PORT PORTB
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
36 #define SW_PACECAR PC6
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
37 #define SW_TANK PB0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
38 #define SW_START PB1
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
39
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
40 #define SPEAKER_PORT PORTD
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
41 #define SPEAKER PD7
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
42
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
43 */
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
44
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
45
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
46 void init_hardware(void) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
47 RS232_init(); // initialize RS485 interface
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
48 RS232_puts_p(PSTR("CARRERA beta loading\n"));
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
49
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
50 initADC();
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
51
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
52 // set LED output
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
53 DDR(LED1_PORT) |= _BV(LED1);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
54 DDR(LED2_PORT) |= _BV(LED2);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
55 DDR(LED3_PORT) |= _BV(LED3);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
56 DDR(LED4_PORT) |= _BV(LED4);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
57 DDR(LED5_PORT) |= _BV(LED5);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
58
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
59 // set Controller Input Pull-UPs
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
60 CONTROLLER_PORT |= (_BV(CONTROLLER1_SW) | _BV(CONTROLLER2_SW) | _BV(CONTROLLER3_SW) | _BV(CONTROLLER4_SW));
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
61
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
62 // switch pull-ups
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
63 SW_FUEL_PORT |= _BV(SW_FUEL);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
64
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
65 //RAIL_DETECT_PORT |= _BV(RAIL_DETECT); // enable internal pull-up
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
66 DDR(RAIL_POWER_PORT) |= _BV(RAIL_POWER);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
67
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
68
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
69 LED(1, 1); _delay_ms(50);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
70 LED(2, 1); _delay_ms(50);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
71 LED(3, 1); _delay_ms(50);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
72 LED(4, 1); _delay_ms(50);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
73 LED(5, 1); _delay_ms(50);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
74 LED(1, 0); _delay_ms(50);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
75 LED(2, 0); _delay_ms(50);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
76 LED(3, 0); _delay_ms(50);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
77 LED(4, 0); _delay_ms(50);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
78 LED(5, 0); _delay_ms(50);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
79
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
80 //TCCR0 = (1<<CS01); //divide by 8
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
81
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
82
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
83 // setup data bit timer
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
84 TCCR2 = (1<<CS21); //divide by 8
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
85 TCCR2 |= (1<<WGM21); // set compare match
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
86 OCR2 = TIMER2_50US;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
87 TIMSK |= 1<<OCIE2; //enable timer2 interrupt
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
88
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
89 // setup data packet timer
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
90 //TCCR1A = (1<<COM1A1);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
91 TCCR1B = (1<<CS11); //divide by 8
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
92 TCCR1B |= (1<<WGM12); // set compare match
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
93 //TCCR1B = (1<<CS11) | (1<<CS10); //divide by 64
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
94 //TCNT1 = TIMER_7500NS;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
95 OCR1A = TIMER1_7500NS;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
96 TIMSK |= 1<<OCIE1A; //enable timer1 interrupt
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
97
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
98 RS232_puts_p(PSTR("INIT OK\n"));
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
99
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
100 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
101
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
102
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
103
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
104 volatile uint8_t datalen = 0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
105 char data[10]; // 8 bytes data buffer + string termination
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
106
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
107 static char buffer[RS232_BUFSIZE+1];
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
108 static uint8_t buffer_len;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
109
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
110
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
111 // USART0 RX interrupt
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
112 ISR ( USART_RXC_vect ) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
113 char c = UDR;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
114
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
115 // check for buffer overflow
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
116 if (buffer_len==sizeof(buffer)) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
117 buffer_len=0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
118 if (c == 27) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
119 // escape sequence, store to empty buffer
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
120 buffer[buffer_len++] = c;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
121 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
122 } else {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
123 // collect characters until end of line
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
124 if (c == 27) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
125 // escape sequence, clear buffer
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
126 buffer_len = 0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
127 buffer[buffer_len++] = c;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
128 } else if ( (c==0xff) && (buffer_len > 3) ) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
129 buffer[buffer_len]=0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
130
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
131 // packet end received, parse the received packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
132
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
133 // wait for the next packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
134 buffer_len=0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
135 } else {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
136 buffer[buffer_len++]=c;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
137 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
138 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
139 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
140
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
141
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
142 volatile uint16_t transmit_buffer;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
143 volatile uint16_t transmit_buffer_queue;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
144 volatile uint8_t transmit_len;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
145 volatile uint8_t transmit_len_next;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
146 volatile uint8_t transmit_len_queue;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
147 ISR ( TIMER2_COMP_vect ) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
148 //OCR2 = TIMER2_50US; // make sure that timer2 is 50µs !!!
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
149 // data packet timer 100µs pro bit...
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
150 if (transmit_len >= 0xFE) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
151 if (transmit_len != 0xFF) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
152 RAIL_POWER_PORT |= _BV(RAIL_POWER); // end of transmission
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
153 transmit_len = 0xFF;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
154 transmit_buffer = transmit_buffer_queue;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
155 transmit_buffer_queue = 0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
156 transmit_len_next = transmit_len_queue;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
157 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
158 } else {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
159 uint16_t bit = (1<<(transmit_len & 0b01111111));
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
160 uint16_t clock;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
161 if ((transmit_len & 0b10000000) == 0) clock = 0; else clock = 0xffff;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
162 if ( ((transmit_buffer ^ clock) & bit) != 0 )
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
163 RAIL_POWER_PORT |= _BV(RAIL_POWER); else
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
164 RAIL_POWER_PORT &= ~_BV(RAIL_POWER);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
165 if ( (transmit_len & 0b10000000) == 0 ) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
166 // block 0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
167 //if (transmit_len == 0) transmit_len = 0xFF; else transmit_len |= 0b10000000; // set clock
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
168 transmit_len |= 0b10000000; // set clock
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
169 } else {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
170 // block 1, output the current bit
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
171 transmit_len &= 0b01111111; // reset clock
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
172 //if (transmit_len != 0) transmit_len--; // next bit
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
173 if (transmit_len == 0) transmit_len = 0xFE; else transmit_len--; // next bit
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
174 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
175 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
176 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
177
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
178 int insert_queue(uint16_t tmp, uint8_t len) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
179 if (transmit_buffer_queue == 0) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
180 transmit_buffer_queue = tmp;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
181 transmit_len_queue = len;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
182 return 1;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
183 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
184 return 0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
185 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
186
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
187
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
188 int do_controller(uint8_t controller) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
189 // read controller X speed & encode controller data packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
190 uint16_t tmp;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
191 switch (controller) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
192 case 0: tmp = getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR; break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
193 case 1: tmp = getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR; break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
194 case 2: tmp = getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR; break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
195 case 3: tmp = getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR; break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
196 case 4: tmp = 0; break; // todo regler 5
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
197 case 5: tmp = 0; break; // todo regler 6
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
198 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
199 tmp = 0b1000000000 | (controller << 6) | ((tmp & 0xF) << 1);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
200 if ( (PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) tmp |= 1; // benzinstand aktiv - tankmodusschalter
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
201 if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)) != 0) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
202 tmp |= (1<<5);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
203 LED(controller+1, 0);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
204 } else LED(controller+1, 1);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
205
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
206 return insert_queue(tmp, 9);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
207 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
208
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
209 unsigned char mirror( unsigned char n ) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
210 // mirror all 8 bits
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
211 n = ((n >> 1) & 0x55) | ((n << 1) & 0xaa);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
212 n = ((n >> 2) & 0x33) | ((n << 2) & 0xcc);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
213 n = ((n >> 4) & 0x0f) | ((n << 4) & 0xf0);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
214 return n;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
215 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
216
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
217
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
218 int do_program(uint8_t controller, uint8_t command, uint8_t parameter) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
219 // send program data packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
220 uint16_t tmp;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
221 tmp = 0b1000000000000 | (mirror(parameter) << 4) | mirror(command)| (mirror(controller) >> 5);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
222
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
223 return insert_queue(tmp, 12);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
224 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
225
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
226 int do_active(void) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
227 // send controller active data packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
228 uint16_t tmp = 0b10000000;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
229 if ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b11000001;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
230 if ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10100001;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
231 if ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10010001;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
232 if ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10001001;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
233 // todo: regler 5 und 6
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
234
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
235 return insert_queue(tmp, 7);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
236 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
237
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
238 int do_pace_ghost(void) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
239 // send ghost and pacecar data packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
240 // todo: at the moment, both disabled!
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
241 uint16_t tmp = 0b1111100000;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
242 if ( (PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) tmp |= 1; // benzinstand aktiv - tankmodusschalter
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
243 // todo: PC, NH, TK, (KFR, FR)
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
244
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
245 return insert_queue(tmp, 9);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
246 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
247
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
248 /*
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
249 TODO: DIE TIMER1 ISR DARF DIE ADC NICHT ABFRAGEN, NICHTMAL PAKETE BAUEN, NUR TRIGGERN
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
250 DIE PAKETE MÃœSSEN IN DER MAIN UNIT GEBAUT WERDEN UND IN EINE QUEUE GESCHOBEN WERDEN
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
251 EINES VORBAUEN IN Q+1, DIE TIMER2 ISR MUSS DANN Q = Q+1 und Q+1 = 0 SETZEN, ERST DANN DARF
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
252 NEUES PAKET IN Q+1 EINGEFÃœGT WERDEN
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
253 */
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
254
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
255
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
256 ISR ( TIMER1_COMPA_vect ) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
257 //OCR2 = 0xFF; // make sure that timer2 is synced to timer1, give enough cycles to prepare
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
258 LED(4,2);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
259 // trigger packet transfer:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
260 transmit_len = transmit_len_next;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
261
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
262 // here is some more time to do something else...
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
263 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
264
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
265
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
266 int main(void)
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
267 {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
268
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
269 unsigned char s[30];
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
270 uint16_t tmp;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
271 uint8_t packet_index = 1;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
272
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
273
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
274 init_hardware();
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
275
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
276 itoa(TIMER2_50US, s, 10);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
277 RS232_puts(s);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
278
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
279 // switch on rails power
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
280 RAIL_POWER_PORT |= _BV(RAIL_POWER);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
281
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
282 while (1) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
283 //RS232_putc(PIN(RAIL_DETECT_PORT));
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
284
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
285 // check for short circuit on the rails
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
286 if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
287 _delay_ms(1);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
288 if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
289 cli(); // disable ALL Interrupts
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
290 RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // disable rails power
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
291 RS232_puts_p(PSTR("!!! SHORT CIRCUIT ON RAILS, POWERED OFF !!!\n"));
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
292 while (1) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
293 LED(1, 0);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
294 _delay_ms(100);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
295 LED(1, 1);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
296 _delay_ms(100);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
297 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
298 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
299 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
300
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
301
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
302
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
303
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
304 switch (packet_index) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
305 case 1:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
306 if (do_program(7, 19, 0)) packet_index++; // reset
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
307 //do_program(7, 16, 3); // led an startampel
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
308 //do_program(0, 4, 0); //
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
309 break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
310 case 2:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
311 if (do_pace_ghost()) packet_index++;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
312 break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
313 case 3:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
314 if (do_active()) packet_index++;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
315 break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
316 case 4:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
317 if (do_controller(0)) packet_index++;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
318 break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
319 case 5:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
320 if (do_controller(4)) packet_index++;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
321 break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
322 case 6:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
323 if (do_controller(1)) packet_index++;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
324 break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
325 case 7:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
326 if (do_controller(5)) packet_index++;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
327 break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
328 case 8:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
329 if (do_controller(2)) packet_index++;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
330 break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
331 case 9:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
332 if (do_active()) packet_index++;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
333 break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
334 case 10:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
335 if (do_controller(3)) packet_index = 1;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
336 // last packet, so reset packet index
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
337 break;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
338 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
339
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
340
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
341
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
342
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
343 /*
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
344 do_controller(0);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
345 itoa (transmit_len_queue, s, 10);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
346 RS232_puts(s);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
347 RS232_putc(' ');
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
348 itoa (transmit_buffer_queue, s, 2);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
349 RS232_puts(s);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
350
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
351 RS232_putc('\n');
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
352 */
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
353 /*
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
354 itoa (tmp, s, 2);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
355 RS232_puts(s);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
356 RS232_putc('\n');
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
357 */
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
358
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
359
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
360 } // main loop end
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
361 };
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
362

mercurial