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;
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)) {
}
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)
#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;
u32 tx_timeouts;
u32 tx_collisions;
u32 tx_ok;
+
+struct bsb_stats {
+#define P(x) u32 x;
+ BSB_STATS
+#undef P
};
/*