blob: 38cb23b25ac232797ca45e3630ab018fd0073534 [file] [log] [blame]
Harald Welte9469e042020-12-15 23:09:40 +01001/*
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
21enum e1usb_dev_capability {
22 /*! Does this board have a GPS-DO */
23 ICE1USB_DEV_CAP_GPSDO,
24};
25
Harald Weltecac342a2022-01-30 20:41:12 +010026/***********************************************************************
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 Munautc3083342022-01-13 00:50:10 +010036enum ice1usb_gpsdo_mode {
37 ICE1USB_GPSDO_MODE_DISABLED = 0,
38 ICE1USB_GPSDO_MODE_AUTO = 1,
39};
40
41enum 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
48enum 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
56struct e1usb_gpsdo_tune {
57 uint16_t coarse;
58 uint16_t fine;
59} __attribute__((packed));
60
61struct e1usb_gpsdo_status {
62 uint8_t state;
Harald Weltecac342a2022-01-30 20:41:12 +010063 uint8_t antenna_state; /*!< Antenna state */
Sylvain Munautc3083342022-01-13 00:50:10 +010064 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 Munautcfb8b0b2022-10-04 13:54:49 +020068 int16_t err_acc; /*!< Accumulated error */
Sylvain Munautc3083342022-01-13 00:50:10 +010069} __attribute__((packed));
70
Harald Welte9469e042020-12-15 23:09:40 +010071
Harald Weltecac342a2022-01-30 20:41:12 +010072/***********************************************************************
73 * Control Endpoint / E1 Interface Requests
74 ***********************************************************************/
Harald Welte9469e042020-12-15 23:09:40 +010075
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 Welte1b89f3b2022-01-13 10:03:42 +010082#define ICE1USB_INTF_GET_ERRORS 0x06 /*!< struct ice1usb_irq_err */
Harald Welte9469e042020-12-15 23:09:40 +010083
84//enum e1usb_intf_capability { };
85
86enum 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
93enum ice1usb_tx_timing {
94 ICE1USB_TX_TIME_SRC_LOCAL = 0,
95 ICE1USB_TX_TIME_SRC_REMOTE = 1,
96};
97
98enum 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 */
105struct 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
113enum 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 */
123struct ice1usb_rx_config {
124 uint8_t mode; /*!< enum ice1usb_rx_mode */
125} __attribute__((packed));
Harald Welte805f2cf2020-12-14 17:31:03 +0100126
127
128/***********************************************************************
129 * Interrupt Endpoint
130 ***********************************************************************/
131
132enum ice1usb_irq_type {
133 ICE1USB_IRQ_T_ERRCNT = 1,
134};
135
Harald Welte51baa362022-01-01 15:22:25 +0100136/* Ensue to keep those in sync with e1.h */
Harald Welte805f2cf2020-12-14 17:31:03 +0100137#define ICE1USB_ERR_F_ALIGN_ERR 0x01
138#define ICE1USB_ERR_F_LOS 0x02
Harald Welte51baa362022-01-01 15:22:25 +0100139#define ICE1USB_ERR_F_RAI 0x04
Harald Welte805f2cf2020-12-14 17:31:03 +0100140
141struct 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
150struct ice1usb_irq {
151 uint8_t type; /*!< enum ice1usb_irq_type */
152 union {
153 struct ice1usb_irq_err errors;
154 } u;
155} __attribute__((packed));