From: Martin Mares Date: Wed, 26 Feb 2020 17:43:55 +0000 (+0100) Subject: BSB: Improved interface X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=7af20f2577a732c8ff5c07fd60b8ba67e577f50e;p=home-hw.git BSB: Improved interface --- diff --git a/bsb/daemon/Makefile b/bsb/daemon/Makefile index 8afe8d2..e66cedd 100644 --- a/bsb/daemon/Makefile +++ b/bsb/daemon/Makefile @@ -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 diff --git a/bsb/daemon/burrow-bsb.c b/bsb/daemon/burrow-bsb.c index 9e02008..6563458 100644 --- a/bsb/daemon/burrow-bsb.c +++ b/bsb/daemon/burrow-bsb.c @@ -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) diff --git a/bsb/firmware/interface.h b/bsb/firmware/interface.h index 84595c2..a4f4240 100644 --- a/bsb/firmware/interface.h +++ b/bsb/firmware/interface.h @@ -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 }; /*