diff options
| author | hathach <[email protected]> | 2018-12-05 17:45:38 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-12-05 17:45:38 +0700 |
| commit | b2ec8230d9acffbc0df280832b0341b82584b226 (patch) | |
| tree | 25e4eae94d5731873fee9da2bfe216eec6d0cc2a /src/osal | |
| parent | cf60b206528fc955bbdd1bfec2c7016a985313ea (diff) | |
| parent | 27793cbd3dba550f9a7124d5e539325904b795e8 (diff) | |
Merge pull request #19 from hathach/devlocal
queue lock/unlock with isr
Diffstat (limited to 'src/osal')
| -rw-r--r-- | src/osal/osal_freertos.h | 4 | ||||
| -rw-r--r-- | src/osal/osal_mynewt.h | 4 | ||||
| -rw-r--r-- | src/osal/osal_none.h | 96 |
3 files changed, 82 insertions, 22 deletions
diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index 52cadd798..704aafd64 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -139,7 +139,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..62b5b45e8 100644 --- a/src/osal/osal_mynewt.h +++ b/src/osal/osal_mynewt.h @@ -75,7 +75,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..4d5a4dd57 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -93,12 +93,11 @@ static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) static inline tusb_error_t 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;
- }
+ while (sem_hdl->count == 0) { }
+ if (sem_hdl->count == 0) {
+ sem_hdl->count--;
+ break;
+ }
}
return TUSB_ERROR_NONE;
}
@@ -124,40 +123,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
-typedef tu_fifo_t osal_queue_def_t;
-typedef tu_fifo_t* osal_queue_t;
+#if MODE_HOST_SUPPORTED
+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 MODE_HOST_SUPPORTED
+ 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
+
+#if MODE_HOST_SUPPORTED
+ 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;
}
|
