lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

  • 1 participants
  • 97203 discussions
Change in osmo-e1-hardware[master]: icE1usb fw: Expose the GPS NMEA data as a CDC ACM
by tnt 16 Jan '22

16 Jan '22
tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26914 ) Change subject: icE1usb fw: Expose the GPS NMEA data as a CDC ACM ...................................................................... icE1usb fw: Expose the GPS NMEA data as a CDC ACM Note that this is read-only. We drop all data from the host because we can't have the host reconfigure the module ... Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com> Change-Id: Ieb6a653ece882c5f90ab27da1bca04c94184dc5a --- M firmware/ice40-riscv/icE1usb/Makefile M firmware/ice40-riscv/icE1usb/fw_app.c M firmware/ice40-riscv/icE1usb/gps.c M firmware/ice40-riscv/icE1usb/usb_desc_app.c M firmware/ice40-riscv/icE1usb/usb_desc_ids.h A firmware/ice40-riscv/icE1usb/usb_gps.c A firmware/ice40-riscv/icE1usb/usb_gps.h M gateware/cores/no2usb 8 files changed, 247 insertions(+), 9 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/14/26914/1 diff --git a/firmware/ice40-riscv/icE1usb/Makefile b/firmware/ice40-riscv/icE1usb/Makefile index 6725f6a..a6e9138 100644 --- a/firmware/ice40-riscv/icE1usb/Makefile +++ b/firmware/ice40-riscv/icE1usb/Makefile @@ -54,6 +54,7 @@ usb_desc_ids.h \ usb_dev.h \ usb_e1.h \ + usb_gps.h \ usb_str_app.gen.h \ $(NULL) @@ -65,6 +66,7 @@ usb_desc_app.c \ usb_dev.c \ usb_e1.c \ + usb_gps.c \ $(NULL) diff --git a/firmware/ice40-riscv/icE1usb/fw_app.c b/firmware/ice40-riscv/icE1usb/fw_app.c index c5c2b7c..78da8b6 100644 --- a/firmware/ice40-riscv/icE1usb/fw_app.c +++ b/firmware/ice40-riscv/icE1usb/fw_app.c @@ -21,6 +21,7 @@ #include "spi.h" #include "usb_dev.h" #include "usb_e1.h" +#include "usb_gps.h" #include "utils.h" @@ -105,6 +106,7 @@ usb_dev_init(); usb_dfu_rt_init(); usb_e1_init(); + usb_gps_init(); /* Start */ led_state(true); @@ -168,5 +170,6 @@ /* GPS poll */ gps_poll(); + usb_gps_poll(); } } diff --git a/firmware/ice40-riscv/icE1usb/gps.c b/firmware/ice40-riscv/icE1usb/gps.c index 2fd6ab8..c1ad3a8 100644 --- a/firmware/ice40-riscv/icE1usb/gps.c +++ b/firmware/ice40-riscv/icE1usb/gps.c @@ -13,6 +13,7 @@ #include "console.h" #include "gps.h" #include "misc.h" +#include "usb_gps.h" #include "utils.h" #include "config.h" @@ -217,6 +218,9 @@ /* If we do, process it locally to update our state */ _gps_parse_nmea(nmea); + + /* And queue it for USB */ + usb_gps_puts(nmea); } void diff --git a/firmware/ice40-riscv/icE1usb/usb_desc_app.c b/firmware/ice40-riscv/icE1usb/usb_desc_app.c index 22a81d3..e0edf80 100644 --- a/firmware/ice40-riscv/icE1usb/usb_desc_app.c +++ b/firmware/ice40-riscv/icE1usb/usb_desc_app.c @@ -42,7 +42,6 @@ } __attribute__ ((packed)) e1[2]; /* CDC */ -#if 0 struct { struct usb_intf_desc intf_ctl; struct usb_cdc_hdr_desc cdc_hdr; @@ -53,7 +52,6 @@ struct usb_ep_desc ep_data_out; struct usb_ep_desc ep_data_in; } __attribute__ ((packed)) cdc; -#endif /* DFU Runtime */ struct { @@ -207,7 +205,6 @@ }, }, }, -#if 0 .cdc = { .intf_ctl = { .bLength = sizeof(struct usb_intf_desc), @@ -230,21 +227,24 @@ .bLength = sizeof(struct usb_cdc_acm_desc), .bDescriptorType = USB_CS_DT_INTF, .bDescriptorsubtype = USB_CDC_DST_ACM, + /* Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, */ + /* and the notification Serial_State */ .bmCapabilities = 0x02, }, .cdc_union = { .bLength = sizeof(struct usb_cdc_union_desc) + 1, .bDescriptorType = USB_CS_DT_INTF, .bDescriptorsubtype = USB_CDC_DST_UNION, - .bMasterInterface = 1, - .bSlaveInterface = { 2 }, + .bMasterInterface = USB_INTF_GPS_CDC_CTL, + .bSlaveInterface = { USB_INTF_GPS_CDC_DATA }, }, .ep_ctl = { .bLength = sizeof(struct usb_ep_desc), .bDescriptorType = USB_DT_EP, .bEndpointAddress = USB_EP_GPS_CDC_CTL, .bmAttributes = 0x03, - .wMaxPacketSize = 64, + /* Longest notif is SERIAL_STATE with 2 data bytes */ + .wMaxPacketSize = sizeof(struct usb_ctrl_req) + 2, .bInterval = 0x40, }, .intf_data = { @@ -275,7 +275,6 @@ .bInterval = 0x00, }, }, -#endif .dfu = { .intf = { .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 00dbb34..3fbc417 100644 --- a/firmware/ice40-riscv/icE1usb/usb_desc_ids.h +++ b/firmware/ice40-riscv/icE1usb/usb_desc_ids.h @@ -9,9 +9,15 @@ #define USB_INTF_E1(p) (0 + (p)) #define USB_INTF_DFU 2 -#define USB_INTF_NUM 3 +#define USB_INTF_GPS_CDC_CTL 3 +#define USB_INTF_GPS_CDC_DATA 4 +#define USB_INTF_NUM 5 #define USB_EP_E1_IN(p) (0x82 + (3 * (p))) #define USB_EP_E1_OUT(p) (0x01 + (3 * (p))) #define USB_EP_E1_FB(p) (0x81 + (3 * (p))) #define USB_EP_E1_INT(p) (0x83 + (3 * (p))) + +#define USB_EP_GPS_CDC_CTL 0x88 +#define USB_EP_GPS_CDC_OUT 0x09 +#define USB_EP_GPS_CDC_IN 0x89 diff --git a/firmware/ice40-riscv/icE1usb/usb_gps.c b/firmware/ice40-riscv/icE1usb/usb_gps.c new file mode 100644 index 0000000..1c10033 --- /dev/null +++ b/firmware/ice40-riscv/icE1usb/usb_gps.c @@ -0,0 +1,211 @@ +/* + * usb_gps.c + * + * Copyright (C) 2019-2022 Sylvain Munaut <tnt(a)246tNt.com> + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include <stdint.h> +#include <stdbool.h> +#include <string.h> + +#include <no2usb/usb.h> +#include <no2usb/usb_hw.h> +#include <no2usb/usb_priv.h> + +#include <no2usb/usb_proto.h> +#include <no2usb/usb_cdc_proto.h> + +#include "console.h" +#include "usb_desc_ids.h" + + +#define BUF_SIZE_LOG 9 +#define BUF_SIZE (1 << BUF_SIZE_LOG) +#define BUF_MASK (BUF_SIZE - 1) + +static struct { + /* State */ + bool active; + + /* Buffer */ + struct { + unsigned int wr; + unsigned int rd; + char data[BUF_SIZE] __attribute__((aligned(4))); + } buf; +} g_usb_gps; + + +static void +_usb_gps_set_active(bool active) +{ + /* Save new state */ + g_usb_gps.active = active; + + /* Reset FIFO if disabled */ + if (!active) + g_usb_gps.buf.wr = g_usb_gps.buf.rd = 0; +} + +static int +_usb_gps_fill_packet(unsigned int dst_ofs) +{ + unsigned int len; + + /* Len available, limited to 64 */ + len = (g_usb_gps.buf.wr - g_usb_gps.buf.rd) & BUF_MASK; + + if (len > 64) + len = 64; + + /* Copy block */ + usb_data_write(dst_ofs, &g_usb_gps.buf.data[g_usb_gps.buf.rd], (len + 3) & ~3); + + /* Increment read pointer */ + g_usb_gps.buf.rd = (g_usb_gps.buf.rd + len) & BUF_MASK; + + /* If length was not multiple of 4, we emptied the FIFO, + * so we reset it to 0 so we're aligned again */ + if (len & 3) + g_usb_gps.buf.wr = g_usb_gps.buf.rd = 0; + + return len; +} + + +void +usb_gps_puts(const char *str) +{ + unsigned int nxt; + char c; + + if (!g_usb_gps.active) + return; + + while ((c = *str++) != '\0') + { + /* Next write pointer pos and full check */ + nxt = (g_usb_gps.buf.wr + 1) & BUF_MASK; + if (nxt == g_usb_gps.buf.rd) + /* If overflow, we keep the latest content ... */ + g_usb_gps.buf.rd = (g_usb_gps.buf.rd + 1) & BUF_MASK; + + /* Write data */ + g_usb_gps.buf.data[g_usb_gps.buf.wr] = c; + + /* Update write pointer */ + g_usb_gps.buf.wr = nxt; + } +} + +void +usb_gps_poll(void) +{ + volatile struct usb_ep *ep_regs; + + /* OUT EP: We accept data and throw it away */ + ep_regs = &usb_ep_regs[USB_EP_GPS_CDC_OUT & 0x1f].out; + ep_regs->bd[0].csr = USB_BD_STATE_RDY_DATA | USB_BD_LEN(64); + + /* IN EP: Send whatever is queued */ + ep_regs = &usb_ep_regs[USB_EP_GPS_CDC_OUT & 0x1f].in; + + if ((ep_regs->bd[0].csr & USB_BD_STATE_MSK) != USB_BD_STATE_RDY_DATA) + { + int len = _usb_gps_fill_packet(ep_regs->bd[0].ptr); + + if (len) + ep_regs->bd[0].csr = USB_BD_STATE_RDY_DATA | USB_BD_LEN(len); + else + ep_regs->bd[0].csr = 0; + } +} + + +static enum usb_fnd_resp +_cdc_set_conf(const struct usb_conf_desc *conf) +{ + const struct usb_intf_desc *intf; + + if (!conf) + return USB_FND_SUCCESS; + + /* Configure control interface */ + intf = usb_desc_find_intf(conf, USB_INTF_GPS_CDC_CTL, 0, NULL); + if (!intf) + return USB_FND_ERROR; + + usb_ep_boot(intf, USB_EP_GPS_CDC_CTL, false); + + /* Configure data interface */ + intf = usb_desc_find_intf(conf, USB_INTF_GPS_CDC_DATA, 0, NULL); + if (!intf) + return USB_FND_ERROR; + + usb_ep_boot(intf, USB_EP_GPS_CDC_OUT, false); + usb_ep_boot(intf, USB_EP_GPS_CDC_IN, false); + + return USB_FND_SUCCESS; +} + +static enum usb_fnd_resp +_cdc_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer) +{ + static const struct usb_cdc_line_coding linecoding = { + .dwDTERate = 115200, + .bCharFormat = 2, + .bParityType = 0, + .bDataBits = 8, + }; + + /* Check this is handled here */ + if (USB_REQ_TYPE_RCPT(req) != (USB_REQ_TYPE_CLASS | USB_REQ_RCPT_INTF)) + return USB_FND_CONTINUE; + + if (req->wIndex != USB_INTF_GPS_CDC_CTL) + return USB_FND_CONTINUE; + + /* Process request */ + switch (req->bRequest) { + case USB_REQ_CDC_SEND_ENCAPSULATED_COMMAND: + /* We don't support any, so just accept and don't care */ + return USB_FND_SUCCESS; + + case USB_REQ_CDC_GET_ENCAPSULATED_RESPONSE: + /* Never anything to return */ + xfer->len = 0; + return USB_FND_SUCCESS; + + case USB_REQ_CDC_SET_LINE_CODING: + /* We only support 1 config, doesn't matter what the hosts sends */ + return USB_FND_SUCCESS; + + case USB_REQ_CDC_GET_LINE_CODING: + /* We only support 1 config, send that back */ + xfer->data = (void*)&linecoding; + xfer->len = sizeof(linecoding); + return USB_FND_ERROR; + + case USB_REQ_CDC_SET_CONTROL_LINE_STATE: + /* Enable if DTR is set */ + _usb_gps_set_active((req->wValue & 1) != 0); + return USB_FND_SUCCESS; + } + + /* Anything else is not handled */ + return USB_FND_ERROR; +} + + +static struct usb_fn_drv _cdc_drv = { + .set_conf = _cdc_set_conf, + .ctrl_req = _cdc_ctrl_req, +}; + +void +usb_gps_init(void) +{ + memset(&g_usb_gps, 0x00, sizeof(g_usb_gps)); + usb_register_function_driver(&_cdc_drv); +} diff --git a/firmware/ice40-riscv/icE1usb/usb_gps.h b/firmware/ice40-riscv/icE1usb/usb_gps.h new file mode 100644 index 0000000..3324a45 --- /dev/null +++ b/firmware/ice40-riscv/icE1usb/usb_gps.h @@ -0,0 +1,13 @@ +/* + * usb_gps.h + * + * Copyright (C) 2019-2022 Sylvain Munaut <tnt(a)246tNt.com> + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +void usb_gps_puts(const char *str); + +void usb_gps_poll(void); +void usb_gps_init(void); diff --git a/gateware/cores/no2usb b/gateware/cores/no2usb index e9d1fbb..fdf42a6 160000 --- a/gateware/cores/no2usb +++ b/gateware/cores/no2usb @@ -1 +1 @@ -Subproject commit e9d1fbb8a1796444091cd8a39e2a4318530b4daf +Subproject commit fdf42a6571a4ae49556626e6fffca1582796f7e8 -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26914 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: Ieb6a653ece882c5f90ab27da1bca04c94184dc5a Gerrit-Change-Number: 26914 Gerrit-PatchSet: 1 Gerrit-Owner: tnt <tnt(a)246tNt.com> Gerrit-MessageType: newchange
2 4
0 0
Change in osmo-e1-hardware[master]: icE1usb fw: Add GPSDO VCXO trimming loop
by tnt 16 Jan '22

16 Jan '22
tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26915 ) Change subject: icE1usb fw: Add GPSDO VCXO trimming loop ...................................................................... icE1usb fw: Add GPSDO VCXO trimming loop Rather basic and not super well tested, use with caution Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com> Change-Id: I5f9ce6621492be967d6a44d31f270e107f3ef686 --- M firmware/ice40-riscv/icE1usb/Makefile M firmware/ice40-riscv/icE1usb/fw_app.c A firmware/ice40-riscv/icE1usb/gpsdo.c A firmware/ice40-riscv/icE1usb/gpsdo.h 4 files changed, 279 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/15/26915/1 diff --git a/firmware/ice40-riscv/icE1usb/Makefile b/firmware/ice40-riscv/icE1usb/Makefile index a6e9138..25c65d1 100644 --- a/firmware/ice40-riscv/icE1usb/Makefile +++ b/firmware/ice40-riscv/icE1usb/Makefile @@ -49,6 +49,7 @@ config.h \ e1.h \ gps.h \ + gpsdo.h \ ice1usb_proto.h \ misc.h \ usb_desc_ids.h \ @@ -62,6 +63,7 @@ e1.c \ fw_app.c \ gps.c \ + gpsdo.c \ misc.c \ usb_desc_app.c \ usb_dev.c \ diff --git a/firmware/ice40-riscv/icE1usb/fw_app.c b/firmware/ice40-riscv/icE1usb/fw_app.c index 78da8b6..c1fe295 100644 --- a/firmware/ice40-riscv/icE1usb/fw_app.c +++ b/firmware/ice40-riscv/icE1usb/fw_app.c @@ -15,6 +15,7 @@ #include "console.h" #include "e1.h" #include "gps.h" +#include "gpsdo.h" #include "led.h" #include "misc.h" #include "mini-printf.h" @@ -94,12 +95,13 @@ pdm_set(PDM_E1_RX1, true, 128 + d, false); #endif - /* Setup clock tuning */ - pdm_set(PDM_CLK_HI, true, 2048, false); - pdm_set(PDM_CLK_LO, false, 0, false); - /* GPS init */ gps_init(); +#if defined(BOARD_ICE1USB_PROTO_ICEBREAKER) || defined(BOARD_ICE1USB_PROTO_BITSY) + gpsdo_init(VCTXO_TAITIEN_VT40); +#else + gpsdo_init(VCTXO_SITIME_SIT3808_E); +#endif /* Enable USB directly */ usb_init(&app_stack_desc); @@ -170,6 +172,7 @@ /* GPS poll */ gps_poll(); + gpsdo_poll(); usb_gps_poll(); } } diff --git a/firmware/ice40-riscv/icE1usb/gpsdo.c b/firmware/ice40-riscv/icE1usb/gpsdo.c new file mode 100644 index 0000000..ca9b806 --- /dev/null +++ b/firmware/ice40-riscv/icE1usb/gpsdo.c @@ -0,0 +1,254 @@ +/* + * gpsdo.c + * + * Copyright (C) 2019-2022 Sylvain Munaut <tnt(a)246tNt.com> + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include <stdint.h> +#include <string.h> + +#include "console.h" +#include "gps.h" +#include "gpsdo.h" +#include "misc.h" + + +struct { + /* Current tuning */ + struct { + uint16_t coarse; + uint16_t fine; + } tune; + + /* Measurements */ + struct { + uint32_t tick_prev; /* Previous tick value */ + uint32_t last; /* Last measurement */ + int skip; /* Number of measurement left to discard */ + int invalid; /* Number of consecutive invalid measurements */ + } meas; + + /* FSM */ + enum { + STATE_DISABLED, /* Forced to manual */ + STATE_HOLD_OVER, /* GPS invalid data, hold */ + STATE_TUNE_COARSE, /* Adjust coarse tuning until we're +- 3 Hz */ + STATE_TUNE_FINE, /* Fine tracking */ + } state; + + /* Coarse tuning */ + struct { + int vctxo_sensitivity; + int step; + } coarse; + + /* Fine tracking */ + struct { + int acc; + int div; + } fine; + +} g_gpsdo; + + +/* VCXTO sensitivity vs 'coarse' count for fast initial acquisition */ + /* + * Note that the spec if often a guaranteed minimum range and goes + * from ~0.1V to 3.2V instead of 0-3.3V so actual sensitivity is + * higher than the "theoritical value". We boost it by ~ 10% here. + */ +static const int +vctxo_sensitivity[] = { + /* +- 50 ppm pull range => ~ 0.75 Hz / hi-count (set to 0.85) */ + [VCTXO_TAITIEN_VT40] = 300, + + /* +- 100 ppm pull range => ~ 1.50 Hz / hi-count (set to 1.6) */ + [VCTXO_SITIME_SIT3808_E] = 160, +}; + +/* Tuning params */ +#define TARGET 30720000 +#define MAX_DEV_VALID 1000 +#define MAX_DEV_FINE 3 +#define MAX_INVALID 5 + + +static void +_gpsdo_coarse_start(void) +{ + /* Set the state */ + g_gpsdo.state = STATE_TUNE_COARSE; + + /* Skip a few measurements to be safe */ + g_gpsdo.meas.skip = 3; + + /* Reset coarse tuning state */ + g_gpsdo.coarse.step = 0; + + /* Put the fine adjust back in the middle point */ + g_gpsdo.tune.coarse += ((int)g_gpsdo.tune.fine - 2048) >> 6; + g_gpsdo.tune.fine = 2048; + + pdm_set(PDM_CLK_HI, true, g_gpsdo.tune.coarse, false); + pdm_set(PDM_CLK_LO, true, g_gpsdo.tune.fine, false); +} + +static void +_gpsdo_fine_start(void) +{ + /* Set the state */ + g_gpsdo.state = STATE_TUNE_FINE; + + /* Reset the long term error tracking */ + g_gpsdo.fine.acc = 0; + g_gpsdo.fine.div = 0; +} + +static void +_gpsdo_coarse_tune(uint32_t tick_diff) +{ + int freq_diff = (int)tick_diff - TARGET; + + /* Is the measurement good enough to switch to fine ? */ + if ((freq_diff > -MAX_DEV_FINE) && (freq_diff < MAX_DEV_FINE)) { + _gpsdo_fine_start(); + return; + } + + /* Estimate correction and apply it */ + g_gpsdo.tune.coarse -= (freq_diff * g_gpsdo.coarse.vctxo_sensitivity) >> 8; + pdm_set(PDM_CLK_HI, true, g_gpsdo.tune.coarse, false); + + /* Skip next measurement */ + g_gpsdo.meas.skip = 1; + + /* Debug */ +#ifdef GPSDO_DEBUG + printf("[+] GPSDO Coarse: err=%d tune=%d\n", freq_diff, g_gpsdo.tune.coarse); +#endif +} + +static void +_gpsdo_fine_track(uint32_t tick_diff) +{ + int freq_diff = (int)tick_diff - TARGET; + uint16_t tune; + + /* Did we deviate too much ? */ + if ((freq_diff < -2*MAX_DEV_FINE) && (freq_diff > 2*MAX_DEV_FINE)) { + _gpsdo_coarse_start(); + return; + } + + /* Accumulate long term error */ + g_gpsdo.fine.acc += freq_diff; + + /* Update fine tuning value */ + if (((g_gpsdo.fine.acc >= 0) && (freq_diff > 0)) || + ((g_gpsdo.fine.acc <= 0) && (freq_diff < 0))) + { + g_gpsdo.tune.fine -= freq_diff; + } + + if (g_gpsdo.fine.acc) { + if (++g_gpsdo.fine.div > 10) { + g_gpsdo.fine.div = 0; + if (g_gpsdo.fine.acc > 0) + g_gpsdo.tune.fine--; + else if (g_gpsdo.fine.acc < 0) + g_gpsdo.tune.fine++; + } + } else { + g_gpsdo.fine.div = 0; + } + + /* Apply value with a bias from long term accumulator */ + tune = g_gpsdo.tune.fine - (g_gpsdo.fine.acc / 2); + pdm_set(PDM_CLK_LO, true, tune, false); + + /* Debug */ +#ifdef GPSDO_DEBUG + printf("[+] GPSDO Fine: err=%d acc=%d tune=%d\n", freq_diff, g_gpsdo.fine.acc, g_gpsdo.tune.fine); +#endif +} + + +void +gpsdo_poll(void) +{ + uint32_t tick_now, tick_diff; + bool valid; + + /* Get current tick and check if there was a PPS and estimate frequency */ + tick_now = time_pps_read(); + + if (tick_now == g_gpsdo.meas.tick_prev) + return; + + g_gpsdo.meas.last = tick_diff = tick_now - g_gpsdo.meas.tick_prev; + g_gpsdo.meas.tick_prev = tick_now; + + /* If we're currently discarding samples, skip it */ + if (g_gpsdo.meas.skip) { + g_gpsdo.meas.skip--; + return; + } + + /* If we're disabled, nothing else to do */ + if (g_gpsdo.state == STATE_DISABLED) + return; + + /* Check GPS state */ + if (!gps_has_valid_fix()) { + /* No GPS fix, go to hold-over */ + g_gpsdo.state = STATE_HOLD_OVER; + return; + } + + /* Check measurement plausibility */ + valid = (tick_diff > (TARGET - MAX_DEV_VALID)) && (tick_diff < (TARGET + MAX_DEV_VALID)); + + if (valid) { + /* If we're in hold-over, switch to active */ + if (g_gpsdo.state == STATE_HOLD_OVER) { + _gpsdo_coarse_start(); + return; + } + } else { + /* Count invalid measurements and if too many of + * them, we go back to hold-over */ + if (++g_gpsdo.meas.invalid >= MAX_INVALID) { + g_gpsdo.state = STATE_HOLD_OVER; + return; + } + } + + g_gpsdo.meas.invalid = 0; + + /* If we reach here, we have a valid fix, valid measurement and + * we're not in hold-over or disabled. Feed the correct loop */ + if (g_gpsdo.state == STATE_TUNE_COARSE) + _gpsdo_coarse_tune(tick_diff); + else if (g_gpsdo.state == STATE_TUNE_FINE) + _gpsdo_fine_track(tick_diff); +} + + +void +gpsdo_init(enum gpsdo_vctxo_model vctxo) +{ + /* State */ + memset(&g_gpsdo, 0x00, sizeof(g_gpsdo)); + + /* Default tune to middle range */ + g_gpsdo.tune.coarse = 2048; + g_gpsdo.tune.fine = 2048; + + pdm_set(PDM_CLK_HI, true, g_gpsdo.tune.coarse, false); + pdm_set(PDM_CLK_LO, true, g_gpsdo.tune.fine, false); + + /* Initial state and config */ + g_gpsdo.state = STATE_HOLD_OVER; + g_gpsdo.coarse.vctxo_sensitivity = vctxo_sensitivity[vctxo]; +} diff --git a/firmware/ice40-riscv/icE1usb/gpsdo.h b/firmware/ice40-riscv/icE1usb/gpsdo.h new file mode 100644 index 0000000..181e4b9 --- /dev/null +++ b/firmware/ice40-riscv/icE1usb/gpsdo.h @@ -0,0 +1,16 @@ +/* + * gpsdo.h + * + * Copyright (C) 2019-2022 Sylvain Munaut <tnt(a)246tNt.com> + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +enum gpsdo_vctxo_model { + VCTXO_TAITIEN_VT40 = 0, /* VTEUALJANF-30.720000 */ + VCTXO_SITIME_SIT3808_E = 1, /* SIT3808AI-D2-33EE-30.720000T */ +}; + +void gpsdo_poll(void); +void gpsdo_init(enum gpsdo_vctxo_model vctxo); -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26915 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: I5f9ce6621492be967d6a44d31f270e107f3ef686 Gerrit-Change-Number: 26915 Gerrit-PatchSet: 1 Gerrit-Owner: tnt <tnt(a)246tNt.com> Gerrit-MessageType: newchange
2 3
0 0
Change in osmo-e1-hardware[master]: icE1usb fw: Add USB control for the GPSDO function
by tnt 16 Jan '22

