summaryrefslogtreecommitdiff
path: root/tinyusb
diff options
context:
space:
mode:
Diffstat (limited to 'tinyusb')
-rw-r--r--tinyusb/class/hid_host.c4
-rw-r--r--tinyusb/class/msc_host.c44
-rw-r--r--tinyusb/class/msc_host.h17
-rw-r--r--tinyusb/common/compiler/compiler.h14
-rw-r--r--tinyusb/host/ehci/ehci.c31
5 files changed, 64 insertions, 46 deletions
diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c
index 9018c6123..5dc450fa9 100644
--- a/tinyusb/class/hid_host.c
+++ b/tinyusb/class/hid_host.c
@@ -214,7 +214,7 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
OSAL_SUBTASK_BEGIN
-#if 0
+#if 1
//------------- SET IDLE request -------------//
// TODO this request can be stalled by device (indicate not supported),
// until we have clear stall handler, temporarily disable it.
@@ -224,7 +224,9 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
0, NULL ),
error
);
+#endif
+#if 0
//------------- Get Report Descriptor TODO HID parser -------------//
if ( p_desc_hid->bNumDescriptors )
{
diff --git a/tinyusb/class/msc_host.c b/tinyusb/class/msc_host.c
index 00aebeba9..1e11a4b85 100644
--- a/tinyusb/class/msc_host.c
+++ b/tinyusb/class/msc_host.c
@@ -51,26 +51,10 @@
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
-typedef struct {
- pipe_handle_t bulk_in, bulk_out;
- uint8_t interface_number;
+STATIC_VAR msch_interface_t msch_data[TUSB_CFG_HOST_DEVICE_MAX] TUSB_CFG_ATTR_USBRAM;
- uint8_t max_lun;
- uint16_t block_size;
- uint32_t last_lba; // last logical block address
-
- uint8_t vendor_id[8];
- uint8_t product_id[16];
-
- msc_cmd_block_wrapper_t cbw;
- msc_cmd_status_wrapper_t csw;
- ATTR_ALIGNED(4) uint8_t buffer[100];
-}msch_interface_t;
-
-STATIC_VAR msch_interface_t msch_data[TUSB_CFG_HOST_DEVICE_MAX] TUSB_CFG_ATTR_USBRAM; // TODO to be static
-
-// TODO rename this
-STATIC_VAR uint8_t msch_buffer[10] TUSB_CFG_ATTR_USBRAM;
+// buffer used to read scsi information when mounted, largest reponse data currently is inquiry
+ATTR_ALIGNED(4) STATIC_VAR uint8_t msch_buffer[sizeof(scsi_inquiry_data_t)] TUSB_CFG_ATTR_USBRAM;
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
@@ -110,7 +94,7 @@ tusb_error_t tusbh_msc_get_capacity(uint8_t dev_addr, uint32_t* p_last_lba, uint
//--------------------------------------------------------------------+
// CLASS-USBH API (don't require to verify parameters)
//--------------------------------------------------------------------+
-static tusb_error_t scsi_command_send(msch_interface_t * p_msch, scsi_cmd_type_t cmd_code, uint8_t lun)
+static tusb_error_t scsi_command_send(msch_interface_t * p_msch, scsi_cmd_type_t cmd_code, uint8_t lun, uint8_t* p_data)
{
p_msch->cbw.signature = 0x43425355;
p_msch->cbw.tag = 0xCAFECAFE;
@@ -175,7 +159,7 @@ static tusb_error_t scsi_command_send(msch_interface_t * p_msch, scsi_cmd_type_t
}
ASSERT_STATUS( hcd_pipe_xfer(p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cmd_block_wrapper_t), false) );
- ASSERT_STATUS( hcd_pipe_queue_xfer(p_msch->bulk_in , p_msch->buffer, p_msch->cbw.xfer_bytes) );
+ ASSERT_STATUS( hcd_pipe_queue_xfer(p_msch->bulk_in , p_data, p_msch->cbw.xfer_bytes) );
ASSERT_STATUS( hcd_pipe_xfer(p_msch->bulk_in , &p_msch->csw, sizeof(msc_cmd_status_wrapper_t), true) );
}
@@ -240,28 +224,24 @@ tusb_error_t msch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
// while( !hcd_pipe_is_idle(msch_data[dev_addr-1].bulk_in) )
//------------- SCSI Inquiry -------------//
- scsi_command_send(&msch_data[dev_addr-1], SCSI_CMD_INQUIRY, 0);
+ scsi_command_send(&msch_data[dev_addr-1], SCSI_CMD_INQUIRY, 0, msch_buffer);
osal_task_delay(2);
- memcpy(msch_data[dev_addr-1].vendor_id,
- ((scsi_inquiry_data_t*)msch_data[dev_addr-1].buffer)->vendor_id,
- 8);
- memcpy(msch_data[dev_addr-1].product_id,
- ((scsi_inquiry_data_t*)msch_data[dev_addr-1].buffer)->product_id,
- 16);
+ memcpy(msch_data[dev_addr-1].vendor_id , ((scsi_inquiry_data_t*) msch_buffer)->vendor_id , 8);
+ memcpy(msch_data[dev_addr-1].product_id, ((scsi_inquiry_data_t*) msch_buffer)->product_id, 16);
#if 0
//------------- SCSI Request Sense -------------//
- scsi_command_send(&msch_data[dev_addr-1], SCSI_CMD_REQUEST_SENSE, 0);
+ scsi_command_send(&msch_data[dev_addr-1], SCSI_CMD_REQUEST_SENSE, 0, msch_buffer);
osal_task_delay(2);
#endif
//------------- SCSI Read Capacity 10 -------------//
- scsi_command_send(&msch_data[dev_addr-1], SCSI_CMD_READ_CAPACITY_10, 0);
+ scsi_command_send(&msch_data[dev_addr-1], SCSI_CMD_READ_CAPACITY_10, 0, msch_buffer);
osal_task_delay(2);
- msch_data[dev_addr-1].last_lba = __be2le( ((scsi_read_capacity10_data_t*)msch_data[dev_addr-1].buffer)->last_lba );
- msch_data[dev_addr-1].block_size = (uint16_t) __be2le( ((scsi_read_capacity10_data_t*)msch_data[dev_addr-1].buffer)->block_size );
+ msch_data[dev_addr-1].last_lba = __be2le( ((scsi_read_capacity10_data_t*)msch_buffer)->last_lba );
+ msch_data[dev_addr-1].block_size = (uint16_t) __be2le( ((scsi_read_capacity10_data_t*)msch_buffer)->block_size );
tusbh_msc_mounted_cb(dev_addr);
diff --git a/tinyusb/class/msc_host.h b/tinyusb/class/msc_host.h
index 324dad984..65265ddb9 100644
--- a/tinyusb/class/msc_host.h
+++ b/tinyusb/class/msc_host.h
@@ -76,6 +76,8 @@ tusb_error_t tusbh_msc_write10(uint8_t dev_addr, void const * p_data, uint32_t
//------------- Application Callback -------------//
void tusbh_msc_mounted_cb(uint8_t dev_addr);
+void tusbh_msc_unmounted_isr(uint8_t dev_addr);
+void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event);
//--------------------------------------------------------------------+
@@ -83,6 +85,21 @@ void tusbh_msc_mounted_cb(uint8_t dev_addr);
//--------------------------------------------------------------------+
#ifdef _TINY_USB_SOURCE_FILE_
+typedef struct {
+ pipe_handle_t bulk_in, bulk_out;
+ uint8_t interface_number;
+
+ uint8_t max_lun;
+ uint16_t block_size;
+ uint32_t last_lba; // last logical block address
+
+ uint8_t vendor_id[8];
+ uint8_t product_id[16];
+
+ msc_cmd_block_wrapper_t cbw;
+ msc_cmd_status_wrapper_t csw;
+}msch_interface_t;
+
void msch_init(void);
tusb_error_t msch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
void msch_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes);
diff --git a/tinyusb/common/compiler/compiler.h b/tinyusb/common/compiler/compiler.h
index e1f06b307..683237b54 100644
--- a/tinyusb/common/compiler/compiler.h
+++ b/tinyusb/common/compiler/compiler.h
@@ -52,12 +52,7 @@
#ifndef _TUSB_COMPILER_H_
#define _TUSB_COMPILER_H_
-#ifdef _TEST_
- #define ATTR_ALWAYS_INLINE
- #define STATIC_
- #define STATIC_VAR
- #define INLINE_
-#else
+#ifndef _TEST_
#define STATIC_ static
#define INLINE_ inline
@@ -67,9 +62,14 @@
#else
#define STATIC_VAR static
#endif
+ #define ATTR_TEST_WEAK
+#else
+ #define ATTR_ALWAYS_INLINE
+ #define STATIC_
+ #define STATIC_VAR
+ #define INLINE_
#endif
-// TODO refractor ATTR_PACKED(x)
#if defined(__GNUC__)
#include "compiler_gcc.h"
#elif defined __ICCARM__ // IAR compiler
diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c
index b2948e0db..40c59616e 100644
--- a/tinyusb/host/ehci/ehci.c
+++ b/tinyusb/host/ehci/ehci.c
@@ -446,6 +446,7 @@ tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl)
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl );
// async list needs async advance handshake to make sure host controller has released cached data
+ // non-control does not use async advance, it will eventually free by control pipe close
// period list queue element is guarantee to be free in the next frame (1 ms)
p_qhd->is_removing = 1; // TODO redundant, only apply to control queue head
@@ -620,29 +621,47 @@ static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd)
p_qhd->qtd_overlay.buffer_err ||p_qhd->qtd_overlay.babble_err || p_qhd->qtd_overlay.xact_err )
//p_qhd->qtd_overlay.non_hs_period_missed_uframe || p_qhd->qtd_overlay.pingstate_err TODO split transaction error
{ // current qhd has error in transaction
- uint16_t total_xferred_bytes;
tusb_xfer_type_t const xfer_type = qhd_get_xfer_type(p_qhd);
tusb_event_t error_event;
- // TODO allow stall with control pipe
// no error bits are set, endpoint is halted due to STALL
error_event = ( !(p_qhd->qtd_overlay.buffer_err || p_qhd->qtd_overlay.babble_err ||
p_qhd->qtd_overlay.xact_err) ) ? TUSB_EVENT_XFER_STALLED : TUSB_EVENT_XFER_ERROR;
p_qhd->total_xferred_bytes += p_qhd->p_qtd_list_head->expected_bytes - p_qhd->p_qtd_list_head->total_bytes;
- hal_debugger_breakpoint();
+ // TODO skip unplugged device
+ if ( TUSB_EVENT_XFER_ERROR == error_event ) hal_debugger_breakpoint();
p_qhd->p_qtd_list_head->used = 0; // free QTD
qtd_remove_1st_from_qhd(p_qhd);
- // subtract setup size if it is control xfer
- total_xferred_bytes = p_qhd->total_xferred_bytes - (xfer_type == TUSB_XFER_CONTROL ? min8_of(8, p_qhd->total_xferred_bytes) : 0);
+ if ( TUSB_XFER_CONTROL == xfer_type )
+ {
+ p_qhd->total_xferred_bytes -= min8_of(8, p_qhd->total_xferred_bytes); // subtract setup size
+
+ // control cannot be halted --> clear all qtd list
+ p_qhd->p_qtd_list_head = NULL;
+ p_qhd->p_qtd_list_tail = NULL;
+
+ p_qhd->qtd_overlay.next.terminate = 1;
+ p_qhd->qtd_overlay.alternate.terminate = 1;
+ p_qhd->qtd_overlay.halted = 0;
+
+ #if 0 // no need to mark control qtds as not used
+ ehci_qtd_t *p_setup = get_control_qtds(dev_addr);
+ ehci_qtd_t *p_data = p_setup + 1;
+ ehci_qtd_t *p_status = p_setup + 2;
+
+ p_setup->used = p_data->used = p_status = 0;
+ #endif
+ }
// call USBH callback
usbh_xfer_isr( qhd_create_pipe_handle(p_qhd, xfer_type),
p_qhd->class_code, error_event,
- total_xferred_bytes);
+ p_qhd->total_xferred_bytes);
+
p_qhd->total_xferred_bytes = 0;
}
}