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