trennfix/sw: Temporary first working time measurement method
[eisenbahn.git] / trennfix / sw / mm / include / mm / mm_switch.h
CommitLineData
70095677
PH
1#ifndef MM_SWITCH_H
2#define MM_SWITCH_H
3
4#include <stdint.h>
d0047978 5#include <config/hardware.h>
70095677 6
7c08d02a
PH
7enum mm_recstate {
8 MM_IDLE = 0,
9 MM_FIRST_FAST_SAMPLE,
10 MM_FIRST_SLOW_SAMPLE, /* If clock arrives, we stay on the fast path! */
11 MM_FAST_SAMPLE,
12 MM_FAST_WAIT_FOR_CLOCK,
9c77e706 13 MM_SLOW_SAMPLE_DELAY,
7c08d02a 14 MM_SLOW_SAMPLE,
9c77e706 15 MM_SLOW_WAIT_FOR_CLOCK_DELAY,
7c08d02a
PH
16 MM_SLOW_WAIT_FOR_CLOCK,
17};
18
19#ifdef MM_USE_REGISTER_VARS
20
21uint8_t register shift_command asm("r2");
22uint8_t register shift_function asm("r3");
23uint8_t register shift_address asm("r4");
b1a7e65e 24uint8_t register recstate asm("r5");
7c08d02a 25uint8_t register bitno asm("r6");
b1a7e65e
PH
26uint8_t register sense_last asm("r8");
27uint8_t register time_h asm("r9");
28uint8_t register time_l asm("r10");
29uint8_t register bit_val asm("r11");
7c08d02a
PH
30
31static void inline __attribute((unused)) mm_init(void)
32{
33 bitno = 0;
34 recstate = MM_IDLE;
b1a7e65e
PH
35 time_h = 0;
36 bit_val = 23;
7c08d02a
PH
37}
38
39#else
40
41#define mm_init(...)
42
43#endif
44
b1a7e65e
PH
45
46
70095677
PH
47/*
48 * mm_switch_command - Callback function!
49 *
50 * This function must be defined whenever the mm_switch module is used.
51 * It will be called from interrupt context whenever a new valid command
52 * has arrived.
53 *
54 * decoder is in the range from 1 to 25. Other values will not occur.
55 *
56 * key is in the range from 0 to 8:
57 *
58 * 1 - key1 green pressed
59 * 2 - key1 red pressed
60 * 3 - key2 green pressed
61 * 4 - key2 red pressed
62 * ...
63 * 0 - all keys up
64 *
65 */
66void mm_switch_command(uint8_t decoder, uint8_t key);
67
56b25f8b
PH
68/*
69 * empty comment :-)
70 */
71void mm_switch_drive_cb(uint8_t address, uint8_t speed, uint8_t functions, uint8_t flags);
72
73void mm_switch_drive(uint8_t decoder, uint8_t function, uint8_t command);
74
d0047978 75void mm_switch_pinchange_callback(void);
70095677 76
70095677 77#endif