drivers: udc: remove no more required pending state flag

Pending state flag was only used by the UDC nRF USBD driver.
With the introduction of busy state flag it is no longer needed
and can be removed.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
Johann Fischer 2023-01-03 13:49:34 +01:00 committed by Carles Cufí
commit 00adb2a539
5 changed files with 17 additions and 47 deletions

View file

@ -83,27 +83,16 @@ int udc_register_ep(const struct device *dev, struct udc_ep_config *const cfg)
return 0; return 0;
} }
struct net_buf *udc_buf_get(const struct device *dev, const uint8_t ep, struct net_buf *udc_buf_get(const struct device *dev, const uint8_t ep)
const bool pending)
{ {
struct udc_ep_config *ep_cfg; struct udc_ep_config *ep_cfg;
struct net_buf *buf;
ep_cfg = udc_get_ep_cfg(dev, ep); ep_cfg = udc_get_ep_cfg(dev, ep);
if (ep_cfg == NULL) { if (ep_cfg == NULL) {
return NULL; return NULL;
} }
buf = net_buf_get(&ep_cfg->fifo, K_NO_WAIT); return net_buf_get(&ep_cfg->fifo, K_NO_WAIT);
if (buf != NULL) {
ep_cfg->stat.pending = 0;
} else {
if (pending) {
ep_cfg->stat.pending = 1;
}
}
return buf;
} }
struct net_buf *udc_buf_get_all(const struct device *dev, const uint8_t ep) struct net_buf *udc_buf_get_all(const struct device *dev, const uint8_t ep)
@ -133,28 +122,16 @@ struct net_buf *udc_buf_get_all(const struct device *dev, const uint8_t ep)
return buf; return buf;
} }
struct net_buf *udc_buf_peek(const struct device *dev, const uint8_t ep, struct net_buf *udc_buf_peek(const struct device *dev, const uint8_t ep)
const bool pending)
{ {
struct udc_ep_config *ep_cfg; struct udc_ep_config *ep_cfg;
struct net_buf *buf = NULL;
ep_cfg = udc_get_ep_cfg(dev, ep); ep_cfg = udc_get_ep_cfg(dev, ep);
if (ep_cfg == NULL) { if (ep_cfg == NULL) {
return NULL; return NULL;
} }
buf = k_fifo_peek_head(&ep_cfg->fifo); return k_fifo_peek_head(&ep_cfg->fifo);
if (buf == NULL && pending) {
ep_cfg->stat.pending = 1;
}
if (buf != NULL) {
ep_cfg->stat.pending = 0;
}
return buf;
} }
void udc_buf_put(struct udc_ep_config *const ep_cfg, void udc_buf_put(struct udc_ep_config *const ep_cfg,
@ -361,7 +338,6 @@ int udc_ep_enable_internal(const struct device *dev,
cfg->stat.odd = 0; cfg->stat.odd = 0;
cfg->stat.halted = 0; cfg->stat.halted = 0;
cfg->stat.pending = 0;
cfg->stat.data1 = false; cfg->stat.data1 = false;
ret = api->ep_enable(dev, cfg); ret = api->ep_enable(dev, cfg);
cfg->stat.enabled = ret ? false : true; cfg->stat.enabled = ret ? false : true;

View file

@ -87,13 +87,11 @@ void udc_ep_set_busy(const struct device *dev, const uint8_t ep,
* *
* @param[in] dev Pointer to device struct of the driver instance * @param[in] dev Pointer to device struct of the driver instance
* @param[in] ep Endpoint representation structure * @param[in] ep Endpoint representation structure
* @param[in] pending Mark endpoint pending if there is no request in the FIFO
* *
* @return pointer to UDC request or NULL on error. * @return pointer to UDC request or NULL on error.
*/ */
struct net_buf *udc_buf_get(const struct device *dev, struct net_buf *udc_buf_get(const struct device *dev,
const uint8_t ep, const uint8_t ep);
const bool pending);
/** /**
* @brief Get all UDC request from endpoint FIFO. * @brief Get all UDC request from endpoint FIFO.
@ -118,13 +116,11 @@ struct net_buf *udc_buf_get_all(const struct device *dev,
* *
* @param[in] dev Pointer to device struct of the driver instance * @param[in] dev Pointer to device struct of the driver instance
* @param[in] ep Endpoint representation structure * @param[in] ep Endpoint representation structure
* @param[in] pending Mark endpoint pending if there is no request in the FIFO
* *
* @return pointer to request or NULL on error. * @return pointer to request or NULL on error.
*/ */
struct net_buf *udc_buf_peek(const struct device *dev, struct net_buf *udc_buf_peek(const struct device *dev,
const uint8_t ep, const uint8_t ep);
const bool pending);
/** /**
* @brief Put request at the tail of endpoint FIFO. * @brief Put request at the tail of endpoint FIFO.

View file

@ -181,7 +181,7 @@ static int usbfsotg_xfer_start(const struct device *dev,
uint8_t *data_ptr; uint8_t *data_ptr;
size_t len; size_t len;
buf = udc_buf_peek(dev, cfg->addr, true); buf = udc_buf_peek(dev, cfg->addr);
if (buf == NULL) { if (buf == NULL) {
return -ENODATA; return -ENODATA;
} }
@ -301,7 +301,7 @@ static inline int work_handler_setup(const struct device *dev)
struct net_buf *buf; struct net_buf *buf;
int err; int err;
buf = udc_buf_get(dev, USB_CONTROL_EP_OUT, true); buf = udc_buf_get(dev, USB_CONTROL_EP_OUT);
if (buf == NULL) { if (buf == NULL) {
return -ENODATA; return -ENODATA;
} }
@ -354,7 +354,7 @@ static inline int work_handler_out(const struct device *dev,
struct net_buf *buf; struct net_buf *buf;
int err = 0; int err = 0;
buf = udc_buf_get(dev, ep, true); buf = udc_buf_get(dev, ep);
if (buf == NULL) { if (buf == NULL) {
return -ENODATA; return -ENODATA;
} }
@ -392,7 +392,7 @@ static inline int work_handler_in(const struct device *dev,
{ {
struct net_buf *buf; struct net_buf *buf;
buf = udc_buf_get(dev, ep, true); buf = udc_buf_get(dev, ep);
if (buf == NULL) { if (buf == NULL) {
return -ENODATA; return -ENODATA;
} }
@ -562,7 +562,7 @@ static ALWAYS_INLINE void isr_handle_xfer_done(const struct device *dev,
priv->busy[odd] = false; priv->busy[odd] = false;
priv->out_buf[odd] = NULL; priv->out_buf[odd] = NULL;
} else { } else {
buf = udc_buf_peek(dev, ep_cfg->addr, true); buf = udc_buf_peek(dev, ep_cfg->addr);
} }
if (buf == NULL) { if (buf == NULL) {
@ -591,7 +591,7 @@ static ALWAYS_INLINE void isr_handle_xfer_done(const struct device *dev,
ep_cfg->stat.odd = !odd; ep_cfg->stat.odd = !odd;
ep_cfg->stat.data1 = !data1; ep_cfg->stat.data1 = !data1;
buf = udc_buf_peek(dev, ep_cfg->addr, true); buf = udc_buf_peek(dev, ep_cfg->addr);
if (buf == NULL) { if (buf == NULL) {
LOG_ERR("No buffer for ep 0x%02x", ep); LOG_ERR("No buffer for ep 0x%02x", ep);
udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS, NULL); udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS, NULL);

View file

@ -92,7 +92,7 @@ static void udc_event_xfer_in_next(const struct device *dev, const uint8_t ep)
return; return;
} }
buf = udc_buf_peek(dev, ep, false); buf = udc_buf_peek(dev, ep);
if (buf != NULL) { if (buf != NULL) {
nrfx_usbd_transfer_t xfer = { nrfx_usbd_transfer_t xfer = {
.p_data = {.tx = buf->data}, .p_data = {.tx = buf->data},
@ -142,7 +142,7 @@ static void udc_event_fake_status_in(const struct device *dev)
{ {
struct net_buf *buf; struct net_buf *buf;
buf = udc_buf_get(dev, USB_CONTROL_EP_IN, true); buf = udc_buf_get(dev, USB_CONTROL_EP_IN);
if (unlikely(buf == NULL)) { if (unlikely(buf == NULL)) {
LOG_DBG("ep 0x%02x queue is empty", USB_CONTROL_EP_IN); LOG_DBG("ep 0x%02x queue is empty", USB_CONTROL_EP_IN);
return; return;
@ -160,7 +160,7 @@ static void udc_event_xfer_in(const struct device *dev,
switch (event->data.eptransfer.status) { switch (event->data.eptransfer.status) {
case NRFX_USBD_EP_OK: case NRFX_USBD_EP_OK:
buf = udc_buf_get(dev, ep, true); buf = udc_buf_get(dev, ep);
if (buf == NULL) { if (buf == NULL) {
LOG_ERR("ep 0x%02x queue is empty", ep); LOG_ERR("ep 0x%02x queue is empty", ep);
__ASSERT_NO_MSG(false); __ASSERT_NO_MSG(false);
@ -221,7 +221,7 @@ static void udc_event_xfer_out_next(const struct device *dev, const uint8_t ep)
return; return;
} }
buf = udc_buf_peek(dev, ep, true); buf = udc_buf_peek(dev, ep);
if (buf != NULL) { if (buf != NULL) {
nrfx_usbd_transfer_t xfer = { nrfx_usbd_transfer_t xfer = {
.p_data = {.rx = buf->data}, .p_data = {.rx = buf->data},
@ -266,7 +266,7 @@ static void udc_event_xfer_out(const struct device *dev,
LOG_ERR("OUT transfer failed %d", err_code); LOG_ERR("OUT transfer failed %d", err_code);
} }
buf = udc_buf_get(dev, ep, true); buf = udc_buf_get(dev, ep);
if (buf == NULL) { if (buf == NULL) {
LOG_ERR("ep 0x%02x ok, queue is empty", ep); LOG_ERR("ep 0x%02x ok, queue is empty", ep);
return; return;

View file

@ -74,8 +74,6 @@ struct udc_ep_stat {
uint32_t enabled : 1; uint32_t enabled : 1;
/** Endpoint is halted (returning STALL PID) */ /** Endpoint is halted (returning STALL PID) */
uint32_t halted : 1; uint32_t halted : 1;
/** Endpoint transfer (usually OUT) is pending for a request */
uint32_t pending : 1;
/** Last submitted PID is DATA1 */ /** Last submitted PID is DATA1 */
uint32_t data1 : 1; uint32_t data1 : 1;
/** If double buffering is supported, last used buffer is odd */ /** If double buffering is supported, last used buffer is odd */