Statistics
| Branch: | Revision:

root / scout_avr / src / bom.h @ cc9ca04e

History | View | Annotate | Download (1.22 KB)

1
#ifndef _BOM_H
2
#define _BOM_H
3

    
4
extern "C" {
5
#include <stdint.h>
6
}
7

    
8
// constants for direction
9
#define BOM_FRONT 0
10
#define BOM_BACK  1
11
#define BOM_LEFT  2
12
#define BOM_RIGHT 3
13

    
14
// timing, in us, for read of valid bits
15
#define MIN_LOW_PW 600
16
#define MAX_LOW_PW 1400
17
#define MIN_HIGH_PW 1600
18
#define MAX_HIGH_PW 2400
19

    
20
// returned by bom_get if there is no new data since last call
21
#define BOM_NO_DATA -1
22

    
23
// i/o pins
24
// if these are changed, remember to change bom_init and/or ISRs
25
#define PIN_BOM_SIG PINB
26
#define P_BOM_SIG0 PB0
27
#define P_BOM_SIG1 PB1
28
#define P_BOM_SIG2 PB2
29
#define P_BOM_SIG3 PB3
30

    
31
#define PORT_BOM_EMIT PORTF
32
#define P_BOM_EMIT0 PF4
33
#define P_BOM_EMIT1 PF5
34
#define P_BOM_EMIT2 PF6
35
#define P_BOM_EMIT3 PF7
36

    
37
typedef uint8_t bom_msg_t;
38

    
39
inline char bom_msg_get_robot_id(bom_msg_t msg) {
40
    return msg >> 2;
41
}
42
inline char bom_msg_get_dir(bom_msg_t msg) {
43
    return msg & 3;
44
}
45
inline bom_msg_t bom_msg_make(char id, char dir) {
46
    return (id << 2) | (dir & 3);
47
}
48

    
49
void set_robot_id(char id);
50
char get_robot_id(void);
51

    
52
// NOTE: call range_init before bom_init to ensure timer 5 is set up!
53
void bom_init(void);
54
void bom_send(char dir);
55
int bom_get(char dir);
56

    
57
// toggles output - should be called at around 76 kHz
58
void bom_isr();
59

    
60
#endif