Merge pull request #15734 from bergzand/pr/usbus/atomic_utils
usbus: Use atomic_utils for endpoint flag operations
This commit is contained in:
commit
02552dbaeb
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#define USB_H_USER_IS_RIOT_INTERNAL
|
#define USB_H_USER_IS_RIOT_INTERNAL
|
||||||
|
|
||||||
|
#include "atomic_utils.h"
|
||||||
#include "kernel_defines.h"
|
#include "kernel_defines.h"
|
||||||
#include "bitarithm.h"
|
#include "bitarithm.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
@ -175,36 +176,26 @@ usbus_endpoint_t *usbus_add_endpoint(usbus_t *usbus, usbus_interface_t *iface,
|
|||||||
return ep;
|
return ep;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t _get_ep_bitflag(usbdev_ep_t *ep)
|
static inline uint8_t _get_ep_bitnum(usbdev_ep_t *ep)
|
||||||
{
|
{
|
||||||
/* Endpoint activity bit flag, lower USBDEV_NUM_ENDPOINTS bits are
|
/* Endpoint activity bit flag, lower USBDEV_NUM_ENDPOINTS bits are
|
||||||
* useb as OUT endpoint flags, upper bit are IN endpoints */
|
* useb as OUT endpoint flags, upper bit are IN endpoints */
|
||||||
return 1 << ((ep->dir == USB_EP_DIR_IN ? USBDEV_NUM_ENDPOINTS
|
return (ep->dir == USB_EP_DIR_IN ? USBDEV_NUM_ENDPOINTS
|
||||||
: 0x00) + ep->num);
|
: 0x00) + ep->num;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _set_ep_event(usbus_t *usbus, usbdev_ep_t *ep)
|
static void _set_ep_event(usbus_t *usbus, usbdev_ep_t *ep)
|
||||||
{
|
{
|
||||||
if (irq_is_in()) {
|
atomic_bit_u32_t bitflag = atomic_bit_u32(&usbus->ep_events,
|
||||||
usbus->ep_events |= _get_ep_bitflag(ep);
|
_get_ep_bitnum(ep));
|
||||||
}
|
atomic_set_bit_u32(bitflag);
|
||||||
else {
|
|
||||||
unsigned state = irq_disable();
|
|
||||||
usbus->ep_events |= _get_ep_bitflag(ep);
|
|
||||||
irq_restore(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
thread_flags_set(thread_get(usbus->pid), USBUS_THREAD_FLAG_USBDEV_EP);
|
thread_flags_set(thread_get(usbus->pid), USBUS_THREAD_FLAG_USBDEV_EP);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t _get_and_reset_ep_events(usbus_t *usbus)
|
static inline uint32_t _get_and_reset_ep_events(usbus_t *usbus)
|
||||||
{
|
{
|
||||||
unsigned state = irq_disable();
|
return atomic_fetch_and_u32(&usbus->ep_events, 0);
|
||||||
uint32_t res = usbus->ep_events;
|
|
||||||
|
|
||||||
usbus->ep_events = 0;
|
|
||||||
irq_restore(state);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _signal_handlers(usbus_t *usbus, uint16_t flag,
|
static void _signal_handlers(usbus_t *usbus, uint16_t flag,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user