summaryrefslogtreecommitdiff
path: root/tinyusb/osal
diff options
context:
space:
mode:
authorhathach <[email protected]>2014-04-18 14:45:21 +0700
committerhathach <[email protected]>2014-04-18 14:45:21 +0700
commit4091ddc4fc31da1b0c33538145e59df4ea9b6d51 (patch)
tree1bd2d5a227120021c810829723daaaa3ceac05cd /tinyusb/osal
parent6aecb62be2af8889d82f2cd3cee0fd794c353338 (diff)
move osal_queue_send of osal_none to osal_none.c
Diffstat (limited to 'tinyusb/osal')
-rw-r--r--tinyusb/osal/osal_none.c26
-rw-r--r--tinyusb/osal/osal_none.h43
2 files changed, 28 insertions, 41 deletions
diff --git a/tinyusb/osal/osal_none.c b/tinyusb/osal/osal_none.c
index e9eaa842a..263a90822 100644
--- a/tinyusb/osal/osal_none.c
+++ b/tinyusb/osal/osal_none.c
@@ -37,7 +37,7 @@
/**************************************************************************/
#include "tusb_option.h"
-#include "osal.h" // TODO refractor
+#include "osal.h"
#if TUSB_CFG_OS == TUSB_OS_NONE
@@ -51,11 +51,31 @@
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-//volatile uint32_t osal_tick_current = 0;
//--------------------------------------------------------------------+
-// IMPLEMENTATION
+// QUEUE API
//--------------------------------------------------------------------+
+// when queue is full, it will overwrite the oldest data in the queue
+tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, void const * data)
+{
+ //TODO mutex lock hal_interrupt_disable
+ memcpy( queue_hdl->buffer + (queue_hdl->wr_idx * queue_hdl->item_size),
+ data,
+ queue_hdl->item_size);
+ queue_hdl->wr_idx = (queue_hdl->wr_idx + 1) % queue_hdl->depth;
+
+ if (queue_hdl->depth == queue_hdl->count) // queue is full, 1st rd is overwritten
+ {
+ queue_hdl->rd_idx = queue_hdl->wr_idx; // keep full state
+ }else
+ {
+ queue_hdl->count++;
+ }
+
+ //TODO mutex unlock hal_interrupt_enable
+
+ return TUSB_ERROR_NONE;
+}
#endif
diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h
index 3ca9a925a..f927f1707 100644
--- a/tinyusb/osal/osal_none.h
+++ b/tinyusb/osal/osal_none.h
@@ -148,11 +148,8 @@ uint32_t tusb_tick_get(void);
typedef volatile uint8_t osal_semaphore_t;
typedef osal_semaphore_t * osal_semaphore_handle_t;
-#define OSAL_SEM_DEF(name)\
- osal_semaphore_t name
-
-#define OSAL_SEM_REF(name)\
- &name
+#define OSAL_SEM_DEF(name) osal_semaphore_t name
+#define OSAL_SEM_REF(name) &name
static inline osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem)
@@ -165,7 +162,6 @@ static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t sem_hdl)
static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t sem_hdl)
{
(*sem_hdl)++;
-
return TUSB_ERROR_NONE;
}
@@ -196,11 +192,8 @@ static inline void osal_semaphore_reset(osal_semaphore_handle_t sem_hdl)
typedef osal_semaphore_t osal_mutex_t;
typedef osal_semaphore_handle_t osal_mutex_handle_t;
-#define OSAL_MUTEX_DEF(name)\
- osal_mutex_t name
-
-#define OSAL_MUTEX_REF(name)\
- &name
+#define OSAL_MUTEX_DEF(name) osal_mutex_t name
+#define OSAL_MUTEX_REF(name) &name
static inline osal_mutex_handle_t osal_mutex_create(osal_mutex_t * p_mutex) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline osal_mutex_handle_t osal_mutex_create(osal_mutex_t * p_mutex)
@@ -257,33 +250,7 @@ static inline osal_queue_handle_t osal_queue_create(osal_queue_t * const p_queue
p_queue->count = p_queue->wr_idx = p_queue->rd_idx = 0;
return (osal_queue_handle_t) p_queue;
}
-
-// TODO move to osal_none.c
-// when queue is full, it will overwrite the oldest data in the queue
-static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, void const * data) ATTR_ALWAYS_INLINE;
-static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, void const * data)
-{
- //TODO mutex lock hal_interrupt_disable
-
- memcpy( queue_hdl->buffer + (queue_hdl->wr_idx * queue_hdl->item_size),
- data,
- queue_hdl->item_size);
-
- queue_hdl->wr_idx = (queue_hdl->wr_idx + 1) % queue_hdl->depth;
-
- if (queue_hdl->depth == queue_hdl->count) // queue is full, 1st rd is overwritten
- {
- queue_hdl->rd_idx = queue_hdl->wr_idx; // keep full state
- }else
- {
- queue_hdl->count++;
- }
-
- //TODO mutex unlock hal_interrupt_enable
-
- return TUSB_ERROR_NONE;
-}
-
+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)
{