28#ifndef _TUSB_OSAL_RTX4_H_
29#define _TUSB_OSAL_RTX4_H_
40TU_ATTR_ALWAYS_INLINE
static inline void osal_task_delay(uint32_t msec)
42 uint16_t hi = msec >> 16;
50TU_ATTR_ALWAYS_INLINE
static inline uint16_t msec2wait(uint32_t msec) {
51 if (msec == OSAL_TIMEOUT_WAIT_FOREVER)
53 else if (msec >= 0xFFFE)
63typedef OS_ID osal_semaphore_t;
66 os_sem_init(semdef, 0);
70TU_ATTR_ALWAYS_INLINE
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl,
bool in_isr) {
74 isr_sem_send(sem_hdl);
79TU_ATTR_ALWAYS_INLINE
static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec) {
80 return os_sem_wait(sem_hdl, msec2wait(msec)) != OS_R_TMO;
83TU_ATTR_ALWAYS_INLINE
static inline void osal_semaphore_reset(osal_semaphore_t
const sem_hdl) {
90typedef OS_MUT osal_mutex_def_t;
91typedef OS_ID osal_mutex_t;
93TU_ATTR_ALWAYS_INLINE
static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef)
99TU_ATTR_ALWAYS_INLINE
static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec)
101 return os_mut_wait(mutex_hdl, msec2wait(msec)) != OS_R_TMO;
104TU_ATTR_ALWAYS_INLINE
static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
106 return os_mut_release(mutex_hdl) == OS_R_OK;
114#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \
115 os_mbx_declare(_name##__mbox, _depth); \
116 _declare_box(_name##__pool, sizeof(_type), _depth); \
117 osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .pool = _name##__pool, .mbox = _name##__mbox };
130TU_ATTR_ALWAYS_INLINE
static inline osal_queue_t osal_queue_create(
osal_queue_def_t* qdef)
132 os_mbx_init(qdef->mbox, (qdef->depth + 4) * 4);
133 _init_box(qdef->pool, ((qdef->item_sz+3)/4)*(qdef->depth) + 3, qdef->item_sz);
137TU_ATTR_ALWAYS_INLINE
static inline bool osal_queue_receive(osal_queue_t qhdl,
void* data, uint32_t msec)
140 os_mbx_wait(qhdl->mbox, &buf, msec2wait(msec));
141 memcpy(data, buf, qhdl->item_sz);
142 _free_box(qhdl->pool, buf);
146TU_ATTR_ALWAYS_INLINE
static inline bool osal_queue_send(osal_queue_t qhdl,
void const * data,
bool in_isr)
148 void* buf = _alloc_box(qhdl->pool);
149 memcpy(buf, data, qhdl->item_sz);
152 os_mbx_send(qhdl->mbox, buf, 0xFFFF);
156 isr_mbx_send(qhdl->mbox, buf);
161TU_ATTR_ALWAYS_INLINE
static inline bool osal_queue_empty(osal_queue_t qhdl)
163 return os_mbx_check(qhdl->mbox) == qhdl->depth;
Definition osal_freertos.h:58
Definition osal_none.h:47