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