Project

General

Profile

Statistics
| Branch: | Revision:

root / scout_avr / src / bom.h @ ac53b84f

History | View | Annotate | Download (1.3 KB)

1
#ifndef _BOM_H
2
#define _BOM_H
3

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

    
8
#include <bom/bom.h>
9

    
10
// constants for direction
11
#define BOM_FRONT (bom::bom::FRONT)
12
#define BOM_BACK  (bom::bom::BACK)
13
#define BOM_LEFT  (bom::bom::LEFT)
14
#define BOM_RIGHT (bom::bom::RIGHT)
15

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

    
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
#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

    
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
// NOTE: call range_init before bom_init to ensure timer 5 is set up!
55
void bom_init(void);
56
void bom_send(char dir);
57
int bom_get(char dir);
58

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

    
62
#endif