trennfix/sw: Added smokefix, further modularized the mm decoder
[eisenbahn.git] / trennfix / sw / config / trennfix_0.4.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)
d0047978 10#define PIN_TRIGGER _PIN(PORTB, PB0)
70095677
PH
11#define BTN_PRESSED (!PINVAL(PIN_BTN))
12
70095677
PH
13#define STOP_TIMER1 ({TCCR1 = 0; TCNT1 = 1;})
14
f12652df 15#define PWM_CYCLE 14
d0047978 16
70095677
PH
17static inline void setup_hw(void)
18{
19 /* Turn off the 1/8 clock prescaler - now running at 16MHz*/
20 CLKPR = (1 << CLKPCE);
21 CLKPR = 0;
22
f12652df
PH
23 setpin(PIN_LED, 0);
24 setpin(PIN_TRIGGER, 0);
25 setpin(PIN_BTN, 1); /* Need pullup */
70095677
PH
26 INPUT_PIN(PIN_SENSE);
27 INPUT_PIN(PIN_BTN);
28 OUTPUT_PIN(PIN_DRIVE);
29 OUTPUT_PIN(PIN_LED);
d0047978 30 OUTPUT_PIN(PIN_TRIGGER);
f12652df 31
70095677
PH
32 GIMSK |= _BV(PCIE); /* Enable pin change interrupt for sense port */
33 PCMSK |= _BV(PCINT4); /* PB4, Rail sense input */
34
35 /* Change interrupt for button */
36 PCMSK |= _BV(PCINT1); /* PB1 */
37
38 /* Setup timer 0, used for mm_switch */
39 TCCR0A = 0; /* Normal mode */
d0047978 40 TCCR0B = 2; /* Prescaler 8 */
f12652df 41
b1a7e65e 42 TIMSK |= _BV(TOIE0);
b1a7e65e 43 TCCR0B = 2;
70095677 44
f12652df 45#ifdef WITH_PWM
dc41eb22 46 /* Timer 1 as PWM */
d0047978
PH
47 OCR1C = PWM_CYCLE;
48 OCR1B = PWM_CYCLE;
49 TCCR1 = 0x5;
50
dc41eb22
PH
51 GTCCR |= _BV(PWM1B) | _BV(COM1B0);
52#endif
53
70095677
PH
54}
55
93cb14d4
PH
56/*
57 * Function to trigger an oscilloscope on the drive pin
58 *
59 * Can be altered to use the LED.
60 *
61 */
d0047978
PH
62static inline void __attribute__((unused)) trigger(void)
63{
64 setpin(PIN_TRIGGER, 1);
65 setpin(PIN_TRIGGER, 0);
66}
67
d0047978
PH
68static inline void __attribute__((unused)) trigger_on(void)
69{
70 setpin(PIN_TRIGGER, 1);
71}
72
73static inline void __attribute__((unused)) trigger_off(void)
93cb14d4 74{
d0047978 75 setpin(PIN_TRIGGER, 0);
93cb14d4 76}
70095677 77
93cb14d4
PH
78/*
79 * Configuration for mm receiver code.
80 */
c839c431 81#define MM_SENSE (PINVAL(PIN_SENSE))
b1a7e65e 82#define MM_TIMER_INT_VECT TIMER0_OVF_vect
70095677 83
d0047978
PH
84#define MM_TSTART { \
85 GTCCR |= _BV(TSM) | _BV(PSR0); \
86 TCNT0 = 0; \
d0047978
PH
87 GTCCR &= ~_BV(TSM); \
88 }
89
b1a7e65e 90#define MM_RESETFLAG TIFR |= _BV(OVF0)
f12652df
PH
91//#define MM_USE_QUEUE
92#define MM_QUEUE_DEPTH 8
93#define MM_USE_CALLBACK
dc41eb22
PH
94
95#ifdef USE_REGISTER_VARS
b1a7e65e
PH
96uint8_t register drive_on asm("r12");
97uint8_t register slope asm("r13");
dc41eb22 98#endif
70095677
PH
99
100#endif