mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
implement tu_edpt_release()
This commit is contained in:
parent
a5fb20533c
commit
110879074f
@ -52,8 +52,12 @@ void tu_edpt_bind_driver(uint8_t ep2drv[][2], tusb_desc_interface_t const* p_des
|
||||
// Calculate total length of n interfaces (depending on IAD)
|
||||
uint16_t tu_desc_get_interface_total_len(tusb_desc_interface_t const* desc_itf, uint8_t itf_count, uint16_t max_len);
|
||||
|
||||
// Claim an endpoint with provided mutex
|
||||
bool tu_edpt_claim(tu_edpt_state_t* ep_state, osal_mutex_t mutex);
|
||||
|
||||
// Release an endpoint with provided mutex
|
||||
bool tu_edpt_release(tu_edpt_state_t* ep_state, osal_mutex_t mutex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1202,23 +1202,19 @@ bool usbh_edpt_claim(uint8_t dev_addr, uint8_t ep_addr)
|
||||
// TODO has some duplication code with device, refactor later
|
||||
bool usbh_edpt_release(uint8_t dev_addr, uint8_t ep_addr)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
// addr0 is always available
|
||||
if (dev_addr == 0) return true;
|
||||
|
||||
usbh_device_t* dev = get_device(dev_addr);
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
tu_edpt_state_t* ep_state = &dev->ep_status[epnum][dir];
|
||||
|
||||
lock_device(dev_addr);
|
||||
|
||||
// can only release the endpoint if it is claimed and not busy
|
||||
bool const ret = (dev->ep_status[epnum][dir].busy == 0) && (dev->ep_status[epnum][dir].claimed == 1);
|
||||
if (ret)
|
||||
{
|
||||
dev->ep_status[epnum][dir].claimed = 0;
|
||||
}
|
||||
|
||||
unlock_device(dev_addr);
|
||||
|
||||
return ret;
|
||||
#if TUSB_OPT_MUTEX
|
||||
return tu_edpt_release(ep_state, &_usbh_mutex[dev_addr-1]);
|
||||
#else
|
||||
return tu_edpt_release(ep_state, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
// TODO has some duplication code with device, refactor later
|
||||
|
22
src/tusb.c
22
src/tusb.c
@ -92,6 +92,28 @@ bool tu_edpt_claim(tu_edpt_state_t* ep_state, osal_mutex_t mutex)
|
||||
return available;
|
||||
}
|
||||
|
||||
bool tu_edpt_release(tu_edpt_state_t* ep_state, osal_mutex_t mutex)
|
||||
{
|
||||
(void) mutex;
|
||||
|
||||
#if TUSB_OPT_MUTEX
|
||||
osal_mutex_lock(mutex, OSAL_TIMEOUT_WAIT_FOREVER);
|
||||
#endif
|
||||
|
||||
// can only release the endpoint if it is claimed and not busy
|
||||
bool const ret = (ep_state->claimed == 1) && (ep_state->busy == 0);
|
||||
if (ret)
|
||||
{
|
||||
ep_state->claimed = 0;
|
||||
}
|
||||
|
||||
#if TUSB_OPT_MUTEX
|
||||
osal_mutex_unlock(mutex);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool tu_edpt_validate(tusb_desc_endpoint_t const * desc_ep, tusb_speed_t speed)
|
||||
{
|
||||
uint16_t const max_packet_size = tu_edpt_packet_size(desc_ep);
|
||||
|
Loading…
x
Reference in New Issue
Block a user