drivers: udc_ambiq: defer enqueue event if the endpoint is stalled

Ambiq USB HAL do not expect endpoint transaction request when an
endpoint is stalled. This commit addresses this behavior in shim driver
by checking for endpoint's stall status when enqueue request is
received, and defer it until endpoint stall is cleared.

Signed-off-by: Chew Zeh Yang <zeon.chew@ambiq.com>
This commit is contained in:
Chew Zeh Yang 2024-11-27 16:07:59 +08:00 committed by Benjamin Cabé
commit 0d02cdca46

View file

@ -265,7 +265,10 @@ static int udc_ambiq_ep_enqueue(const struct device *dev, struct udc_ep_config *
udc_ambiq_ep_xfer_complete_callback(dev, USB_CONTROL_EP_IN, 0, 0, NULL);
return 0;
}
k_msgq_put(&drv_msgq, &evt, K_NO_WAIT);
if (!ep_cfg->stat.halted) {
k_msgq_put(&drv_msgq, &evt, K_NO_WAIT);
}
return 0;
}
@ -299,6 +302,9 @@ static int udc_ambiq_ep_set_halt(const struct device *dev, struct udc_ep_config
LOG_DBG("Halt ep 0x%02x", ep_cfg->addr);
am_hal_usb_ep_stall(priv->usb_handle, ep_cfg->addr);
if (USB_EP_GET_IDX(ep_cfg->addr)) {
ep_cfg->stat.halted = true;
}
return 0;
}
@ -311,6 +317,17 @@ static int udc_ambiq_ep_clear_halt(const struct device *dev, struct udc_ep_confi
am_hal_usb_ep_clear_stall(priv->usb_handle, ep_cfg->addr);
ep_cfg->stat.halted = false;
/* Resume queued transfer if any */
if (udc_buf_peek(dev, ep_cfg->addr)) {
struct udc_ambiq_event evt = {
.ep = ep_cfg->addr,
.type = UDC_AMBIQ_EVT_XFER,
};
k_msgq_put(&drv_msgq, &evt, K_NO_WAIT);
}
return 0;
}