diff options
| author | William D. Jones <[email protected]> | 2019-01-10 09:58:06 -0500 |
|---|---|---|
| committer | William D. Jones <[email protected]> | 2019-01-10 09:58:06 -0500 |
| commit | b367baeaf1d64930654f136a2409f1322fc73ab2 (patch) | |
| tree | 710698145d52c72b807971d05512330fde2cc9b1 /src/osal | |
| parent | e4d6f336f0d5004fd9ee3074305b7980ba777dfd (diff) | |
| parent | 5804e56e3c2ab4480bf72d94d997f769a645af47 (diff) | |
Merge branch 'master' of https://github.com/hathach/tinyusb into stm32f4
Diffstat (limited to 'src/osal')
| -rw-r--r-- | src/osal/osal.h | 4 | ||||
| -rw-r--r-- | src/osal/osal_freertos.h | 29 | ||||
| -rw-r--r-- | src/osal/osal_mynewt.h | 25 | ||||
| -rw-r--r-- | src/osal/osal_none.h | 113 |
4 files changed, 91 insertions, 80 deletions
diff --git a/src/osal/osal.h b/src/osal/osal.h index 6846b5757..f38a5305f 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -68,8 +68,6 @@ typedef void (*osal_task_func_t)( void * ); * uint32_t tusb_hal_millis(void)
*
* Task
- * osal_task_def_t
- * bool osal_task_create(osal_task_def_t* taskdef)
* void osal_task_delay(uint32_t msec)
*
* Queue
@@ -83,7 +81,7 @@ 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, uint32_t *p_error)
+ * bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec)
* void osal_semaphore_reset(osal_semaphore_t const sem_hdl)
*
* Mutex
diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index 52cadd798..3e3fa7e95 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -65,27 +65,6 @@ static inline bool in_isr(void) //--------------------------------------------------------------------+ // TASK API //--------------------------------------------------------------------+ -#define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) \ - static uint8_t _name##_##buf[_stack_sz*sizeof(StackType_t)]; \ - osal_task_def_t _name = { .func = _func, .prio = _prio, .stack_sz = _stack_sz, .buf = _name##_##buf, .strname = _str }; - -typedef struct -{ - osal_task_func_t func; - - uint16_t prio; - uint16_t stack_sz; - void* buf; - const char* strname; - - StaticTask_t stask; -}osal_task_def_t; - -static inline bool osal_task_create(osal_task_def_t* taskdef) -{ - return NULL != xTaskCreateStatic(taskdef->func, taskdef->strname, taskdef->stack_sz, NULL, taskdef->prio, (StackType_t*) taskdef->buf, &taskdef->stask); -} - static inline void osal_task_delay(uint32_t msec) { vTaskDelay( pdMS_TO_TICKS(msec) ); @@ -107,10 +86,10 @@ 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, uint32_t *err) +static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec) { 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); + return xSemaphoreTake(sem_hdl, ticks); } static inline void osal_semaphore_reset(osal_semaphore_t const sem_hdl) @@ -139,7 +118,9 @@ static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl) //--------------------------------------------------------------------+ // QUEUE API //--------------------------------------------------------------------+ -#define OSAL_QUEUE_DEF(_name, _depth, _type) \ + +// role device/host is used by OS NONE for mutex (disable usb isr) only +#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \ static _type _name##_##buf[_depth];\ osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf }; diff --git a/src/osal/osal_mynewt.h b/src/osal/osal_mynewt.h index cb09680e0..d63ea731d 100644 --- a/src/osal/osal_mynewt.h +++ b/src/osal/osal_mynewt.h @@ -46,27 +46,6 @@ //--------------------------------------------------------------------+ // TASK API //--------------------------------------------------------------------+ -#define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) \ - static os_stack_t _name##_##buf[_stack_sz]; \ - osal_task_def_t _name = { .func = _func, .prio = _prio, .stack_sz = _stack_sz, .buf = _name##_##buf, .strname = _str }; - -typedef struct -{ - struct os_task mynewt_task; - osal_task_func_t func; - - uint16_t prio; - uint16_t stack_sz; - void* buf; - const char* strname; -}osal_task_def_t; - -static inline bool osal_task_create(osal_task_def_t* taskdef) -{ - return OS_OK == os_task_init(&taskdef->mynewt_task, taskdef->strname, taskdef->func, NULL, taskdef->prio, OS_WAIT_FOREVER, - (os_stack_t*) taskdef->buf, taskdef->stack_sz); -} - static inline void osal_task_delay(uint32_t msec) { os_time_delay( os_time_ms_to_ticks32(msec) ); @@ -75,7 +54,9 @@ static inline void osal_task_delay(uint32_t msec) //--------------------------------------------------------------------+ // QUEUE API //--------------------------------------------------------------------+ -#define OSAL_QUEUE_DEF(_name, _depth, _type) \ + +// role device/host is used by OS NONE for mutex (disable usb isr) only +#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \ static _type _name##_##buf[_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};\ diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 40ecb9c37..55db674ce 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -51,15 +51,11 @@ //--------------------------------------------------------------------+
// TASK API
-// Virtually do nothing in osal none
//--------------------------------------------------------------------+
-#define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) osal_task_def_t _name;
-typedef uint8_t osal_task_def_t;
-
-static inline bool osal_task_create(osal_task_def_t* taskdef)
+static inline void osal_task_delay(uint32_t msec)
{
- (void) taskdef;
- return true;
+ uint32_t start = tusb_hal_millis();
+ while ( ( tusb_hal_millis() - start ) < msec ) {}
}
//--------------------------------------------------------------------+
@@ -90,17 +86,15 @@ static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) sem_hdl->count = 0;
}
-static inline tusb_error_t osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) {
+// TODO blocking for now
+static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec)
+{
(void) msec;
- while (true) {
- while (sem_hdl->count == 0) {
- }
- if (sem_hdl->count == 0) {
- sem_hdl->count--;
- break;
- }
- }
- return TUSB_ERROR_NONE;
+
+ while (sem_hdl->count == 0) { }
+ sem_hdl->count--;
+
+ return true;
}
//--------------------------------------------------------------------+
@@ -124,40 +118,97 @@ static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef) //--------------------------------------------------------------------+
#include "common/tusb_fifo.h"
-#define OSAL_QUEUE_DEF(_name, _depth, _type) TU_FIFO_DEF(_name, _depth, _type, false)
+// extern to avoid including dcd.h and hcd.h
+#if TUSB_OPT_DEVICE_ENABLED
+extern void dcd_int_disable(uint8_t rhport);
+extern void dcd_int_enable(uint8_t rhport);
+#endif
+
+#if TUSB_OPT_HOST_ENABLED
+extern void hcd_int_disable(uint8_t rhport);
+extern void hcd_int_enable(uint8_t rhport);
+#endif
+
+typedef struct
+{
+ uint8_t role; // device or host
+ tu_fifo_t ff;
+}osal_queue_def_t;
+
+typedef osal_queue_def_t* osal_queue_t;
+
+// role device/host is used by OS NONE for mutex (disable usb isr) only
+#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \
+ uint8_t _name##_buf[_depth*sizeof(_type)]; \
+ osal_queue_def_t _name = { \
+ .role = _role, \
+ .ff = { \
+ .buffer = _name##_buf, \
+ .depth = _depth, \
+ .item_size = sizeof(_type), \
+ .overwritable = false, \
+ }\
+ }
+
+// lock queue by disable usb isr
+static inline void _osal_q_lock(osal_queue_t qhdl)
+{
+#if TUSB_OPT_DEVICE_ENABLED
+ if (qhdl->role == OPT_MODE_DEVICE) dcd_int_disable(TUD_OPT_RHPORT);
+#endif
+
+#if TUSB_OPT_HOST_ENABLED
+ if (qhdl->role == OPT_MODE_HOST) hcd_int_disable(TUH_OPT_RHPORT);
+#endif
+}
+
+// unlock queue
+static inline void _osal_q_unlock(osal_queue_t qhdl)
+{
+#if TUSB_OPT_DEVICE_ENABLED
+ if (qhdl->role == OPT_MODE_DEVICE) dcd_int_enable(TUD_OPT_RHPORT);
+#endif
-typedef tu_fifo_t osal_queue_def_t;
-typedef tu_fifo_t* osal_queue_t;
+#if TUSB_OPT_HOST_ENABLED
+ if (qhdl->role == OPT_MODE_HOST) hcd_int_enable(TUH_OPT_RHPORT);
+#endif
+}
static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
{
- tu_fifo_clear(qdef);
+ tu_fifo_clear(&qdef->ff);
return (osal_queue_t) qdef;
}
-static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr)
+static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, bool in_isr)
{
if (!in_isr) {
- tusb_hal_int_disable_all();
+ _osal_q_lock(qhdl);
}
- bool success = tu_fifo_write( (tu_fifo_t*) queue_hdl, data);
+
+ bool success = tu_fifo_write(&qhdl->ff, data);
+
if (!in_isr) {
- tusb_hal_int_enable_all();
+ _osal_q_unlock(qhdl);
}
+
return success;
}
-static inline void osal_queue_reset(osal_queue_t const queue_hdl)
+static inline void osal_queue_reset(osal_queue_t const qhdl)
{
// tusb_hal_int_disable_all();
- tu_fifo_clear( (tu_fifo_t*) queue_hdl);
+ tu_fifo_clear(&qhdl->ff);
// tusb_hal_int_enable_all();
}
-static inline bool osal_queue_receive(osal_queue_t const queue_hdl, void* data) {
- tusb_hal_int_disable_all();
- bool success = tu_fifo_read(queue_hdl, data);
- tusb_hal_int_enable_all();
+// non blocking
+static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data)
+{
+ _osal_q_lock(qhdl);
+ bool success = tu_fifo_read(&qhdl->ff, data);
+ _osal_q_unlock(qhdl);
+
return success;
}
|