16 Jan '22
tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26916 ) Change subject: icE1usb fw: Add USB control for the GPSDO function ...................................................................... icE1usb fw: Add USB control for the GPSDO function Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com> Change-Id: If92aa68d8a49349fa0d6d556eec81bbb80be989c --- M firmware/ice40-riscv/icE1usb/gpsdo.c M firmware/ice40-riscv/icE1usb/gpsdo.h M firmware/ice40-riscv/icE1usb/ice1usb_proto.h M firmware/ice40-riscv/icE1usb/usb_dev.c 4 files changed, 189 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/16/26916/1 diff --git a/firmware/ice40-riscv/icE1usb/gpsdo.c b/firmware/ice40-riscv/icE1usb/gpsdo.c index ca9b806..ae131d4 100644 --- a/firmware/ice40-riscv/icE1usb/gpsdo.c +++ b/firmware/ice40-riscv/icE1usb/gpsdo.c @@ -13,6 +13,8 @@ #include "gpsdo.h" #include "misc.h" +#include "ice1usb_proto.h" + struct { /* Current tuning */ @@ -74,6 +76,72 @@ #define MAX_INVALID 5 +static void _gpsdo_coarse_start(void); + + +void +gpsdo_get_status(struct e1usb_gpsdo_status *status) +{ + const uint8_t state_map[] = { + [STATE_DISABLED] = ICE1USB_GPSDO_STATE_DISABLED, + [STATE_HOLD_OVER] = ICE1USB_GPSDO_STATE_HOLD_OVER, + [STATE_TUNE_COARSE] = ICE1USB_GPSDO_STATE_TUNE_COARSE, + [STATE_TUNE_FINE] = ICE1USB_GPSDO_STATE_TUNE_FINE, + }; + const uint8_t ant_map[] = { + [ANT_UNKNOWN] = ICE1USB_GPSDO_ANT_UNKNOWN, + [ANT_OK] = ICE1USB_GPSDO_ANT_OK, + [ANT_OPEN] = ICE1USB_GPSDO_ANT_OPEN, + [ANT_SHORT] = ICE1USB_GPSDO_ANT_SHORT, + }; + + status->state = state_map[g_gpsdo.state]; + status->antenna_status = ant_map[gps_antenna_status()]; + status->valid_fix = gps_has_valid_fix(); + status->mode = (g_gpsdo.state == STATE_DISABLED) ? ICE1USB_GPSDO_MODE_DISABLED : ICE1USB_GPSDO_MODE_AUTO; + status->tune.coarse = g_gpsdo.tune.coarse; + status->tune.fine = g_gpsdo.tune.fine; + status->freq_est = g_gpsdo.meas.last; +} + +void +gpsdo_enable(bool enable) +{ + if (!enable) + g_gpsdo.state = STATE_DISABLED; + else if (g_gpsdo.state == STATE_DISABLED) + g_gpsdo.state = STATE_HOLD_OVER; +} + +bool +gpsdo_enabled(void) +{ + return g_gpsdo.state != STATE_DISABLED; +} + +void +gpsdo_set_tune(uint16_t coarse, uint16_t fine) +{ + /* Set value */ + g_gpsdo.tune.coarse = coarse; + g_gpsdo.tune.fine = fine; + + pdm_set(PDM_CLK_HI, true, g_gpsdo.tune.coarse, false); + pdm_set(PDM_CLK_LO, true, g_gpsdo.tune.fine, false); + + /* If we were in 'fine' mode, reset to coarse */ + if (g_gpsdo.state == STATE_TUNE_FINE) + _gpsdo_coarse_start(); +} + +void +gpsdo_get_tune(uint16_t *coarse, uint16_t *fine) +{ + *coarse = g_gpsdo.tune.coarse; + *fine = g_gpsdo.tune.fine; +} + + static void _gpsdo_coarse_start(void) { diff --git a/firmware/ice40-riscv/icE1usb/gpsdo.h b/firmware/ice40-riscv/icE1usb/gpsdo.h index 181e4b9..a771db7 100644 --- a/firmware/ice40-riscv/icE1usb/gpsdo.h +++ b/firmware/ice40-riscv/icE1usb/gpsdo.h @@ -12,5 +12,16 @@ VCTXO_SITIME_SIT3808_E = 1, /* SIT3808AI-D2-33EE-30.720000T */ }; +struct e1usb_gpsdo_status; + + +void gpsdo_get_status(struct e1usb_gpsdo_status *status); + +void gpsdo_enable(bool enable); +bool gpsdo_enabled(void); + +void gpsdo_set_tune(uint16_t coarse, uint16_t fine); +void gpsdo_get_tune(uint16_t *coarse, uint16_t *fine); + void gpsdo_poll(void); void gpsdo_init(enum gpsdo_vctxo_model vctxo); diff --git a/firmware/ice40-riscv/icE1usb/ice1usb_proto.h b/firmware/ice40-riscv/icE1usb/ice1usb_proto.h index 9ac2136..a249537 100644 --- a/firmware/ice40-riscv/icE1usb/ice1usb_proto.h +++ b/firmware/ice40-riscv/icE1usb/ice1usb_proto.h @@ -17,12 +17,51 @@ /*! returns a bit-mask of optional device capabilities (see enum e1usb_dev_capability) */ #define ICE1USB_DEV_GET_CAPABILITIES 0x01 #define ICE1USB_DEV_GET_FW_BUILD 0x02 +#define ICE1USB_DEV_GET_GPSDO_STATUS 0x10 +#define ICE1USB_DEV_GET_GPSDO_MODE 0x12 /*!< uint8_t */ +#define ICE1USB_DEV_SET_GPSDO_MODE 0x13 /*!< wValue = mode */ +#define ICE1USB_DEV_GET_GPSDO_TUNE 0x14 /*!< data = struct e1usb_gpsdo_tune */ +#define ICE1USB_DEV_SET_GPSDO_TUNE 0x15 /*!< data = struct e1usb_gpsdo_tune */ enum e1usb_dev_capability { /*! Does this board have a GPS-DO */ ICE1USB_DEV_CAP_GPSDO, }; +enum ice1usb_gpsdo_mode { + ICE1USB_GPSDO_MODE_DISABLED = 0, + ICE1USB_GPSDO_MODE_AUTO = 1, +}; + +enum ice1usb_gpsdo_antenna_state { + ICE1USB_GPSDO_ANT_UNKNOWN = 0, + ICE1USB_GPSDO_ANT_OK = 1, + ICE1USB_GPSDO_ANT_OPEN = 2, + ICE1USB_GPSDO_ANT_SHORT = 3, +}; + +enum ice1usb_gpsdo_state { + ICE1USB_GPSDO_STATE_DISABLED = 0, + ICE1USB_GPSDO_STATE_CALIBRATE = 1, + ICE1USB_GPSDO_STATE_HOLD_OVER = 2, + ICE1USB_GPSDO_STATE_TUNE_COARSE = 3, + ICE1USB_GPSDO_STATE_TUNE_FINE = 4, +}; + +struct e1usb_gpsdo_tune { + uint16_t coarse; + uint16_t fine; +} __attribute__((packed)); + +struct e1usb_gpsdo_status { + uint8_t state; + uint8_t antenna_status; /*!< Antenna status */ + uint8_t valid_fix; /*!< Valid GPS Fix (0/1) */ + uint8_t mode; /*!< Current configured operating mode */ + struct e1usb_gpsdo_tune tune; /*!< Current VCXO tuning values */ + uint32_t freq_est; /*!< Latest frequency estimate measurement */ +} __attribute__((packed)); + /* Interface Requests */ diff --git a/firmware/ice40-riscv/icE1usb/usb_dev.c b/firmware/ice40-riscv/icE1usb/usb_dev.c index e19d9a0..2997a33 100644 --- a/firmware/ice40-riscv/icE1usb/usb_dev.c +++ b/firmware/ice40-riscv/icE1usb/usb_dev.c @@ -12,6 +12,7 @@ #include <no2usb/usb_proto.h> #include "console.h" +#include "gpsdo.h" #include "misc.h" #include "ice1usb_proto.h" @@ -20,6 +21,61 @@ const char *fw_build_str = BUILD_INFO; +static void +_get_gpsdo_status(struct usb_ctrl_req *req, struct usb_xfer *xfer) +{ + struct e1usb_gpsdo_status status; + + gpsdo_get_status(&status); + + memcpy(xfer->data, &status, sizeof(struct e1usb_gpsdo_status)); + xfer->len = sizeof(struct e1usb_gpsdo_status); +} + +static void +_get_gpsdo_mode(struct usb_ctrl_req *req, struct usb_xfer *xfer) +{ + xfer->data[0] = gpsdo_enabled() ? ICE1USB_GPSDO_MODE_DISABLED : ICE1USB_GPSDO_MODE_AUTO; + xfer->len = 1; +} + +static void +_set_gpsdo_mode(struct usb_ctrl_req *req, struct usb_xfer *xfer) +{ + gpsdo_enable(req->wValue != ICE1USB_GPSDO_MODE_DISABLED); +} + +static void +_get_gpsdo_tune(struct usb_ctrl_req *req, struct usb_xfer *xfer) +{ + uint16_t coarse, fine; + struct e1usb_gpsdo_tune tune; + + gpsdo_get_tune(&coarse, &fine); + tune.coarse = coarse; + tune.fine = fine; + + memcpy(xfer->data, &tune, sizeof(struct e1usb_gpsdo_tune)); + xfer->len = sizeof(struct e1usb_gpsdo_tune); +} + +static bool +_set_gpsdo_tune_done(struct usb_xfer *xfer) +{ + const struct e1usb_gpsdo_tune *tune = (const void *) xfer->data; + gpsdo_set_tune(tune->coarse, tune->fine); + return true; +} + +static void +_set_gpsdo_tune(struct usb_ctrl_req *req, struct usb_xfer *xfer) +{ + xfer->cb_done = _set_gpsdo_tune_done; + xfer->cb_ctx = req; + xfer->len = sizeof(struct e1usb_gpsdo_tune); +} + + static enum usb_fnd_resp _usb_dev_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer) { @@ -37,6 +93,21 @@ xfer->data = (void*) fw_build_str; xfer->len = strlen(fw_build_str); break; + case ICE1USB_DEV_GET_GPSDO_STATUS: + _get_gpsdo_status(req, xfer); + break; + case ICE1USB_DEV_GET_GPSDO_MODE: + _get_gpsdo_mode(req, xfer); + break; + case ICE1USB_DEV_SET_GPSDO_MODE: + _set_gpsdo_mode(req, xfer); + break; + case ICE1USB_DEV_GET_GPSDO_TUNE: + _get_gpsdo_tune(req, xfer); + break; + case ICE1USB_DEV_SET_GPSDO_TUNE: + _set_gpsdo_tune(req, xfer); + break; default: return USB_FND_ERROR; } -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26916 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: If92aa68d8a49349fa0d6d556eec81bbb80be989c Gerrit-Change-Number: 26916 Gerrit-PatchSet: 1 Gerrit-Owner: tnt <tnt(a)246tNt.com> Gerrit-MessageType: newchange
2 3
0 0
Change in osmo-e1-hardware[master]: icE1usb fw: New ICE1USB_INTF_GET_ERRORS control request
by tnt 16 Jan '22

