diff options
| author | hathach <[email protected]> | 2022-03-09 17:17:27 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2022-03-09 17:17:36 +0700 |
| commit | a5fb20533cc1c9e0ed155083c1bbcb3e7be75e67 (patch) | |
| tree | 59d69dcf6af8a5d1b5a13a311226e6e8d1386181 /src/tusb.c | |
| parent | 708f05668d681439e521379e281d087d1910a0f3 (diff) | |
adding tusb_private.h to implement common edpt claim
Diffstat (limited to 'src/tusb.c')
| -rw-r--r-- | src/tusb.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/tusb.c b/src/tusb.c index c6c04262c..6ed2a3c05 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -29,6 +29,7 @@ #if CFG_TUH_ENABLED || CFG_TUD_ENABLED #include "tusb.h" +#include "common/tusb_private.h" // TODO clean up #if CFG_TUD_ENABLED @@ -67,6 +68,30 @@ bool tusb_inited(void) // Internal Helper for both Host and Device stack //--------------------------------------------------------------------+ +bool tu_edpt_claim(tu_edpt_state_t* ep_state, osal_mutex_t mutex) +{ + (void) mutex; + +#if TUSB_OPT_MUTEX + // pre-check to help reducing mutex lock + TU_VERIFY((ep_state->busy == 0) && (ep_state->claimed == 0)); + osal_mutex_lock(mutex, OSAL_TIMEOUT_WAIT_FOREVER); +#endif + + // can only claim the endpoint if it is not busy and not claimed yet. + bool const available = (ep_state->busy == 0) && (ep_state->claimed == 0); + if (available) + { + ep_state->claimed = 1; + } + +#if TUSB_OPT_MUTEX + osal_mutex_unlock(mutex); +#endif + + return available; +} + 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); |
