summaryrefslogtreecommitdiff
path: root/tinyusb/osal/osal_none.h
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-02-28 16:45:54 +0700
committerhathach <[email protected]>2018-02-28 16:45:54 +0700
commit30124b9b02e067c967aca642823f3ed4cb7f618d (patch)
tree5823eb3dfd498e85420d26b3924057bf272c42b4 /tinyusb/osal/osal_none.h
parentc961bb47feee422746f5aa81e48b00a50a4cbf0e (diff)
refactor osal queue API
Diffstat (limited to 'tinyusb/osal/osal_none.h')
-rw-r--r--tinyusb/osal/osal_none.h45
1 files changed, 19 insertions, 26 deletions
diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h
index d7302d2cf..1a833b07d 100644
--- a/tinyusb/osal/osal_none.h
+++ b/tinyusb/osal/osal_none.h
@@ -44,6 +44,7 @@
#define _TUSB_OSAL_NONE_H_
#include "osal_common.h"
+#include "common/fifo.h"
#ifdef __cplusplus
extern "C" {
@@ -225,38 +226,30 @@ static inline void osal_mutex_reset(osal_mutex_handle_t mutex_hdl)
//--------------------------------------------------------------------+
// QUEUE API
//--------------------------------------------------------------------+
-typedef struct{
- uint8_t* const buffer ; ///< buffer pointer
- uint8_t const depth ; ///< max items
- uint8_t const item_size ; ///< size of each item
- volatile uint8_t count ; ///< number of items in queue
- volatile uint8_t wr_idx ; ///< write pointer
- volatile uint8_t rd_idx ; ///< read pointer
-} osal_queue_t;
+typedef fifo_t* osal_queue_t;
-typedef osal_queue_t * osal_queue_handle_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);
-// use to declare a queue, within the scope of tinyusb, should only use primitive type only
-#define OSAL_QUEUE_DEF(name, queue_depth, type)\
- STATIC_ASSERT(queue_depth < 256, "OSAL Queue only support up to 255 depth");\
- type name##_buffer[queue_depth];\
- osal_queue_t name = {\
- .buffer = (uint8_t*) name##_buffer,\
- .depth = queue_depth,\
- .item_size = sizeof(type)\
- }
+ *ff = (fifo_t) {
+ .buffer = buf, .depth = depth, .item_size = item_size,
+ .count = 0, .wr_idx =0, .rd_idx = 0, .overwritable = false
+ };
-#define OSAL_QUEUE_REF(name) (&name)
+ return (osal_queue_t) ff;
+}
-static inline osal_queue_handle_t osal_queue_create(osal_queue_t * const p_queue) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
-static inline osal_queue_handle_t osal_queue_create(osal_queue_t * const p_queue)
+
+static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data)
{
- p_queue->count = p_queue->wr_idx = p_queue->rd_idx = 0;
- return (osal_queue_handle_t) p_queue;
+ return fifo_write( (fifo_t*) queue_hdl, data);
}
-tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, void const * data);
-static inline void osal_queue_flush(osal_queue_handle_t const queue_hdl) ATTR_ALWAYS_INLINE;
-static inline void osal_queue_flush(osal_queue_handle_t const queue_hdl)
+
+static inline void osal_queue_flush(osal_queue_t const queue_hdl)
{
queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0;
}