16 Jan '22
Hello laforge, I'd like you to do a code review. Please visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26911 to review the following change. Change subject: icE1usb fw: New ICE1USB_INTF_GET_ERRORS control request ...................................................................... icE1usb fw: New ICE1USB_INTF_GET_ERRORS control request This allows the host driver to obtain the current errors, as they would normally be reported over the IRQ endpoint. One important use case for this is to obtain the initial error state when the driver starts up. Change-Id: I6301bb23234c66afe083ceb500cff8a40813e8b6 --- M firmware/ice40-riscv/icE1usb/ice1usb_proto.h M firmware/ice40-riscv/icE1usb/usb_e1.c 2 files changed, 21 insertions(+), 12 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/11/26911/1 diff --git a/firmware/ice40-riscv/icE1usb/ice1usb_proto.h b/firmware/ice40-riscv/icE1usb/ice1usb_proto.h index d0d7304..9ac2136 100644 --- a/firmware/ice40-riscv/icE1usb/ice1usb_proto.h +++ b/firmware/ice40-riscv/icE1usb/ice1usb_proto.h @@ -32,6 +32,7 @@ #define ICE1USB_INTF_GET_TX_CFG 0x03 /*!< struct ice1usb_tx_config */ #define ICE1USB_INTF_SET_RX_CFG 0x04 /*!< struct ice1usb_rx_config */ #define ICE1USB_INTF_GET_RX_CFG 0x05 /*!< struct ice1usb_rx_config */ +#define ICE1USB_INTF_GET_ERRORS 0x06 /*!< struct ice1usb_irq_err */ //enum e1usb_intf_capability { }; diff --git a/firmware/ice40-riscv/icE1usb/usb_e1.c b/firmware/ice40-riscv/icE1usb/usb_e1.c index 6d0d3cf..6fdaa91 100644 --- a/firmware/ice40-riscv/icE1usb/usb_e1.c +++ b/firmware/ice40-riscv/icE1usb/usb_e1.c @@ -95,6 +95,15 @@ } } +static void +_fill_irq_err(struct ice1usb_irq_err *out, const struct e1_error_count *cur_err) +{ + out->crc = cur_err->crc; + out->align = cur_err->align; + out->ovfl = cur_err->ovfl; + out->unfl = cur_err->unfl; + out->flags = cur_err->flags; +} static void _usb_e1_run(int port) @@ -112,18 +121,9 @@ if ((ep_regs->bd[0].csr & USB_BD_STATE_MSK) != USB_BD_STATE_RDY_DATA) { const struct e1_error_count *cur_err = e1_get_error_count(port); if (memcmp(cur_err, &usb_e1->last_err, sizeof(*cur_err))) { - struct ice1usb_irq errmsg = { - .type = ICE1USB_IRQ_T_ERRCNT, - .u = { - .errors = { - .crc = cur_err->crc, - .align = cur_err->align, - .ovfl = cur_err->ovfl, - .unfl = cur_err->unfl, - .flags = cur_err->flags, - } - } - }; + struct ice1usb_irq errmsg; + errmsg.type = ICE1USB_IRQ_T_ERRCNT; + _fill_irq_err(&errmsg.u.errors, cur_err); printf("E"); usb_data_write(ep_regs->bd[0].ptr, &errmsg, sizeof(errmsg)); ep_regs->bd[0].csr = USB_BD_STATE_RDY_DATA | USB_BD_LEN(sizeof(errmsg)); @@ -374,6 +374,7 @@ static enum usb_fnd_resp _e1_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer) { + const struct e1_error_count *cur_err; struct usb_e1_state *usb_e1; int port; @@ -420,6 +421,13 @@ memcpy(xfer->data, &usb_e1->rx_cfg, sizeof(struct ice1usb_rx_config)); xfer->len = sizeof(struct ice1usb_rx_config); break; + case ICE1USB_INTF_GET_ERRORS: + if (req->wLength < sizeof(struct ice1usb_irq_err)) + return USB_FND_ERROR; + cur_err = e1_get_error_count(port); + _fill_irq_err((struct ice1usb_irq_err *)xfer->data, cur_err); + xfer->len = sizeof(struct ice1usb_irq_err); + break; default: return USB_FND_ERROR; } -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26911 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: I6301bb23234c66afe083ceb500cff8a40813e8b6 Gerrit-Change-Number: 26911 Gerrit-PatchSet: 1 Gerrit-Owner: tnt <tnt(a)246tNt.com> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
2 3
0 0
Change in osmo-e1-hardware[master]: common fw: Add hexval() utility function
by tnt 16 Jan '22

