update osal API
add osal_semaphore_delete(), osal_mutex_delete(), osal_queue_delete()
This commit is contained in:
@@ -74,15 +74,18 @@ typedef void (*osal_task_func_t)( void * );
|
|||||||
// Should be implemented as static inline function in osal_port.h header
|
// Should be implemented as static inline function in osal_port.h header
|
||||||
/*
|
/*
|
||||||
osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef);
|
osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef);
|
||||||
|
bool osal_semaphore_delete(osal_semaphore_t semd_hdl);
|
||||||
bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr);
|
bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr);
|
||||||
bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec);
|
bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec);
|
||||||
void osal_semaphore_reset(osal_semaphore_t sem_hdl); // TODO removed
|
void osal_semaphore_reset(osal_semaphore_t sem_hdl); // TODO removed
|
||||||
|
|
||||||
osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef);
|
osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef);
|
||||||
|
bool osal_mutex_delete(osal_mutex_t mutex_hdl)
|
||||||
bool osal_mutex_lock (osal_mutex_t sem_hdl, uint32_t msec);
|
bool osal_mutex_lock (osal_mutex_t sem_hdl, uint32_t msec);
|
||||||
bool osal_mutex_unlock(osal_mutex_t mutex_hdl);
|
bool osal_mutex_unlock(osal_mutex_t mutex_hdl);
|
||||||
|
|
||||||
osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
|
osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
|
||||||
|
bool osal_queue_delete(osal_queue_t qhdl);
|
||||||
bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec);
|
bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec);
|
||||||
bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr);
|
bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr);
|
||||||
bool osal_queue_empty(osal_queue_t qhdl);
|
bool osal_queue_empty(osal_queue_t qhdl);
|
||||||
|
@@ -24,8 +24,8 @@
|
|||||||
* This file is part of the TinyUSB stack.
|
* This file is part of the TinyUSB stack.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TUSB_OSAL_FREERTOS_H_
|
#ifndef TUSB_OSAL_FREERTOS_H_
|
||||||
#define _TUSB_OSAL_FREERTOS_H_
|
#define TUSB_OSAL_FREERTOS_H_
|
||||||
|
|
||||||
// FreeRTOS Headers
|
// FreeRTOS Headers
|
||||||
#include TU_INCLUDE_PATH(CFG_TUSB_OS_INC_PATH,FreeRTOS.h)
|
#include TU_INCLUDE_PATH(CFG_TUSB_OS_INC_PATH,FreeRTOS.h)
|
||||||
@@ -114,6 +114,11 @@ TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_delete(osal_semaphore_t semd_hdl) {
|
||||||
|
vSemaphoreDelete(semd_hdl);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) {
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) {
|
||||||
if ( !in_isr ) {
|
if ( !in_isr ) {
|
||||||
return xSemaphoreGive(sem_hdl) != 0;
|
return xSemaphoreGive(sem_hdl) != 0;
|
||||||
@@ -153,6 +158,11 @@ TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_de
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_delete(osal_mutex_t mutex_hdl) {
|
||||||
|
vSemaphoreDelete(mutex_hdl);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec) {
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec) {
|
||||||
return osal_semaphore_wait(mutex_hdl, msec);
|
return osal_semaphore_wait(mutex_hdl, msec);
|
||||||
}
|
}
|
||||||
@@ -181,6 +191,11 @@ TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_de
|
|||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_delete(osal_queue_t qhdl) {
|
||||||
|
vQueueDelete(qhdl);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) {
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) {
|
||||||
return xQueueReceive(qhdl, data, _osal_ms2tick(msec));
|
return xQueueReceive(qhdl, data, _osal_ms2tick(msec));
|
||||||
}
|
}
|
||||||
|
@@ -36,8 +36,7 @@
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// TASK API
|
// TASK API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec)
|
TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) {
|
||||||
{
|
|
||||||
os_time_delay( os_time_ms_to_ticks32(msec) );
|
os_time_delay( os_time_ms_to_ticks32(msec) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,25 +46,26 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec)
|
|||||||
typedef struct os_sem osal_semaphore_def_t;
|
typedef struct os_sem osal_semaphore_def_t;
|
||||||
typedef struct os_sem* osal_semaphore_t;
|
typedef struct os_sem* osal_semaphore_t;
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef)
|
TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) {
|
||||||
{
|
|
||||||
return (os_sem_init(semdef, 0) == OS_OK) ? (osal_semaphore_t) semdef : NULL;
|
return (os_sem_init(semdef, 0) == OS_OK) ? (osal_semaphore_t) semdef : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_delete(osal_semaphore_t semd_hdl) {
|
||||||
{
|
(void) semd_hdl;
|
||||||
|
return true; // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) {
|
||||||
(void) in_isr;
|
(void) in_isr;
|
||||||
return os_sem_release(sem_hdl) == OS_OK;
|
return os_sem_release(sem_hdl) == OS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) {
|
||||||
{
|
|
||||||
uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? OS_TIMEOUT_NEVER : os_time_ms_to_ticks32(msec);
|
uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? OS_TIMEOUT_NEVER : os_time_ms_to_ticks32(msec);
|
||||||
return os_sem_pend(sem_hdl, ticks) == OS_OK;
|
return os_sem_pend(sem_hdl, ticks) == OS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl)
|
static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) {
|
||||||
{
|
|
||||||
// TODO implement later
|
// TODO implement later
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,19 +75,21 @@ static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl)
|
|||||||
typedef struct os_mutex osal_mutex_def_t;
|
typedef struct os_mutex osal_mutex_def_t;
|
||||||
typedef struct os_mutex* osal_mutex_t;
|
typedef struct os_mutex* osal_mutex_t;
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef)
|
TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef) {
|
||||||
{
|
|
||||||
return (os_mutex_init(mdef) == OS_OK) ? (osal_mutex_t) mdef : NULL;
|
return (os_mutex_init(mdef) == OS_OK) ? (osal_mutex_t) mdef : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_delete(osal_mutex_t mutex_hdl) {
|
||||||
{
|
(void) mutex_hdl;
|
||||||
|
return true; // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec) {
|
||||||
uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? OS_TIMEOUT_NEVER : os_time_ms_to_ticks32(msec);
|
uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? OS_TIMEOUT_NEVER : os_time_ms_to_ticks32(msec);
|
||||||
return os_mutex_pend(mutex_hdl, ticks) == OS_OK;
|
return os_mutex_pend(mutex_hdl, ticks) == OS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl) {
|
||||||
{
|
|
||||||
return os_mutex_release(mutex_hdl) == OS_OK;
|
return os_mutex_release(mutex_hdl) == OS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +103,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hd
|
|||||||
static struct os_event _name##_##evbuf[_depth];\
|
static struct os_event _name##_##evbuf[_depth];\
|
||||||
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf, .evbuf = _name##_##evbuf};\
|
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf, .evbuf = _name##_##evbuf};\
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
uint16_t depth;
|
uint16_t depth;
|
||||||
uint16_t item_sz;
|
uint16_t item_sz;
|
||||||
void* buf;
|
void* buf;
|
||||||
@@ -116,17 +117,20 @@ typedef struct
|
|||||||
|
|
||||||
typedef osal_queue_def_t* osal_queue_t;
|
typedef osal_queue_def_t* osal_queue_t;
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
|
TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) {
|
||||||
{
|
if ( OS_OK != os_mempool_init(&qdef->mpool, qdef->depth, qdef->item_sz, qdef->buf, "usb queue") ) return NULL;
|
||||||
if ( OS_OK != os_mempool_init(&qdef->mpool, qdef->depth, qdef->item_sz, qdef->buf, "usbd queue") ) return NULL;
|
if ( OS_OK != os_mempool_init(&qdef->epool, qdef->depth, sizeof(struct os_event), qdef->evbuf, "usb evqueue") ) return NULL;
|
||||||
if ( OS_OK != os_mempool_init(&qdef->epool, qdef->depth, sizeof(struct os_event), qdef->evbuf, "usbd evqueue") ) return NULL;
|
|
||||||
|
|
||||||
os_eventq_init(&qdef->evq);
|
os_eventq_init(&qdef->evq);
|
||||||
return (osal_queue_t) qdef;
|
return (osal_queue_t) qdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_delete(osal_queue_t qhdl) {
|
||||||
{
|
(void) qhdl;
|
||||||
|
return true; // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) {
|
||||||
(void) msec; // os_eventq_get() does not take timeout, always behave as msec = WAIT_FOREVER
|
(void) msec; // os_eventq_get() does not take timeout, always behave as msec = WAIT_FOREVER
|
||||||
|
|
||||||
struct os_event* ev;
|
struct os_event* ev;
|
||||||
@@ -139,8 +143,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, v
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr)
|
static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr) {
|
||||||
{
|
|
||||||
(void) in_isr;
|
(void) in_isr;
|
||||||
|
|
||||||
// get a block from mem pool for data
|
// get a block from mem pool for data
|
||||||
@@ -150,8 +153,7 @@ static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in
|
|||||||
|
|
||||||
// get a block from event pool to put into queue
|
// get a block from event pool to put into queue
|
||||||
struct os_event* ev = (struct os_event*) os_memblock_get(&qhdl->epool);
|
struct os_event* ev = (struct os_event*) os_memblock_get(&qhdl->epool);
|
||||||
if (!ev)
|
if (!ev) {
|
||||||
{
|
|
||||||
os_memblock_put(&qhdl->mpool, ptr);
|
os_memblock_put(&qhdl->mpool, ptr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -163,8 +165,7 @@ static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_empty(osal_queue_t qhdl)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_empty(osal_queue_t qhdl) {
|
||||||
{
|
|
||||||
return STAILQ_EMPTY(&qhdl->evq.evq_list);
|
return STAILQ_EMPTY(&qhdl->evq.evq_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,6 +54,12 @@ TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_
|
|||||||
return semdef;
|
return semdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_delete(osal_semaphore_t semd_hdl) {
|
||||||
|
(void) semd_hdl;
|
||||||
|
return true; // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) {
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) {
|
||||||
(void) in_isr;
|
(void) in_isr;
|
||||||
sem_hdl->count++;
|
sem_hdl->count++;
|
||||||
@@ -90,6 +96,11 @@ TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_de
|
|||||||
return mdef;
|
return mdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_delete(osal_mutex_t mutex_hdl) {
|
||||||
|
(void) mutex_hdl;
|
||||||
|
return true; // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec) {
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec) {
|
||||||
return osal_semaphore_wait(mutex_hdl, msec);
|
return osal_semaphore_wait(mutex_hdl, msec);
|
||||||
}
|
}
|
||||||
@@ -143,6 +154,11 @@ TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_de
|
|||||||
return (osal_queue_t) qdef;
|
return (osal_queue_t) qdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_delete(osal_queue_t qhdl) {
|
||||||
|
(void) qhdl;
|
||||||
|
return true; // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) {
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) {
|
||||||
(void) msec; // not used, always behave as msec = 0
|
(void) msec; // not used, always behave as msec = 0
|
||||||
|
|
||||||
|
@@ -24,8 +24,8 @@
|
|||||||
* This file is part of the TinyUSB stack.
|
* This file is part of the TinyUSB stack.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TUSB_OSAL_PICO_H_
|
#ifndef TUSB_OSAL_PICO_H_
|
||||||
#define _TUSB_OSAL_PICO_H_
|
#define TUSB_OSAL_PICO_H_
|
||||||
|
|
||||||
#include "pico/time.h"
|
#include "pico/time.h"
|
||||||
#include "pico/sem.h"
|
#include "pico/sem.h"
|
||||||
@@ -33,42 +33,42 @@
|
|||||||
#include "pico/critical_section.h"
|
#include "pico/critical_section.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// TASK API
|
// TASK API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec)
|
TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) {
|
||||||
{
|
|
||||||
sleep_ms(msec);
|
sleep_ms(msec);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Binary Semaphore API
|
// Binary Semaphore API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
typedef struct semaphore osal_semaphore_def_t, *osal_semaphore_t;
|
typedef struct semaphore osal_semaphore_def_t, * osal_semaphore_t;
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef)
|
TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) {
|
||||||
{
|
|
||||||
sem_init(semdef, 0, 255);
|
sem_init(semdef, 0, 255);
|
||||||
return semdef;
|
return semdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_delete(osal_semaphore_t semd_hdl) {
|
||||||
{
|
(void) semd_hdl;
|
||||||
|
return true; // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) {
|
||||||
(void) in_isr;
|
(void) in_isr;
|
||||||
sem_release(sem_hdl);
|
sem_release(sem_hdl);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) {
|
||||||
{
|
|
||||||
return sem_acquire_timeout_ms(sem_hdl, msec);
|
return sem_acquire_timeout_ms(sem_hdl, msec);
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl)
|
TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) {
|
||||||
{
|
|
||||||
sem_reset(sem_hdl, 0);
|
sem_reset(sem_hdl, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,21 +76,23 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset(osal_semaphore_t s
|
|||||||
// MUTEX API
|
// MUTEX API
|
||||||
// Within tinyusb, mutex is never used in ISR context
|
// Within tinyusb, mutex is never used in ISR context
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
typedef struct mutex osal_mutex_def_t, *osal_mutex_t;
|
typedef struct mutex osal_mutex_def_t, * osal_mutex_t;
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef)
|
TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef) {
|
||||||
{
|
|
||||||
mutex_init(mdef);
|
mutex_init(mdef);
|
||||||
return mdef;
|
return mdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_delete(osal_mutex_t mutex_hdl) {
|
||||||
{
|
(void) mutex_hdl;
|
||||||
|
return true; // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec) {
|
||||||
return mutex_enter_timeout_ms(mutex_hdl, msec);
|
return mutex_enter_timeout_ms(mutex_hdl, msec);
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl) {
|
||||||
{
|
|
||||||
mutex_exit(mutex_hdl);
|
mutex_exit(mutex_hdl);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -100,75 +102,54 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hd
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
#include "common/tusb_fifo.h"
|
#include "common/tusb_fifo.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
tu_fifo_t ff;
|
||||||
tu_fifo_t ff;
|
struct critical_section critsec; // osal_queue may be used in IRQs, so need critical section
|
||||||
struct critical_section critsec; // osal_queue may be used in IRQs, so need critical section
|
|
||||||
} osal_queue_def_t;
|
} osal_queue_def_t;
|
||||||
|
|
||||||
typedef osal_queue_def_t* osal_queue_t;
|
typedef osal_queue_def_t* osal_queue_t;
|
||||||
|
|
||||||
// role device/host is used by OS NONE for mutex (disable usb isr) only
|
// role device/host is used by OS NONE for mutex (disable usb isr) only
|
||||||
#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \
|
#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \
|
||||||
uint8_t _name##_buf[_depth*sizeof(_type)]; \
|
uint8_t _name##_buf[_depth*sizeof(_type)]; \
|
||||||
osal_queue_def_t _name = { \
|
osal_queue_def_t _name = { \
|
||||||
.ff = TU_FIFO_INIT(_name##_buf, _depth, _type, false) \
|
.ff = TU_FIFO_INIT(_name##_buf, _depth, _type, false) \
|
||||||
}
|
}
|
||||||
|
|
||||||
// lock queue by disable USB interrupt
|
TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) {
|
||||||
TU_ATTR_ALWAYS_INLINE static inline void _osal_q_lock(osal_queue_t qhdl)
|
|
||||||
{
|
|
||||||
critical_section_enter_blocking(&qhdl->critsec);
|
|
||||||
}
|
|
||||||
|
|
||||||
// unlock queue
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline void _osal_q_unlock(osal_queue_t qhdl)
|
|
||||||
{
|
|
||||||
critical_section_exit(&qhdl->critsec);
|
|
||||||
}
|
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
|
|
||||||
{
|
|
||||||
critical_section_init(&qdef->critsec);
|
critical_section_init(&qdef->critsec);
|
||||||
tu_fifo_clear(&qdef->ff);
|
tu_fifo_clear(&qdef->ff);
|
||||||
return (osal_queue_t) qdef;
|
return (osal_queue_t) qdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_delete(osal_queue_t qhdl) {
|
||||||
{
|
osal_queue_def_t* qdef = (osal_queue_def_t*) qhdl;
|
||||||
|
critical_section_deinit(&qdef->critsec);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) {
|
||||||
(void) msec; // not used, always behave as msec = 0
|
(void) msec; // not used, always behave as msec = 0
|
||||||
|
|
||||||
// TODO: revisit... docs say that mutexes are never used from IRQ context,
|
critical_section_enter_blocking(&qhdl->critsec);
|
||||||
// however osal_queue_recieve may be. therefore my assumption is that
|
|
||||||
// the fifo mutex is not populated for queues used from an IRQ context
|
|
||||||
//assert(!qhdl->ff.mutex);
|
|
||||||
|
|
||||||
_osal_q_lock(qhdl);
|
|
||||||
bool success = tu_fifo_read(&qhdl->ff, data);
|
bool success = tu_fifo_read(&qhdl->ff, data);
|
||||||
_osal_q_unlock(qhdl);
|
critical_section_exit(&qhdl->critsec);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send(osal_queue_t qhdl, void const* data, bool in_isr) {
|
||||||
{
|
|
||||||
// TODO: revisit... docs say that mutexes are never used from IRQ context,
|
|
||||||
// however osal_queue_recieve may be. therefore my assumption is that
|
|
||||||
// the fifo mutex is not populated for queues used from an IRQ context
|
|
||||||
//assert(!qhdl->ff.mutex);
|
|
||||||
(void) in_isr;
|
(void) in_isr;
|
||||||
|
|
||||||
_osal_q_lock(qhdl);
|
critical_section_enter_blocking(&qhdl->critsec);
|
||||||
bool success = tu_fifo_write(&qhdl->ff, data);
|
bool success = tu_fifo_write(&qhdl->ff, data);
|
||||||
_osal_q_unlock(qhdl);
|
critical_section_exit(&qhdl->critsec);
|
||||||
|
|
||||||
TU_ASSERT(success);
|
TU_ASSERT(success);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_empty(osal_queue_t qhdl)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_empty(osal_queue_t qhdl) {
|
||||||
{
|
|
||||||
// TODO: revisit; whether this is true or not currently, tu_fifo_empty is a single
|
// TODO: revisit; whether this is true or not currently, tu_fifo_empty is a single
|
||||||
// volatile read.
|
// volatile read.
|
||||||
|
|
||||||
@@ -178,7 +159,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_empty(osal_queue_t qhdl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _TUSB_OSAL_PICO_H_ */
|
#endif
|
||||||
|
@@ -25,8 +25,8 @@
|
|||||||
* This file is part of the TinyUSB stack.
|
* This file is part of the TinyUSB stack.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TUSB_OSAL_RTTHREAD_H_
|
#ifndef TUSB_OSAL_RTTHREAD_H_
|
||||||
#define _TUSB_OSAL_RTTHREAD_H_
|
#define TUSB_OSAL_RTTHREAD_H_
|
||||||
|
|
||||||
// RT-Thread Headers
|
// RT-Thread Headers
|
||||||
#include "rtthread.h"
|
#include "rtthread.h"
|
||||||
@@ -133,4 +133,4 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_empty(osal_queue_t qhdl) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _TUSB_OSAL_RTTHREAD_H_ */
|
#endif
|
||||||
|
@@ -25,8 +25,8 @@
|
|||||||
* This file is part of the TinyUSB stack.
|
* This file is part of the TinyUSB stack.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TUSB_OSAL_RTX4_H_
|
#ifndef TUSB_OSAL_RTX4_H_
|
||||||
#define _TUSB_OSAL_RTX4_H_
|
#define TUSB_OSAL_RTX4_H_
|
||||||
|
|
||||||
#include <rtl.h>
|
#include <rtl.h>
|
||||||
|
|
||||||
@@ -37,8 +37,7 @@ extern "C" {
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// TASK API
|
// TASK API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec)
|
TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) {
|
||||||
{
|
|
||||||
uint16_t hi = msec >> 16;
|
uint16_t hi = msec >> 16;
|
||||||
uint16_t lo = msec;
|
uint16_t lo = msec;
|
||||||
while (hi--) {
|
while (hi--) {
|
||||||
@@ -48,12 +47,13 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline uint16_t msec2wait(uint32_t msec) {
|
TU_ATTR_ALWAYS_INLINE static inline uint16_t msec2wait(uint32_t msec) {
|
||||||
if (msec == OSAL_TIMEOUT_WAIT_FOREVER)
|
if (msec == OSAL_TIMEOUT_WAIT_FOREVER) {
|
||||||
return 0xFFFF;
|
return 0xFFFF;
|
||||||
else if (msec >= 0xFFFE)
|
} else if (msec >= 0xFFFE) {
|
||||||
return 0xFFFE;
|
return 0xFFFE;
|
||||||
else
|
} else {
|
||||||
return msec;
|
return msec;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@@ -67,6 +67,11 @@ TU_ATTR_ALWAYS_INLINE static inline OS_ID osal_semaphore_create(osal_semaphore_d
|
|||||||
return semdef;
|
return semdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_delete(osal_semaphore_t semd_hdl) {
|
||||||
|
(void) semd_hdl;
|
||||||
|
return true; // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) {
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) {
|
||||||
if ( !in_isr ) {
|
if ( !in_isr ) {
|
||||||
os_sem_send(sem_hdl);
|
os_sem_send(sem_hdl);
|
||||||
@@ -90,19 +95,21 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset(osal_semaphore_t c
|
|||||||
typedef OS_MUT osal_mutex_def_t;
|
typedef OS_MUT osal_mutex_def_t;
|
||||||
typedef OS_ID osal_mutex_t;
|
typedef OS_ID osal_mutex_t;
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef)
|
TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef) {
|
||||||
{
|
|
||||||
os_mut_init(mdef);
|
os_mut_init(mdef);
|
||||||
return mdef;
|
return mdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_delete(osal_mutex_t mutex_hdl) {
|
||||||
{
|
(void) mutex_hdl;
|
||||||
|
return true; // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec) {
|
||||||
return os_mut_wait(mutex_hdl, msec2wait(msec)) != OS_R_TMO;
|
return os_mut_wait(mutex_hdl, msec2wait(msec)) != OS_R_TMO;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl) {
|
||||||
{
|
|
||||||
return os_mut_release(mutex_hdl) == OS_R_OK;
|
return os_mut_release(mutex_hdl) == OS_R_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,9 +123,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hd
|
|||||||
_declare_box(_name##__pool, sizeof(_type), _depth); \
|
_declare_box(_name##__pool, sizeof(_type), _depth); \
|
||||||
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .pool = _name##__pool, .mbox = _name##__mbox };
|
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .pool = _name##__pool, .mbox = _name##__mbox };
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint16_t depth;
|
uint16_t depth;
|
||||||
uint16_t item_sz;
|
uint16_t item_sz;
|
||||||
U32* pool;
|
U32* pool;
|
||||||
@@ -127,15 +132,13 @@ typedef struct
|
|||||||
|
|
||||||
typedef osal_queue_def_t* osal_queue_t;
|
typedef osal_queue_def_t* osal_queue_t;
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
|
TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) {
|
||||||
{
|
|
||||||
os_mbx_init(qdef->mbox, (qdef->depth + 4) * 4);
|
os_mbx_init(qdef->mbox, (qdef->depth + 4) * 4);
|
||||||
_init_box(qdef->pool, ((qdef->item_sz+3)/4)*(qdef->depth) + 3, qdef->item_sz);
|
_init_box(qdef->pool, ((qdef->item_sz+3)/4)*(qdef->depth) + 3, qdef->item_sz);
|
||||||
return qdef;
|
return qdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) {
|
||||||
{
|
|
||||||
void* buf;
|
void* buf;
|
||||||
os_mbx_wait(qhdl->mbox, &buf, msec2wait(msec));
|
os_mbx_wait(qhdl->mbox, &buf, msec2wait(msec));
|
||||||
memcpy(data, buf, qhdl->item_sz);
|
memcpy(data, buf, qhdl->item_sz);
|
||||||
@@ -143,23 +146,23 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, v
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_delete(osal_queue_t qhdl) {
|
||||||
{
|
(void) qhdl;
|
||||||
|
return true; // nothing to do ?
|
||||||
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr) {
|
||||||
void* buf = _alloc_box(qhdl->pool);
|
void* buf = _alloc_box(qhdl->pool);
|
||||||
memcpy(buf, data, qhdl->item_sz);
|
memcpy(buf, data, qhdl->item_sz);
|
||||||
if ( !in_isr )
|
if ( !in_isr ) {
|
||||||
{
|
|
||||||
os_mbx_send(qhdl->mbox, buf, 0xFFFF);
|
os_mbx_send(qhdl->mbox, buf, 0xFFFF);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
isr_mbx_send(qhdl->mbox, buf);
|
isr_mbx_send(qhdl->mbox, buf);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_empty(osal_queue_t qhdl)
|
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_empty(osal_queue_t qhdl) {
|
||||||
{
|
|
||||||
return os_mbx_check(qhdl->mbox) == qhdl->depth;
|
return os_mbx_check(qhdl->mbox) == qhdl->depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -237,8 +237,8 @@ bool tu_edpt_stream_init(tu_edpt_stream_t* s, bool is_host, bool is_tx, bool ove
|
|||||||
bool tu_edpt_stream_deinit(tu_edpt_stream_t* s) {
|
bool tu_edpt_stream_deinit(tu_edpt_stream_t* s) {
|
||||||
(void) s;
|
(void) s;
|
||||||
#if OSAL_MUTEX_REQUIRED
|
#if OSAL_MUTEX_REQUIRED
|
||||||
if (s->ff->mutex_wr) osal_mutex_delete(s->ff->mutex_wr);
|
if (s->ff.mutex_wr) osal_mutex_delete(s->ff.mutex_wr);
|
||||||
if (s->ff->mutex_rd) osal_mutex_delete(s->ff->mutex_rd);
|
if (s->ff.mutex_rd) osal_mutex_delete(s->ff.mutex_rd);
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user