trennfix/sw: Register variables, restructuring, whatever
[eisenbahn.git] / trennfix / sw / config / trennfix_attiny25.h
CommitLineData
70095677
PH
1#ifndef __HARDWARE_H
2#define __HARDWARE_H
3
93cb14d4 4#include <pin_magic.h>
70095677
PH
5
6#define PIN_LED _PIN(PORTB, PORTB2)
7#define PIN_SENSE _PIN(PORTB, PORTB4)
7c08d02a
PH
8//#define PIN_DRIVE _PIN(PORTB, PORTB3)
9#define PIN_DRIVE PIN_LED
70095677
PH
10#define PIN_BTN _PIN(PORTB, PB1)
11
70095677
PH
12#define BTN_PRESSED (!PINVAL(PIN_BTN))
13
14#define START_TIMER0 ({TCNT0 = 0; TCCR0B = 2;})
15#define START_TIMER1 ({TCNT1 = 1; TCCR1 = 7; GTCCR |= 2;})
16#define STOP_TIMER1 ({TCCR1 = 0; TCNT1 = 1;})
17
18
93cb14d4
PH
19/*
20 * Various sinks for valuable program memory
21 *
22 */
23// #define USE_EEPROM_UPDATE /* 14 bytes */
24//#define INTERPRET_DRIVE_COMMANDS
25#define INTERPRET_DRIVE_SIMPLE
26
70095677
PH
27static inline void setup_hw(void)
28{
29 /* Turn off the 1/8 clock prescaler - now running at 16MHz*/
30 CLKPR = (1 << CLKPCE);
31 CLKPR = 0;
32
33 INPUT_PIN(PIN_SENSE);
34 INPUT_PIN(PIN_BTN);
35 OUTPUT_PIN(PIN_DRIVE);
36 OUTPUT_PIN(PIN_LED);
37 setpin(PIN_BTN, 1); /* Need pullup */
38
39 GIMSK |= _BV(PCIE); /* Enable pin change interrupt for sense port */
40 PCMSK |= _BV(PCINT4); /* PB4, Rail sense input */
41
42 /* Change interrupt for button */
43 PCMSK |= _BV(PCINT1); /* PB1 */
44
45 /* Setup timer 0, used for mm_switch */
46 TCCR0A = 0; /* Normal mode */
47 TCCR0B = 0; /* Timer off */
48 TIMSK |= _BV(OCIE0A); /* Get a match interrupt */
49
50 /* We need 13 + 45,5 us delay, That's 464 clocks @8MHz*/
51 //OCR0A = 91; /* Prescaler 8 is used */
52
53 /* Timer 1 for timeout */
54 /* We set it to 1024us by prescaler 64 and running full 256 */
55 // TCCR1 = 7;
56 // TIMSK |= _BV(TOIE1); /* Overflow interrupt */
57}
58
93cb14d4
PH
59/*
60 * Function to trigger an oscilloscope on the drive pin
61 *
62 * Can be altered to use the LED.
63 *
64 */
65static void __attribute__((unused)) trigger(void)
66{
67 setpin(PIN_DRIVE, 1);
68 _delay_us(4);
69 setpin(PIN_DRIVE, 0);
70 _delay_us(4);
71}
70095677 72
93cb14d4
PH
73/*
74 * Configuration for mm receiver code.
75 */
70095677 76
93cb14d4 77#define MM_SENSE (!PINVAL(PIN_SENSE))
7c08d02a
PH
78#define MM_TSTART_FAST ({TCNT0 = 0; GTCCR |= 1; OCR0A = 120; TCCR0B = 2;})
79#define MM_TSTART_SLOW ({TCNT0 = 0; GTCCR |= 1; OCR0A = 230; TCCR0B = 2;})
93cb14d4
PH
80#define MM_TSTOP ({TCCR0B = 0;})
81#define MM_TIMER_INT_VECT TIMER0_COMPA_vect
70095677 82
93cb14d4
PH
83/* Costs 63 bytes program memory */
84#define MM_FILTER_REPEATED
70095677 85
93cb14d4 86#define USE_EEPROM_UPDATE
70095677 87#endif