32#ifndef TINYUSB_OSAL_MUTEX_CANCELABLE 
   33#define TINYUSB_OSAL_MUTEX_CANCELABLE 0 
   40TU_ATTR_ALWAYS_INLINE 
static inline void osal_task_delay(uint32_t msec)
 
   51typedef sema_t  osal_semaphore_def_t;    
 
   52typedef sema_t *osal_semaphore_t;        
 
   55static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef)
 
   58    return (osal_semaphore_t)semdef;
 
   62static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, 
bool in_isr)
 
   69static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec)
 
   75TU_ATTR_ALWAYS_INLINE 
static inline void osal_semaphore_reset(osal_semaphore_t 
const sem_hdl)
 
   82typedef mutex_t  osal_mutex_def_t;  
 
   86static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef)
 
   90    return (osal_mutex_t)mdef;
 
   93#if TINYUSB_OSAL_MUTEX_CANCELABLE 
   94static void _osal_mutex_lock_timeout(
void *arg)
 
  101static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec)
 
  104#if TINYUSB_OSAL_MUTEX_CANCELABLE 
  107    ztimer_t _timer = { .callback = _osal_mutex_lock_timeout, .arg = &_mc };
 
  113    assert(msec == OSAL_TIMEOUT_WAIT_FOREVER);
 
  120static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
 
  131#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \ 
  133    static _type _name##_##q_items[_depth];   \ 
  134    osal_queue_def_t _name = { \ 
  135                                .buffer = _name##_##q_items, \ 
  136                                .size = sizeof(_type), \ 
  154typedef osal_queue_def_t *osal_queue_t;
 
  156TU_ATTR_ALWAYS_INLINE 
static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
 
  165    return (osal_queue_t)qdef;
 
  169static inline bool osal_queue_send(osal_queue_t qhdl, 
void const * data, 
bool in_isr)
 
  199    memcpy(qhdl->buffer + (qhdl->tail * (qhdl->size)), data, qhdl->size);
 
  201    qhdl->tail = (qhdl->tail + 1) % qhdl->depth;
 
  209#if TINYUSB_OSAL_MUTEX_CANCELABLE 
  210static void _osal_queue_lock_timeout(
void *arg)
 
  217static inline bool osal_queue_receive(osal_queue_t qhdl, 
void* data, uint32_t msec)
 
  233    assert(qhdl->front != qhdl->tail);
 
  236    memcpy(data, qhdl->buffer + (qhdl->front * (qhdl->size)), qhdl->size);
 
  238    qhdl->front = (qhdl->front + 1) % qhdl->depth;
 
  243TU_ATTR_ALWAYS_INLINE 
static inline bool osal_queue_empty(osal_queue_t qhdl)
 
#define assert(cond)
abort the program if assertion is false
 
void mutex_unlock(mutex_t *mutex)
Unlocks the mutex.
 
void mutex_cancel(mutex_cancel_t *mc)
Cancels a call to mutex_lock_cancelable.
 
static mutex_cancel_t mutex_cancel_init(mutex_t *mutex)
Initialize a mutex cancellation structure.
 
int mutex_lock_cancelable(mutex_cancel_t *mc)
Locks a mutex, blocking.
 
static void mutex_init(mutex_t *mutex)
Initializes a mutex object.
 
static void mutex_lock(mutex_t *mutex)
Locks a mutex, blocking.
 
void sema_create(sema_t *sema, unsigned int value)
Creates semaphore dynamically.
 
static int sema_wait(sema_t *sema)
Wait for a semaphore being posted (without timeout).
 
static int sema_wait_timed_ztimer(sema_t *sema, ztimer_clock_t *clock, uint32_t timeout)
Wait for a semaphore being posted, using ztimer as backend.
 
static unsigned sema_get_value(const sema_t *sema)
Get a semaphore's current value.
 
int sema_post(sema_t *sema)
Signal semaphore.
 
uint32_t ztimer_set(ztimer_clock_t *clock, ztimer_t *timer, uint32_t val)
Set a timer on a clock.
 
void ztimer_sleep(ztimer_clock_t *clock, uint32_t duration)
Put the calling thread to sleep for the specified number of ticks.
 
ztimer_clock_t *const ZTIMER_MSEC
Default ztimer millisecond clock.
 
struct list_node list_node_t
List node structure.
 
Mutex for thread synchronization.
 
A cancellation structure for use with mutex_lock_cancelable and mutex_cancel.