Change in osmo-e1-hardware[master]: icE1usb: Report errors via the newly-added Interrupt Endpoint

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Thu Dec 17 17:02:57 UTC 2020


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/21777 )


Change subject: icE1usb: Report errors via the newly-added Interrupt Endpoint
......................................................................

icE1usb: Report errors via the newly-added Interrupt Endpoint

Instead of just reporting flags, we actually report error counts
so the host software can maintain proper (rate) counter about the
frequency of each type of error.

Closes: OS#4674
Change-Id: If157fde9d4ca05910b09537e19f37603c6d925f0
---
M firmware/ice40-riscv/icE1usb/ice1usb_proto.h
M firmware/ice40-riscv/icE1usb/usb_desc_app.c
M firmware/ice40-riscv/icE1usb/usb_e1.c
3 files changed, 79 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/77/21777/1

diff --git a/firmware/ice40-riscv/icE1usb/ice1usb_proto.h b/firmware/ice40-riscv/icE1usb/ice1usb_proto.h
index b636ec6..5f5f31c 100644
--- a/firmware/ice40-riscv/icE1usb/ice1usb_proto.h
+++ b/firmware/ice40-riscv/icE1usb/ice1usb_proto.h
@@ -68,3 +68,32 @@
 struct ice1usb_rx_config {
 	uint8_t mode;		/*!< enum ice1usb_rx_mode */
 } __attribute__((packed));
+
+
+/***********************************************************************
+ * Interrupt Endpoint
+ ***********************************************************************/
+
+enum ice1usb_irq_type {
+	ICE1USB_IRQQ_T_ERRCNT		= 1,
+};
+
+/* Ensue ro keep those in sync with e1.h */
+#define ICE1USB_ERR_F_ALIGN_ERR	0x01
+#define ICE1USB_ERR_F_TICK_ERR	0x02
+
+struct ice1usb_irq_err {
+	/* 16-bit little-endian counters */
+	uint16_t crc;
+	uint16_t align;
+	uint16_t ovfl;
+	uint16_t unfl;
+	uint8_t flags;
+} __attribute__((packed));
+
+struct ice1usb_irq {
+	uint8_t type; 		/*!< enum ice1usb_irq_type */
+	union {
+		struct ice1usb_irq_err errors;
+	} u;
+} __attribute__((packed));
diff --git a/firmware/ice40-riscv/icE1usb/usb_desc_app.c b/firmware/ice40-riscv/icE1usb/usb_desc_app.c
index 9fe3968..153d70e 100644
--- a/firmware/ice40-riscv/icE1usb/usb_desc_app.c
+++ b/firmware/ice40-riscv/icE1usb/usb_desc_app.c
@@ -28,12 +28,14 @@
 			struct usb_ep_desc ep_data_in;
 			struct usb_ep_desc ep_data_out;
 			struct usb_ep_desc ep_fb;
+			struct usb_ep_desc ep_interrupt;
 		} __attribute__ ((packed)) off;
 		struct {
 			struct usb_intf_desc intf;
 			struct usb_ep_desc ep_data_in;
 			struct usb_ep_desc ep_data_out;
 			struct usb_ep_desc ep_fb;
+			struct usb_ep_desc ep_interrupt;
 		} __attribute__ ((packed)) on;
 	} __attribute__ ((packed)) e1;
 
@@ -79,7 +81,7 @@
 				.bDescriptorType	= USB_DT_INTF,
 				.bInterfaceNumber	= 0,
 				.bAlternateSetting	= 0,
-				.bNumEndpoints		= 3,
+				.bNumEndpoints		= 4,
 				.bInterfaceClass	= 0xff,
 				.bInterfaceSubClass	= 0xe1,
 				.bInterfaceProtocol	= 0x00,
@@ -109,6 +111,14 @@
 				.wMaxPacketSize		= 0,
 				.bInterval		= 3,
 			},
