Skip to content

Commit 87caef4

Browse files
jfischer-nokartben
authored andcommitted
usb: device_next: keep loopback function transfers going
Do not report canceled transfers as an error and continue the transfers regardless of the previous transfer status. Signed-off-by: Johann Fischer <[email protected]>
1 parent 8c1b7ac commit 87caef4

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

subsys/usb/device_next/class/loopback.c

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -157,49 +157,42 @@ static int lb_request_handler(struct usbd_class_data *const c_data,
157157
{
158158
struct udc_buf_info *bi = (struct udc_buf_info *)net_buf_user_data(buf);
159159
struct lb_data *data = usbd_class_get_private(c_data);
160-
161-
LOG_DBG("Transfer finished %s -> ep 0x%02x, len %u, err %d",
162-
c_data->name, bi->ep, buf->len, err);
160+
const size_t len = buf->len;
161+
const uint8_t ep = bi->ep;
162+
int ret = 0;
163163

164164
if (bi->ep == lb_get_bulk_out(c_data)) {
165165
atomic_clear_bit(&data->state, LB_FUNCTION_OUT_ENGAGED);
166+
if (err == 0) {
167+
memcpy(lb_buf, buf->data, MIN(sizeof(lb_buf), buf->len));
168+
}
166169
}
167170

168171
if (bi->ep == lb_get_bulk_in(c_data)) {
169172
atomic_clear_bit(&data->state, LB_FUNCTION_IN_ENGAGED);
170173
}
171174

172-
if (err) {
173-
if (err == -ECONNABORTED) {
174-
LOG_INF("request ep 0x%02x, len %u cancelled",
175-
bi->ep, buf->len);
176-
} else {
177-
LOG_ERR("request ep 0x%02x, len %u failed",
178-
bi->ep, buf->len);
179-
}
180-
181-
net_buf_unref(buf);
182-
183-
return err;
175+
net_buf_unref(buf);
176+
if (err == -ECONNABORTED) {
177+
LOG_INF("Transfer ep 0x%02x, len %u cancelled", ep, len);
178+
} else if (err != 0) {
179+
LOG_ERR("Transfer ep 0x%02x, len %u failed", ep, len);
180+
ret = err;
181+
} else {
182+
LOG_DBG("Transfer ep 0x%02x, len %u finished", ep, len);
184183
}
185184

186-
if (bi->ep == lb_get_bulk_out(c_data)) {
187-
memcpy(lb_buf, buf->data, MIN(sizeof(lb_buf), buf->len));
188-
net_buf_unref(buf);
189-
if (!atomic_test_bit(&data->state, LB_FUNCTION_BULK_MANUAL)) {
185+
if (!atomic_test_bit(&data->state, LB_FUNCTION_BULK_MANUAL)) {
186+
if (ep == lb_get_bulk_out(c_data)) {
190187
lb_submit_bulk_out(c_data);
191188
}
192-
}
193189

194-
if (bi->ep == lb_get_bulk_in(c_data)) {
195-
bi->ep = lb_get_bulk_out(c_data);
196-
net_buf_unref(buf);
197-
if (!atomic_test_bit(&data->state, LB_FUNCTION_BULK_MANUAL)) {
190+
if (ep == lb_get_bulk_in(c_data)) {
198191
lb_submit_bulk_in(c_data);
199192
}
200193
}
201194

202-
return 0;
195+
return ret;
203196
}
204197

205198
static void lb_update(struct usbd_class_data *c_data,

0 commit comments

Comments
 (0)