Skip to content

Commit 0f4fc76

Browse files
jfischer-nokartben
authored andcommitted
drivers: udc_rpi_pico: use atomic_t instead of k_event for value passing
Use atomic_t instead of k_event for event value passing. Signed-off-by: Johann Fischer <[email protected]>
1 parent dfe483d commit 0f4fc76

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

drivers/usb/udc/udc_rpi_pico.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ struct rpi_pico_data {
6262
* 15..0 for OUT endpoints.
6363
*/
6464
struct k_event events;
65-
struct k_event xfer_new;
66-
struct k_event xfer_finished;
65+
atomic_t xfer_new;
66+
atomic_t xfer_finished;
6767
struct rpi_pico_ep_data out_ep[USB_NUM_ENDPOINTS];
6868
struct rpi_pico_ep_data in_ep[USB_NUM_ENDPOINTS];
6969
bool rwu_pending;
7070
uint8_t setup[8];
7171
};
7272

73-
static inline uint32_t udc_ep_to_bmsk(const uint8_t ep)
73+
static inline int udc_ep_to_bnum(const uint8_t ep)
7474
{
7575
if (USB_EP_DIR_IS_IN(ep)) {
76-
return BIT(16UL + USB_EP_GET_IDX(ep));
76+
return 16UL + USB_EP_GET_IDX(ep);
7777
}
7878

79-
return BIT(USB_EP_GET_IDX(ep));
79+
return USB_EP_GET_IDX(ep);
8080
}
8181

8282
static inline uint8_t udc_pull_ep_from_bmsk(uint32_t *const bitmap)
@@ -507,7 +507,7 @@ static ALWAYS_INLINE void rpi_pico_thread_handler(void *const arg)
507507
if (evt & BIT(RPI_PICO_EVT_XFER_FINISHED)) {
508508
k_event_clear(&priv->events, BIT(RPI_PICO_EVT_XFER_FINISHED));
509509

510-
eps = k_event_clear(&priv->xfer_finished, UINT32_MAX);
510+
eps = atomic_clear(&priv->xfer_finished);
511511

512512
while (eps) {
513513
ep = udc_pull_ep_from_bmsk(&eps);
@@ -531,7 +531,7 @@ static ALWAYS_INLINE void rpi_pico_thread_handler(void *const arg)
531531
if (evt & BIT(RPI_PICO_EVT_XFER_NEW)) {
532532
k_event_clear(&priv->events, BIT(RPI_PICO_EVT_XFER_NEW));
533533

534-
eps = k_event_clear(&priv->xfer_new, UINT32_MAX);
534+
eps = atomic_clear(&priv->xfer_new);
535535

536536
while (eps) {
537537
ep = udc_pull_ep_from_bmsk(&eps);
@@ -604,7 +604,7 @@ static void rpi_pico_handle_buff_status_in(const struct device *dev, const uint8
604604
__ASSERT(err == 0, "Failed to start new IN transaction");
605605
udc_ep_buf_clear_zlp(buf);
606606
} else {
607-
k_event_post(&priv->xfer_finished, udc_ep_to_bmsk(ep));
607+
atomic_set_bit(&priv->xfer_finished, udc_ep_to_bnum(ep));
608608
k_event_post(&priv->events, BIT(RPI_PICO_EVT_XFER_FINISHED));
609609
}
610610
}
@@ -634,7 +634,7 @@ static void rpi_pico_handle_buff_status_out(const struct device *dev, const uint
634634
err = rpi_pico_prep_rx(dev, buf, ep_cfg);
635635
__ASSERT(err == 0, "Failed to start new OUT transaction");
636636
} else {
637-
k_event_post(&priv->xfer_finished, udc_ep_to_bmsk(ep));
637+
atomic_set_bit(&priv->xfer_finished, udc_ep_to_bnum(ep));
638638
k_event_post(&priv->events, BIT(RPI_PICO_EVT_XFER_FINISHED));
639639
}
640640
}
@@ -828,7 +828,7 @@ static int udc_rpi_pico_ep_enqueue(const struct device *dev,
828828
udc_buf_put(cfg, buf);
829829

830830
if (!cfg->stat.halted) {
831-
k_event_post(&priv->xfer_new, udc_ep_to_bmsk(cfg->addr));
831+
atomic_set_bit(&priv->xfer_new, udc_ep_to_bnum(cfg->addr));
832832
k_event_post(&priv->events, BIT(RPI_PICO_EVT_XFER_NEW));
833833
}
834834

@@ -984,7 +984,7 @@ static int udc_rpi_pico_ep_clear_halt(const struct device *dev,
984984
if (udc_ep_is_busy(cfg)) {
985985
rpi_pico_handle_xfer_next(dev, cfg);
986986
} else if (udc_buf_peek(cfg)) {
987-
k_event_post(&priv->xfer_new, udc_ep_to_bmsk(cfg->addr));
987+
atomic_set_bit(&priv->xfer_new, udc_ep_to_bnum(cfg->addr));
988988
k_event_post(&priv->events, BIT(RPI_PICO_EVT_XFER_NEW));
989989
}
990990

@@ -1144,8 +1144,8 @@ static int udc_rpi_pico_driver_preinit(const struct device *dev)
11441144

11451145
k_mutex_init(&data->mutex);
11461146
k_event_init(&priv->events);
1147-
k_event_init(&priv->xfer_new);
1148-
k_event_init(&priv->xfer_finished);
1147+
atomic_clear(&priv->xfer_new);
1148+
atomic_clear(&priv->xfer_finished);
11491149

11501150
data->caps.rwup = true;
11511151
data->caps.mps0 = UDC_MPS0_64;

0 commit comments

Comments
 (0)