Просмотр исходного кода

added osal_queue_empty() API

ported for osal none/freertos/mynewt
hathach 6 лет назад
Родитель
Сommit
4e8d414bc6
4 измененных файлов с 26 добавлено и 6 удалено
  1. 1 0
      src/osal/osal.h
  2. 9 4
      src/osal/osal_freertos.h
  3. 6 0
      src/osal/osal_mynewt.h
  4. 10 2
      src/osal/osal_none.h

+ 1 - 0
src/osal/osal.h

@@ -80,6 +80,7 @@ static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl);
 static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
 static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data);
 static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, bool in_isr);
+static inline bool osal_queue_empty(osal_queue_t const qhdl);
 
 #if 0  // TODO remove subtask related macros later
 // Sub Task

+ 9 - 4
src/osal/osal_freertos.h

@@ -118,14 +118,19 @@ static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
   return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq);
 }
 
-static inline bool osal_queue_receive(osal_queue_t const queue_hdl, void* data)
+static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data)
 {
-  return xQueueReceive(queue_hdl, data, portMAX_DELAY);
+  return xQueueReceive(qhdl, data, portMAX_DELAY);
 }
 
-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)
 {
-  return in_isr ? xQueueSendToBackFromISR(queue_hdl, data, NULL) : xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER);
+  return in_isr ? xQueueSendToBackFromISR(qhdl, data, NULL) : xQueueSendToBack(qhdl, data, OSAL_TIMEOUT_WAIT_FOREVER);
+}
+
+static inline bool osal_queue_empty(osal_queue_t const qhdl)
+{
+  return uxQueueMessagesWaiting(qhdl) > 0;
 }
 
 #ifdef __cplusplus

+ 6 - 0
src/osal/osal_mynewt.h

@@ -161,6 +161,12 @@ static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, b
   return true;
 }
 
+static inline bool osal_queue_empty(osal_queue_t const qhdl)
+{
+  return STAILQ_EMPTY(&qhdl->evq.evq_list);
+}
+
+
 #ifdef __cplusplus
  }
 #endif

+ 10 - 2
src/osal/osal_none.h

@@ -142,7 +142,7 @@ typedef osal_queue_def_t* osal_queue_t;
     }\
   }
 
-// lock queue by disable usb isr
+// lock queue by disable USB interrupt
 static inline void _osal_q_lock(osal_queue_t qhdl)
 {
   (void) qhdl;
@@ -176,7 +176,6 @@ static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
   return (osal_queue_t) qdef;
 }
 
-// non blocking
 static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data)
 {
   _osal_q_lock(qhdl);
@@ -203,6 +202,15 @@ static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, b
   return success;
 }
 
+static inline bool osal_queue_empty(osal_queue_t const qhdl)
+{
+  _osal_q_lock(qhdl);
+  bool is_empty = tu_fifo_empty(&qhdl->ff);
+  _osal_q_unlock(qhdl);
+
+  return is_empty;
+}
+
 #ifdef __cplusplus
  }
 #endif