summaryrefslogtreecommitdiff
path: root/tinyusb
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-03-08 11:42:28 +0700
committerhathach <[email protected]>2018-03-08 11:42:28 +0700
commit817f23e5e0f976814dfa0b5ccfa1f9f5cd1c3885 (patch)
tree80ed4682ad3770c22c4677aae19cc004a8091256 /tinyusb
parentd28e7e3966bd4ac471b667c73d2cb1451808e641 (diff)
enhance
- add ASSERT_ - rename edpt_equal -
Diffstat (limited to 'tinyusb')
-rw-r--r--tinyusb/class/hid/hid_device.c2
-rw-r--r--tinyusb/class/msc/msc_device.c6
-rw-r--r--tinyusb/common/common.h1
-rw-r--r--tinyusb/common/fifo.c15
-rw-r--r--tinyusb/common/fifo.h1
-rw-r--r--tinyusb/common/verify.h14
-rw-r--r--tinyusb/device/dcd.h2
7 files changed, 36 insertions, 5 deletions
diff --git a/tinyusb/class/hid/hid_device.c b/tinyusb/class/hid/hid_device.c
index 00fd2660e..5ce98f80a 100644
--- a/tinyusb/class/hid/hid_device.c
+++ b/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);
}
diff --git a/tinyusb/class/msc/msc_device.c b/tinyusb/class/msc/msc_device.c
index ac5953662..381bbf07f 100644
--- a/tinyusb/class/msc/msc_device.c
+++ b/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 );
diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h
index 9a37c6c97..8c6a6c72f 100644
--- a/tinyusb/common/common.h
+++ b/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"
diff --git a/tinyusb/common/fifo.c b/tinyusb/common/fifo.c
index 8db3f04ac..397514dc0 100644
--- a/tinyusb/common/fifo.c
+++ b/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.
diff --git a/tinyusb/common/fifo.h b/tinyusb/common/fifo.h
index e162b5d5e..936719c2d 100644
--- a/tinyusb/common/fifo.h
+++ b/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);
diff --git a/tinyusb/common/verify.h b/tinyusb/common/verify.h
index b2d49071d..f48e91662 100644
--- a/tinyusb/common/verify.h
+++ b/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
diff --git a/tinyusb/device/dcd.h b/tinyusb/device/dcd.h
index c6691fab1..3cf732d23 100644
--- a/tinyusb/device/dcd.h
+++ b/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);
}