blob: 8cf8439404816b50c8484e487255917847c1e99e [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
Sylvain Munaut09dc0372022-10-05 12:39:54 +020023/*! performs an I2C register access (read/write depends on direction) */
24#define ICE1USB_DEV_I2C_REG_ACCESS 0x10
25
26
Harald Welte9469e042020-12-15 23:09:40 +010027enum e1usb_dev_capability {
28 /*! Does this board have a GPS-DO */
29 ICE1USB_DEV_CAP_GPSDO,
30};
31
Harald Weltecac342a2022-01-30 20:41:12 +010032/***********************************************************************
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 Munautc3083342022-01-13 00:50:10 +010042enum ice1usb_gpsdo_mode {
43 ICE1USB_GPSDO_MODE_DISABLED = 0,
44 ICE1USB_GPSDO_MODE_AUTO = 1,
45};
46
47enum 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
54enum 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
62struct e1usb_gpsdo_tune {
63 uint16_t coarse;
64 uint16_t fine;
65} __attribute__((packed));
66
67struct e1usb_gpsdo_status {
68 uint8_t state;
Harald Weltecac342a2022-01-30 20:41:12 +010069 uint8_t antenna_state; /*!< Antenna state */
Sylvain Munautc3083342022-01-13 00:50:10 +010070 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 Munautcfb8b0b2022-10-04 13:54:49 +020074 int16_t err_acc; /*!< Accumulated error */
Sylvain Munautc3083342022-01-13 00:50:10 +010075} __attribute__((packed));
76
Harald Welte9469e042020-12-15 23:09:40 +010077
Harald Weltecac342a2022-01-30 20:41:12 +010078/***********************************************************************
79 * Control Endpoint / E1 Interface Requests
80 ***********************************************************************/
Harald Welte9469e042020-12-15 23:09:40 +010081
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 Welte1b89f3b2022-01-13 10:03:42 +010088#define ICE1USB_INTF_GET_ERRORS 0x06 /*!< struct ice1usb_irq_err */
Harald Welte9469e042020-12-15 23:09:40 +010089
90//enum e1usb_intf_capability { };
91
92enum 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
99enum ice1usb_tx_timing {
100 ICE1USB_TX_TIME_SRC_LOCAL = 0,
101 ICE1USB_TX_TIME_SRC_REMOTE = 1,
102};
103
104enum 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 */
111struct 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
119enum 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 */
129struct ice1usb_rx_config {
130 uint8_t mode; /*!< enum ice1usb_rx_mode */
131} __attribute__((packed));
Harald Welte805f2cf2020-12-14 17:31:03 +0100132
133
134/***********************************************************************
135 * Interrupt Endpoint
136 ***********************************************************************/
137
138enum ice1usb_irq_type {
139 ICE1USB_IRQ_T_ERRCNT = 1,
140};
141
Harald Welte51baa362022-01-01 15:22:25 +0100142/* Ensue to keep those in sync with e1.h */
Harald Welte805f2cf2020-12-14 17:31:03 +0100143#define ICE1USB_ERR_F_ALIGN_ERR 0x01
144#define ICE1USB_ERR_F_LOS 0x02
Harald Welte51baa362022-01-01 15:22:25 +0100145#define ICE1USB_ERR_F_RAI 0x04
Harald Welte805f2cf2020-12-14 17:31:03 +0100146
147struct 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
156struct ice1usb_irq {
157 uint8_t type; /*!< enum ice1usb_irq_type */
158 union {
159 struct ice1usb_irq_err errors;
160 } u;
161} __attribute__((packed));