]> mj.ucw.cz Git - home-hw.git/blob - bsb/firmware/interface.h
BSB: Improved interface
[home-hw.git] / bsb / firmware / interface.h
1 /*
2  *      Boiler System Bus Gateway -- Interface Definitions
3  *
4  *      (c) 2020 Martin Mareš <mj@ucw.cz>
5  */
6
7 #define BSB_USB_VENDOR 0x4242
8 #define BSB_USB_PRODUCT 0x0003
9 #define BSB_USB_VERSION 0x0100
10
11 /*
12  *      Endpoints:
13  *
14  *      0x00 = control endpoint
15  *              Vendor-defined request 0x00 sends struct bsb_stats in little endian.
16  *
17  *      0x01 = bulk endpoint
18  *              Used for sending frames to BSB.
19  *
20  *      0x82 = interrupt endpoint
21  *              Used for receiving frames from BSB.
22  *              Also transmits 1-byte status reports on frames sent on endpoint 0x01.
23  */
24
25 // Status sent on the interrupt endpoint
26 #define BSB_TX_RESULTS \
27         P(NONE) \
28         P(OK) \
29         P(OVERRUN) \
30         P(MALFORMED) \
31         P(FORBIDDEN) \
32         P(TIMEOUT) \
33         P(TOO_MANY_RETRIES)
34
35 enum bsb_tx_result {
36 #define P(x) TX_RESULT_##x,
37         BSB_TX_RESULTS
38 #undef P
39 };
40
41 // Statistics sent on the control endpoint
42 #define BSB_STATS \
43         P(rx_noise) \
44         P(rx_errors) \
45         P(rx_invalid) \
46         P(rx_overruns) \
47         P(rx_timeouts) \
48         P(rx_bad_crc) \
49         P(rx_ok) \
50         P(tx_overruns) \
51         P(tx_rejects) \
52         P(tx_timeouts) \
53         P(tx_collisions) \
54         P(tx_ok)
55
56         u32 rx_noise;
57         u32 rx_errors;
58         u32 rx_invalid;
59         u32 rx_overruns;
60         u32 rx_timeouts;
61         u32 rx_bad_crc;
62         u32 rx_ok;
63         u32 tx_overruns;
64         u32 tx_rejects;
65         u32 tx_timeouts;
66         u32 tx_collisions;
67         u32 tx_ok;
68
69 struct bsb_stats {
70 #define P(x) u32 x;
71         BSB_STATS
72 #undef P
73 };
74
75 /*
76  *      Structure of BSB frames
77  *
78  *              start of frame (0xdc)
79  *              source address XOR 0x80
80  *              destination address
81  *              length
82  *              operation
83  *              <parameters depending on operation>
84  *              16-bit CRC
85  */
86
87 enum bsb_address {
88         BSB_ADDR_BOILER = 0,
89         BSB_ADDR_EXT_BOARD = 3,
90         BSB_ADDR_ROOM1 = 6,
91         BSB_ADDR_ROOM2 = 7,
92         BSB_ADDR_GATEWAY = 0x42,
93         BSB_ADDR_BROADCAST = 0x7f,
94 };
95
96 enum bsb_op {
97         BSB_OP_REQUEST_INFO = 1,
98         BSB_OP_INFO = 2,
99         BSB_OP_SET = 3,
100         BSB_OP_ACK = 4,
101         BSB_OP_NACK = 5,
102         BSB_OP_QUERY = 6,
103         BSB_OP_ANSWER = 7,
104         BSB_OP_ERROR = 8,
105         BSB_OP_QUERY_DEFAULT = 0x0f,
106         BSB_OP_ANSWER_DEFAULT = 0x10,
107 };