blackbox/main.h

Fri, 09 Dec 2011 22:15:50 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Fri, 09 Dec 2011 22:15:50 +0100
changeset 66
1e220602b7a7
parent 64
61f88f973eba
child 69
27c0c0095e26
permissions
-rw-r--r--

pitlane response enter/exit pitlane, led lit when car is in pitlane

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
47
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 43
diff changeset
7 #define VERSION "1.3"
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
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
19 #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
20 #define I2C_SCL PC0
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
21 #define I2C_SDA PC1
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
22
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
23 #define LED1_PORT PORTA
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
24 #define LED2_PORT PORTA
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
25 #define LED3_PORT PORTC
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
26 #define LED4_PORT PORTC
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
27 #define LED5_PORT PORTC
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
28 #define LED1 PA4
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
29 #define LED2 PA5
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
30 #define LED3 PC7
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
31 #define LED4 PC2
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
32 #define LED5 PC3
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
33
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
34 #define SW_PACECAR_PORT PORTC
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
35 #define SW_START_PORT PORTB
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
36 #define SW_FUEL_PORT PORTB
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
37 #define SW_PACECAR PC6
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
38 #define SW_FUEL PB0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
39 #define SW_START PB1
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 #define SPEAKER_PORT PORTD
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
42 #define SPEAKER PD7
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 RAIL_POWER_PORT PORTD
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
45 #define RAIL_POWER PD4 // high = rails powered
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
46 #define RAIL_DETECT_PORT PORTA
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
47 #define RAIL_DETECT PA7 // low = short circuit detection
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 #define CONTROLLER_PORT PORTB
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
50 #define CONTROLLER_MAX 360 // full throttle ADC value
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
51 #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
52 #define CONTROLLER1_SW PB4
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
53 #define CONTROLLER2_SW PB5
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
54 #define CONTROLLER3_SW PB6
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
55 #define CONTROLLER4_SW PB7
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
56 #define CONTROLLER1_SPEED 0 // ADC channel #
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
57 #define CONTROLLER2_SPEED 1 // ADC channel #
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
58 #define CONTROLLER3_SPEED 2 // ADC channel #
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
59 #define CONTROLLER4_SPEED 3 // ADC channel #
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
60
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
61 // TIMING STUFF
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
62 /*
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
63 #define TIMER0_DIVISOR 8
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
64 #define VALUE_50US 0.45e-4
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
65 #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
66 */
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 #define VALUE_7500NS 0.85e-2
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
69 #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
70 */
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
71 //#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
72 #define TIMER0_DIVISOR 8
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
73 #define VALUE0_250US 0.25e-3
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
74 #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
75 #define TIMER0_2300NS (uint8_t)(2300/250)
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
76
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
77 #define TIMER2_DIVISOR 8
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
78 #define VALUE2_50US 0.50e-4
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
79 #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
80 #define VALUE2_250US 2.5e-4
ff76255904c4 implemented response reader to carrerashark
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
81 #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
82
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
83 #define TIMER1_DIVISOR 8
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
84 #define VALUE1_7500NS 0.75e-2
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
85 #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
86 #define VALUE1_500NS 0.5e-3
018d4d63ad3b implemented 500ns timer and set jumpstart time
Malte Bayer <mbayer@neo-soft.org>
parents: 38
diff changeset
87 #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
88
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
89 #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
90 #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
91
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
92
64
61f88f973eba structured vars in pitlane code
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
93 // constants
61f88f973eba structured vars in pitlane code
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
94 #define MAX_SLOTS 6
61f88f973eba structured vars in pitlane code
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
95
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
96
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
97 // MAYBE USELESS STUFF:
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
98
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
99 #define uchar unsigned char
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
100 #define uint unsigned int
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 // Macro used to write to a single I/O pin
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
103 #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
104
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
105 // Macro used to read from a single I/O pin
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
106 #define readBit(port,bit) (((port) >> (bit)) & 1)
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 // we have internal AREF...
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
109 // #define EXT_AREF 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 #endif

mercurial