16 Jan '22
tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26912 ) Change subject: common fw: Add hexval() utility function ...................................................................... common fw: Add hexval() utility function Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com> Change-Id: I724c14d1dee9e268f666030053fbf62ce5e1ba71 --- M firmware/ice40-riscv/common/utils.c M firmware/ice40-riscv/common/utils.h 2 files changed, 14 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/12/26912/1 diff --git a/firmware/ice40-riscv/common/utils.c b/firmware/ice40-riscv/common/utils.c index 1ac111b..7c7d3d0 100644 --- a/firmware/ice40-riscv/common/utils.c +++ b/firmware/ice40-riscv/common/utils.c @@ -36,6 +36,19 @@ return buf; } +uint8_t +hexval(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + else if (c >= 'a' && c <= 'f') + return 10 + (c - 'a'); + else if (c >= 'A' && c <= 'F') + return 10 + (c - 'A'); + else + return 0; +} + void _panic(const char *file, int lineno, const char *fmt, ...) diff --git a/firmware/ice40-riscv/common/utils.h b/firmware/ice40-riscv/common/utils.h index 03359ae..37cc88e 100644 --- a/firmware/ice40-riscv/common/utils.h +++ b/firmware/ice40-riscv/common/utils.h @@ -10,6 +10,7 @@ #include <stdbool.h> char *hexstr(void *d, int n, bool space); +uint8_t hexval(char c); void _panic(const char *file, int lineno, const char *fmt, ...); #define panic(fmt, ...) _panic(__FILE__, __LINE__, fmt, ##__VA_ARGS__) -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26912 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: I724c14d1dee9e268f666030053fbf62ce5e1ba71 Gerrit-Change-Number: 26912 Gerrit-PatchSet: 1 Gerrit-Owner: tnt <tnt(a)246tNt.com> Gerrit-MessageType: newchange
2 3
0 0
Change in osmo-e1-hardware[master]: icE1usb fw: Import GPS module driver code
by tnt 16 Jan '22

