blackbox/main.h

Tue, 13 Dec 2011 18:41:13 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Tue, 13 Dec 2011 18:41:13 +0100
changeset 79
027e164b32f3
parent 73
ec888cfa024e
child 89
4b5b4c7ba03d
permissions
-rw-r--r--

Added tag STABLE1 for changeset d9126a55295c

0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
1 #ifndef MAIN_H
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
2 #define MAIN_H
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
3
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
4 #include <avr/wdt.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
5 #include <stdint.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
6
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
7 #define VERSION "1.5"
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
8
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
9 #define COUNTDOWN_DELAY 10 // x/10 seconds
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
10
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
11 // Hardware config
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
12 #define LAP_COUNTER_PORT PORTB
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
13 #define LAP_COUNTER PB2
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 #define MODUL_PORT PORTD
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
16 #define MODUL_ST4 PD5
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
17 #define MODUL_ST6 PD6
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
18
69
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 64
diff changeset
19 #define RESPONSEWIRE_PORT MODUL_PORT
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 64
diff changeset
20 #define RESPONSEWIRE_PIN MODUL_ST4
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 64
diff changeset
21
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
22 #define I2C_PORT PORTC
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
23 #define I2C_SCL PC0
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
24 #define I2C_SDA PC1
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
25
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
26 #define LED1_PORT PORTA
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
27 #define LED2_PORT PORTA
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
28 #define LED3_PORT PORTC
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
29 #define LED4_PORT PORTC
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
30 #define LED5_PORT PORTC
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
31 #define LED1 PA4
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
32 #define LED2 PA5
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
33 #define LED3 PC7
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
34 #define LED4 PC2
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
35 #define LED5 PC3
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
36
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
37 #define SW_PACECAR_PORT PORTC
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
38 #define SW_START_PORT PORTB
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
39 #define SW_FUEL_PORT PORTB
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
40 #define SW_PACECAR PC6
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
41 #define SW_FUEL PB0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
42 #define SW_START PB1
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 #define SPEAKER_PORT PORTD
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
45 #define SPEAKER PD7
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
46
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
47 #define RAIL_POWER_PORT PORTD
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
48 #define RAIL_POWER PD4 // high = rails powered
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
49 #define RAIL_DETECT_PORT PORTA
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
50 #define RAIL_DETECT PA7 // low = short circuit detection
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 #define CONTROLLER_PORT PORTB
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
53 #define CONTROLLER_MAX 360 // full throttle ADC value
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
54 #define CONTROLLER_DIVISOR (uint8_t)(CONTROLLER_MAX/15)
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
55 #define CONTROLLER1_SW PB4
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
56 #define CONTROLLER2_SW PB5
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
57 #define CONTROLLER3_SW PB6
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
58 #define CONTROLLER4_SW PB7
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
59 #define CONTROLLER1_SPEED 0 // ADC channel #
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
60 #define CONTROLLER2_SPEED 1 // ADC channel #
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
61 #define CONTROLLER3_SPEED 2 // ADC channel #
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
62 #define CONTROLLER4_SPEED 3 // ADC channel #
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
63
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
64 // TIMING STUFF
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
65 /*
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
66 #define TIMER0_DIVISOR 8
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
67 #define VALUE_50US 0.45e-4
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
68 #define TIMER_50US 0xff - (uint8_t)(VALUE_50US * F_CPU/TIMER0_DIVISOR)
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
69 */
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
70 /*
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
71 #define VALUE_7500NS 0.85e-2
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
72 #define TIMER_7500NS 0xffff - (uint16_t)(VALUE_7500NS * F_CPU/TIMER1_DIVISOR)
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 //#define TIMER_7500NS (uint16_t)(VALUE_7500NS * F_CPU/TIMER1_DIVISOR)
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
75 #define TIMER0_DIVISOR 8
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
76 #define VALUE0_250US 0.25e-3
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
77 #define TIMER0_250US 0xff - (uint8_t)(VALUE0_250US * F_CPU/TIMER0_DIVISOR)
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
78 #define TIMER0_2300NS (uint8_t)(2300/250)
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
79
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
80 #define TIMER2_DIVISOR 8
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
81 #define VALUE2_50US 0.50e-4
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
82 #define TIMER2_50US (uint8_t)(VALUE2_50US * F_CPU/TIMER2_DIVISOR)
38
ff76255904c4 implemented response reader to carrerashark
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
83 #define VALUE2_250US 2.5e-4
ff76255904c4 implemented response reader to carrerashark
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
84 #define TIMER2_250US (uint8_t)((VALUE2_250US * F_CPU/TIMER2_DIVISOR) - 2)
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
85
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
86 #define TIMER1_DIVISOR 8
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
87 #define VALUE1_7500NS 0.75e-2
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
88 #define TIMER1_7500NS (uint16_t)(VALUE1_7500NS * F_CPU/TIMER1_DIVISOR)
42
018d4d63ad3b implemented 500ns timer and set jumpstart time
Malte Bayer <mbayer@neo-soft.org>
parents: 38
diff changeset
89 #define VALUE1_500NS 0.5e-3
018d4d63ad3b implemented 500ns timer and set jumpstart time
Malte Bayer <mbayer@neo-soft.org>
parents: 38
diff changeset
90 #define TIMER1_500NS (uint16_t)((VALUE1_500NS * F_CPU/TIMER1_DIVISOR) + 2) // MEASURE THIS EXACTLY WITH SCOPE
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
91
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
92 #define DDR(x) (*(&x - 1)) // address of data direction register of port x
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
93 #define PIN(x) (*(&x - 2)) // address of input register of port x
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
94
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
95
64
61f88f973eba structured vars in pitlane code
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
96 // constants
61f88f973eba structured vars in pitlane code
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
97 #define MAX_SLOTS 6
61f88f973eba structured vars in pitlane code
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
98
0
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 // MAYBE USELESS STUFF:
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 #define uchar unsigned char
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
103 #define uint unsigned int
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
104
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
105 // Macro used to write to a single I/O pin
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
106 #define writeBit(port,bit,value) { if ((value)>0) (port) |= (1<<bit); else (port) &= ~(1<<bit); }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
107
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
108 // Macro used to read from a single I/O pin
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
109 #define readBit(port,bit) (((port) >> (bit)) & 1)
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 // we have internal AREF...
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
112 // #define EXT_AREF 1
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 #endif

mercurial