/* Allocate USBD event. 
This function should be called prior to usbd_evt_put(). */
static struct usbd_event* usbd_evt_alloc(void)
/* Allocate USBD event. 
This function should be called prior to usbd_evt_put(). */
static struct usbd_event* usbd_evt_alloc(void)
{
	struct usbd_event *ev;
	struct usbd_mem_block block;
	if (k_mem_slab_alloc(&fifo_elem_slab,
			     (void **)&block.data, K_NO_WAIT)) {
		LOG_ERR("USBD event allocation failed!");
		usbd_evt_flush();
		if (k_mem_slab_alloc(&fifo_elem_slab, (void **)&block.data, K_NO_WAIT)) {
			LOG_ERR("USBD event memory corrupted");
			__ASSERT_NO_MSG(0);
			return NULL;
		}
		ev = (struct usbd_event *)block.data;
		ev->block = block;
		ev->evt_type = USBD_EVT_REINIT;
		usbd_evt_put(ev);
		usbd_work_schedule();
		return NULL;
	}
	ev = (struct usbd_event *)block.data;
	ev->block = block;
	return ev;
}