16 Jan '22
tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26913 ) Change subject: icE1usb fw: Import GPS module driver code ...................................................................... icE1usb fw: Import GPS module driver code This only initializes the GPS module and keeps track of the antenna and fix status Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com> Change-Id: I24811f872fafefc7f8dfaa3028c4288001a87d2f --- M firmware/ice40-riscv/icE1usb/Makefile M firmware/ice40-riscv/icE1usb/fw_app.c A firmware/ice40-riscv/icE1usb/gps.c A firmware/ice40-riscv/icE1usb/gps.h 4 files changed, 318 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/13/26913/1 diff --git a/firmware/ice40-riscv/icE1usb/Makefile b/firmware/ice40-riscv/icE1usb/Makefile index 36fd921..6725f6a 100644 --- a/firmware/ice40-riscv/icE1usb/Makefile +++ b/firmware/ice40-riscv/icE1usb/Makefile @@ -48,6 +48,7 @@ HEADERS_app=\ config.h \ e1.h \ + gps.h \ ice1usb_proto.h \ misc.h \ usb_desc_ids.h \ @@ -59,6 +60,7 @@ SOURCES_app=\ e1.c \ fw_app.c \ + gps.c \ misc.c \ usb_desc_app.c \ usb_dev.c \ diff --git a/firmware/ice40-riscv/icE1usb/fw_app.c b/firmware/ice40-riscv/icE1usb/fw_app.c index 880d2d6..c5c2b7c 100644 --- a/firmware/ice40-riscv/icE1usb/fw_app.c +++ b/firmware/ice40-riscv/icE1usb/fw_app.c @@ -14,6 +14,7 @@ #include "console.h" #include "e1.h" +#include "gps.h" #include "led.h" #include "misc.h" #include "mini-printf.h" @@ -96,6 +97,9 @@ pdm_set(PDM_CLK_HI, true, 2048, false); pdm_set(PDM_CLK_LO, false, 0, false); + /* GPS init */ + gps_init(); + /* Enable USB directly */ usb_init(&app_stack_desc); usb_dev_init(); @@ -161,5 +165,8 @@ /* E1 poll */ usb_e1_poll(); + + /* GPS poll */ + gps_poll(); } } diff --git a/firmware/ice40-riscv/icE1usb/gps.c b/firmware/ice40-riscv/icE1usb/gps.c new file mode 100644 index 0000000..2fd6ab8 --- /dev/null +++ b/firmware/ice40-riscv/icE1usb/gps.c @@ -0,0 +1,286 @@ +/* + * gps.c + * + * Copyright (C) 2019-2022 Sylvain Munaut <tnt(a)246tNt.com> + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include <stddef.h> +#include <stdbool.h> +#include <stdint.h> +#include <string.h> + +#include "console.h" +#include "gps.h" +#include "misc.h" +#include "utils.h" + +#include "config.h" + + +struct gps_uart { + uint32_t data; + uint32_t csr; +} __attribute__((packed,aligned(4))); + +#define GPS_UART_CSR_DIV(baud) ((SYS_CLK_FREQ+(baud)/2)/(baud)-2) +#define GPS_UART_CSR_TX_EMPTY (1 << 29) +#define GPS_UART_DATA_EMPTY (1 << 31) + +static volatile struct gps_uart * const gps_uart_regs = (void*)(GPS_UART_BASE); + + +static struct { + /* NMEA rx state */ + struct { + enum { + GNS_WAIT = 0, + GNS_READ = 1, + GNS_CK_HI = 2, + GNS_CK_LO = 3, + GNS_END_CR = 4, + GNS_END_LF = 5, + } state; + + int len; + uint8_t cksum; + char buf[95]; /* Max length is actually 82 + 1 (\0) */ + } nmea; + + /* Current lock state */ + struct { + bool valid; + } fix; + + /* Reported antenna state */ + enum gps_antenna_state antenna; +} g_gps; + + +static void +_gps_empty(bool wait_eol) +{ + bool eol = false; + + uint32_t c; + while (1) { + c = gps_uart_regs->data; + if (c & GPS_UART_DATA_EMPTY) { + if (!wait_eol || eol) + break; + } else { + eol = (c == '\n'); + } + } +} + +static void +_gps_send(const char *s) +{ + char cksum = 0; + + /* Start sentence */ + gps_uart_regs->data = '$'; + + /* Send payload */ + while (*s) + cksum ^= (gps_uart_regs->data = *s++); + + /* Send checksum */ + gps_uart_regs->data = '*'; + + s = hexstr(&cksum, 1, false); + gps_uart_regs->data = *s++; + gps_uart_regs->data = *s++; + + gps_uart_regs->data = '\r'; + gps_uart_regs->data = '\n'; +} + +static const char * +_gps_query(void) +{ + uint32_t c; + while (1) { + /* Get next char */ + c = gps_uart_regs->data; + if (c & GPS_UART_DATA_EMPTY) + break; + + /* Always store it */ + if (g_gps.nmea.len == sizeof(g_gps.nmea.buf)) + g_gps.nmea.state = GNS_WAIT; + else + g_gps.nmea.buf[g_gps.nmea.len++] = c; + + /* State */ + if (c == '$') { + /* '$' always triggers reset */ + g_gps.nmea.state = GNS_READ; + g_gps.nmea.cksum = 0; + g_gps.nmea.len = 1; + g_gps.nmea.buf[0] = '$'; + } else { + switch (g_gps.nmea.state) { + case GNS_READ: + if (c == '*') + g_gps.nmea.state = GNS_CK_HI; + else + g_gps.nmea.cksum ^= c; + break; + case GNS_CK_HI: + g_gps.nmea.cksum ^= hexval(c) << 4; + g_gps.nmea.state = GNS_CK_LO; + break; + case GNS_CK_LO: + g_gps.nmea.cksum ^= hexval(c); + g_gps.nmea.state = GNS_END_CR; + break; + case GNS_END_CR: + g_gps.nmea.state = (c == '\r') ? GNS_END_LF : GNS_WAIT; + break; + case GNS_END_LF: + g_gps.nmea.state = GNS_WAIT; + g_gps.nmea.buf[g_gps.nmea.len] = 0x00; + if (c == '\n') + return g_gps.nmea.buf; + break; + default: + g_gps.nmea.state = GNS_WAIT; + g_gps.nmea.len = 0; + break; + } + } + } + return NULL; +} + +void +_gps_parse_nmea(const char *nmea) +{ + /* Very basic parsing, we just look at GSA messages and consider + * that if we have a 3D fix with PDOP < 5, the timing data should + * be usable + */ + if (!strncmp(nmea, "$GPGSA", 6)) + { + /* Check for Autonomous 3D fix (fixed field positions) */ + if ((nmea[7] != 'A') || (nmea[9] != '3')) { + g_gps.fix.valid = false; + return; + } + + /* Find PDOP */ + const char *p = nmea; + for (int i=0; (i < 15) && (*p != '*'); i += (*(p++)==',') ); + + /* Is it low enough ? */ + g_gps.fix.valid = (p[1] < '5'); + } + + /* Parse TXT ANTENNA Status */ + if (!strncmp(nmea, "$GPTXT", 6) && nmea[13] == '0' && nmea[14] == '1') + { + if (!strncmp(&nmea[16], "ANTENNA OK", 10)) + g_gps.antenna = ANT_OK; + else if (!strncmp(&nmea[16], "ANTENNA OPEN", 12)) + g_gps.antenna = ANT_OPEN; + else if (!strncmp(&nmea[16], "ANTENNA SHORT", 13)) + g_gps.antenna = ANT_SHORT; + else + g_gps.antenna = ANT_UNKNOWN; + } +} + + +bool +gps_has_valid_fix(void) +{ + return g_gps.fix.valid; +} + +enum gps_antenna_state +gps_antenna_status(void) +{ + return g_gps.antenna; +} + +void +gps_poll(void) +{ + const char *nmea; + + /* Check if we have anything from the module */ + nmea = _gps_query(); + if (!nmea) + return; + + /* If we do, process it locally to update our state */ + _gps_parse_nmea(nmea); +} + +void +gps_init(void) +{ + int i; + + /* State init */ + memset(&g_gps, 0x00, sizeof(g_gps)); + + /* Configure reset gpio */ + gpio_out(3, false); + gpio_dir(3, true); + + /* Attempt reset sequence at 9600 baud and then 115200 baud */ + for (i=0; i<2; i++) + { + uint32_t start_time = time_now_read(); + bool init_ok; + + /* Assert reset */ + gpio_out(3, false); + + /* Configure uart and empty buffer */ + gps_uart_regs->csr = i ? GPS_UART_CSR_DIV(115200) : GPS_UART_CSR_DIV(9600); + _gps_empty(false); + + /* Wait 100 ms */ + delay(100); + + /* Release reset line */ + gpio_out(3, true); + + /* Wait for first line of output as sign it's ready, timeout after 1s */ + while (!time_elapsed(start_time, SYS_CLK_FREQ)) + if ((init_ok = (_gps_query() != NULL))) + break; + + if (init_ok) { + printf("[+] GPS ok at %d baud\n", i ? 115200 : 9600); + break; + } + } + + /* Failed ? */ + if (i == 2) { + printf("[!] GPS init failed\n"); + return; + } + + /* If success was at 9600 baud, need to speed up */ + if (i == 0) { + /* Configure GPS to use serial at 115200 baud */ + _gps_send("PCAS01,5"); + + /* Add dummy byte which will be mangled during baudrate switch ... */ + gps_uart_regs->data = 0x00; + while (!(gps_uart_regs->csr & GPS_UART_CSR_TX_EMPTY)); + + /* Set uart to 115200 and empty uart buffer, line aligned */ + gps_uart_regs->csr = GPS_UART_CSR_DIV(115200) ; + _gps_empty(true); + } + + /* Configure GPS to be GPS-only (no GLONASS/BEIDOU) */ + _gps_send("PCAS04,1"); +} diff --git a/firmware/ice40-riscv/icE1usb/gps.h b/firmware/ice40-riscv/icE1usb/gps.h new file mode 100644 index 0000000..57ef271 --- /dev/null +++ b/firmware/ice40-riscv/icE1usb/gps.h @@ -0,0 +1,23 @@ +/* + * gps.h + * + * Copyright (C) 2019-2022 Sylvain Munaut <tnt(a)246tNt.com> + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include <stdbool.h> + +enum gps_antenna_state { + ANT_UNKNOWN = 0, + ANT_OK, + ANT_OPEN, + ANT_SHORT +}; + +bool gps_has_valid_fix(void); +enum gps_antenna_state gps_antenna_status(void); + +void gps_poll(void); +void gps_init(void); -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26913 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: I24811f872fafefc7f8dfaa3028c4288001a87d2f Gerrit-Change-Number: 26913 Gerrit-PatchSet: 1 Gerrit-Owner: tnt <tnt(a)246tNt.com> Gerrit-MessageType: newchange
2 4
0 0
Change in osmo-e1-hardware[master]: icE1usb fw: Add function to enable/disable E1 led runner
by tnt 15 Jan '22

