]> git.tdb.fi Git - model-railway-devices.git/blob - arducontrol/arducontrol.c
Add support for S88 feedback modules
[model-railway-devices.git] / arducontrol / arducontrol.c
1 /*
2 Firmware for model railway control interface
3
4 ATMega pinout:
5 D0 - serial RX
6 D1 - serial TX
7 D2 - Polarity control
8 D3 - Power control
9
10 Connections for Pololu high-powered motor driver:
11 D2 <-> DIR
12 D3 <-> PWM
13
14 Connections for S88 bus:
15 D4 <-> RESET
16 D5 <-> LOAD
17 D6 <-> CLOCK
18 D7 <-> DATA
19
20 ADC connections:
21 ADC0 - current sensor (adjusted for 185 mV/A, centered at Vcc/2)
22 ADC1 - input voltage (adjusted for divisor of 11)
23
24 This is not a complete control device.  Rather, it is a low-level bus driver,
25 intended to be controlled with a computer program.  In particular, no state is
26 kept about locomotives or solenoids.  It is up to the controlling program to
27 maintain a refresh cycle, turn off solenoids after a sufficient delay, etc.
28
29 Commands are received as a packetized stream over the serial interface.  Each
30 packet begins with a header byte, which is bitwise not of the packet's length,
31 not including the header byte itself.  The longest allowed packet is 15 bytes.
32 Thus, the high four bits of the header byte are always ones.  The first data
33 byte specifies the command, and the rest of the packet is command arguments.
34
35 After a command has been processed, a similarly packetized response is sent.
36
37 Track output is asynchronous up to a single packet.  If an output command is
38 received while a previous packet is still being sent to the track, execution
39 blocks until the operation completes.  The command returns as soon as sending
40 its data to the track can start.
41 */
42 #include <avr/io.h>
43 #include <avr/interrupt.h>
44 #include "interface.h"
45 #include "monitor.h"
46 #include "output.h"
47 #include "s88.h"
48
49 int main(void)
50 {
51         output_init();
52         interface_init();
53         monitor_init();
54         s88_init();
55
56         sei();
57
58         while(1)
59         {
60                 interface_check();
61                 monitor_check();
62                 s88_check();
63         }
64
65         return 0;
66 }