summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-11-02 17:26:35 +0700
committerhathach <[email protected]>2018-11-02 17:26:35 +0700
commit2708632a6a65e467cae131ce38082d6a45a837d0 (patch)
tree1fa8ce2c15b45155c3263ef6a97e4a605dd9cb7a /src
parent4683dc1e680bbed3909b2b1dc519886b2cee0107 (diff)
clean up osal
Diffstat (limited to 'src')
-rw-r--r--src/device/usbd_pvt.h3
-rw-r--r--src/osal/osal.c1
-rw-r--r--src/osal/osal.h6
-rw-r--r--src/osal/osal_freertos.h79
-rw-r--r--src/osal/osal_none.h88
-rw-r--r--src/tusb.h1
6 files changed, 88 insertions, 90 deletions
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h
index d7e014cb1..0b6b56d7d 100644
--- a/src/device/usbd_pvt.h
+++ b/src/device/usbd_pvt.h
@@ -39,6 +39,7 @@
#define USBD_PVT_H_
#include "osal/osal.h"
+#include "common/tusb_fifo.h"
#ifdef __cplusplus
extern "C" {
@@ -68,7 +69,7 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_d
#define usbd_control_xfer_st(_rhport, _dir, _buffer, _len) \
do { \
if (_len) { \
- tusb_error_t err; \
+ uint32_t err; \
dcd_control_xfer(_rhport, _dir, (uint8_t*) _buffer, _len); \
osal_semaphore_wait( _usbd_ctrl_sem, OSAL_TIMEOUT_CONTROL_XFER, &err ); \
STASK_ASSERT_ERR( err ); \
diff --git a/src/osal/osal.c b/src/osal/osal.c
index 4507b0b8f..f5105d4d1 100644
--- a/src/osal/osal.c
+++ b/src/osal/osal.c
@@ -39,7 +39,6 @@
#include "tusb_option.h"
#include "osal.h"
-
//--------------------------------------------------------------------+
// TICK API
//--------------------------------------------------------------------+
diff --git a/src/osal/osal.h b/src/osal/osal.h
index c40ab661d..2ca06f66e 100644
--- a/src/osal/osal.h
+++ b/src/osal/osal.h
@@ -79,7 +79,7 @@ typedef void (*osal_task_func_t)( void * );
* Queue
* osal_queue_def_t, osal_queue_t
* osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
- * osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error)
+ * osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, uint32_t *p_error)
* bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr)
* osal_queue_reset()
*
@@ -87,14 +87,14 @@ typedef void (*osal_task_func_t)( void * );
* osal_semaphore_def_t, osal_semaphore_t
* osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef)
* bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
- * void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error)
+ * void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, uint32_t *p_error)
* void osal_semaphore_reset(osal_semaphore_t const sem_hdl)
*
* Mutex
* osal_mutex_t
* osal_mutex_create(osal_mutex_def_t* mdef)
* bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
- * void osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec, tusb_error_t *p_error)
+ * void osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec, uint32_t *p_error)
*/
#if CFG_TUSB_OS == OPT_OS_FREERTOS
diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h
index f41e91c67..ae988ec1f 100644
--- a/src/osal/osal_freertos.h
+++ b/src/osal/osal_freertos.h
@@ -92,45 +92,6 @@ static inline void osal_task_delay(uint32_t msec)
}
//--------------------------------------------------------------------+
-// QUEUE API
-//--------------------------------------------------------------------+
-#define OSAL_QUEUE_DEF(_name, _depth, _type) \
- static _type _name##_##buf[_depth];\
- osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf };
-
-typedef struct
-{
- uint16_t depth;
- uint16_t item_sz;
- void* buf;
-
- StaticQueue_t sq;
-}osal_queue_def_t;
-
-typedef QueueHandle_t osal_queue_t;
-
-static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
-{
- return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq);
-}
-
-static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *err)
-{
- uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec);
- (*err) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT);
-}
-
-static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr)
-{
- return in_isr ? xQueueSendToBackFromISR(queue_hdl, data, NULL) : xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER);
-}
-
-static inline void osal_queue_reset(osal_queue_t const queue_hdl)
-{
- xQueueReset(queue_hdl);
-}
-
-//--------------------------------------------------------------------+
// Semaphore API
//--------------------------------------------------------------------+
typedef StaticSemaphore_t osal_semaphore_def_t;
@@ -146,7 +107,7 @@ static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
return in_isr ? xSemaphoreGiveFromISR(sem_hdl, NULL) : xSemaphoreGive(sem_hdl);
}
-static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *err)
+static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, uint32_t *err)
{
uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec);
(*err) = (xSemaphoreTake(sem_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT);
@@ -175,6 +136,44 @@ static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
return xSemaphoreGive(mutex_hdl);
}
+//--------------------------------------------------------------------+
+// QUEUE API
+//--------------------------------------------------------------------+
+#define OSAL_QUEUE_DEF(_name, _depth, _type) \
+ static _type _name##_##buf[_depth];\
+ osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf };
+
+typedef struct
+{
+ uint16_t depth;
+ uint16_t item_sz;
+ void* buf;
+
+ StaticQueue_t sq;
+}osal_queue_def_t;
+
+typedef QueueHandle_t osal_queue_t;
+
+static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
+{
+ return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq);
+}
+
+static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, uint32_t *err)
+{
+ uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec);
+ (*err) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT);
+}
+
+static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr)
+{
+ return in_isr ? xQueueSendToBackFromISR(queue_hdl, data, NULL) : xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER);
+}
+
+static inline void osal_queue_reset(osal_queue_t const queue_hdl)
+{
+ xQueueReset(queue_hdl);
+}
#ifdef __cplusplus
}
diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h
index 39748800b..796ddc15f 100644
--- a/src/osal/osal_none.h
+++ b/src/osal/osal_none.h
@@ -43,8 +43,6 @@
#ifndef _TUSB_OSAL_NONE_H_
#define _TUSB_OSAL_NONE_H_
-#include "common/tusb_fifo.h"
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -120,49 +118,6 @@ static inline bool osal_task_create(osal_task_def_t* taskdef)
#define STASK_ASSERT_HDLR(_cond, _func) TU_VERIFY_HDLR(_cond, TU_BREAKPOINT(); _func; TASK_RESTART, TUSB_ERROR_FAILED)
//--------------------------------------------------------------------+
-// QUEUE API
-//--------------------------------------------------------------------+
-#define OSAL_QUEUE_DEF(_name, _depth, _type) TU_FIFO_DEF(_name, _depth, _type, false)
-
-typedef tu_fifo_t osal_queue_def_t;
-typedef tu_fifo_t* osal_queue_t;
-
-static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
-{
- tu_fifo_clear(qdef);
- return (osal_queue_t) qdef;
-}
-
-static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr)
-{
- (void) in_isr;
- return tu_fifo_write( (tu_fifo_t*) queue_hdl, data);
-}
-
-static inline void osal_queue_reset(osal_queue_t const queue_hdl)
-{
- queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0;
-}
-
-#define osal_queue_receive(_q_hdl, p_data, _msec, _err) \
- do { \
- _timeout = tusb_hal_millis(); \
- _state = __LINE__; case __LINE__: \
- if( (_q_hdl)->count == 0 ) { \
- if ( ((_msec) != OSAL_TIMEOUT_WAIT_FOREVER) && ( _timeout + (_msec) <= tusb_hal_millis()) ) \
- *(_err) = TUSB_ERROR_OSAL_TIMEOUT; \
- else \
- return TUSB_ERROR_OSAL_WAITING; \
- } else{ \
- /* Enter critical ? */ \
- tu_fifo_read(queue_hdl, p_data); \
- /* Exit critical ? */ \
- *(_err) = TUSB_ERROR_NONE; \
- } \
- }while(0)
-
-
-//--------------------------------------------------------------------+
// Semaphore API
//--------------------------------------------------------------------+
typedef struct
@@ -236,6 +191,49 @@ static inline bool osal_mutex_lock_notask(osal_mutex_t mutex_hdl)
}
}
+//--------------------------------------------------------------------+
+// QUEUE API
+//--------------------------------------------------------------------+
+#include "common/tusb_fifo.h"
+
+#define OSAL_QUEUE_DEF(_name, _depth, _type) TU_FIFO_DEF(_name, _depth, _type, false)
+
+typedef tu_fifo_t osal_queue_def_t;
+typedef tu_fifo_t* osal_queue_t;
+
+static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
+{
+ tu_fifo_clear(qdef);
+ return (osal_queue_t) qdef;
+}
+
+static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr)
+{
+ (void) in_isr;
+ return tu_fifo_write( (tu_fifo_t*) queue_hdl, data);
+}
+
+static inline void osal_queue_reset(osal_queue_t const queue_hdl)
+{
+ queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0;
+}
+
+#define osal_queue_receive(_q_hdl, p_data, _msec, _err) \
+ do { \
+ _timeout = tusb_hal_millis(); \
+ _state = __LINE__; case __LINE__: \
+ if( (_q_hdl)->count == 0 ) { \
+ if ( ((_msec) != OSAL_TIMEOUT_WAIT_FOREVER) && ( _timeout + (_msec) <= tusb_hal_millis()) ) \
+ *(_err) = TUSB_ERROR_OSAL_TIMEOUT; \
+ else \
+ return TUSB_ERROR_OSAL_WAITING; \
+ } else{ \
+ /* Enter critical ? */ \
+ tu_fifo_read(_q_hdl, p_data); \
+ /* Exit critical ? */ \
+ *(_err) = TUSB_ERROR_NONE; \
+ } \
+ }while(0)
#ifdef __cplusplus
}
diff --git a/src/tusb.h b/src/tusb.h
index 01fdf5ed3..c0246ccc8 100644
--- a/src/tusb.h
+++ b/src/tusb.h
@@ -49,6 +49,7 @@
#include "common/tusb_common.h"
#include "tusb_hal.h"
#include "osal/osal.h"
+#include "common/tusb_fifo.h"
//------------- HOST -------------//
#if MODE_HOST_SUPPORTED