15 Jan '22
tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26906 ) Change subject: icE1usb fw: Add function to enable/disable E1 led runner ...................................................................... icE1usb fw: Add function to enable/disable E1 led runner Also don't force enable the runner in the e1_platform_led_set callback. Due to GPIO shortage, the E1 leds control are multiplexed with SPI so this adds a method to temporarely stop the runner so SPI can be used. Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com> Change-Id: Ie671daab5ee5e0b5f58de9d4fef1f0ca7d6d02b6 --- M firmware/ice40-riscv/icE1usb/misc.c M firmware/ice40-riscv/icE1usb/misc.h 2 files changed, 17 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/06/26906/1 diff --git a/firmware/ice40-riscv/icE1usb/misc.c b/firmware/ice40-riscv/icE1usb/misc.c index 4b32fcd..bd9198a 100644 --- a/firmware/ice40-riscv/icE1usb/misc.c +++ b/firmware/ice40-riscv/icE1usb/misc.c @@ -47,6 +47,18 @@ void +e1_led_run(void) +{ + misc_regs->e1_led |= 0x100; +} + +void +e1_led_pause(void) +{ + misc_regs->e1_led &= 0xff; +} + +void e1_led_set(bool enable, uint8_t cfg) { misc_regs->e1_led = (enable ? 0x100 : 0x000) | cfg; @@ -66,10 +78,11 @@ tmp = misc_regs->e1_led; tmp &= ~(3 << shift); - tmp |= 0x100 | ((state & 3) << shift); + tmp |= ((state & 3) << shift); misc_regs->e1_led = tmp; } + uint16_t e1_tick_read(int port) { diff --git a/firmware/ice40-riscv/icE1usb/misc.h b/firmware/ice40-riscv/icE1usb/misc.h index dac5730..b4baef1 100644 --- a/firmware/ice40-riscv/icE1usb/misc.h +++ b/firmware/ice40-riscv/icE1usb/misc.h @@ -26,7 +26,10 @@ void pdm_set(int chan, bool enable, unsigned value, bool normalize); +void e1_led_run(void); +void e1_led_pause(void); void e1_led_set(bool enable, uint8_t cfg); + uint16_t e1_tick_read(int port); void reboot(int fw); -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26906 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: Ie671daab5ee5e0b5f58de9d4fef1f0ca7d6d02b6 Gerrit-Change-Number: 26906 Gerrit-PatchSet: 1 Gerrit-Owner: tnt <tnt(a)246tNt.com> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
2 3
0 0
Change in osmo-e1-hardware[master]: icE1usb fw: Add GPIO access functions
by tnt 15 Jan '22

