39TU_ATTR_ALWAYS_INLINE
static inline void osal_task_delay(uint32_t msec)
41 os_time_delay( os_time_ms_to_ticks32(msec) );
48typedef struct os_sem* osal_semaphore_t;
50TU_ATTR_ALWAYS_INLINE
static inline osal_semaphore_t osal_semaphore_create(
osal_semaphore_def_t* semdef)
52 return (os_sem_init(semdef, 0) == OS_OK) ? (osal_semaphore_t) semdef : NULL;
55TU_ATTR_ALWAYS_INLINE
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl,
bool in_isr)
58 return os_sem_release(sem_hdl) == OS_OK;
61TU_ATTR_ALWAYS_INLINE
static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec)
63 uint32_t
const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? OS_TIMEOUT_NEVER : os_time_ms_to_ticks32(msec);
64 return os_sem_pend(sem_hdl, ticks) == OS_OK;
67static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl)
75typedef struct os_mutex osal_mutex_def_t;
76typedef struct os_mutex* osal_mutex_t;
78TU_ATTR_ALWAYS_INLINE
static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef)
80 return (os_mutex_init(mdef) == OS_OK) ? (osal_mutex_t) mdef : NULL;
83TU_ATTR_ALWAYS_INLINE
static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec)
85 uint32_t
const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? OS_TIMEOUT_NEVER : os_time_ms_to_ticks32(msec);
86 return os_mutex_pend(mutex_hdl, ticks) == OS_OK;
89TU_ATTR_ALWAYS_INLINE
static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
91 return os_mutex_release(mutex_hdl) == OS_OK;
99#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \
100 static _type _name##_##buf[_depth];\
101 static struct os_event _name##_##evbuf[_depth];\
102 osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf, .evbuf = _name##_##evbuf};\
111 struct os_mempool mpool;
112 struct os_mempool epool;
114 struct os_eventq evq;
119TU_ATTR_ALWAYS_INLINE
static inline osal_queue_t osal_queue_create(
osal_queue_def_t* qdef)
121 if ( OS_OK != os_mempool_init(&qdef->mpool, qdef->depth, qdef->item_sz, qdef->buf,
"usbd queue") )
return NULL;
122 if ( OS_OK != os_mempool_init(&qdef->epool, qdef->depth,
sizeof(
struct os_event), qdef->evbuf,
"usbd evqueue") )
return NULL;
124 os_eventq_init(&qdef->evq);
125 return (osal_queue_t) qdef;
128TU_ATTR_ALWAYS_INLINE
static inline bool osal_queue_receive(osal_queue_t qhdl,
void* data, uint32_t msec)
133 ev = os_eventq_get(&qhdl->evq);
135 memcpy(data, ev->ev_arg, qhdl->item_sz);
136 os_memblock_put(&qhdl->mpool, ev->ev_arg);
137 os_memblock_put(&qhdl->epool, ev);
142static inline bool osal_queue_send(osal_queue_t qhdl,
void const * data,
bool in_isr)
147 void* ptr = os_memblock_get(&qhdl->mpool);
148 if (!ptr)
return false;
149 memcpy(ptr, data, qhdl->item_sz);
152 struct os_event* ev = (
struct os_event*) os_memblock_get(&qhdl->epool);
155 os_memblock_put(&qhdl->mpool, ptr);
158 tu_memclr(ev,
sizeof(
struct os_event));
161 os_eventq_put(&qhdl->evq, ev);
166TU_ATTR_ALWAYS_INLINE
static inline bool osal_queue_empty(osal_queue_t qhdl)
168 return STAILQ_EMPTY(&qhdl->evq.evq_list);
Definition osal_freertos.h:58
Definition osal_none.h:47