trennfix/sw: Makefile: Move objects etc into build folder
[eisenbahn.git] / trennfix / sw / config / trennfix_0.4.h
... / ...
CommitLineData
1#ifndef __HARDWARE_H
2#define __HARDWARE_H
3
4#include <pin_magic.h>
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#define PIN_TRIGGER _PIN(PORTB, PB0)
11#define BTN_PRESSED (!PINVAL(PIN_BTN))
12
13#define STOP_TIMER1 ({TCCR1 = 0; TCNT1 = 1;})
14
15#define PWM_CYCLE 14
16
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
23 setpin(PIN_LED, 0);
24 setpin(PIN_TRIGGER, 0);
25 setpin(PIN_BTN, 1); /* Need pullup */
26 INPUT_PIN(PIN_SENSE);
27 INPUT_PIN(PIN_BTN);
28 OUTPUT_PIN(PIN_DRIVE);
29 OUTPUT_PIN(PIN_LED);
30 OUTPUT_PIN(PIN_TRIGGER);
31
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 */
40 TCCR0B = 2; /* Prescaler 8 */
41
42 TIMSK |= _BV(TOIE0);
43 TCCR0B = 2;
44
45#ifdef WITH_PWM
46 /* Timer 1 as PWM */
47 OCR1C = PWM_CYCLE;
48 OCR1B = PWM_CYCLE;
49 TCCR1 = 0x5;
50
51 GTCCR |= _BV(PWM1B) | _BV(COM1B0);
52#endif
53
54}
55
56/*
57 * Function to trigger an oscilloscope on the drive pin
58 *
59 * Can be altered to use the LED.
60 *
61 */
62static inline void __attribute__((unused)) trigger(void)
63{
64 setpin(PIN_TRIGGER, 1);
65 setpin(PIN_TRIGGER, 0);
66}
67
68static inline void __attribute__((unused)) trigger_on(void)
69{
70 setpin(PIN_TRIGGER, 1);
71}
72
73static inline void __attribute__((unused)) trigger_off(void)
74{
75 setpin(PIN_TRIGGER, 0);
76}
77
78/*
79 * Configuration for mm receiver code.
80 */
81#define MM_SENSE (PINVAL(PIN_SENSE))
82#define MM_TIMER_INT_VECT TIMER0_OVF_vect
83
84#define MM_TSTART { \
85 GTCCR |= _BV(TSM) | _BV(PSR0); \
86 TCNT0 = 0; \
87 GTCCR &= ~_BV(TSM); \
88 }
89
90#define MM_RESETFLAG TIFR |= _BV(OVF0)
91//#define MM_USE_QUEUE
92#define MM_QUEUE_DEPTH 8
93#define MM_USE_CALLBACK
94
95#ifdef USE_REGISTER_VARS
96uint8_t register drive_on asm("r12");
97uint8_t register slope asm("r13");
98#endif
99
100#endif