15 Jan '22
tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26907 ) Change subject: icE1usb fw: Add GPIO access functions ...................................................................... icE1usb fw: Add GPIO access functions The 32 bit register is split in different fields to speed up access to the 'in' field. The oe/out fields can't be split because all writes are 32 bit wide (i.e. no support for byte enable in the gateware) Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com> Change-Id: Ic25377bb777e5d25939f0e8cfe6b7c6ef8641f6d --- M firmware/ice40-riscv/icE1usb/misc.c M firmware/ice40-riscv/icE1usb/misc.h 2 files changed, 38 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/07/26907/1 diff --git a/firmware/ice40-riscv/icE1usb/misc.c b/firmware/ice40-riscv/icE1usb/misc.c index bd9198a..50aec43 100644 --- a/firmware/ice40-riscv/icE1usb/misc.c +++ b/firmware/ice40-riscv/icE1usb/misc.c @@ -15,7 +15,11 @@ struct misc { uint32_t warmboot; - uint32_t gpio; + struct { + uint16_t oe_out; + uint8_t in; + uint8_t _rsvd; + } gpio; uint32_t e1_led; uint32_t _rsvd; struct { @@ -47,6 +51,35 @@ void +gpio_dir(int n, bool output) +{ + uint16_t mask = 256 << n; + + if (output) + misc_regs->gpio.oe_out |= mask; + else + misc_regs->gpio.oe_out &= ~mask; +} + +void +gpio_out(int n, bool val) +{ + uint16_t mask = 1 << n; + + if (val) + misc_regs->gpio.oe_out |= mask; + else + misc_regs->gpio.oe_out &= ~mask; +} + +bool +gpio_in(int n) +{ + return (misc_regs->gpio.in & (1 << n)) != 0; +} + + +void e1_led_run(void) { misc_regs->e1_led |= 0x100; diff --git a/firmware/ice40-riscv/icE1usb/misc.h b/firmware/ice40-riscv/icE1usb/misc.h index b4baef1..76d5a7d 100644 --- a/firmware/ice40-riscv/icE1usb/misc.h +++ b/firmware/ice40-riscv/icE1usb/misc.h @@ -26,6 +26,10 @@ void pdm_set(int chan, bool enable, unsigned value, bool normalize); +void gpio_dir(int n, bool output); +void gpio_out(int n, bool val); +bool gpio_in(int n); + void e1_led_run(void); void e1_led_pause(void); void e1_led_set(bool enable, uint8_t cfg); -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26907 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: Ic25377bb777e5d25939f0e8cfe6b7c6ef8641f6d Gerrit-Change-Number: 26907 Gerrit-PatchSet: 1 Gerrit-Owner: tnt <tnt(a)246tNt.com> Gerrit-MessageType: newchange
2 3
0 0
Change in osmo-e1-hardware[master]: icE1usb fw: Move handling of device-wide request in usb_dev.c
by tnt 15 Jan '22

