diff options
| author | hathach <[email protected]> | 2022-03-09 17:26:55 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2022-03-09 17:26:55 +0700 |
| commit | 110879074f3785c07bf3f125e26a2bbaa51897e4 (patch) | |
| tree | db262f25c2281f3af22f16e941dd94ac8f7a4fd3 /src/tusb.c | |
| parent | a5fb20533cc1c9e0ed155083c1bbcb3e7be75e67 (diff) | |
implement tu_edpt_release()
Diffstat (limited to 'src/tusb.c')
| -rw-r--r-- | src/tusb.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/tusb.c b/src/tusb.c index 6ed2a3c05..c86bdd891 100644 --- a/src/tusb.c +++ b/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); |
