summaryrefslogtreecommitdiff
path: root/tinyusb/osal
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-04-10 01:13:31 +0700
committerhathach <[email protected]>2013-04-10 01:18:32 +0700
commite14aa4197d290fc7f294d42d4886fb5892c9f360 (patch)
tree20743d8b56c7cb9b9f66b83987235fe45e17772f /tinyusb/osal
parente6a44b3fe9a0af6ce33f8340c8703bf0bbc43d5a (diff)
change osal_queue_send(osal_queue_handle_t const queue_hdl, uint32_t data) signature to osal_queue_send(osal_queue_handle_t const queue_hdl, const void * data)
- support any size queue message (instead of fixed uint32_t)
Diffstat (limited to 'tinyusb/osal')
-rw-r--r--tinyusb/osal/osal.h2
-rw-r--r--tinyusb/osal/osal_freeRTOS.h6
-rw-r--r--tinyusb/osal/osal_none.h27
3 files changed, 20 insertions, 15 deletions
diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h
index 0ae4907db..3904e2c77 100644
--- a/tinyusb/osal/osal.h
+++ b/tinyusb/osal/osal.h
@@ -173,7 +173,7 @@ typedef osal_queue_t * osal_queue_handle_t;
osal_queue_handle_t osal_queue_create (osal_queue_t *p_queue);
void osal_queue_receive (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error);
-tusb_error_t osal_queue_send (osal_queue_handle_t const queue_hdl, uint32_t data);
+tusb_error_t osal_queue_send (osal_queue_handle_t const queue_hdl, const void * data);
void osal_queue_flush(osal_queue_handle_t const queue_hdl);
//--------------------------------------------------------------------+
diff --git a/tinyusb/osal/osal_freeRTOS.h b/tinyusb/osal/osal_freeRTOS.h
index aa899d60d..1a970f6b2 100644
--- a/tinyusb/osal/osal_freeRTOS.h
+++ b/tinyusb/osal/osal_freeRTOS.h
@@ -126,11 +126,11 @@ static inline void osal_queue_receive (osal_queue_handle_t const queue_hdl, uint
(*p_error) = ( xQueueReceive(queue_hdl, p_data, osal_tick_from_msec(msec)) == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT;
}
-static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, uint32_t data) ATTR_ALWAYS_INLINE;
-static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, uint32_t data)
+static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, const void * data) ATTR_ALWAYS_INLINE;
+static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, const void * data)
{
portBASE_TYPE taskWaken;
- return ( xQueueSendFromISR(queue_hdl, &data, &taskWaken) == pdTRUE ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_QUEUE_FAILED;
+ return ( xQueueSendFromISR(queue_hdl, data, &taskWaken) == pdTRUE ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_QUEUE_FAILED;
}
#ifdef __cplusplus
diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h
index 41a3801e9..67435bedc 100644
--- a/tinyusb/osal/osal_none.h
+++ b/tinyusb/osal/osal_none.h
@@ -203,11 +203,12 @@ static inline void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl)
// QUEUE API
//--------------------------------------------------------------------+
typedef struct{
- uint32_t * const buffer ; ///< buffer pointer
- uint8_t const depth ; ///< buffer size
- volatile uint8_t count ; ///< bytes in fifo
- volatile uint8_t wr_idx ; ///< write pointer
- volatile uint8_t rd_idx ; ///< read pointer
+ void * 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 osal_queue_t * osal_queue_handle_t;
@@ -216,8 +217,9 @@ typedef osal_queue_t * osal_queue_handle_t;
#define OSAL_QUEUE_DEF(name, queue_depth, type)\
uint32_t name##_buffer[queue_depth];\
osal_queue_t name = {\
- .buffer = name##_buffer,\
- .depth = queue_depth\
+ .buffer = name##_buffer,\
+ .depth = queue_depth,\
+ .item_size = sizeof(type)\
}
static inline osal_queue_handle_t osal_queue_create(osal_queue_t * const p_queue) ATTR_ALWAYS_INLINE;
@@ -228,12 +230,15 @@ static inline osal_queue_handle_t osal_queue_create(osal_queue_t * const p_queue
}
// 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, uint32_t data) ATTR_ALWAYS_INLINE;
-static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, uint32_t data)
+static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, const void * data) ATTR_ALWAYS_INLINE;
+static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, const void * data)
{
//TODO mutex lock hal_interrupt_disable
- queue_hdl->buffer[queue_hdl->wr_idx] = data;
+ 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
@@ -266,7 +271,7 @@ static inline void osal_queue_flush(osal_queue_handle_t const queue_hdl)
return TUSB_ERROR_OSAL_WAITING;\
} else{\
/*TODO mutex lock hal_interrupt_disable */\
- *p_data = queue_hdl->buffer[queue_hdl->rd_idx];\
+ 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 */\