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