]> mj.ucw.cz Git - home-hw.git/commitdiff
BSB: Improved interface
authorMartin Mares <mj@ucw.cz>
Wed, 26 Feb 2020 17:43:55 +0000 (18:43 +0100)
committerMartin Mares <mj@ucw.cz>
Wed, 26 Feb 2020 17:43:55 +0000 (18:43 +0100)
bsb/daemon/Makefile
bsb/daemon/burrow-bsb.c
bsb/firmware/interface.h

index 8afe8d2ec2112242e553687b9beb54c4b86c76c0..e66ceddd5d14d6939efd0847853dbbdb9daa5b89 100644 (file)
@@ -7,5 +7,7 @@ LDFLAGS=$(USB_LDFLAGS) $(CURL_LDFLAGS)
 
 all: burrow-bsb
 
+burrow-usb: burrow-usb.c ../firmware/interface.h
+
 clean:
        rm -f burrow-bsb
index 9e02008f3ec73c48b45e3354234c9cede091680d..6563458c7c0bd3bb29cae24c4e2178149fdf80f4 100644 (file)
@@ -18,8 +18,11 @@ static struct libusb_context *usb_ctxt;
 static struct libusb_device_handle *devh;
 
 typedef unsigned char byte;
+typedef uint32_t u32;
 typedef unsigned int uint;
 
+#include "../firmware/interface.h"
+
 static void die(const char *msg, ...)
 {
        va_list args;
@@ -57,7 +60,7 @@ static void open_device(void)
                struct libusb_device_descriptor desc;
                libusb_device *dev = devlist[i];
                if (!libusb_get_device_descriptor(dev, &desc)) {
-                       if (desc.idVendor == 0x4242 && desc.idProduct == 0x0003) {
+                       if (desc.idVendor == BSB_USB_VENDOR && desc.idProduct == BSB_USB_PRODUCT) {
                                fprintf(stderr, "Found device at usb%d.%d\n", libusb_get_bus_number(dev), libusb_get_device_address(dev));
 
                                if (err = libusb_open(dev, &devh)) {
@@ -85,18 +88,9 @@ static inline uint get_u32_le(byte *p)
 }
 
 static const char * const stat_names[] = {
-       "rx_noise",
-       "rx_errors",
-       "rx_invalid",
-       "rx_overruns",
-       "rx_timeouts",
-       "rx_bad_crc",
-       "rx_ok",
-       "tx_overruns",
-       "tx_rejects",
-       "tx_timeouts",
-       "tx_collisions",
-       "tx_ok",
+#define P(x) #x,
+       BSB_STATS
+#undef P
 };
 
 static void show_stats(byte *resp, uint len)
index 84595c29d0e8d9502fb4b5678d5f67be4936b187..a4f42406b9e86c056644bd8170eaf12d31e290eb 100644 (file)
@@ -8,19 +8,51 @@
 #define BSB_USB_PRODUCT 0x0003
 #define BSB_USB_VERSION 0x0100
 
+/*
+ *     Endpoints:
+ *
+ *     0x00 = control endpoint
+ *             Vendor-defined request 0x00 sends struct bsb_stats in little endian.
+ *
+ *     0x01 = bulk endpoint
+ *             Used for sending frames to BSB.
+ *
+ *     0x82 = interrupt endpoint
+ *             Used for receiving frames from BSB.
+ *             Also transmits 1-byte status reports on frames sent on endpoint 0x01.
+ */
+
 // Status sent on the interrupt endpoint
+#define BSB_TX_RESULTS \
+       P(NONE) \
+       P(OK) \
+       P(OVERRUN) \
+       P(MALFORMED) \
+       P(FORBIDDEN) \
+       P(TIMEOUT) \
+       P(TOO_MANY_RETRIES)
+
 enum bsb_tx_result {
-       TX_RESULT_NONE,
-       TX_RESULT_OK,
-       TX_RESULT_OVERRUN,
-       TX_RESULT_MALFORMED,
-       TX_RESULT_FORBIDDEN,
-       TX_RESULT_TIMEOUT,
-       TX_RESULT_TOO_MANY_RETRIES,
+#define P(x) TX_RESULT_##x,
+       BSB_TX_RESULTS
+#undef P
 };
 
-// Sent via USB in little-endian format
-struct bsb_stats {
+// Statistics sent on the control endpoint
+#define BSB_STATS \
+       P(rx_noise) \
+       P(rx_errors) \
+       P(rx_invalid) \
+       P(rx_overruns) \
+       P(rx_timeouts) \
+       P(rx_bad_crc) \
+       P(rx_ok) \
+       P(tx_overruns) \
+       P(tx_rejects) \
+       P(tx_timeouts) \
+       P(tx_collisions) \
+       P(tx_ok)
+
        u32 rx_noise;
        u32 rx_errors;
        u32 rx_invalid;
@@ -33,6 +65,11 @@ struct bsb_stats {
        u32 tx_timeouts;
        u32 tx_collisions;
        u32 tx_ok;
+
+struct bsb_stats {
+#define P(x) u32 x;
+       BSB_STATS
+#undef P
 };
 
 /*