43 #ifndef _TUSB_OSAL_NONE_H_
44 #define _TUSB_OSAL_NONE_H_
55 uint32_t tusb_tick_get(
void);
56 #define osal_tick_get tusb_tick_get
72 #define OSAL_TASK_DEF(code, stack_depth, prio)
74 #define osal_task_create(x) TUSB_ERROR_NONE
76 #define OSAL_TASK_FUNCTION(task_func, p_para) tusb_error_t task_func(void * p_para)
78 #define TASK_RESTART \
81 #define OSAL_TASK_LOOP_BEGIN \
82 ATTR_UNUSED static uint32_t timeout = 0;\
83 static uint16_t state = 0;\
88 #define OSAL_TASK_LOOP_END \
92 return TUSB_ERROR_NONE;
95 #define osal_task_delay(msec) \
97 timeout = osal_tick_get();\
98 state = __LINE__; case __LINE__:\
99 if ( timeout + osal_tick_from_msec(msec) > osal_tick_get() ) \
100 return TUSB_ERROR_OSAL_WAITING;\
106 #define OSAL_SUBTASK_INVOKED_AND_WAIT(subtask, status) \
108 state = __LINE__; case __LINE__:\
111 if (TUSB_ERROR_OSAL_WAITING == status) \
112 return TUSB_ERROR_OSAL_WAITING;\
116 #define OSAL_SUBTASK_BEGIN OSAL_TASK_LOOP_BEGIN
117 #define OSAL_SUBTASK_END OSAL_TASK_LOOP_END
120 #define SUBTASK_EXIT(error) \
122 TASK_RESTART; return error;\
125 #define _SUBTASK_ASSERT_ERROR_HANDLER(error, func_call) \
126 func_call; TASK_RESTART; return error
128 #define SUBTASK_ASSERT_STATUS(sts) \
129 ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, , tusb_error_t status = (tusb_error_t)(sts),\
130 TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status])
132 #define SUBTASK_ASSERT_STATUS_WITH_HANDLER(sts, func_call) \
133 ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, func_call, tusb_error_t status = (tusb_error_t)(sts),\
134 TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status])
137 #define SUBTASK_ASSERT(condition) \
138 ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, , , \
139 (condition), TUSB_ERROR_OSAL_TASK_FAILED, "%s", "evaluated to false")
141 #define SUBTASK_ASSERT_WITH_HANDLER(condition, func_call) \
142 ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, func_call, ,\
143 condition, TUSB_ERROR_OSAL_TASK_FAILED, "%s", "evaluated to false")
149 typedef osal_semaphore_t * osal_semaphore_handle_t;
151 #define OSAL_SEM_DEF(name)\
152 osal_semaphore_t name
154 #define OSAL_SEM_REF(name)\
158 static inline osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem)
161 return (osal_semaphore_handle_t) p_sem;
165 static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t sem_hdl)
169 return TUSB_ERROR_NONE;
172 static inline void osal_semaphore_reset(osal_semaphore_handle_t sem_hdl)
ATTR_ALWAYS_INLINE;
173 static inline void osal_semaphore_reset(osal_semaphore_handle_t sem_hdl)
178 #define osal_semaphore_wait(sem_hdl, msec, p_error) \
180 timeout = osal_tick_get();\
181 state = __LINE__; case __LINE__:\
182 if( *(sem_hdl) == 0 ) {\
183 if ( ( ((uint32_t) (msec)) != OSAL_TIMEOUT_WAIT_FOREVER) && (timeout + osal_tick_from_msec(msec) <= osal_tick_get()) ) \
184 *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
186 return TUSB_ERROR_OSAL_WAITING;\
189 *(p_error) = TUSB_ERROR_NONE;\
197 typedef osal_semaphore_handle_t osal_mutex_handle_t;
199 #define OSAL_MUTEX_DEF(name)\
202 #define OSAL_MUTEX_REF(name)\
206 static inline osal_mutex_handle_t osal_mutex_create(osal_mutex_t * p_mutex)
209 return (osal_mutex_handle_t) p_mutex;
213 static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t mutex_hdl)
217 return TUSB_ERROR_NONE;
220 static inline void osal_mutex_reset(osal_mutex_handle_t mutex_hdl)
ATTR_ALWAYS_INLINE;
221 static inline void osal_mutex_reset(osal_mutex_handle_t mutex_hdl)
226 #define osal_mutex_wait osal_semaphore_wait
233 uint8_t
const depth ;
234 uint8_t
const item_size ;
243 #define OSAL_QUEUE_DEF(name, queue_depth, type)\
244 STATIC_ASSERT(queue_depth < 256, "OSAL Queue only support up to 255 depth");\
245 type name##_buffer[queue_depth];\
246 osal_queue_t name = {\
247 .buffer = (uint8_t*) name##_buffer,\
248 .depth = queue_depth,\
249 .item_size = sizeof(type)\
252 #define OSAL_QUEUE_REF(name) (&name)
255 static inline osal_queue_handle_t osal_queue_create(
osal_queue_t *
const p_queue)
258 return (osal_queue_handle_t) p_queue;
264 static inline tusb_error_t osal_queue_send(osal_queue_handle_t
const queue_hdl,
void const * data)
284 return TUSB_ERROR_NONE;
287 static inline void osal_queue_flush(osal_queue_handle_t
const queue_hdl)
ATTR_ALWAYS_INLINE;
288 static inline void osal_queue_flush(osal_queue_handle_t
const queue_hdl)
293 #define osal_queue_receive(queue_hdl, p_data, msec, p_error) \
295 timeout = osal_tick_get();\
296 state = __LINE__; case __LINE__:\
297 if( queue_hdl->count == 0 ) {\
298 if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( timeout + osal_tick_from_msec(msec) <= osal_tick_get() )) \
299 *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
301 return TUSB_ERROR_OSAL_WAITING;\
304 memcpy(p_data, queue_hdl->buffer + (queue_hdl->rd_idx * queue_hdl->item_size), queue_hdl->item_size);\
305 queue_hdl->rd_idx = (queue_hdl->rd_idx + 1) % queue_hdl->depth;\
308 *(p_error) = TUSB_ERROR_NONE;\
#define ATTR_WARN_UNUSED_RESULT
The warn_unused_result attribute causes a warning to be emitted if a caller of the function with this...
uint8_t const item_size
size of each item
volatile uint8_t rd_idx
read pointer
volatile uint8_t count
number of items in queue
volatile uint8_t wr_idx
write pointer
tusb_error_t
Error Code returned.
uint8_t *const buffer
buffer pointer
uint8_t const depth
buffer size
#define ATTR_ALWAYS_INLINE
Generally, functions are not inlined unless optimization is specified. For functions declared inline...