+			.ep_interrupt = {
+				.bLength		= sizeof(struct usb_ep_desc),
+				.bDescriptorType	= USB_DT_EP,
+				.bEndpointAddress	= 0x83,
+				.bmAttributes		= 0x03,
+				.wMaxPacketSize		= 10,
+				.bInterval		= 3,
+			},
 		},
 		.on = {
 			.intf = {
@@ -116,7 +126,7 @@
 				.bDescriptorType	= USB_DT_INTF,
 				.bInterfaceNumber	= 0,
 				.bAlternateSetting	= 1,
-				.bNumEndpoints		= 3,
+				.bNumEndpoints		= 4,
 				.bInterfaceClass	= 0xff,
 				.bInterfaceSubClass	= 0xe1,
 				.bInterfaceProtocol	= 0x00,
@@ -146,6 +156,14 @@
 				.wMaxPacketSize		= 8,
 				.bInterval		= 3,
 			},
+			.ep_interrupt = {
+				.bLength		= sizeof(struct usb_ep_desc),
+				.bDescriptorType	= USB_DT_EP,
+				.bEndpointAddress	= 0x83,
+				.bmAttributes		= 0x03,
+				.wMaxPacketSize		= 10,
+				.bInterval		= 3,
+			},
 		},
 	},
 #if 0
diff --git a/firmware/ice40-riscv/icE1usb/usb_e1.c b/firmware/ice40-riscv/icE1usb/usb_e1.c
index f94b897..bb21998 100644
--- a/firmware/ice40-riscv/icE1usb/usb_e1.c
+++ b/firmware/ice40-riscv/icE1usb/usb_e1.c
@@ -25,6 +25,7 @@
 	int in_bdi;		/* buffer descriptor index for IN EP */
 	struct ice1usb_tx_config tx_cfg;
 	struct ice1usb_rx_config rx_cfg;
+	struct e1_error_count last_err;
 } g_usb_e1 = {
 	/* default configuration at power-up */
 	.tx_cfg = {
@@ -86,6 +87,29 @@
 	if (!g_usb_e1.running)
 		return;
 
+	/* EP3 IRQ */
+	if ((usb_ep_regs[3].in.bd[0].csr & USB_BD_STATE_MSK) != USB_BD_STATE_RDY_DATA) {
+		const struct e1_error_count *cur_err = e1_get_error_count();
+		if (memcmp(cur_err, &g_usb_e1.last_err, sizeof(*cur_err))) {
+			struct ice1usb_irq errmsg = {
+				.type = ICE1USB_IRQQ_T_ERRCNT,
+				.u = {
+					.errors = {
+						.crc = cur_err->crc,
+						.align = cur_err->align,
+						.ovfl = cur_err->ovfl,
+						.unfl = cur_err->unfl,
+						.flags = cur_err->flags,
+					}
+				}
+			};
+			printf("E");
+			usb_data_write(usb_ep_regs[3].in.bd[0].ptr, &errmsg, sizeof(errmsg));
+			usb_ep_regs[3].in.bd[0].csr = USB_BD_STATE_RDY_DATA | USB_BD_LEN(sizeof(errmsg));
+			g_usb_e1.last_err = *cur_err;
+		}
+	}
+
 	/* EP2 IN */
 	bdi = g_usb_e1.in_bdi;
 
@@ -212,6 +236,7 @@
 	usb_ep_boot(intf, 0x01, true);
 	usb_ep_boot(intf, 0x81, true);
 	usb_ep_boot(intf, 0x82, true);
+	usb_ep_boot(intf, 0x83, true);
 
 	return USB_FND_SUCCESS;
 }
@@ -274,6 +299,11 @@
 	/* EP1 IN: Queue buffer */
 	_usb_fill_feedback_ep();
 
+	/* EP3 IN: Interrupt */
+	usb_ep_regs[3].in.status = USB_EP_TYPE_INT;
+	usb_ep_regs[3].in.bd[0].ptr = 68;
+	usb_ep_regs[3].in.bd[0].csr = 0;
+
 	return USB_FND_SUCCESS;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/21777
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-e1-hardware
Gerrit-Branch: master
Gerrit-Change-Id: If157fde9d4ca05910b09537e19f37603c6d925f0
Gerrit-Change-Number: 21777
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201217/43cf727a/attachment.htm>


More information about the gerrit-log mailing list