blob: 0ed43c46935499642c85e32814eab472462712e7 [file] [log] [blame]
Sylvain Munautbc9f5c42020-09-14 10:22:29 +02001/*
2 * e1.h
3 *
4 * Copyright (C) 2019-2020 Sylvain Munaut <tnt@246tNt.com>
5 * SPDX-License-Identifier: GPL-3.0-or-later
6 */
7
8#pragma once
9
Sylvain Munaut2c0c1362022-01-03 18:48:08 +010010
11/* control */
12
Sylvain Munaut3da51512022-01-03 22:12:59 +010013void e1_init(int port, uint16_t rx_cr, uint16_t tx_cr);
Sylvain Munaut0cc16132022-01-10 13:26:15 +010014void e1_start(int port);
15void e1_stop(int port);
16
Sylvain Munaut3da51512022-01-03 22:12:59 +010017void e1_poll(int port);
18void e1_debug_print(int port, bool data);
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020019
Sylvain Munaut3da51512022-01-03 22:12:59 +010020void e1_rx_config(int port, uint16_t cr);
Sylvain Munaut4fd71552022-01-10 12:28:28 +010021void e1_tx_config(int port, uint16_t cr);
Harald Welte6add0aa2020-12-16 00:02:11 +010022
Sylvain Munaut2c0c1362022-01-03 18:48:08 +010023
24/* data flow */
25
Sylvain Munaut3da51512022-01-03 22:12:59 +010026unsigned int e1_rx_need_data(int port, unsigned int usb_addr, unsigned int max_len, unsigned int *pos);
27unsigned int e1_tx_feed_data(int port, unsigned int usb_addr, unsigned int len);
Sylvain Munaut3da51512022-01-03 22:12:59 +010028unsigned int e1_rx_level(int port);
Sylvain Munaut4fd71552022-01-10 12:28:28 +010029unsigned int e1_tx_level(int port);
Sylvain Munaut2c0c1362022-01-03 18:48:08 +010030
31
32/* error reporting */
33
Harald Welte805f2cf2020-12-14 17:31:03 +010034#define E1_ERR_F_ALIGN_ERR 0x01
35#define E1_ERR_F_LOS 0x02
Harald Welte51baa362022-01-01 15:22:25 +010036#define E1_ERR_F_RAI 0x04
Harald Welte805f2cf2020-12-14 17:31:03 +010037
38struct e1_error_count {
39 uint16_t crc;
40 uint16_t align;
41 uint16_t ovfl;
42 uint16_t unfl;
43 uint8_t flags;
44};
45
Sylvain Munaut3da51512022-01-03 22:12:59 +010046const struct e1_error_count *e1_get_error_count(int port);
Harald Welte805f2cf2020-12-14 17:31:03 +010047
Sylvain Munaut2c0c1362022-01-03 18:48:08 +010048
49/* external function provided by the platform; used by E1 driver to control LEDs */
50
Harald Welte52765672020-12-15 18:35:42 +010051enum e1_platform_led {
52 E1P_LED_GREEN = 0,
53 E1P_LED_YELLOW = 1,
54};
55
56enum e1_platform_led_state {
57 E1P_LED_ST_OFF = 0,
58 E1P_LED_ST_ON = 1,
59 E1P_LED_ST_BLINK = 2,
60 E1P_LED_ST_BLINK_FAST = 3
61};
62
Sylvain Munaut8f31a9e2022-01-03 22:09:03 +010063extern void e1_platform_led_set(int port, enum e1_platform_led led,
Harald Welte52765672020-12-15 18:35:42 +010064 enum e1_platform_led_state state);