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 -----
  • 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

January 2022

  • 3 participants
  • 781 discussions
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
Change in osmo-e1-hardware[master]: icE1usb fw: Add access functions for the 'time' hardware
by tnt 15 Jan '22

15 Jan '22
tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26908 ) Change subject: icE1usb fw: Add access functions for the 'time' hardware ...................................................................... icE1usb fw: Add access functions for the 'time' hardware The hardware has a tick counter (constantly incremented every cycle) and a pps counter (which is the tick counter captured at the pps edge). Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com> Change-Id: I2122ea3d636c8a430c6eb945b0c11e26e02fee43 --- M firmware/ice40-riscv/icE1usb/misc.c M firmware/ice40-riscv/icE1usb/misc.h 2 files changed, 33 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/08/26908/1 diff --git a/firmware/ice40-riscv/icE1usb/misc.c b/firmware/ice40-riscv/icE1usb/misc.c index 50aec43..b8419aa 100644 --- a/firmware/ice40-riscv/icE1usb/misc.c +++ b/firmware/ice40-riscv/icE1usb/misc.c @@ -122,6 +122,34 @@ return misc_regs->e1_tick[port].tx; } + +bool +time_elapsed(uint32_t ref, unsigned int tick) +{ + return ((misc_regs->time.now - ref) & 0x7fffffff) >= tick; +} + +void +delay(unsigned int ms) +{ + uint32_t ref = misc_regs->time.now; + ms *= SYS_CLK_FREQ / 1000; + while (!time_elapsed(ref, ms)); +} + +uint32_t +time_pps_read(void) +{ + return misc_regs->time.pps; +} + +uint32_t +time_now_read(void) +{ + return misc_regs->time.now; +} + + void reboot(int fw) { diff --git a/firmware/ice40-riscv/icE1usb/misc.h b/firmware/ice40-riscv/icE1usb/misc.h index 76d5a7d..b72793f 100644 --- a/firmware/ice40-riscv/icE1usb/misc.h +++ b/firmware/ice40-riscv/icE1usb/misc.h @@ -36,4 +36,9 @@ uint16_t e1_tick_read(int port); +bool time_elapsed(uint32_t ref, unsigned int tick); +void delay(unsigned int ms); +uint32_t time_pps_read(void); +uint32_t time_now_read(void); + void reboot(int fw); -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26908 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: I2122ea3d636c8a430c6eb945b0c11e26e02fee43 Gerrit-Change-Number: 26908 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: Have usb_e1 handle the E1 polling and multi port
by tnt 15 Jan '22

15 Jan '22
tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26902 ) Change subject: icE1usb fw: Have usb_e1 handle the E1 polling and multi port ...................................................................... icE1usb fw: Have usb_e1 handle the E1 polling and multi port The init already takes care of both port and also calling e1_init, so it makes sense to have a usb_e1_poll() that encapsulate both the actual e1 hardware poll and running the usb stuff for both port. Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com> Change-Id: Icf81efcdc5c8f13480ba2652bc6e7c1ca226ae4d --- M firmware/ice40-riscv/icE1usb/fw_app.c M firmware/ice40-riscv/icE1usb/usb_e1.c M firmware/ice40-riscv/icE1usb/usb_e1.h 3 files changed, 14 insertions(+), 7 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/02/26902/1 diff --git a/firmware/ice40-riscv/icE1usb/fw_app.c b/firmware/ice40-riscv/icE1usb/fw_app.c index 5e9812c..3fbec7c 100644 --- a/firmware/ice40-riscv/icE1usb/fw_app.c +++ b/firmware/ice40-riscv/icE1usb/fw_app.c @@ -158,9 +158,6 @@ usb_poll(); /* E1 poll */ - for (int port=0; port<2; port++) { - e1_poll(port); - usb_e1_run(port); - } + usb_e1_poll(); } } diff --git a/firmware/ice40-riscv/icE1usb/usb_e1.c b/firmware/ice40-riscv/icE1usb/usb_e1.c index 96ca72a..5d32924 100644 --- a/firmware/ice40-riscv/icE1usb/usb_e1.c +++ b/firmware/ice40-riscv/icE1usb/usb_e1.c @@ -96,8 +96,8 @@ } -void -usb_e1_run(int port) +static void +_usb_e1_run(int port) { struct usb_e1_state *usb_e1 = _get_state(port); volatile struct usb_ep *ep_regs; @@ -210,6 +210,16 @@ _usb_fill_feedback_ep(port); } +void +usb_e1_poll(void) +{ + for (int i=0; i<2; i++) { + e1_poll(i); + _usb_e1_run(i); + } +} + + static enum usb_fnd_resp _e1_set_conf(const struct usb_conf_desc *conf) { diff --git a/firmware/ice40-riscv/icE1usb/usb_e1.h b/firmware/ice40-riscv/icE1usb/usb_e1.h index 06723ea..65ebb61 100644 --- a/firmware/ice40-riscv/icE1usb/usb_e1.h +++ b/firmware/ice40-riscv/icE1usb/usb_e1.h @@ -7,5 +7,5 @@ #pragma once -void usb_e1_run(int port); +void usb_e1_poll(void); void usb_e1_init(void); -- To view, visit https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26902 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: Icf81efcdc5c8f13480ba2652bc6e7c1ca226ae4d Gerrit-Change-Number: 26902 Gerrit-PatchSet: 1 Gerrit-Owner: tnt <tnt(a)246tNt.com> Gerrit-MessageType: newchange
2 2
0 0
  • ← Newer
  • 1
  • ...
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • ...
  • 79
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.