15 Jan '22
tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26909 ) Change subject: icE1usb fw: Move handling of device-wide request in usb_dev.c ...................................................................... icE1usb fw: Move handling of device-wide request in usb_dev.c We have upcoming ones not related to the E1 interface, so really it make more sense to not have those in usb_e1.c Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com> Change-Id: I686916bb2b2cb90e94ac9c595deab19f189fcd49 --- M firmware/ice40-riscv/icE1usb/Makefile M firmware/ice40-riscv/icE1usb/fw_app.c A firmware/ice40-riscv/icE1usb/usb_dev.c A firmware/ice40-riscv/icE1usb/usb_dev.h M firmware/ice40-riscv/icE1usb/usb_e1.c 5 files changed, 67 insertions(+), 38 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/09/26909/1 diff --git a/firmware/ice40-riscv/icE1usb/Makefile b/firmware/ice40-riscv/icE1usb/Makefile index 0022bd9..1240a9f 100644 --- a/firmware/ice40-riscv/icE1usb/Makefile +++ b/firmware/ice40-riscv/icE1usb/Makefile @@ -50,6 +50,7 @@ ice1usb_proto.h \ misc.h \ usb_desc_ids.h \ + usb_dev.h \ usb_e1.h \ usb_str_app.gen.h \ $(NULL) @@ -59,6 +60,7 @@ fw_app.c \ misc.c \ usb_desc_app.c \ + usb_dev.c \ usb_e1.c \ $(NULL) diff --git a/firmware/ice40-riscv/icE1usb/fw_app.c b/firmware/ice40-riscv/icE1usb/fw_app.c index 3fbec7c..41ef3ab 100644 --- a/firmware/ice40-riscv/icE1usb/fw_app.c +++ b/firmware/ice40-riscv/icE1usb/fw_app.c @@ -18,6 +18,7 @@ #include "misc.h" #include "mini-printf.h" #include "spi.h" +#include "usb_dev.h" #include "usb_e1.h" #include "utils.h" @@ -97,6 +98,7 @@ /* Enable USB directly */ usb_init(&app_stack_desc); + usb_dev_init(); usb_dfu_rt_init(); usb_e1_init(); diff --git a/firmware/ice40-riscv/icE1usb/usb_dev.c b/firmware/ice40-riscv/icE1usb/usb_dev.c new file mode 100644 index 0000000..1187047 --- /dev/null +++ b/firmware/ice40-riscv/icE1usb/usb_dev.c @@ -0,0 +1,48 @@ +/* + * usb_dev.c + * + * Copyright (C) 2019-2022 Sylvain Munaut <tnt(a)246tNt.com> + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include <stdint.h> + +#include <no2usb/usb.h> +#include <no2usb/usb_proto.h> + +#include "console.h" +#include "misc.h" + +#include "ice1usb_proto.h" + + +static enum usb_fnd_resp +_usb_dev_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer) +{ + /* Check it's a device-wide vendor request */ + if (USB_REQ_TYPE_RCPT(req) != (USB_REQ_TYPE_VENDOR | USB_REQ_RCPT_DEV)) + return USB_FND_CONTINUE; + + /* Dispatch / Handle */ + switch (req->bRequest) { + case ICE1USB_DEV_GET_CAPABILITIES: + xfer->data[0] = (1 << ICE1USB_DEV_CAP_GPSDO); + xfer->len = 1; + break; + default: + return USB_FND_ERROR; + } + + return USB_FND_SUCCESS; +} + + +static struct usb_fn_drv _dev_drv = { + .ctrl_req = _usb_dev_ctrl_req, +}; + +void +usb_dev_init(void) +{ + usb_register_function_driver(&_dev_drv); +} diff --git a/firmware/ice40-riscv/icE1usb/usb_dev.h b/firmware/ice40-riscv/icE1usb/usb_dev.h new file mode 100644 index 0000000..ca32a46 --- /dev/null +++ b/firmware/ice40-riscv/icE1usb/usb_dev.h @@ -0,0 +1,10 @@ +/* + * usb_dev.h + * + * Copyright (C) 2019-2022 Sylvain Munaut <tnt(a)246tNt.com> + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +void usb_dev_init(void); diff --git a/firmware/ice40-riscv/icE1usb/usb_e1.c b/firmware/ice40-riscv/icE1usb/usb_e1.c index 5d32924..6d0d3cf 100644 --- a/firmware/ice40-riscv/icE1usb/usb_e1.c +++ b/firmware/ice40-riscv/icE1usb/usb_e1.c @@ -371,13 +371,16 @@ return true; } -/* per-interface requests */ static enum usb_fnd_resp -_e1_ctrl_req_intf(struct usb_ctrl_req *req, struct usb_xfer *xfer) +_e1_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer) { struct usb_e1_state *usb_e1; int port; + /* Check it's for an E1 interface */ + if (USB_REQ_TYPE_RCPT(req) != (USB_REQ_TYPE_VENDOR | USB_REQ_RCPT_INTF)) + return USB_FND_CONTINUE; + /* Get matching port (if any) */ port = _ifnum2port(req->wIndex); if (port < 0) @@ -424,42 +427,6 @@ return USB_FND_SUCCESS; } -/* device-global requests */ -static enum usb_fnd_resp -_e1_ctrl_req_dev(struct usb_ctrl_req *req, struct usb_xfer *xfer) -{ - switch (req->bRequest) { - case ICE1USB_DEV_GET_CAPABILITIES: - xfer->data[0] = (1 << ICE1USB_DEV_CAP_GPSDO); - xfer->len = 1; - break; - default: - return USB_FND_ERROR; - } - - return USB_FND_SUCCESS; -} - - -/* USB host issues a control request to us */ -static enum usb_fnd_resp -_e1_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer) -{ - if (USB_REQ_TYPE(req) != USB_REQ_TYPE_VENDOR) - return USB_FND_CONTINUE; - - switch (USB_REQ_RCPT(req)) { - case USB_REQ_RCPT_DEV: - return _e1_ctrl_req_dev(req, xfer); - case USB_REQ_RCPT_INTF: - return _e1_ctrl_req_intf(req, xfer); - case USB_REQ_RCPT_EP: - case USB_REQ_RCPT_OTHER: - default: - return USB_FND_ERROR; - } -} - static struct usb_fn_drv _e1_drv = { .set_conf = _e1_set_conf, -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26909 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: I686916bb2b2cb90e94ac9c595deab19f189fcd49 Gerrit-Change-Number: 26909 Gerrit-PatchSet: 1 Gerrit-Owner: tnt <tnt(a)246tNt.com> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
2 3
0 0
Change in osmo-e1-hardware[master]: icE1usb fw: Add support for the ICE1USB_DEV_GET_FW_BUILD control request
by tnt 15 Jan '22

15 Jan '22
tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26910 ) Change subject: icE1usb fw: Add support for the ICE1USB_DEV_GET_FW_BUILD control request ...................................................................... icE1usb fw: Add support for the ICE1USB_DEV_GET_FW_BUILD control request This was already defined but not implemented Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com> Change-Id: Id65734153c92ef87bc9ecf967447e9bf11804f24 --- M firmware/ice40-riscv/icE1usb/Makefile M firmware/ice40-riscv/icE1usb/fw_app.c M firmware/ice40-riscv/icE1usb/usb_dev.c M firmware/ice40-riscv/icE1usb/usb_dev.h 4 files changed, 13 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/10/26910/1 diff --git a/firmware/ice40-riscv/icE1usb/Makefile b/firmware/ice40-riscv/icE1usb/Makefile index 1240a9f..36fd921 100644 --- a/firmware/ice40-riscv/icE1usb/Makefile +++ b/firmware/ice40-riscv/icE1usb/Makefile @@ -10,11 +10,12 @@ DFU_UTIL = dfu-util TAG_PREFIX = icE1usb-fw -GITVER = $(shell git describe --match '$(TAG_PREFIX)*') +GITVER = $(shell git describe --match '$(TAG_PREFIX)*' --dirty) TARGET = $(GITVER) BOARD_DEFINE=BOARD_$(shell echo $(BOARD) | tr a-z\- A-Z_) 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)\"" NO2USB_FW_VERSION=0 include ../../../gateware/cores/no2usb/fw/fw.mk diff --git a/firmware/ice40-riscv/icE1usb/fw_app.c b/firmware/ice40-riscv/icE1usb/fw_app.c index 41ef3ab..880d2d6 100644 --- a/firmware/ice40-riscv/icE1usb/fw_app.c +++ b/firmware/ice40-riscv/icE1usb/fw_app.c @@ -69,7 +69,7 @@ /* Init console IO */ console_init(); - puts("Booting App image..\n"); + printf("\n\nBooting %s\n", fw_build_str); /* LED */ led_init(); diff --git a/firmware/ice40-riscv/icE1usb/usb_dev.c b/firmware/ice40-riscv/icE1usb/usb_dev.c index 1187047..e19d9a0 100644 --- a/firmware/ice40-riscv/icE1usb/usb_dev.c +++ b/firmware/ice40-riscv/icE1usb/usb_dev.c @@ -6,6 +6,7 @@ */ #include <stdint.h> +#include <string.h> #include <no2usb/usb.h> #include <no2usb/usb_proto.h> @@ -16,6 +17,9 @@ #include "ice1usb_proto.h" +const char *fw_build_str = BUILD_INFO; + + static enum usb_fnd_resp _usb_dev_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer) { @@ -29,6 +33,10 @@ xfer->data[0] = (1 << ICE1USB_DEV_CAP_GPSDO); xfer->len = 1; break; + case ICE1USB_DEV_GET_FW_BUILD: + xfer->data = (void*) fw_build_str; + xfer->len = strlen(fw_build_str); + break; default: return USB_FND_ERROR; } diff --git a/firmware/ice40-riscv/icE1usb/usb_dev.h b/firmware/ice40-riscv/icE1usb/usb_dev.h index ca32a46..b2c4855 100644 --- a/firmware/ice40-riscv/icE1usb/usb_dev.h +++ b/firmware/ice40-riscv/icE1usb/usb_dev.h @@ -7,4 +7,6 @@ #pragma once +extern const char *fw_build_str; + void usb_dev_init(void); -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26910 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: Id65734153c92ef87bc9ecf967447e9bf11804f24 Gerrit-Change-Number: 26910 Gerrit-PatchSet: 1 Gerrit-Owner: tnt <tnt(a)246tNt.com> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
2 3
0 0
  • ← Newer
  • 1
  • ...
  • 9689
  • 9690
  • 9691
  • 9692
  • 9693
  • 9694
  • 9695
  • ...
  • 9721
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.