|
|
@@ -150,6 +150,57 @@ static inline osal_task_t osal_task_create(osal_func_t code, const char* name, u
|
|
|
ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, func_call, ,\
|
|
|
condition, TUSB_ERROR_OSAL_TASK_FAILED, "%s", "evaluated to false")
|
|
|
|
|
|
+//--------------------------------------------------------------------+
|
|
|
+// QUEUE API
|
|
|
+//--------------------------------------------------------------------+
|
|
|
+typedef fifo_t* osal_queue_t;
|
|
|
+
|
|
|
+static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size)
|
|
|
+{
|
|
|
+ fifo_t* ff = (fifo_t* ) tu_malloc( sizeof(fifo_t) );
|
|
|
+ uint8_t* buf = (uint8_t*) tu_malloc( depth*item_size );
|
|
|
+
|
|
|
+ VERIFY( ff && buf, NULL);
|
|
|
+
|
|
|
+ *ff = (fifo_t) {
|
|
|
+ .buffer = buf, .depth = depth, .item_size = item_size,
|
|
|
+ .count = 0, .wr_idx =0, .rd_idx = 0, .overwritable = false
|
|
|
+ };
|
|
|
+
|
|
|
+ return (osal_queue_t) ff;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data)
|
|
|
+{
|
|
|
+ return fifo_write( (fifo_t*) queue_hdl, data);
|
|
|
+}
|
|
|
+
|
|
|
+static inline void osal_queue_flush(osal_queue_t const queue_hdl)
|
|
|
+{
|
|
|
+ queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0;
|
|
|
+}
|
|
|
+
|
|
|
+#define osal_queue_receive(queue_hdl, p_data, msec, p_error) \
|
|
|
+ do {\
|
|
|
+ timeout = osal_tick_get();\
|
|
|
+ state = __LINE__; case __LINE__:\
|
|
|
+ if( queue_hdl->count == 0 ) {\
|
|
|
+ if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( timeout + osal_tick_from_msec(msec) <= osal_tick_get() )) /* time out */ \
|
|
|
+ *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
|
|
|
+ else\
|
|
|
+ return TUSB_ERROR_OSAL_WAITING;\
|
|
|
+ } else{\
|
|
|
+ /*TODO mutex lock hal_interrupt_disable */\
|
|
|
+ memcpy(p_data, queue_hdl->buffer + (queue_hdl->rd_idx * queue_hdl->item_size), queue_hdl->item_size);\
|
|
|
+ queue_hdl->rd_idx = (queue_hdl->rd_idx + 1) % queue_hdl->depth;\
|
|
|
+ queue_hdl->count--;\
|
|
|
+ /*TODO mutex unlock hal_interrupt_enable */\
|
|
|
+ *(p_error) = TUSB_ERROR_NONE;\
|
|
|
+ }\
|
|
|
+ }while(0)
|
|
|
+
|
|
|
+
|
|
|
//--------------------------------------------------------------------+
|
|
|
// Semaphore API
|
|
|
//--------------------------------------------------------------------+
|
|
|
@@ -173,11 +224,10 @@ static inline osal_semaphore_t osal_semaphore_create(uint32_t max_count, uint32_
|
|
|
return sem_data;
|
|
|
}
|
|
|
|
|
|
-static inline tusb_error_t osal_semaphore_post(osal_semaphore_t sem_hdl)
|
|
|
+static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl)
|
|
|
{
|
|
|
if (sem_hdl->count < sem_hdl->max_count ) sem_hdl->count++;
|
|
|
-
|
|
|
- return TUSB_ERROR_NONE;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl)
|
|
|
@@ -210,7 +260,7 @@ static inline osal_mutex_t osal_mutex_create(void)
|
|
|
return osal_semaphore_create(1, 0);
|
|
|
}
|
|
|
|
|
|
-static inline tusb_error_t osal_mutex_release(osal_mutex_t mutex_hdl)
|
|
|
+static inline bool osal_mutex_release(osal_mutex_t mutex_hdl)
|
|
|
{
|
|
|
return osal_semaphore_post(mutex_hdl);
|
|
|
}
|
|
|
@@ -223,55 +273,7 @@ static inline void osal_mutex_reset(osal_mutex_t mutex_hdl)
|
|
|
|
|
|
#define osal_mutex_wait osal_semaphore_wait
|
|
|
|
|
|
-//--------------------------------------------------------------------+
|
|
|
-// QUEUE API
|
|
|
-//--------------------------------------------------------------------+
|
|
|
-typedef fifo_t* osal_queue_t;
|
|
|
-
|
|
|
-static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size)
|
|
|
-{
|
|
|
- fifo_t* ff = (fifo_t* ) tu_malloc( sizeof(fifo_t) );
|
|
|
- uint8_t* buf = (uint8_t*) tu_malloc( depth*item_size );
|
|
|
-
|
|
|
- VERIFY( ff && buf, NULL);
|
|
|
-
|
|
|
- *ff = (fifo_t) {
|
|
|
- .buffer = buf, .depth = depth, .item_size = item_size,
|
|
|
- .count = 0, .wr_idx =0, .rd_idx = 0, .overwritable = false
|
|
|
- };
|
|
|
-
|
|
|
- return (osal_queue_t) ff;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data)
|
|
|
-{
|
|
|
- return fifo_write( (fifo_t*) queue_hdl, data);
|
|
|
-}
|
|
|
-
|
|
|
-static inline void osal_queue_flush(osal_queue_t const queue_hdl)
|
|
|
-{
|
|
|
- queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0;
|
|
|
-}
|
|
|
|
|
|
-#define osal_queue_receive(queue_hdl, p_data, msec, p_error) \
|
|
|
- do {\
|
|
|
- timeout = osal_tick_get();\
|
|
|
- state = __LINE__; case __LINE__:\
|
|
|
- if( queue_hdl->count == 0 ) {\
|
|
|
- if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( timeout + osal_tick_from_msec(msec) <= osal_tick_get() )) /* time out */ \
|
|
|
- *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
|
|
|
- else\
|
|
|
- return TUSB_ERROR_OSAL_WAITING;\
|
|
|
- } else{\
|
|
|
- /*TODO mutex lock hal_interrupt_disable */\
|
|
|
- memcpy(p_data, queue_hdl->buffer + (queue_hdl->rd_idx * queue_hdl->item_size), queue_hdl->item_size);\
|
|
|
- queue_hdl->rd_idx = (queue_hdl->rd_idx + 1) % queue_hdl->depth;\
|
|
|
- queue_hdl->count--;\
|
|
|
- /*TODO mutex unlock hal_interrupt_enable */\
|
|
|
- *(p_error) = TUSB_ERROR_NONE;\
|
|
|
- }\
|
|
|
- }while(0)
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
}
|