blob: e3abdb90f5b705000c7f97af138fece57bdd194f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/* SPDX-License-Identifier: GPL-2.0-only */
#include <console/usb.h>
#include "ehci_debug.h"
static void usbdebug_tx_byte(struct dbgp_pipe *pipe, unsigned char data)
{
if (!dbgp_try_get(pipe))
return;
pipe->buf[pipe->bufidx++] = data;
if (pipe->bufidx >= 8) {
dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx);
pipe->bufidx = 0;
}
dbgp_put(pipe);
}
static void usbdebug_tx_flush(struct dbgp_pipe *pipe)
{
if (!dbgp_try_get(pipe))
return;
if (pipe->bufidx > 0) {
dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx);
pipe->bufidx = 0;
}
dbgp_put(pipe);
}
static unsigned char usbdebug_rx_byte(struct dbgp_pipe *pipe)
{
unsigned char data = 0xff;
if (!dbgp_try_get(pipe))
return 0xff;
while (pipe->bufidx >= pipe->buflen) {
pipe->buflen = 0;
pipe->bufidx = 0;
int count = dbgp_bulk_read_x(pipe, pipe->buf, 8);
if (count>0)
pipe->buflen = count;
}
data = pipe->buf[pipe->bufidx++];
dbgp_put(pipe);
return data;
}
void usb_tx_byte(int idx, unsigned char data)
{
usbdebug_tx_byte(dbgp_console_output(), data);
}
void usb_tx_flush(int idx)
{
usbdebug_tx_flush(dbgp_console_output());
}
unsigned char usb_rx_byte(int idx)
{
return usbdebug_rx_byte(dbgp_console_input());
}
int usb_can_rx_byte(int idx)
{
return dbgp_ep_is_active(dbgp_console_input());
}
|