laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-e1-hardware/+/29612 )

Change subject: icE1usb fw: Add support for building 1 channel version
......................................................................

icE1usb fw: Add support for building 1 channel version

Signed-off-by: Sylvain Munaut <[email protected]>
Change-Id: I147bb90fca3cead8db776ecfd60c23b4b8bafe2d
---
M firmware/ice40-riscv/icE1usb/Makefile
M firmware/ice40-riscv/icE1usb/usb_desc_app.c
M firmware/ice40-riscv/icE1usb/usb_desc_ids.h
M firmware/ice40-riscv/icE1usb/usb_e1.c
4 files changed, 23 insertions(+), 11 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/firmware/ice40-riscv/icE1usb/Makefile 
b/firmware/ice40-riscv/icE1usb/Makefile
index ed765f6..b05a532 100644
--- a/firmware/ice40-riscv/icE1usb/Makefile
+++ b/firmware/ice40-riscv/icE1usb/Makefile
@@ -17,6 +17,10 @@
 CFLAGS=-Wall -Wextra -Wno-unused-parameter -Os -march=rv32i -mabi=ilp32 
-ffreestanding -flto -nostartfiles -fomit-frame-pointer -Wl,--gc-section 
--specs=nano.specs -D$(BOARD_DEFINE) -I. -I../common
 CFLAGS += -DBUILD_INFO="\"$(GITVER) built $(shell date) on $(shell hostname)\""

+ifeq ($(SINGLE_CHANNEL),1)
+CFLAGS += -DNUM_E1_PORTS=1
+endif
+
 NO2USB_FW_VERSION=0
 include ../../../gateware/cores/no2usb/fw/fw.mk
 CFLAGS += $(INC_no2usb)
diff --git a/firmware/ice40-riscv/icE1usb/usb_desc_app.c 
b/firmware/ice40-riscv/icE1usb/usb_desc_app.c
index 7dfc304..63b0b5c 100644
--- a/firmware/ice40-riscv/icE1usb/usb_desc_app.c
+++ b/firmware/ice40-riscv/icE1usb/usb_desc_app.c
@@ -39,7 +39,7 @@
                        struct usb_ep_desc ep_fb;
                        struct usb_ep_desc ep_interrupt;
                } __attribute__ ((packed)) on;
-       } __attribute__ ((packed)) e1[2];
+       } __attribute__ ((packed)) e1[NUM_E1_PORTS];

        /* CDC */
        struct {
@@ -142,6 +142,7 @@
                        },
                },
        },
+#if NUM_E1_PORTS >= 2
        .e1[1] = {
                .off = {
                        .intf = {
@@ -210,6 +211,7 @@
                        },
                },
        },
+#endif
        .cdc = {
                .intf_ctl = {
                        .bLength                = sizeof(struct usb_intf_desc),
diff --git a/firmware/ice40-riscv/icE1usb/usb_desc_ids.h 
b/firmware/ice40-riscv/icE1usb/usb_desc_ids.h
index 192092e..ab3d156 100644
--- a/firmware/ice40-riscv/icE1usb/usb_desc_ids.h
+++ b/firmware/ice40-riscv/icE1usb/usb_desc_ids.h
@@ -7,12 +7,16 @@

 #pragma once

+#ifndef NUM_E1_PORTS
+# define NUM_E1_PORTS 2
+#endif
+
 #define USB_INTF_E1(p)         (0 + (p))
-#define USB_INTF_GPS_CDC_CTL   2
-#define USB_INTF_GPS_CDC_DATA  3
-#define USB_INTF_GPSDO         4
-#define USB_INTF_DFU           5
-#define USB_INTF_NUM           6
+#define USB_INTF_GPS_CDC_CTL   (NUM_E1_PORTS + 0)
+#define USB_INTF_GPS_CDC_DATA  (NUM_E1_PORTS + 1)
+#define USB_INTF_GPSDO         (NUM_E1_PORTS + 2)
+#define USB_INTF_DFU           (NUM_E1_PORTS + 3)
+#define USB_INTF_NUM           (NUM_E1_PORTS + 4)

 #define USB_EP_E1_IN(p)                (0x82 + (3 * (p)))
 #define USB_EP_E1_OUT(p)       (0x01 + (3 * (p)))
diff --git a/firmware/ice40-riscv/icE1usb/usb_e1.c 
b/firmware/ice40-riscv/icE1usb/usb_e1.c
index 4e52408..328ff3f 100644
--- a/firmware/ice40-riscv/icE1usb/usb_e1.c
+++ b/firmware/ice40-riscv/icE1usb/usb_e1.c
@@ -29,7 +29,7 @@
        struct e1_error_count last_err;
 };

-static struct usb_e1_state g_usb_e1[2];
+static struct usb_e1_state g_usb_e1[NUM_E1_PORTS];

 /* default configuration at power-up */
 static const struct ice1usb_tx_config tx_cfg_default = {
@@ -53,7 +53,7 @@
 static struct usb_e1_state *
 _get_state(int port)
 {
-       if ((port < 0) || (port > 1))
+       if ((port < 0) || (port >= NUM_E1_PORTS))
                panic("_get_state invalid port %d", port);
        return &g_usb_e1[port];
 }
@@ -63,7 +63,9 @@
 {
        switch (bInterfaceNumber) {
        case USB_INTF_E1(0): return 0;
+#if NUM_E1_PORTS >= 2
        case USB_INTF_E1(1): return 1;
+#endif
        default:
                /* Don't panic since this will be handled as USB STALL */
                return -1;
@@ -209,7 +211,7 @@
 void
 usb_e1_poll(void)
 {
-       for (int i=0; i<2; i++) {
+       for (int i=0; i<NUM_E1_PORTS; i++) {
                e1_poll(i);
                _usb_e1_run(i);
        }
@@ -225,7 +227,7 @@
        if (!conf)
                return USB_FND_SUCCESS;

-       for (int port=0; port<2; port++)
+       for (int port=0; port<NUM_E1_PORTS; port++)
        {
                intf = usb_desc_find_intf(conf, USB_INTF_E1(port), 0, NULL);
                if (!intf)
@@ -445,7 +447,7 @@
        uint32_t rx_cr = _rx_config_reg(&rx_cfg_default);
        uint32_t tx_cr = _tx_config_reg(&tx_cfg_default);

-       for (int i=0; i<2; i++) {
+       for (int i=0; i<NUM_E1_PORTS; i++) {
                struct usb_e1_state *usb_e1 = _get_state(i);
                memset(usb_e1, 0x00, sizeof(struct usb_e1_state));
                usb_e1->tx_cfg = tx_cfg_default;

--
To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/29612
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: I147bb90fca3cead8db776ecfd60c23b4b8bafe2d
Gerrit-Change-Number: 29612
Gerrit-PatchSet: 2
Gerrit-Owner: tnt <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-MessageType: merged

Reply via email to