tnt has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-e1-hardware/+/36684?usp=email )

Change subject: icE1usb fw: Implement E1 line monitor task
......................................................................

icE1usb fw: Implement E1 line monitor task

The results are not used yet, just collected ...

Signed-off-by: Sylvain Munaut <[email protected]>
Change-Id: Id310b65b7cd83c3bbae90ecd4a82b09a3989d91f
---
M firmware/ice40-riscv/icE1usb/e1.c
M firmware/ice40-riscv/icE1usb/e1.h
M firmware/ice40-riscv/icE1usb/usb_e1.c
3 files changed, 72 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  manawyrm: Looks good to me, but someone else must approve
  jolly: Looks good to me, but someone else must approve
  laforge: Looks good to me, but someone else must approve
  tnt: Looks good to me, approved




diff --git a/firmware/ice40-riscv/icE1usb/e1.c 
b/firmware/ice40-riscv/icE1usb/e1.c
index 5e4fa33..1582cec 100644
--- a/firmware/ice40-riscv/icE1usb/e1.c
+++ b/firmware/ice40-riscv/icE1usb/e1.c
@@ -16,6 +16,7 @@

 #include "dma.h"
 #include "led.h" // FIXME
+#include "misc.h"
 #include "utils.h"


@@ -260,6 +261,14 @@
                enum e1_pipe_state state;
        } tx;

+       struct {
+               uint16_t rx_pulse;
+               uint16_t rx_sample;
+               uint16_t rx_one;
+
+               uint16_t _val;
+       } linemon;
+
        struct e1_error_count errors;
 };

@@ -696,6 +705,53 @@
 }

 void
+e1_linemon_update(void)
+{
+       static int cycle = -1;
+
+       /* Initial boot */
+       if (cycle == -1) {
+               e1_tick_sel(TICK_RX_PULSE);
+               cycle = 0;
+               return;
+       }
+
+       /* Current cycle ? */
+       switch (cycle) {
+               /* Read initial values */
+       case 0:
+       case 2:
+       case 4:
+               for (int port=0; port<NUM_E1_PORTS; port++)
+                       g_e1[port].linemon._val = e1_tick_read(port);
+               break;
+
+               /* Actual reading */
+       case 1:
+               for (int port=0; port<NUM_E1_PORTS; port++)
+                       g_e1[port].linemon.rx_pulse = e1_tick_read(port) - 
g_e1[port].linemon._val;
+               e1_tick_sel(TICK_RX_SAMPLE);
+               break;
+
+       case 3:
+               for (int port=0; port<NUM_E1_PORTS; port++)
+                       g_e1[port].linemon.rx_sample = e1_tick_read(port) - 
g_e1[port].linemon._val;
+               e1_tick_sel(TICK_RX_ONE);
+               break;
+
+       case 5:
+               for (int port=0; port<NUM_E1_PORTS; port++)
+                       g_e1[port].linemon.rx_one = e1_tick_read(port) - 
g_e1[port].linemon._val;
+               e1_tick_sel(TICK_RX_PULSE);
+               break;
+       }
+
+       /* Next cycle */
+       if (++cycle == 6)
+               cycle = 0;
+}
+
+void
 e1_debug_print(int port, bool data)
 {
        volatile struct e1_core *e1_regs = _get_regs(port);
@@ -706,6 +762,8 @@
        printf("CSR: Rx %04x / Tx %04x\n", e1_regs->rx.csr, e1_regs->tx.csr);
        printf("InF: Rx %d / Tx %d\n", e1->rx.in_flight, e1->tx.in_flight);
        printf("Sta: Rx %d / Tx %d\n", e1->rx.state, e1->tx.state);
+       printf("Tck: P %d / S %d / O %d\n",
+               e1->linemon.rx_pulse, e1->linemon.rx_sample, 
e1->linemon.rx_one);

        e1f_debug(&e1->rx.fifo, "Rx FIFO");
        e1f_debug(&e1->tx.fifo, "Tx FIFO");
diff --git a/firmware/ice40-riscv/icE1usb/e1.h 
b/firmware/ice40-riscv/icE1usb/e1.h
index 0ed43c4..883e1ec 100644
--- a/firmware/ice40-riscv/icE1usb/e1.h
+++ b/firmware/ice40-riscv/icE1usb/e1.h
@@ -15,6 +15,7 @@
 void e1_stop(int port);

 void e1_poll(int port);
+void e1_linemon_update(void);
 void e1_debug_print(int port, bool data);

 void e1_rx_config(int port, uint16_t cr);
diff --git a/firmware/ice40-riscv/icE1usb/usb_e1.c 
b/firmware/ice40-riscv/icE1usb/usb_e1.c
index 18d8516..843aeef 100644
--- a/firmware/ice40-riscv/icE1usb/usb_e1.c
+++ b/firmware/ice40-riscv/icE1usb/usb_e1.c
@@ -433,6 +433,7 @@


 static struct usb_fn_drv _e1_drv = {
+       .sof            = e1_linemon_update,
        .set_conf       = _e1_set_conf,
        .set_intf       = _e1_set_intf,
        .get_intf       = _e1_get_intf,

--
To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/36684?usp=email
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: Id310b65b7cd83c3bbae90ecd4a82b09a3989d91f
Gerrit-Change-Number: 36684
Gerrit-PatchSet: 3
Gerrit-Owner: tnt <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: jolly <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: manawyrm <[email protected]>
Gerrit-Reviewer: roox <[email protected]>
Gerrit-Reviewer: tnt <[email protected]>
Gerrit-MessageType: merged

Reply via email to