blackbox/main.c

Wed, 16 Nov 2011 17:04:10 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Wed, 16 Nov 2011 17:04:10 +0100
changeset 9
20dbe0546a36
parent 8
84249ab5d691
child 10
6d6e982bbc41
permissions
-rw-r--r--

added receiver testing stuff

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 "driver/rs232.h"
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
11 #include "driver/adc.h"
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
12
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
13 #include "main.h"
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
14 #include "lowlevel.h"
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
15
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
16 volatile uint8_t program_count = 0;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
17 volatile uint8_t program_id;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
18 volatile uint8_t program_command;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
19 volatile uint8_t program_parameter;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
20
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
21 volatile uint8_t datalen = 0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
22 char data[10]; // 8 bytes data buffer + string termination
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 static char buffer[RS232_BUFSIZE+1];
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
25 static uint8_t buffer_len;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
26
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
27
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
28 volatile uint16_t transmit_buffer;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
29 volatile uint16_t transmit_buffer_queue;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
30 volatile uint8_t transmit_len;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
31 volatile uint8_t transmit_len_next;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
32 volatile uint8_t transmit_len_queue;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
33
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
34 volatile uint16_t response;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
35 volatile uint8_t timer0_delay;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
36
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
37
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
38 ISR ( USART_RXC_vect ) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
39 char c = UDR;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
40
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
41 // check for buffer overflow
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
42 if (buffer_len==sizeof(buffer)) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
43 buffer_len=0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
44 } else {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
45 // collect characters until end of line
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
46 if ( (c==0x0A) ) {
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
47 buffer[buffer_len]=0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
48
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
49 // packet end received, parse the received packet
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
50 switch (buffer[0]) {
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
51 case 'P': // inject a program data word to the rails
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
52 // TODO: at the moment only parameters 0..9 supported
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
53 // needs to build a "human" parser
5
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
54 if (program_count == 0) {
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
55 program_id = buffer[3]-'0';
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
56 program_command = buffer[1]-'0';
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
57 program_parameter = buffer[2]-'0';
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
58 if (program_command < 4)
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
59 program_count = 0x02; // send commands twice (fuel, speed, brake)
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
60 else
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
61 program_count = 0x01;
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
62 RS232_puts_p(PSTR("OK\n"));
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
63 } else RS232_puts_p(PSTR("BUSY\n"));
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
64 break;
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
65
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
66 }
0
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 // wait for the next packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
69 buffer_len=0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
70 } else {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
71 buffer[buffer_len++]=c;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
72 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
73 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
74 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
75
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
76
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
77
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
78 int insert_queue(uint16_t tmp, uint8_t len) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
79 if (transmit_buffer_queue == 0) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
80 transmit_buffer_queue = tmp;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
81 transmit_len_queue = len;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
82 return 1;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
83 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
84 return 0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
85 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
86
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
87
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
88 int do_controller(uint8_t controller) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
89 // read controller X speed & encode controller data packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
90 uint16_t tmp;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
91 switch (controller) {
3
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
92 case 0:
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
93 tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
3
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
94 if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)) != 0) tmp |= (1<<5);
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
95 break;
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
96 case 1:
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
97 tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
3
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
98 if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)) != 0) tmp |= (1<<5);
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
99 break;
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
100 case 2:
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
101 tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
3
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
102 if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)) != 0) tmp |= (1<<5);
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
103 break;
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
104 case 3:
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
105 tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
3
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
106 if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)) != 0) tmp |= (1<<5);
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
107 break;
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
108 case 4: tmp = (1<<5); break; // todo regler 5
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
109 case 5: tmp = (1<<5); break; // todo regler 6
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
110 }
3
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
111 tmp |= 0b1000000000 | (controller << 6);
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
112 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
113
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
114 return insert_queue(tmp, 9);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
115 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
116
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
117 uint8_t mirror( uint8_t n ) {
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
118 n = ((n >> 1) & 0x55) | ((n << 1) & 0xaa);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
119 n = ((n >> 2) & 0x33) | ((n << 2) & 0xcc);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
120 n = ((n >> 4) & 0x0f) | ((n << 4) & 0xf0);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
121 return n;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
122 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
123
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
124 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
125 // send program data packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
126 uint16_t tmp;
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
127 parameter = mirror(parameter);
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
128 controller = mirror(controller);
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
129 command = mirror(command);
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
130 tmp = 0b1000000000000 | (parameter << 4) | command | (controller >> 5);
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
131 return insert_queue(tmp, 12);
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
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
134 int do_active(void) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
135 // send controller active data packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
136 uint16_t tmp = 0b10000000;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
137 if ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b11000001;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
138 if ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10100001;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
139 if ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10010001;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
140 if ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10001001;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
141 // todo: regler 5 und 6
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
142 // todo: wenn Daten enpfangen wurden hier eine Quittierung senden anstatt dem Active Word
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
143
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
144 return insert_queue(tmp, 7);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
145 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
146
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
147 int do_pace_ghost(void) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
148 // send ghost and pacecar data packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
149 // todo: at the moment, both disabled!
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
150 uint16_t tmp = 0b1111100000;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
151 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
152 // todo: PC, NH, TK, (KFR, FR)
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
153
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
154 return insert_queue(tmp, 9);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
155 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
156
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
157 ISR ( TIMER1_COMPA_vect ) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
158 // trigger packet transfer:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
159 transmit_len = transmit_len_next;
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
160 LED(2,2);
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
161
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
162 // here is some more time to do something else...
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
163 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
164
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
165 ISR ( TIMER2_COMP_vect ) {
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
166 //OCR2 = TIMER2_50US; // make sure that timer2 is 50µs !!!
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
167 // data packet timer 100µs pro bit...
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
168 if (transmit_len >= 0xFE) {
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
169 if (transmit_len != 0xFF) {
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
170 RAIL_POWER_PORT |= _BV(RAIL_POWER); // end of transmission
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
171 transmit_len = 0xFF;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
172 transmit_buffer = transmit_buffer_queue;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
173 transmit_buffer_queue = 0;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
174 transmit_len_next = transmit_len_queue;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
175
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
176 // start the response receiver timer
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
177 // TODO: only on 8 timeslots, not on every transmission
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
178 // TODO: give slot number to timer - then store the transmission to 8 slots array
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
179 TCNT0 = TIMER0_250US;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
180 timer0_delay = TIMER0_2300NS;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
181 response = 0;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
182 TIMSK |= _BV(TOIE0);
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
183
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
184 }
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
185 } else {
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
186 uint16_t bit = (1<<(transmit_len & 0b01111111));
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
187 uint16_t clock;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
188 if ((transmit_len & 0b10000000) == 0) clock = 0; else clock = 0xffff;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
189 if ( ((transmit_buffer ^ clock) & bit) != 0 )
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
190 RAIL_POWER_PORT |= _BV(RAIL_POWER); else
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
191 RAIL_POWER_PORT &= ~_BV(RAIL_POWER);
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
192 if ( (transmit_len & 0b10000000) == 0 ) {
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
193 // block 0
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
194 //if (transmit_len == 0) transmit_len = 0xFF; else transmit_len |= 0b10000000; // set clock
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
195 transmit_len |= 0b10000000; // set clock
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
196 } else {
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
197 // block 1, output the current bit
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
198 transmit_len &= 0b01111111; // reset clock
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
199 //if (transmit_len != 0) transmit_len--; // next bit
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
200 if (transmit_len == 0) transmit_len = 0xFE; else transmit_len--; // next bit
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
201 }
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
202 }
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
203
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
204 LED(3,2);
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
205 }
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
206
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
207
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
208 ISR ( TIMER0_OVF_vect ) {
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
209 // TODO: last bit should be set by the sender, not from us!
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
210 TCNT0 = TIMER0_250US;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
211 LED(1,2);
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
212 if (timer0_delay == 0) {
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
213 RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // pull rails low
8
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
214 _delay_us(28); // wait some cycles
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
215 if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) != 0) { // check for logic zero
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
216 if (response == 0) {
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
217 // there is no start bit, so stop the timer and cancel response receiving
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
218 TIMSK &= ~_BV(TOIE0);
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
219 } else {
8
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
220 // we received a bit (logic low)
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
221 response = response << 1;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
222 }
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
223 } else {
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
224 // okay, we have logic high
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
225 response = response << 1;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
226 response |= 1;
8
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
227 //debug:
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
228 RS232_puts("ANSWER RX\n");
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
229 }
8
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
230 _delay_us(20); // wait some cycles
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
231 RAIL_POWER_PORT |= _BV(RAIL_POWER); // restore rails power
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
232 } else timer0_delay--; // 2.3 ms delay not reached yet
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
233 }
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
234
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
235 ISR (INT2_vect) {
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
236 // Lap counter Interrupt
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
237 LED(5,2);
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
238 }
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
239
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
240
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
241 int main(void)
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
242 {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
243
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
244 unsigned char s[30];
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
245 uint16_t tmp;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
246 uint8_t packet_index = 1;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
247
8
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
248 uint8_t btn_start = _BV(SW_START);
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
249 uint8_t old_start = btn_start;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
250 uint8_t mode = 0;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
251 // valid race modes:
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
252 // 0: free drive
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
253 // 1: race countdown initiated
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
254 // 2: countdown 5
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
255 // 3: countdown 4
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
256 // 4: countdown 3
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
257 // 5: countdown 2
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
258 // 6: countdown 1
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
259 // 7: race start initiated (next mode will be zero = free drive)
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
260
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
261
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
262
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
263 init_hardware();
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 // switch on rails power
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
266 RAIL_POWER_PORT |= _BV(RAIL_POWER);
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 while (1) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
269 // check for short circuit on the rails
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
270 check_rails_shortcut();
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
271
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
272 // read in button presses
8
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
273 btn_start = (PIN(SW_START_PORT) & _BV(SW_START));
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
274 if (old_start != btn_start) {
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
275 // start button changed
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
276 if (btn_start == 0) {
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
277 // start button press active
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
278 if (mode == 0) {
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
279 // Initiate race countdown
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
280 mode = 0; // todo: set to 1
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
281 // issue reset command to lap counter
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
282 program_command = 6;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
283 program_parameter = 9;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
284 program_id = 0;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
285 program_count = 1;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
286 } else {
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
287 // do a reset, switch back to free drive mode 0
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
288 mode = 0;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
289 // issue reset command
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
290 program_command = 19;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
291 program_parameter = 0;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
292 program_id = 7;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
293 program_count = 1;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
294 }
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
295 }
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
296 //LAP_COUNTER_PORT |= _BV(LAP_COUNTER);
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
297 } else old_start = btn_start;
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
298 // LAP_COUNTER_PORT &= ~_BV(LAP_COUNTER);
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
299
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
300 switch (packet_index) {
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
301 case 1:
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
302 if (program_count > 0) {
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
303 // command in queue
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
304 if (do_program(program_id, program_command, program_parameter)) {
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
305 packet_index++;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
306 program_count--;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
307 }
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
308 } else {
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
309 // output idle command
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
310 //if (do_program(7, 19, 0)) packet_index++; // reset
8
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
311 //if (do_program(7, 20, 15)) packet_index++; // reset / pitstop detect
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
312 if (insert_queue(0, 0)) packet_index++; // null command
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
313 }
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
314 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
315 case 2:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
316 if (do_pace_ghost()) packet_index++;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
317 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
318 case 3:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
319 if (do_active()) packet_index++;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
320 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
321 case 4:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
322 if (do_controller(0)) packet_index++;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
323 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
324 case 5:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
325 if (do_controller(4)) packet_index++;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
326 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
327 case 6:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
328 if (do_controller(1)) packet_index++;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
329 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
330 case 7:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
331 if (do_controller(5)) packet_index++;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
332 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
333 case 8:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
334 if (do_controller(2)) packet_index++;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
335 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
336 case 9:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
337 if (do_active()) packet_index++;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
338 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
339 case 10:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
340 if (do_controller(3)) packet_index = 1;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
341 // last packet, so reset packet index
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
342 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
343 }
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
344
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
345
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
346 } // main loop end
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
347 };
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
348

mercurial