mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
usbdev_mock: Adapt to xmit API
Includes the adaptations needed in the test application
This commit is contained in:
parent
597f1d19aa
commit
f8e7e2f557
@ -43,7 +43,8 @@ typedef struct {
|
||||
usbdev_ep_t ep; /**< Generic endpoint struct */
|
||||
usbdev_mock_ep_state_t state; /**< Endpoint state */
|
||||
size_t available; /**< Bytes available in the buffer */
|
||||
uint8_t *buf_start; /**< Start location of the buffer */
|
||||
uint8_t *target_buf; /**< Buffer as passed by @ref usbdev_ep_xmit */
|
||||
uint8_t *buf; /**< Internal mock buffer pointer */
|
||||
} usbdev_mock_ep_t;
|
||||
|
||||
/**
|
||||
|
@ -75,16 +75,15 @@ usbdev_ep_t *_new_ep(usbdev_t *dev, usb_ep_type_t type, usb_ep_dir_t dir,
|
||||
|
||||
res = &testdev->out[0];
|
||||
res->ep.num = 0;
|
||||
res->ep.buf = _out_buf;
|
||||
res->buf = _out_buf;
|
||||
}
|
||||
else {
|
||||
res = &testdev->in[0];
|
||||
res->ep.num = 0;
|
||||
res->ep.buf = _in_buf;
|
||||
res->buf = _in_buf;
|
||||
}
|
||||
}
|
||||
if (res) {
|
||||
res->buf_start = res->ep.buf;
|
||||
res->state = EP_STATE_READY;
|
||||
res->available = 0;
|
||||
res->ep.len = buf_len;
|
||||
@ -190,26 +189,30 @@ void _ep_esr(usbdev_ep_t *ep)
|
||||
ep->num, ep->dir == USB_EP_DIR_OUT ? "out" : "in");
|
||||
usbdev_mock_ep_t *mock_ep = (usbdev_mock_ep_t *)ep;
|
||||
|
||||
if (mock_ep->ep.dir == USB_EP_DIR_OUT) {
|
||||
memcpy(mock_ep->target_buf, mock_ep->buf, mock_ep->available);
|
||||
}
|
||||
if (mock_ep->state == EP_STATE_DATA_AVAILABLE) {
|
||||
dev->ep_esr_cb(dev, mock_ep);
|
||||
mock_ep->state = EP_STATE_READY;
|
||||
}
|
||||
}
|
||||
|
||||
int _ready(usbdev_ep_t *ep, size_t len)
|
||||
int _xmit(usbdev_ep_t *ep, uint8_t *buf, size_t len)
|
||||
{
|
||||
DEBUG("[mock]: Readying EP %u, dir %s, len %u\n",
|
||||
ep->num, ep->dir == USB_EP_DIR_OUT ? "out" : "in", (unsigned)len);
|
||||
if (ep->num == 0) {
|
||||
usbdev_mock_t *usbdev_mock = _ep2dev(ep);
|
||||
usbdev_mock_ep_t *mock_ep = (usbdev_mock_ep_t *)ep;
|
||||
|
||||
mock_ep->target_buf = buf;
|
||||
if (ep->dir == USB_EP_DIR_IN) {
|
||||
memcpy(mock_ep->buf + mock_ep->available, mock_ep->target_buf, len);
|
||||
mock_ep->available = len;
|
||||
mock_ep->ep.buf += len;
|
||||
}
|
||||
mock_ep->state = EP_STATE_DATA_AVAILABLE;
|
||||
|
||||
usbdev_mock->ready_cb(usbdev_mock, (usbdev_mock_ep_t *)ep, len);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -224,5 +227,5 @@ static const usbdev_driver_t testdriver = {
|
||||
.ep_get = _ep_get,
|
||||
.ep_set = _ep_set,
|
||||
.ep_esr = _ep_esr,
|
||||
.ready = _ready,
|
||||
.xmit = _xmit,
|
||||
};
|
||||
|
@ -146,7 +146,7 @@ static void _test_sequence(usbdev_mock_t *dev)
|
||||
case TESTPHASE_RESET:
|
||||
next_phase = TESTPHASE_REQ_DEV_INIT;
|
||||
DEBUG("[test]: Requesting device descriptor\n");
|
||||
_build_conf_req(dev->out[0].ep.buf, 8); /* initial config request */
|
||||
_build_conf_req(dev->out[0].buf, 8); /* initial config request */
|
||||
dev->req_len = 8;
|
||||
dev->out[0].state = EP_STATE_DATA_AVAILABLE;
|
||||
dev->out[0].available = 8;
|
||||
@ -157,7 +157,7 @@ static void _test_sequence(usbdev_mock_t *dev)
|
||||
DEBUG("[test]: validating device descriptor\n");
|
||||
TEST_ASSERT_EQUAL_INT(dev->in[0].available, 8);
|
||||
_validate_device_desc_init(
|
||||
(usb_descriptor_device_t *)dev->in[0].buf_start);
|
||||
(usb_descriptor_device_t *)dev->in[0].buf);
|
||||
/* Reset device */
|
||||
DEBUG("[test]: Signalling second USB reset condition\n");
|
||||
dev->usbdev.cb(&dev->usbdev, USBDEV_EVENT_RESET);
|
||||
@ -166,7 +166,7 @@ static void _test_sequence(usbdev_mock_t *dev)
|
||||
case TESTPHASE_RESET2:
|
||||
next_phase = TESTPHASE_SET_ADDRESS;
|
||||
DEBUG("[test]: Set USB address\n");
|
||||
_build_set_addr(dev->out[0].ep.buf);
|
||||
_build_set_addr(dev->out[0].buf);
|
||||
dev->req_len = 0;
|
||||
dev->out[0].state = EP_STATE_DATA_AVAILABLE;
|
||||
dev->out[0].available = 8;
|
||||
@ -175,7 +175,7 @@ static void _test_sequence(usbdev_mock_t *dev)
|
||||
case TESTPHASE_SET_ADDRESS:
|
||||
next_phase = TESTPHASE_REQ_DEV_FULL;
|
||||
DEBUG("[test]: Requesting full device descriptor\n");
|
||||
_build_conf_req(dev->out[0].ep.buf,
|
||||
_build_conf_req(dev->out[0].buf,
|
||||
sizeof(usb_descriptor_device_t));
|
||||
dev->req_len = sizeof(usb_descriptor_device_t);
|
||||
dev->out[0].state = EP_STATE_DATA_AVAILABLE;
|
||||
@ -187,7 +187,7 @@ static void _test_sequence(usbdev_mock_t *dev)
|
||||
sizeof(usb_descriptor_device_t));
|
||||
DEBUG("[test]: Validating full descriptor\n");
|
||||
_validate_device_desc_init(
|
||||
(usb_descriptor_device_t *)dev->in[0].buf_start);
|
||||
(usb_descriptor_device_t *)dev->in[0].buf);
|
||||
|
||||
next_phase = TESTPHASE_FINAL;
|
||||
dev->usbdev.cb(&dev->usbdev, USBDEV_EVENT_ESR);
|
||||
@ -261,8 +261,6 @@ static void _handle_data(usbdev_mock_t *dev, usbdev_mock_ep_t *ep, size_t len)
|
||||
if (ep->available == dev->req_len) {
|
||||
DEBUG("[data]: Full data received from stack\n");
|
||||
req_phase = TEST_REQ_PHASE_OUTACK;
|
||||
/* Reset buffer ptr to the start */
|
||||
ep->ep.buf = ep->buf_start;
|
||||
}
|
||||
else {
|
||||
DEBUG("[data]: Expecting more data from stack: %u/%u\n",
|
||||
|
Loading…
Reference in New Issue
Block a user