]> mj.ucw.cz Git - home-hw.git/blob - bsb/firmware/interface.h
Auto: Meditation mode turned off
[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. Accepts BSB frames. Sender address and CRC
19  *              will be recalculated.
20  *
21  *      0x82 = interrupt endpoint
22  *              Used for receiving frames from BSB and status reports on sent frames.
23  *              The first byte is a status byte (TX_RESULT_xxx), the rest is a frame.
24  *              If status == TX_RESULT_NONE, the frame is a received frame.
25  *              If status == TX_RESULT_OK, the frame is a received reply to the sent frame.
26  *              Otherwise, the status indicates transmit error and the frame is empty.
27  */
28
29 // Status sent on the interrupt endpoint
30 #define BSB_TX_RESULTS \
31         P(NONE) \
32         P(OK) \
33         P(OVERRUN) \
34         P(MALFORMED) \
35         P(FORBIDDEN) \
36         P(TIMEOUT) \
37         P(TOO_MANY_RETRIES)
38
39 enum bsb_tx_result {
40 #define P(x) TX_RESULT_##x,
41         BSB_TX_RESULTS
42 #undef P
43 };
44
45 // Statistics sent on the control endpoint
46 #define BSB_STATS \
47         P(rx_noise) \
48         P(rx_errors) \
49         P(rx_invalid) \
50         P(rx_overruns) \
51         P(rx_timeouts) \
52         P(rx_bad_crc) \
53         P(rx_ok) \
54         P(tx_overruns) \
55         P(tx_rejects) \
56         P(tx_timeouts) \
57         P(tx_collisions) \
58         P(tx_reply_timeouts) \
59         P(tx_ok_no_reply) \
60         P(tx_ok_replied)
61
62 struct bsb_stats {
63 #define P(x) u32 x;
64         BSB_STATS
65 #undef P
66 };
67
68 /*
69  *      Structure of BSB frames
70  *
71  *              start of frame (0xdc)
72  *              source address XOR 0x80
73  *              destination address
74  *              length
75  *              operation
76  *              <parameters depending on operation>
77  *              16-bit CRC
78  */
79
80 // Positions of fields in a frame
81 enum bsb_frame {
82         BF_SOF,
83         BF_SRC,
84         BF_DEST,
85         BF_LEN,
86         BF_OP,
87         BF_BODY,
88 };
89
90 enum bsb_address {
91         BSB_ADDR_BOILER = 0,
92         BSB_ADDR_EXT_BOARD = 3,
93         BSB_ADDR_ROOM1 = 6,
94         BSB_ADDR_ROOM2 = 7,
95         BSB_ADDR_GATEWAY = 0x42,        // That's us
96         BSB_ADDR_BROADCAST = 0x7f,
97 };
98
99 enum bsb_op {
100         BSB_OP_REQUEST_INFO = 1,
101         BSB_OP_INFO = 2,
102         BSB_OP_SET = 3,
103         BSB_OP_ACK = 4,
104         BSB_OP_NACK = 5,
105         BSB_OP_QUERY = 6,
106         BSB_OP_ANSWER = 7,
107         BSB_OP_ERROR = 8,
108         BSB_OP_QUERY_DEFAULT = 0x0f,
109         BSB_OP_ANSWER_DEFAULT = 0x10,
110 };