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

enhance

- add ASSERT_
- rename edpt_equal
-
hathach 8 лет назад
Родитель
Сommit
817f23e5e0

+ 1 - 1
tinyusb/class/hid/hid_device.c

@@ -308,7 +308,7 @@ tusb_error_t hidd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32
   for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
   {
     hidd_interface_t * const p_interface = hidd_class_driver[i].p_interface;
-    if ( (p_interface != NULL) && endpointhandle_is_equal(edpt_hdl, p_interface->ept_handle) )
+    if ( (p_interface != NULL) && edpt_equal(edpt_hdl, p_interface->ept_handle) )
     {
       hidd_class_driver[i].xfer_cb(edpt_hdl.coreid, event, xferred_bytes);
     }

+ 3 - 3
tinyusb/class/msc/msc_device.c

@@ -150,14 +150,14 @@ tusb_error_t mscd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32
   msc_cmd_block_wrapper_t *  const p_cbw = &p_msc->cbw;
   msc_cmd_status_wrapper_t * const p_csw = &p_msc->csw;
 
-  VERIFY(endpointhandle_is_equal(edpt_hdl, p_msc->edpt_out) || endpointhandle_is_equal(edpt_hdl, p_msc->edpt_in), TUSB_ERROR_INVALID_PARA);
+  VERIFY(edpt_equal(edpt_hdl, p_msc->edpt_out) || edpt_equal(edpt_hdl, p_msc->edpt_in), TUSB_ERROR_INVALID_PARA);
 
   //------------- new CBW received -------------//
   if ( !is_waiting_read10_write10 )
   {
-//    if ( endpointhandle_is_equal(p_msc->edpt_in, edpt_hdl) ) return TUSB_ERROR_NONE; // bulk in interrupt for dcd to clean up
+//    if ( edpt_equal(p_msc->edpt_in, edpt_hdl) ) return TUSB_ERROR_NONE; // bulk in interrupt for dcd to clean up
 
-    ASSERT( endpointhandle_is_equal(p_msc->edpt_out, edpt_hdl) &&
+    ASSERT( edpt_equal(p_msc->edpt_out, edpt_hdl) &&
             xferred_bytes == sizeof(msc_cmd_block_wrapper_t)   &&
             event == TUSB_EVENT_XFER_COMPLETE                  &&
             p_cbw->signature == MSC_CBW_SIGNATURE, TUSB_ERROR_INVALID_PARA );

+ 1 - 0
tinyusb/common/common.h

@@ -67,6 +67,7 @@
 #include "verify.h"
 #include "binary.h"
 #include "tusb_errors.h"
+#include "fifo.h"
 
 //------------- TUSB Header -------------//
 #include "tusb_types.h"

+ 15 - 0
tinyusb/common/fifo.c

@@ -64,6 +64,21 @@ static inline bool fifo_initalized(fifo_t* f)
 }
 
 
+void fifo_config(fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable)
+{
+  mutex_lock_if_needed(f);
+
+  f->buffer = (uint8_t*) buffer;
+  f->depth  = depth;
+  f->item_size = item_size;
+  f->overwritable = overwritable;
+
+  f->rd_idx = f->wr_idx = f->count = 0;
+
+  mutex_unlock_if_needed(f);
+}
+
+
 /******************************************************************************/
 /*!
     @brief Read one byte out of the RX buffer.

+ 1 - 0
tinyusb/common/fifo.h

@@ -106,6 +106,7 @@ typedef struct
   }
 
 void fifo_clear(fifo_t *f);
+void fifo_config(fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable);
 
 bool     fifo_write   (fifo_t* f, void const * p_data);
 uint16_t fifo_write_n (fifo_t* f, void const * p_data, uint16_t count);

+ 14 - 0
tinyusb/common/verify.h

@@ -62,8 +62,10 @@
 #if TUSB_CFG_DEBUG >= 1
 //  #define VERIFY_MESS(format, ...) cprintf("[%08ld] %s: %d: verify failed\n", get_millis(), __func__, __LINE__)
   #define VERIFY_MESS(_status)   printf("%s: %d: verify failed, error = %s\n", __PRETTY_FUNCTION__, __LINE__, TUSB_ErrorStr[_status]);
+  #define _ASSERT_MESS()         printf("%s: %d: assert failed\n", __PRETTY_FUNCTION__, __LINE__);
 #else
   #define VERIFY_MESS(_status)
+  #define _ASSERT_MESS()
 #endif
 
 /**
@@ -143,6 +145,18 @@
 
 #define VERIFY_HDLR(...) GET_4TH_ARG(__VA_ARGS__, VERIFY_HDLR_3ARGS, VERIFY_HDLR_2ARGS)(__VA_ARGS__)
 
+
+/*------------------------------------------------------------------*/
+/* ASSERT
+ * basically VERIFY with hal_debugger_breakpoint as handler
+ * - 1 arg : return false if failed
+ * - 2 arg : return error if failed
+ *------------------------------------------------------------------*/
+#define ASSERT_1ARGS(cond)            do { if (!(cond)) { hal_debugger_breakpoint(); _ASSERT_MESS() return false; } } while(0)
+#define ASSERT_2ARGS(cond, _error)    do { if (!(cond)) { hal_debugger_breakpoint(); _ASSERT_MESS() return _error;} } while(0)
+
+#define ASSERT_(...)  GET_3RD_ARG(__VA_ARGS__, ASSERT_2ARGS, ASSERT_1ARGS)(__VA_ARGS__)
+
 #ifdef __cplusplus
  }
 #endif

+ 1 - 1
tinyusb/device/dcd.h

@@ -63,7 +63,7 @@ typedef struct {
   uint8_t index; // must be zero to indicate control
 } endpoint_handle_t;
 
-static inline bool endpointhandle_is_equal(endpoint_handle_t x, endpoint_handle_t y)
+static inline bool edpt_equal(endpoint_handle_t x, endpoint_handle_t y)
 {
   return (x.coreid == y.coreid) && (x.index == y.index);
 }