2013-10-18 20:14:27 -07:00
|
|
|
#include <app.h>
|
2019-06-17 18:28:51 -07:00
|
|
|
#include <lk/debug.h>
|
|
|
|
|
#include <lk/err.h>
|
2013-10-18 20:14:27 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
2019-06-17 18:28:51 -07:00
|
|
|
#include <lk/trace.h>
|
2013-10-18 20:14:27 -07:00
|
|
|
#include <dev/usb.h>
|
|
|
|
|
#include <dev/usbc.h>
|
|
|
|
|
#include <kernel/debug.h>
|
|
|
|
|
#include <kernel/thread.h>
|
|
|
|
|
#include <kernel/event.h>
|
|
|
|
|
|
|
|
|
|
#define LOCAL_TRACE 1
|
|
|
|
|
|
|
|
|
|
extern void usbtest_usb_setup(void);
|
|
|
|
|
|
|
|
|
|
static status_t rx_callback(ep_t endpoint, struct usbc_transfer *transfer);
|
|
|
|
|
static usbc_transfer_t rx;
|
|
|
|
|
static uint8_t rxbuf[4096];
|
|
|
|
|
static volatile bool rxqueued;
|
|
|
|
|
|
|
|
|
|
static status_t tx_callback(ep_t endpoint, struct usbc_transfer *transfer);
|
|
|
|
|
static usbc_transfer_t tx;
|
|
|
|
|
static uint8_t txbuf[4095];
|
|
|
|
|
static volatile bool txqueued;
|
|
|
|
|
|
|
|
|
|
static event_t testevent;
|
|
|
|
|
|
|
|
|
|
/* RX */
|
2019-06-19 20:54:28 -07:00
|
|
|
static void queue_rx_transfer(void) {
|
2013-10-18 20:14:27 -07:00
|
|
|
rx.callback = rx_callback;
|
|
|
|
|
rx.result = 0;
|
|
|
|
|
rx.buf = rxbuf;
|
|
|
|
|
rx.buflen = sizeof(rxbuf);
|
|
|
|
|
rx.bufpos = 0;
|
|
|
|
|
rx.extra = NULL;
|
|
|
|
|
|
|
|
|
|
memset(rxbuf, 0x99, sizeof(rxbuf));
|
|
|
|
|
|
|
|
|
|
rxqueued = true;
|
|
|
|
|
usbc_queue_rx(1, &rx);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 20:54:28 -07:00
|
|
|
static status_t rx_callback(ep_t endpoint, struct usbc_transfer *transfer) {
|
2013-10-18 20:14:27 -07:00
|
|
|
LTRACEF("ep %u, transfer %p\n", endpoint, transfer);
|
|
|
|
|
|
|
|
|
|
rxqueued = false;
|
|
|
|
|
event_signal(&testevent, false);
|
|
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TX */
|
2019-06-19 20:54:28 -07:00
|
|
|
static void queue_tx_transfer(void) {
|
2013-10-18 20:14:27 -07:00
|
|
|
tx.callback = tx_callback;
|
|
|
|
|
tx.result = 0;
|
|
|
|
|
tx.buf = txbuf;
|
|
|
|
|
tx.buflen = sizeof(txbuf);
|
|
|
|
|
tx.bufpos = 0;
|
|
|
|
|
tx.extra = NULL;
|
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < sizeof(txbuf); i++)
|
|
|
|
|
txbuf[i] = i * 3;
|
|
|
|
|
|
|
|
|
|
txqueued = true;
|
|
|
|
|
usbc_queue_tx(1, &tx);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 20:54:28 -07:00
|
|
|
static status_t tx_callback(ep_t endpoint, struct usbc_transfer *transfer) {
|
2013-10-18 20:14:27 -07:00
|
|
|
LTRACEF("ep %u, transfer %p\n", endpoint, transfer);
|
|
|
|
|
|
|
|
|
|
txqueued = false;
|
|
|
|
|
event_signal(&testevent, false);
|
|
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 20:54:28 -07:00
|
|
|
static void usbtest_init(const struct app_descriptor *app) {
|
2013-10-18 20:14:27 -07:00
|
|
|
LTRACE_ENTRY;
|
|
|
|
|
event_init(&testevent, false, EVENT_FLAG_AUTOUNSIGNAL);
|
|
|
|
|
usbtest_usb_setup();
|
|
|
|
|
LTRACE_EXIT;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 20:54:28 -07:00
|
|
|
static void usbtest_entry(const struct app_descriptor *app, void *args) {
|
2013-10-18 20:14:27 -07:00
|
|
|
LTRACE_ENTRY;
|
|
|
|
|
|
|
|
|
|
TRACEF("starting usb stack\n");
|
|
|
|
|
usb_start();
|
|
|
|
|
|
|
|
|
|
// XXX get callback from stack
|
|
|
|
|
thread_sleep(2000);
|
|
|
|
|
|
|
|
|
|
TRACEF("queuing transfers\n");
|
|
|
|
|
queue_rx_transfer();
|
|
|
|
|
queue_tx_transfer();
|
|
|
|
|
|
|
|
|
|
while (event_wait(&testevent) == NO_ERROR) {
|
|
|
|
|
if (!rxqueued) {
|
|
|
|
|
/* dump the state of the transfer */
|
|
|
|
|
LTRACEF("rx transfer completed\n");
|
|
|
|
|
usbc_dump_transfer(&rx);
|
|
|
|
|
hexdump8(rx.buf, MIN(128, rx.bufpos));
|
|
|
|
|
|
|
|
|
|
queue_rx_transfer();
|
|
|
|
|
}
|
|
|
|
|
if (!txqueued) {
|
|
|
|
|
/* dump the state of the transfer */
|
|
|
|
|
LTRACEF("tx transfer completed\n");
|
|
|
|
|
usbc_dump_transfer(&tx);
|
|
|
|
|
|
|
|
|
|
queue_tx_transfer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LTRACE_EXIT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APP_START(usbtest)
|
2016-02-14 12:24:01 -08:00
|
|
|
.init = usbtest_init,
|
2019-06-19 20:54:28 -07:00
|
|
|
.entry = usbtest_entry,
|
|
|
|
|
APP_END
|
2013-10-18 20:14:27 -07:00
|
|
|
|
|
|
|
|
|