mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
remove pipe handle.dev_addr
This commit is contained in:
parent
a486da33ee
commit
0ae8a1aa89
@ -71,13 +71,13 @@ bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid)
|
||||
switch (pipeid)
|
||||
{
|
||||
case CDC_PIPE_NOTIFICATION:
|
||||
return hcd_pipe_is_busy( p_cdc->pipe_notification );
|
||||
return hcd_pipe_is_busy(dev_addr, p_cdc->pipe_notification );
|
||||
|
||||
case CDC_PIPE_DATA_IN:
|
||||
return hcd_pipe_is_busy( p_cdc->pipe_in );
|
||||
return hcd_pipe_is_busy(dev_addr, p_cdc->pipe_in );
|
||||
|
||||
case CDC_PIPE_DATA_OUT:
|
||||
return hcd_pipe_is_busy( p_cdc->pipe_out );
|
||||
return hcd_pipe_is_busy(dev_addr, p_cdc->pipe_out );
|
||||
|
||||
default:
|
||||
return false;
|
||||
@ -101,9 +101,9 @@ tusb_error_t tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length
|
||||
TU_ASSERT( p_data != NULL && length, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
pipe_handle_t pipe_out = cdch_data[dev_addr-1].pipe_out;
|
||||
if ( hcd_pipe_is_busy(pipe_out) ) return TUSB_ERROR_INTERFACE_IS_BUSY;
|
||||
if ( hcd_pipe_is_busy(dev_addr, pipe_out) ) return TUSB_ERROR_INTERFACE_IS_BUSY;
|
||||
|
||||
return hcd_pipe_xfer( pipe_out, (void *) p_data, length, is_notify);
|
||||
return hcd_pipe_xfer(dev_addr, pipe_out, (void *) p_data, length, is_notify);
|
||||
}
|
||||
|
||||
tusb_error_t tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify)
|
||||
@ -112,9 +112,9 @@ tusb_error_t tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length,
|
||||
TU_ASSERT( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
pipe_handle_t pipe_in = cdch_data[dev_addr-1].pipe_in;
|
||||
if ( hcd_pipe_is_busy(pipe_in) ) return TUSB_ERROR_INTERFACE_IS_BUSY;
|
||||
if ( hcd_pipe_is_busy(dev_addr, pipe_in) ) return TUSB_ERROR_INTERFACE_IS_BUSY;
|
||||
|
||||
return hcd_pipe_xfer( pipe_in, p_buffer, length, is_notify);
|
||||
return hcd_pipe_xfer(dev_addr, pipe_in, p_buffer, length, is_notify);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -221,9 +221,9 @@ void cdch_close(uint8_t dev_addr)
|
||||
{
|
||||
cdch_data_t * p_cdc = &cdch_data[dev_addr-1];
|
||||
|
||||
(void) hcd_pipe_close(p_cdc->pipe_notification);
|
||||
(void) hcd_pipe_close(p_cdc->pipe_in);
|
||||
(void) hcd_pipe_close(p_cdc->pipe_out);
|
||||
hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->pipe_notification);
|
||||
hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->pipe_in);
|
||||
hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->pipe_out);
|
||||
|
||||
tu_memclr(p_cdc, sizeof(cdch_data_t));
|
||||
|
||||
|
@ -98,7 +98,7 @@ static inline uint8_t qhd_get_index(ehci_qhd_t const * p_qhd) ATTR_ALWAYS
|
||||
static inline ehci_qhd_t* qhd_next(ehci_qhd_t const * p_qhd) ATTR_ALWAYS_INLINE ATTR_PURE;
|
||||
static inline ehci_qhd_t* qhd_find_free (uint8_t dev_addr) ATTR_PURE ATTR_ALWAYS_INLINE;
|
||||
static inline tusb_xfer_type_t qhd_get_xfer_type(ehci_qhd_t const * p_qhd) ATTR_ALWAYS_INLINE ATTR_PURE;
|
||||
static inline ehci_qhd_t* qhd_get_from_pipe_handle(pipe_handle_t pipe_hdl) ATTR_PURE ATTR_ALWAYS_INLINE;
|
||||
static inline ehci_qhd_t* qhd_get_from_pipe_handle(uint8_t dev_addr, pipe_handle_t pipe_hdl);
|
||||
static inline pipe_handle_t qhd_create_pipe_handle(ehci_qhd_t const * p_qhd);
|
||||
|
||||
// determine if a queue head has bus-related error
|
||||
@ -421,7 +421,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
|
||||
//--------------------------------------------------------------------+
|
||||
pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc, uint8_t class_code)
|
||||
{
|
||||
pipe_handle_t const null_handle = { .dev_addr = 0, .index = 0 };
|
||||
pipe_handle_t const null_handle = { .index = 0 };
|
||||
|
||||
// TODO not support ISO yet
|
||||
if (ep_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) return null_handle;
|
||||
@ -470,16 +470,16 @@ pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint
|
||||
// TODO might need to disable async/period list
|
||||
list_insert( list_head, (ehci_link_t*) p_qhd, EHCI_QUEUE_ELEMENT_QHD);
|
||||
|
||||
return (pipe_handle_t) { .dev_addr = dev_addr, .index = qhd_get_index(p_qhd) };
|
||||
return (pipe_handle_t) { .index = qhd_get_index(p_qhd) };
|
||||
}
|
||||
|
||||
tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes)
|
||||
tusb_error_t hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes)
|
||||
{
|
||||
//------------- TODO pipe handle validate -------------//
|
||||
|
||||
//------------- set up QTD -------------//
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl);
|
||||
ehci_qtd_t *p_qtd = qtd_find_free(pipe_hdl.dev_addr);
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl);
|
||||
ehci_qtd_t *p_qtd = qtd_find_free(dev_addr);
|
||||
|
||||
TU_ASSERT(p_qtd, TUSB_ERROR_EHCI_NOT_ENOUGH_QTD);
|
||||
|
||||
@ -492,11 +492,11 @@ tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete)
|
||||
tusb_error_t hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete)
|
||||
{
|
||||
TU_ASSERT_ERR ( hcd_pipe_queue_xfer(pipe_hdl, buffer, total_bytes) );
|
||||
TU_ASSERT_ERR ( hcd_pipe_queue_xfer(dev_addr, pipe_hdl, buffer, total_bytes) );
|
||||
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl);
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl);
|
||||
|
||||
if ( int_on_complete )
|
||||
{ // the just added qtd is pointed by list_tail
|
||||
@ -508,11 +508,9 @@ tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t t
|
||||
}
|
||||
|
||||
/// pipe_close should only be called as a part of unmount/safe-remove process
|
||||
tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl)
|
||||
bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, pipe_handle_t pipe_hdl)
|
||||
{
|
||||
TU_ASSERT(pipe_hdl.dev_addr > 0, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl );
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, 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
|
||||
@ -522,48 +520,48 @@ tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl)
|
||||
if ( p_qhd->xfer_type == TUSB_XFER_BULK )
|
||||
{
|
||||
TU_ASSERT_ERR( list_remove_qhd(
|
||||
(ehci_link_t*) get_async_head( _usbh_devices[pipe_hdl.dev_addr].rhport ),
|
||||
(ehci_link_t*) p_qhd) );
|
||||
(ehci_link_t*) get_async_head( _usbh_devices[dev_addr].rhport ),
|
||||
(ehci_link_t*) p_qhd), false );
|
||||
}
|
||||
#if EHCI_PERIODIC_LIST // TODO refractor/group this together
|
||||
else
|
||||
{
|
||||
TU_ASSERT_ERR( list_remove_qhd(
|
||||
get_period_head( _usbh_devices[pipe_hdl.dev_addr].rhport, p_qhd->interval_ms ),
|
||||
(ehci_link_t*) p_qhd) );
|
||||
get_period_head( _usbh_devices[dev_addr].rhport, p_qhd->interval_ms ),
|
||||
(ehci_link_t*) p_qhd), false );
|
||||
}
|
||||
#endif
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hcd_pipe_is_busy(pipe_handle_t pipe_hdl)
|
||||
bool hcd_pipe_is_busy(uint8_t dev_addr, pipe_handle_t pipe_hdl)
|
||||
{
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl );
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl);
|
||||
return !p_qhd->qtd_overlay.halted && (p_qhd->p_qtd_list_head != NULL);
|
||||
}
|
||||
|
||||
bool hcd_pipe_is_error(pipe_handle_t pipe_hdl)
|
||||
bool hcd_pipe_is_error(uint8_t dev_addr, pipe_handle_t pipe_hdl)
|
||||
{
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl );
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl);
|
||||
return p_qhd->qtd_overlay.halted;
|
||||
}
|
||||
|
||||
bool hcd_pipe_is_stalled(pipe_handle_t pipe_hdl)
|
||||
bool hcd_pipe_is_stalled(uint8_t dev_addr, pipe_handle_t pipe_hdl)
|
||||
{
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl );
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl);
|
||||
return p_qhd->qtd_overlay.halted && !qhd_has_xact_error(p_qhd);
|
||||
}
|
||||
|
||||
uint8_t hcd_pipe_get_endpoint_addr(pipe_handle_t pipe_hdl)
|
||||
uint8_t hcd_pipe_get_endpoint_addr(uint8_t dev_addr, pipe_handle_t pipe_hdl)
|
||||
{
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl );
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl);
|
||||
return p_qhd->endpoint_number + ( (p_qhd->pid_non_control == EHCI_PID_IN) ? TUSB_DIR_IN_MASK : 0);
|
||||
}
|
||||
|
||||
tusb_error_t hcd_pipe_clear_stall(pipe_handle_t pipe_hdl)
|
||||
tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, pipe_handle_t pipe_hdl)
|
||||
{
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl );
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl);
|
||||
p_qhd->qtd_overlay.halted = 0;
|
||||
// TODO reset data toggle ?
|
||||
return TUSB_ERROR_NONE;
|
||||
@ -927,16 +925,14 @@ static inline ehci_qhd_t* qhd_next(ehci_qhd_t const * p_qhd)
|
||||
return (ehci_qhd_t*) tu_align32(p_qhd->next.address);
|
||||
}
|
||||
|
||||
static inline ehci_qhd_t* qhd_get_from_pipe_handle(pipe_handle_t pipe_hdl)
|
||||
static inline ehci_qhd_t* qhd_get_from_pipe_handle(uint8_t dev_addr, pipe_handle_t pipe_hdl)
|
||||
{
|
||||
return &ehci_data.device[ pipe_hdl.dev_addr-1 ].qhd[ pipe_hdl.index ];
|
||||
return &ehci_data.device[dev_addr-1].qhd[pipe_hdl.index];
|
||||
}
|
||||
|
||||
static inline pipe_handle_t qhd_create_pipe_handle(ehci_qhd_t const * p_qhd)
|
||||
{
|
||||
pipe_handle_t pipe_hdl = {
|
||||
.dev_addr = p_qhd->device_address,
|
||||
};
|
||||
pipe_handle_t pipe_hdl = { };
|
||||
|
||||
// TODO Isochronous transfer support
|
||||
if (TUSB_XFER_CONTROL != p_qhd->xfer_type) // qhd index for control is meaningless
|
||||
|
@ -93,20 +93,19 @@ enum {
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct {
|
||||
uint8_t dev_addr;
|
||||
uint8_t reserved;
|
||||
uint8_t index;
|
||||
uint8_t ep_addr;
|
||||
uint8_t index;
|
||||
uint8_t reserved[2];
|
||||
} pipe_handle_t;
|
||||
|
||||
static inline bool pipehandle_is_valid(pipe_handle_t pipe_hdl)
|
||||
{
|
||||
return pipe_hdl.dev_addr > 0;
|
||||
return true ; // pipe_hdl.dev_addr > 0;
|
||||
}
|
||||
|
||||
static inline bool pipehandle_is_equal(pipe_handle_t x, pipe_handle_t y)
|
||||
{
|
||||
return (x.dev_addr == y.dev_addr) && (x.index == y.index);
|
||||
return (x.index == y.index);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -144,16 +143,16 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
|
||||
// TODO control xfer should be used via usbh layer
|
||||
|
||||
pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * endpoint_desc, uint8_t class_code) ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet
|
||||
tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) /*ATTR_WARN_UNUSED_RESULT*/;
|
||||
tusb_error_t hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet
|
||||
tusb_error_t hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT;
|
||||
bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, pipe_handle_t pipe_hdl);
|
||||
|
||||
bool hcd_pipe_is_busy(pipe_handle_t pipe_hdl) ATTR_PURE;
|
||||
bool hcd_pipe_is_error(pipe_handle_t pipe_hdl) ATTR_PURE;
|
||||
bool hcd_pipe_is_stalled(pipe_handle_t pipe_hdl) ATTR_PURE; // stalled also counted as error
|
||||
bool hcd_pipe_is_busy(uint8_t dev_addr, pipe_handle_t pipe_hdl);
|
||||
bool hcd_pipe_is_error(uint8_t dev_addr, pipe_handle_t pipe_hdl);
|
||||
bool hcd_pipe_is_stalled(uint8_t dev_addr, pipe_handle_t pipe_hdl); // stalled also counted as error
|
||||
tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, pipe_handle_t pipe_hdl);
|
||||
|
||||
uint8_t hcd_pipe_get_endpoint_addr(pipe_handle_t pipe_hdl) ATTR_PURE;
|
||||
tusb_error_t hcd_pipe_clear_stall(pipe_handle_t pipe_hdl);
|
||||
uint8_t hcd_pipe_get_endpoint_addr(uint8_t dev_addr, pipe_handle_t pipe_hdl);
|
||||
|
||||
#if 0
|
||||
tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT;
|
||||
|
@ -204,7 +204,7 @@ bool hub_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t co
|
||||
}
|
||||
|
||||
//------------- Queue the initial Status endpoint transfer -------------//
|
||||
TU_ASSERT( TUSB_ERROR_NONE == hcd_pipe_xfer(hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true) );
|
||||
TU_ASSERT( TUSB_ERROR_NONE == hcd_pipe_xfer(dev_addr, hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true) );
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -248,7 +248,7 @@ void hub_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes)
|
||||
|
||||
void hub_close(uint8_t dev_addr)
|
||||
{
|
||||
(void) hcd_pipe_close(hub_data[dev_addr-1].pipe_status);
|
||||
hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, hub_data[dev_addr-1].pipe_status);
|
||||
tu_memclr(&hub_data[dev_addr-1], sizeof(usbh_hub_t));
|
||||
|
||||
// osal_semaphore_reset(hub_enum_sem_hdl);
|
||||
@ -256,7 +256,7 @@ void hub_close(uint8_t dev_addr)
|
||||
|
||||
tusb_error_t hub_status_pipe_queue(uint8_t dev_addr)
|
||||
{
|
||||
return hcd_pipe_xfer(hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true);
|
||||
return hcd_pipe_xfer(dev_addr, hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user