Harald Welte | 9469e04 | 2020-12-15 23:09:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ice1usb_proto.h |
| 3 | * |
| 4 | * Copyright (C) 2020 Harald Welte <laforge@osmocom.org> |
| 5 | * SPDX-License-Identifier: MIT |
| 6 | * |
| 7 | * Header file describing the USB protocol between the icE1usb firmware and the host |
| 8 | * software (currently really only osmo-e1d) |
| 9 | */ |
| 10 | |
| 11 | #pragma once |
| 12 | |
| 13 | /*********************************************************************** |
| 14 | * Control Endpoint / Device Requests |
| 15 | ***********************************************************************/ |
| 16 | |
| 17 | /*! returns a bit-mask of optional device capabilities (see enum e1usb_dev_capability) */ |
| 18 | #define ICE1USB_DEV_GET_CAPABILITIES 0x01 |
Sylvain Munaut | 321b1c8 | 2022-10-05 12:37:34 +0200 | [diff] [blame] | 19 | |
| 20 | /*! returns a string describing the firmware version */ |
Harald Welte | 9469e04 | 2020-12-15 23:09:40 +0100 | [diff] [blame] | 21 | #define ICE1USB_DEV_GET_FW_BUILD 0x02 |
| 22 | |
Sylvain Munaut | 0036b1f | 2022-10-05 12:39:54 +0200 | [diff] [blame^] | 23 | /*! performs an I2C register access (read/write depends on direction) */ |
| 24 | #define ICE1USB_DEV_I2C_REG_ACCESS 0x10 |
| 25 | |
| 26 | |
Harald Welte | 9469e04 | 2020-12-15 23:09:40 +0100 | [diff] [blame] | 27 | enum e1usb_dev_capability { |
| 28 | /*! Does this board have a GPS-DO */ |
| 29 | ICE1USB_DEV_CAP_GPSDO, |
| 30 | }; |
| 31 | |
Harald Welte | cac342a | 2022-01-30 20:41:12 +0100 | [diff] [blame] | 32 | /*********************************************************************** |
| 33 | * Control Endpoint / GPS-DO Interface Requests |
| 34 | ***********************************************************************/ |
| 35 | |
| 36 | #define ICE1USB_INTF_GET_GPSDO_STATUS 0x10 |
| 37 | #define ICE1USB_INTF_GET_GPSDO_MODE 0x12 /*!< uint8_t */ |
| 38 | #define ICE1USB_INTF_SET_GPSDO_MODE 0x13 /*!< wValue = mode */ |
| 39 | #define ICE1USB_INTF_GET_GPSDO_TUNE 0x14 /*!< data = struct e1usb_gpsdo_tune */ |
| 40 | #define ICE1USB_INTF_SET_GPSDO_TUNE 0x15 /*!< data = struct e1usb_gpsdo_tune */ |
| 41 | |
Sylvain Munaut | c308334 | 2022-01-13 00:50:10 +0100 | [diff] [blame] | 42 | enum ice1usb_gpsdo_mode { |
| 43 | ICE1USB_GPSDO_MODE_DISABLED = 0, |
| 44 | ICE1USB_GPSDO_MODE_AUTO = 1, |
| 45 | }; |
| 46 | |
| 47 | enum ice1usb_gpsdo_antenna_state { |
| 48 | ICE1USB_GPSDO_ANT_UNKNOWN = 0, |
| 49 | ICE1USB_GPSDO_ANT_OK = 1, |
| 50 | ICE1USB_GPSDO_ANT_OPEN = 2, |
| 51 | ICE1USB_GPSDO_ANT_SHORT = 3, |
| 52 | }; |
| 53 | |
| 54 | enum ice1usb_gpsdo_state { |
| 55 | ICE1USB_GPSDO_STATE_DISABLED = 0, |
| 56 | ICE1USB_GPSDO_STATE_CALIBRATE = 1, |
| 57 | ICE1USB_GPSDO_STATE_HOLD_OVER = 2, |
| 58 | ICE1USB_GPSDO_STATE_TUNE_COARSE = 3, |
| 59 | ICE1USB_GPSDO_STATE_TUNE_FINE = 4, |
| 60 | }; |
| 61 | |
| 62 | struct e1usb_gpsdo_tune { |
| 63 | uint16_t coarse; |
| 64 | uint16_t fine; |
| 65 | } __attribute__((packed)); |
| 66 | |
| 67 | struct e1usb_gpsdo_status { |
| 68 | uint8_t state; |
Harald Welte | cac342a | 2022-01-30 20:41:12 +0100 | [diff] [blame] | 69 | uint8_t antenna_state; /*!< Antenna state */ |
Sylvain Munaut | c308334 | 2022-01-13 00:50:10 +0100 | [diff] [blame] | 70 | uint8_t valid_fix; /*!< Valid GPS Fix (0/1) */ |
| 71 | uint8_t mode; /*!< Current configured operating mode */ |
| 72 | struct e1usb_gpsdo_tune tune; /*!< Current VCXO tuning values */ |
| 73 | uint32_t freq_est; /*!< Latest frequency estimate measurement */ |
Sylvain Munaut | cfb8b0b | 2022-10-04 13:54:49 +0200 | [diff] [blame] | 74 | int16_t err_acc; /*!< Accumulated error */ |
Sylvain Munaut | c308334 | 2022-01-13 00:50:10 +0100 | [diff] [blame] | 75 | } __attribute__((packed)); |
| 76 | |
Harald Welte | 9469e04 | 2020-12-15 23:09:40 +0100 | [diff] [blame] | 77 | |
Harald Welte | cac342a | 2022-01-30 20:41:12 +0100 | [diff] [blame] | 78 | /*********************************************************************** |
| 79 | * Control Endpoint / E1 Interface Requests |
| 80 | ***********************************************************************/ |
Harald Welte | 9469e04 | 2020-12-15 23:09:40 +0100 | [diff] [blame] | 81 | |
| 82 | /*! returns a bit-mask of optional device capabilities (see enum e1usb_intf_capability) */ |
| 83 | #define ICE1USB_INTF_GET_CAPABILITIES 0x01 |
| 84 | #define ICE1USB_INTF_SET_TX_CFG 0x02 /*!< struct ice1usb_tx_config */ |
| 85 | #define ICE1USB_INTF_GET_TX_CFG 0x03 /*!< struct ice1usb_tx_config */ |
| 86 | #define ICE1USB_INTF_SET_RX_CFG 0x04 /*!< struct ice1usb_rx_config */ |
| 87 | #define ICE1USB_INTF_GET_RX_CFG 0x05 /*!< struct ice1usb_rx_config */ |
Harald Welte | 1b89f3b | 2022-01-13 10:03:42 +0100 | [diff] [blame] | 88 | #define ICE1USB_INTF_GET_ERRORS 0x06 /*!< struct ice1usb_irq_err */ |
Harald Welte | 9469e04 | 2020-12-15 23:09:40 +0100 | [diff] [blame] | 89 | |
| 90 | //enum e1usb_intf_capability { }; |
| 91 | |
| 92 | enum ice1usb_tx_mode { |
| 93 | ICE1USB_TX_MODE_TRANSP = 0, |
| 94 | ICE1USB_TX_MODE_TS0 = 1, |
| 95 | ICE1USB_TX_MODE_TS0_CRC4 = 2, |
| 96 | ICE1USB_TX_MODE_TS0_CRC4_E = 3, |
| 97 | }; |
| 98 | |
| 99 | enum ice1usb_tx_timing { |
| 100 | ICE1USB_TX_TIME_SRC_LOCAL = 0, |
| 101 | ICE1USB_TX_TIME_SRC_REMOTE = 1, |
| 102 | }; |
| 103 | |
| 104 | enum ice1usb_tx_ext_loopback { |
| 105 | ICE1USB_TX_EXT_LOOPBACK_OFF = 0, |
| 106 | ICE1USB_TX_EXT_LOOPBACK_SAME = 1, |
| 107 | ICE1USB_TX_EXT_LOOPBACK_CROSS = 2, |
| 108 | }; |
| 109 | |
| 110 | /* ICE1USB_INTF_{GET,SET}_TX_CFG */ |
| 111 | struct ice1usb_tx_config { |
| 112 | uint8_t mode; /*!< enum ice1usb_tx_mode */ |
| 113 | uint8_t timing; /*!< enum ice1usb_tx_timing */ |
| 114 | uint8_t ext_loopback; /*!< enum ice1usb_tx_ext_loopback */ |
| 115 | uint8_t alarm; /*!< 1 = transmit alarm; 0 = don't */ |
| 116 | } __attribute__((packed)); |
| 117 | |
| 118 | |
| 119 | enum ice1usb_rx_mode { |
| 120 | /*! transparent, unaligned bitstream */ |
| 121 | ICE1USB_RX_MODE_TRANSP = 0, |
| 122 | /*! alignment to E1 frame */ |
| 123 | ICE1USB_RX_MODE_FRAME = 2, |
| 124 | /*! alignment to E1 multiframe */ |
| 125 | ICE1USB_RX_MODE_MULTIFRAME = 3, |
| 126 | }; |
| 127 | |
| 128 | /* ICE1USB_INTF_{GET,SET}_RX_CFG */ |
| 129 | struct ice1usb_rx_config { |
| 130 | uint8_t mode; /*!< enum ice1usb_rx_mode */ |
| 131 | } __attribute__((packed)); |
Harald Welte | 805f2cf | 2020-12-14 17:31:03 +0100 | [diff] [blame] | 132 | |
| 133 | |
| 134 | /*********************************************************************** |
| 135 | * Interrupt Endpoint |
| 136 | ***********************************************************************/ |
| 137 | |
| 138 | enum ice1usb_irq_type { |
| 139 | ICE1USB_IRQ_T_ERRCNT = 1, |
| 140 | }; |
| 141 | |
Harald Welte | 51baa36 | 2022-01-01 15:22:25 +0100 | [diff] [blame] | 142 | /* Ensue to keep those in sync with e1.h */ |
Harald Welte | 805f2cf | 2020-12-14 17:31:03 +0100 | [diff] [blame] | 143 | #define ICE1USB_ERR_F_ALIGN_ERR 0x01 |
| 144 | #define ICE1USB_ERR_F_LOS 0x02 |
Harald Welte | 51baa36 | 2022-01-01 15:22:25 +0100 | [diff] [blame] | 145 | #define ICE1USB_ERR_F_RAI 0x04 |
Harald Welte | 805f2cf | 2020-12-14 17:31:03 +0100 | [diff] [blame] | 146 | |
| 147 | struct ice1usb_irq_err { |
| 148 | /* 16-bit little-endian counters */ |
| 149 | uint16_t crc; |
| 150 | uint16_t align; |
| 151 | uint16_t ovfl; |
| 152 | uint16_t unfl; |
| 153 | uint8_t flags; |
| 154 | } __attribute__((packed)); |
| 155 | |
| 156 | struct ice1usb_irq { |
| 157 | uint8_t type; /*!< enum ice1usb_irq_type */ |
| 158 | union { |
| 159 | struct ice1usb_irq_err errors; |
| 160 | } u; |
| 161 | } __attribute__((packed)); |