Statistics
| Branch: | Revision:

root / scout_avr / src / bom.h @ 399f7d1b

History | View | Annotate | Download (1.32 KB)

1 f115416e Tom Mullins
#ifndef _BOM_H
2
#define _BOM_H
3
4
extern "C" {
5
#include <stdint.h>
6
}
7
8 399f7d1b Tom Mullins
//#include <bom/bom.h>
9
10 f115416e Tom Mullins
// constants for direction
11 399f7d1b Tom Mullins
#define BOM_FRONT 0 //(bom::bom::FRONT)
12
#define BOM_BACK  1 //(bom::bom::BACK)
13
#define BOM_LEFT  2 //(bom::bom::LEFT)
14
#define BOM_RIGHT 3 //(bom::bom::RIGHT)
15 f115416e Tom Mullins
16
// timing, in us, for read of valid bits
17 31f4a032 Tom Mullins
#define MIN_LOW_PW 600
18
#define MAX_LOW_PW 1400
19
#define MIN_HIGH_PW 1600
20
#define MAX_HIGH_PW 2400
21 f115416e Tom Mullins
22
// returned by bom_get if there is no new data since last call
23
#define BOM_NO_DATA -1
24
25
// i/o pins
26
// if these are changed, remember to change bom_init and/or ISRs
27 cc9ca04e Tom Mullins
#define PIN_BOM_SIG PINB
28
#define P_BOM_SIG0 PB0
29
#define P_BOM_SIG1 PB1
30
#define P_BOM_SIG2 PB2
31
#define P_BOM_SIG3 PB3
32
33
#define PORT_BOM_EMIT PORTF
34
#define P_BOM_EMIT0 PF4
35
#define P_BOM_EMIT1 PF5
36
#define P_BOM_EMIT2 PF6
37
#define P_BOM_EMIT3 PF7
38 f115416e Tom Mullins
39
typedef uint8_t bom_msg_t;
40
41
inline char bom_msg_get_robot_id(bom_msg_t msg) {
42
    return msg >> 2;
43
}
44
inline char bom_msg_get_dir(bom_msg_t msg) {
45
    return msg & 3;
46
}
47
inline bom_msg_t bom_msg_make(char id, char dir) {
48
    return (id << 2) | (dir & 3);
49
}
50
51
void set_robot_id(char id);
52
char get_robot_id(void);
53
54 cc9ca04e Tom Mullins
// NOTE: call range_init before bom_init to ensure timer 5 is set up!
55 f115416e Tom Mullins
void bom_init(void);
56
void bom_send(char dir);
57
int bom_get(char dir);
58
59 812788aa Tom Mullins
// toggles output - should be called at around 76 kHz
60
void bom_isr();
61
62 f115416e Tom Mullins
#endif