summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-12-23 18:54:06 +0700
committerhathach <[email protected]>2019-12-23 18:54:06 +0700
commitbbada1d3e6dba5b339c7cd4129e5df7b3203c11b (patch)
treede9ef9a7d0bff897e84ec46853f21170900d250e
parent94e70f9b016edfcdea165674e17201fda88a089b (diff)
adding lookup table for debugging
add msc scsi command list
-rw-r--r--src/class/msc/msc_device.c32
-rw-r--r--src/common/tusb_common.h23
-rw-r--r--src/device/usbd.c2
-rw-r--r--src/portable/microchip/samg/dcd_samg.c5
4 files changed, 57 insertions, 5 deletions
diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c
index 84fe5a194..93167bc6d 100644
--- a/src/class/msc/msc_device.c
+++ b/src/class/msc/msc_device.c
@@ -98,6 +98,34 @@ static inline uint16_t rdwr10_get_blockcount(uint8_t const command[])
}
//--------------------------------------------------------------------+
+// Debug
+//--------------------------------------------------------------------+
+#if CFG_TUSB_DEBUG >= 2
+
+static lookup_entry_t const _msc_scsi_cmd_lookup[] =
+{
+ { .key = SCSI_CMD_TEST_UNIT_READY , .data = "Test Unit Ready" },
+ { .key = SCSI_CMD_INQUIRY , .data = "Inquiry" },
+ { .key = SCSI_CMD_MODE_SELECT_6 , .data = "Mode_Select 6" },
+ { .key = SCSI_CMD_MODE_SENSE_6 , .data = "Mode_Sense 6" },
+ { .key = SCSI_CMD_START_STOP_UNIT , .data = "Start Stop Unit" },
+ { .key = SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL , .data = "Prevent Allow Medium Removal" },
+ { .key = SCSI_CMD_READ_CAPACITY_10 , .data = "Read Capacity10" },
+ { .key = SCSI_CMD_REQUEST_SENSE , .data = "Request Sense" },
+ { .key = SCSI_CMD_READ_FORMAT_CAPACITY , .data = "Read Format Capacity" },
+ { .key = SCSI_CMD_READ_10 , .data = "Read10" },
+ { .key = SCSI_CMD_WRITE_10 , .data = "Write10" }
+};
+
+static lookup_table_t const _msc_scsi_cmd_table =
+{
+ .count = TU_ARRAY_SIZE(_msc_scsi_cmd_lookup),
+ .items = _msc_scsi_cmd_lookup
+};
+
+#endif
+
+//--------------------------------------------------------------------+
// APPLICATION API
//--------------------------------------------------------------------+
bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier)
@@ -378,7 +406,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
TU_ASSERT( event == XFER_RESULT_SUCCESS &&
xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE );
- TU_LOG2(" Command Block Wrapper\n");
+ TU_LOG2(" SCSI Command: %s\n", lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0]));
// TU_LOG2_MEM(p_cbw, xferred_bytes, 2);
p_csw->signature = MSC_CSW_SIGNATURE;
@@ -544,7 +572,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
// Wait for the command status wrapper complete event
if( (ep_addr == p_msc->ep_in) && (xferred_bytes == sizeof(msc_csw_t)) )
{
- TU_LOG2(" Command Status Wrapper\n");
+ TU_LOG2(" SCSI Status: %u\n", p_csw->status);
// TU_LOG2_MEM(p_csw, xferred_bytes, 2);
// Move to default CMD stage
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h
index f76abca88..5700c1282 100644
--- a/src/common/tusb_common.h
+++ b/src/common/tusb_common.h
@@ -231,6 +231,29 @@ void tu_print_mem(void const *buf, uint16_t count, uint8_t indent);
#define TU_LOG2_LOCATION() TU_LOG1_LOCATION()
#endif
+
+typedef struct
+{
+ uint32_t key;
+ char const * data;
+}lookup_entry_t;
+
+typedef struct
+{
+ uint16_t count;
+ lookup_entry_t const* items;
+} lookup_table_t;
+
+static inline char const* lookup_find(lookup_table_t const* p_table, uint32_t key)
+{
+ for(uint16_t i=0; i<p_table->count; i++)
+ {
+ if (p_table->items[i].key == key) return p_table->items[i].data;
+ }
+
+ return NULL;
+}
+
#endif // CFG_TUSB_DEBUG
#ifndef TU_LOG1
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 5832f2353..949e14096 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -211,7 +211,7 @@ bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event,
//--------------------------------------------------------------------+
// Debugging
//--------------------------------------------------------------------+
-#if CFG_TUSB_DEBUG > 1
+#if CFG_TUSB_DEBUG >= 2
static char const* const _usbd_event_str[DCD_EVENT_COUNT] =
{
"INVALID" ,
diff --git a/src/portable/microchip/samg/dcd_samg.c b/src/portable/microchip/samg/dcd_samg.c
index fd50237dc..a93b26caa 100644
--- a/src/portable/microchip/samg/dcd_samg.c
+++ b/src/portable/microchip/samg/dcd_samg.c
@@ -267,9 +267,9 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
// Read it as 1st packet then continue with transfer if needed
if ( UDP->UDP_CSR[epnum] & (UDP_CSR_RX_DATA_BK0_Msk | UDP_CSR_RX_DATA_BK1_Msk) )
{
- uint16_t const xact_len = (uint16_t) ((UDP->UDP_CSR[epnum] & UDP_CSR_RXBYTECNT_Msk) >> UDP_CSR_RXBYTECNT_Pos);
+// uint16_t const xact_len = (uint16_t) ((UDP->UDP_CSR[epnum] & UDP_CSR_RXBYTECNT_Msk) >> UDP_CSR_RXBYTECNT_Pos);
- TU_LOG2("xact_len = %d\r", xact_len);
+// TU_LOG2("xact_len = %d\r", xact_len);
// // Read from EP fifo
// xact_ep_read(epnum, xfer->buffer, xact_len);
@@ -406,6 +406,7 @@ void dcd_isr(uint8_t rhport)
}
// Endpoint OUT
+ // Ping-Pong is a must for Bulk/Iso
// When both Bank0 and Bank1 are both set, there is not way to know which one comes first
if (UDP->UDP_CSR[epnum] & (UDP_CSR_RX_DATA_BK0_Msk | UDP_CSR_RX_DATA_BK1_Msk))
{