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 | |
| 26 | |
| 27 | /* Interface Requests */ |
| 28 | |
| 29 | /*! returns a bit-mask of optional device capabilities (see enum e1usb_intf_capability) */ |
| 30 | #define ICE1USB_INTF_GET_CAPABILITIES 0x01 |
| 31 | #define ICE1USB_INTF_SET_TX_CFG 0x02 /*!< struct ice1usb_tx_config */ |
| 32 | #define ICE1USB_INTF_GET_TX_CFG 0x03 /*!< struct ice1usb_tx_config */ |
| 33 | #define ICE1USB_INTF_SET_RX_CFG 0x04 /*!< struct ice1usb_rx_config */ |
| 34 | #define ICE1USB_INTF_GET_RX_CFG 0x05 /*!< struct ice1usb_rx_config */ |
| 35 | |
| 36 | //enum e1usb_intf_capability { }; |
| 37 | |
| 38 | enum ice1usb_tx_mode { |
| 39 | ICE1USB_TX_MODE_TRANSP = 0, |
| 40 | ICE1USB_TX_MODE_TS0 = 1, |
| 41 | ICE1USB_TX_MODE_TS0_CRC4 = 2, |
| 42 | ICE1USB_TX_MODE_TS0_CRC4_E = 3, |
| 43 | }; |
| 44 | |
| 45 | enum ice1usb_tx_timing { |
| 46 | ICE1USB_TX_TIME_SRC_LOCAL = 0, |
| 47 | ICE1USB_TX_TIME_SRC_REMOTE = 1, |
| 48 | }; |
| 49 | |
| 50 | enum ice1usb_tx_ext_loopback { |
| 51 | ICE1USB_TX_EXT_LOOPBACK_OFF = 0, |
| 52 | ICE1USB_TX_EXT_LOOPBACK_SAME = 1, |
| 53 | ICE1USB_TX_EXT_LOOPBACK_CROSS = 2, |
| 54 | }; |
| 55 | |
| 56 | /* ICE1USB_INTF_{GET,SET}_TX_CFG */ |
| 57 | struct ice1usb_tx_config { |
| 58 | uint8_t mode; /*!< enum ice1usb_tx_mode */ |
| 59 | uint8_t timing; /*!< enum ice1usb_tx_timing */ |
| 60 | uint8_t ext_loopback; /*!< enum ice1usb_tx_ext_loopback */ |
| 61 | uint8_t alarm; /*!< 1 = transmit alarm; 0 = don't */ |
| 62 | } __attribute__((packed)); |
| 63 | |
| 64 | |
| 65 | enum ice1usb_rx_mode { |
| 66 | /*! transparent, unaligned bitstream */ |
| 67 | ICE1USB_RX_MODE_TRANSP = 0, |
| 68 | /*! alignment to E1 frame */ |
| 69 | ICE1USB_RX_MODE_FRAME = 2, |
| 70 | /*! alignment to E1 multiframe */ |
| 71 | ICE1USB_RX_MODE_MULTIFRAME = 3, |
| 72 | }; |
| 73 | |
| 74 | /* ICE1USB_INTF_{GET,SET}_RX_CFG */ |
| 75 | struct ice1usb_rx_config { |
| 76 | uint8_t mode; /*!< enum ice1usb_rx_mode */ |
| 77 | } __attribute__((packed)); |
Harald Welte | 805f2cf | 2020-12-14 17:31:03 +0100 | [diff] [blame] | 78 | |
| 79 | |
| 80 | /*********************************************************************** |
| 81 | * Interrupt Endpoint |
| 82 | ***********************************************************************/ |
| 83 | |
| 84 | enum ice1usb_irq_type { |
| 85 | ICE1USB_IRQ_T_ERRCNT = 1, |
| 86 | }; |
| 87 | |
Harald Welte | 51baa36 | 2022-01-01 15:22:25 +0100 | [diff] [blame] | 88 | /* Ensue to keep those in sync with e1.h */ |
Harald Welte | 805f2cf | 2020-12-14 17:31:03 +0100 | [diff] [blame] | 89 | #define ICE1USB_ERR_F_ALIGN_ERR 0x01 |
| 90 | #define ICE1USB_ERR_F_LOS 0x02 |
Harald Welte | 51baa36 | 2022-01-01 15:22:25 +0100 | [diff] [blame] | 91 | #define ICE1USB_ERR_F_RAI 0x04 |
Harald Welte | 805f2cf | 2020-12-14 17:31:03 +0100 | [diff] [blame] | 92 | |
| 93 | struct ice1usb_irq_err { |
| 94 | /* 16-bit little-endian counters */ |
| 95 | uint16_t crc; |
| 96 | uint16_t align; |
| 97 | uint16_t ovfl; |
| 98 | uint16_t unfl; |
| 99 | uint8_t flags; |
| 100 | } __attribute__((packed)); |
| 101 | |
| 102 | struct ice1usb_irq { |
| 103 | uint8_t type; /*!< enum ice1usb_irq_type */ |
| 104 | union { |
| 105 | struct ice1usb_irq_err errors; |
| 106 | } u; |
| 107 | } __attribute__((packed)); |