house keeping

This commit is contained in:
hathach
2013-09-27 22:38:23 +07:00
parent 26f75d6cac
commit eb1a101667
15 changed files with 96 additions and 183 deletions

View File

@@ -84,7 +84,7 @@ enum {
HID_REQUEST_CONTROL_SET_PROTOCOL = 0x0b
};
typedef ATTR_PREPACKED struct ATTR_PACKED {
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */

View File

@@ -74,19 +74,33 @@ bool tusbh_msc_is_mounted(uint8_t dev_addr)
msch_data[dev_addr-1].is_initialized;
}
bool tusbh_msc_is_busy(uint8_t dev_addr)
{
return msch_data[dev_addr-1].is_initialized &&
hcd_pipe_is_busy(msch_data[dev_addr-1].bulk_in);
}
bool tusbh_msc_is_failed(uint8_t dev_addr)
{
return msch_data[dev_addr-1].is_initialized &&
hcd_pipe_is_error(msch_data[dev_addr-1].bulk_in);
}
// TODO tusbh_msc_is_stalled
uint8_t const* tusbh_msc_get_vendor_name(uint8_t dev_addr)
{
return tusbh_msc_is_mounted(dev_addr) ? msch_data[dev_addr-1].vendor_id : NULL;
return msch_data[dev_addr-1].is_initialized ? msch_data[dev_addr-1].vendor_id : NULL;
}
uint8_t const* tusbh_msc_get_product_name(uint8_t dev_addr)
{
return tusbh_msc_is_mounted(dev_addr) ? msch_data[dev_addr-1].product_id : NULL;
return msch_data[dev_addr-1].is_initialized ? msch_data[dev_addr-1].product_id : NULL;
}
tusb_error_t tusbh_msc_get_capacity(uint8_t dev_addr, uint32_t* p_last_lba, uint32_t* p_block_size)
{
if ( !tusbh_msc_is_mounted(dev_addr) ) return TUSB_ERROR_MSCH_DEVICE_NOT_MOUNTED;
if ( !msch_data[dev_addr-1].is_initialized ) return TUSB_ERROR_MSCH_DEVICE_NOT_MOUNTED;
ASSERT(p_last_lba != NULL && p_block_size != NULL, TUSB_ERROR_INVALID_PARA);
(*p_last_lba) = msch_data[dev_addr-1].last_lba;
@@ -95,16 +109,6 @@ tusb_error_t tusbh_msc_get_capacity(uint8_t dev_addr, uint32_t* p_last_lba, uint
return TUSB_ERROR_NONE;
}
tusb_interface_status_t tusbh_msc_status(uint8_t dev_addr)
{
if ( !tusbh_msc_is_mounted(dev_addr) ) return TUSB_INTERFACE_STATUS_INVALID_PARA;
if ( hcd_pipe_is_busy(msch_data[dev_addr-1].bulk_in) ) return TUSB_INTERFACE_STATUS_BUSY;
if ( hcd_pipe_is_stalled(msch_data[dev_addr-1].bulk_in) ) return TUSB_INTERFACE_STATUS_ERROR;
return TUSB_INTERFACE_STATUS_READY;
}
static inline void msc_cbw_add_signature(msc_cmd_block_wrapper_t *p_cbw, uint8_t lun) ATTR_ALWAYS_INLINE;
static inline void msc_cbw_add_signature(msc_cmd_block_wrapper_t *p_cbw, uint8_t lun)
{

View File

@@ -59,7 +59,9 @@
// MASS STORAGE Application API
//--------------------------------------------------------------------+
bool tusbh_msc_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
tusb_interface_status_t tusbh_msc_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT;
bool tusbh_msc_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
bool tusbh_msc_is_failed(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
uint8_t const* tusbh_msc_get_vendor_name(uint8_t dev_addr);
uint8_t const* tusbh_msc_get_product_name(uint8_t dev_addr);
tusb_error_t tusbh_msc_get_capacity(uint8_t dev_addr, uint32_t* p_last_lba, uint32_t* p_block_size);
@@ -95,7 +97,7 @@ typedef struct {
uint16_t block_size;
uint32_t last_lba; // last logical block address
bool is_initialized;
volatile bool is_initialized;
uint8_t vendor_id[8];
uint8_t product_id[16];

View File

@@ -61,7 +61,7 @@
// STANDARD DESCRIPTORS
//--------------------------------------------------------------------+
/// USB Standard Device Descriptor (section 9.6.1, table 9-8)
typedef ATTR_PREPACKED struct ATTR_PACKED {
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< DEVICE Descriptor Type.
uint16_t bcdUSB ; ///< BUSB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). This field identifies the release of the USB Specification with which the device and its descriptors are compliant.
@@ -82,7 +82,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
} tusb_descriptor_device_t;
/// USB Standard Configuration Descriptor (section 9.6.1 table 9-10) */
typedef ATTR_PREPACKED struct ATTR_PACKED {
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
uint16_t wTotalLength ; ///< Total length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface, endpoint, and class- or vendor-specific) returned for this configuration.
@@ -95,7 +95,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
} tusb_descriptor_configuration_t;
/// USB Standard Interface Descriptor (section 9.6.1 table 9-12)
typedef ATTR_PREPACKED struct ATTR_PACKED {
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< INTERFACE Descriptor Type
@@ -109,13 +109,13 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
} tusb_descriptor_interface_t;
/// USB Standard Endpoint Descriptor (section 9.6.1 table 9-13)
typedef ATTR_PREPACKED struct ATTR_PACKED {
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< ENDPOINT Descriptor Type
uint8_t bEndpointAddress ; ///< The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: \n Bit 3...0: The endpoint number \n Bit 6...4: Reserved, reset to zero \n Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint.
ATTR_PREPACKED struct ATTR_PACKED {
ATTR_PACKED_STRUCT(struct) {
uint8_t xfer : 2;
uint8_t sync : 2;
uint8_t usage : 2;
@@ -132,7 +132,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
} tusb_descriptor_endpoint_t;
/// USB Other Speed Configuration Descriptor (section 9.6.1 table 9-11)
typedef ATTR_PREPACKED struct ATTR_PACKED {
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
uint16_t wTotalLength ; ///< Total length of data returned
@@ -145,7 +145,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
} tusb_descriptor_other_speed_t;
/// USB Device Qualifier Descriptor (section 9.6.1 table 9-9)
typedef ATTR_PREPACKED struct ATTR_PACKED {
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Device Qualifier Type
uint16_t bcdUSB ; ///< USB specification version number (e.g., 0200H for V2.00)
@@ -159,7 +159,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
} tusb_descriptor_device_qualifier_t;
/// USB Interface Association Descriptor (IAD ECN)
typedef ATTR_PREPACKED struct ATTR_PACKED
typedef ATTR_PACKED_STRUCT(struct)
{
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
@@ -175,7 +175,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED
} tusb_descriptor_interface_association_t;
/// USB Header Descriptor
typedef ATTR_PREPACKED struct ATTR_PACKED
typedef ATTR_PACKED_STRUCT(struct)
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< Descriptor Type

View File

@@ -430,7 +430,7 @@ tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint
tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete)
{
hcd_pipe_queue_xfer(pipe_hdl, buffer, total_bytes);
ASSERT_STATUS ( hcd_pipe_queue_xfer(pipe_hdl, buffer, total_bytes) );
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl);
@@ -481,8 +481,14 @@ bool hcd_pipe_is_busy(pipe_handle_t pipe_hdl)
return !p_qhd->qtd_overlay.halted && (p_qhd->p_qtd_list_head != NULL);
}
bool hcd_pipe_is_idle(pipe_handle_t pipe_hdl)
bool hcd_pipe_is_error(pipe_handle_t pipe_hdl)
{
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl );
return p_qhd->qtd_overlay.halted;
}
bool hcd_pipe_is_idle(pipe_handle_t pipe_hdl)
{ // TODO to be remove
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl );
return (p_qhd->p_qtd_list_head == NULL);
}
@@ -679,13 +685,11 @@ static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd)
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_setup = get_control_qtds(p_qhd->device_address);
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
p_setup->used = p_data->used = p_status->used = 0;
}
// call USBH callback

View File

@@ -126,9 +126,9 @@ typedef struct {
union{
ehci_link_t alternate;
struct {
uint32_t : 5;
uint32_t used : 1;
uint32_t : 10;
uint32_t : 5;
uint32_t used : 1;
uint32_t : 10;
uint32_t expected_bytes : 16;
};
};
@@ -203,8 +203,8 @@ typedef struct {
uint8_t interval_ms; // polling interval in frames (or milisecond)
uint8_t reserved;
ehci_qtd_t *p_qtd_list_head; // head of the scheduled TD list
ehci_qtd_t *p_qtd_list_tail; // tail of the scheduled TD list
ehci_qtd_t * volatile p_qtd_list_head; // head of the scheduled TD list
ehci_qtd_t * volatile p_qtd_list_tail; // tail of the scheduled TD list
}ATTR_ALIGNED(32) ehci_qhd_t;
/// Highspeed Isochronous Transfer Descriptor (section 3.3)