more hcd clean up

This commit is contained in:
hathach 2018-03-12 22:37:12 +07:00
parent c696812cad
commit 80398cb4cb
9 changed files with 48 additions and 46 deletions

View File

@ -334,10 +334,10 @@ bool tusb_dcd_edpt_busy(uint8_t port, uint8_t edpt_addr)
}
// add only, controller virtually cannot know
static tusb_error_t pipe_add_xfer(uint8_t port, uint8_t ed_idx, void * buffer, uint16_t total_bytes, bool int_on_complete)
static bool pipe_add_xfer(uint8_t port, uint8_t ed_idx, void * buffer, uint16_t total_bytes, bool int_on_complete)
{
uint8_t qtd_idx = qtd_find_free(port);
ASSERT(qtd_idx != 0, TUSB_ERROR_DCD_NOT_ENOUGH_QTD);
TU_ASSERT(qtd_idx != 0);
dcd_data_t* p_dcd = dcd_data_ptr[port];
dcd_qhd_t * p_qhd = &p_dcd->qhd[ed_idx];
@ -349,7 +349,7 @@ static tusb_error_t pipe_add_xfer(uint8_t port, uint8_t ed_idx, void * buffer, u
{
if ( p_qhd->list_qtd_idx[free_slot] == 0 ) break; // found free slot
}
ASSERT(free_slot < DCD_QTD_PER_QHD_MAX, TUSB_ERROR_DCD_NOT_ENOUGH_QTD);
TU_ASSERT(free_slot < DCD_QTD_PER_QHD_MAX);
p_qhd->list_qtd_idx[free_slot] = qtd_idx; // add new qtd to qhd's array list
@ -359,20 +359,20 @@ static tusb_error_t pipe_add_xfer(uint8_t port, uint8_t ed_idx, void * buffer, u
if ( free_slot > 0 ) p_dcd->qtd[ p_qhd->list_qtd_idx[free_slot-1] ].next = (uint32_t) p_qtd;
return TUSB_ERROR_NONE;
return true;
}
tusb_error_t tusb_dcd_edpt_queue_xfer(uint8_t port, uint8_t edpt_addr, uint8_t * buffer, uint16_t total_bytes)
bool tusb_dcd_edpt_queue_xfer(uint8_t port, uint8_t edpt_addr, uint8_t * buffer, uint16_t total_bytes)
{
uint8_t ep_idx = edpt_addr2phy(edpt_addr);
return pipe_add_xfer(port, ep_idx, buffer, total_bytes, false);
}
tusb_error_t tusb_dcd_edpt_xfer(uint8_t port, uint8_t edpt_addr, uint8_t * buffer, uint16_t total_bytes, bool int_on_complete)
bool tusb_dcd_edpt_xfer(uint8_t port, uint8_t edpt_addr, uint8_t * buffer, uint16_t total_bytes, bool int_on_complete)
{
uint8_t ep_idx = edpt_addr2phy(edpt_addr);
ASSERT_STATUS ( pipe_add_xfer(port, ep_idx, buffer, total_bytes, int_on_complete) );
VERIFY ( pipe_add_xfer(port, ep_idx, buffer, total_bytes, int_on_complete) );
dcd_qhd_t* p_qhd = &dcd_data_ptr[port]->qhd[ ep_idx ];
dcd_qtd_t* p_qtd = &dcd_data_ptr[port]->qtd[ p_qhd->list_qtd_idx[0] ];
@ -381,7 +381,7 @@ tusb_error_t tusb_dcd_edpt_xfer(uint8_t port, uint8_t edpt_addr, uint8_t * buff
LPC_USB[port]->ENDPTPRIME = BIT_( edpt_phy2pos(ep_idx) ) ;
return TUSB_ERROR_NONE;
return true;
}
//------------- Device Controller Driver's Interrupt Handler -------------//

View File

@ -195,7 +195,7 @@ tusb_error_t cdcd_open(uint8_t port, tusb_descriptor_interface_t const * p_inter
p_cdc->interface_number = p_interface_desc->bInterfaceNumber;
// Prepare for incoming data
tusb_dcd_edpt_xfer(port, p_cdc->edpt_addr[CDC_PIPE_DATA_OUT], _tmp_rx_buf, sizeof(_tmp_rx_buf), true);
TU_ASSERT( tusb_dcd_edpt_xfer(port, p_cdc->edpt_addr[CDC_PIPE_DATA_OUT], _tmp_rx_buf, sizeof(_tmp_rx_buf), true), TUSB_ERROR_DCD_EDPT_XFER);
return TUSB_ERROR_NONE;
@ -269,7 +269,7 @@ tusb_error_t cdcd_xfer_cb(uint8_t port, uint8_t edpt_addr, tusb_event_t event, u
fifo_write_n(&_rx_ff, _tmp_rx_buf, xferred_bytes);
// preparing for next
tusb_dcd_edpt_xfer(port, p_cdc->edpt_addr[CDC_PIPE_DATA_OUT], _tmp_rx_buf, sizeof(_tmp_rx_buf), true);
TU_ASSERT(tusb_dcd_edpt_xfer(port, p_cdc->edpt_addr[CDC_PIPE_DATA_OUT], _tmp_rx_buf, sizeof(_tmp_rx_buf), true), TUSB_ERROR_DCD_EDPT_XFER);
// fire callback
tud_cdc_rx_cb(port);
@ -288,7 +288,7 @@ void cdcd_sof(uint8_t port)
{
uint16_t count = fifo_read_n(&_tx_ff, _tmp_tx_buf, sizeof(_tmp_tx_buf));
tusb_dcd_edpt_xfer(port, edpt, _tmp_tx_buf, count, false);
TU_ASSERT( tusb_dcd_edpt_xfer(port, edpt, _tmp_tx_buf, count, false), TUSB_ERROR_DCD_EDPT_XFER);
}
}

View File

@ -114,11 +114,11 @@ bool tud_hid_keyboard_busy(uint8_t port)
tusb_error_t tud_hid_keyboard_send(uint8_t port, hid_keyboard_report_t const *p_report)
{
ASSERT(tud_mounted(), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
VERIFY(tud_mounted(), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
hidd_interface_t * p_kbd = &keyboardd_data; // TODO &keyboardd_data[port];
ASSERT_STATUS( tusb_dcd_edpt_xfer(port, p_kbd->edpt_addr, (void*) p_report, sizeof(hid_keyboard_report_t), true) ) ;
TU_ASSERT( tusb_dcd_edpt_xfer(port, p_kbd->edpt_addr, (void*) p_report, sizeof(hid_keyboard_report_t), true), TUSB_ERROR_DCD_EDPT_XFER ) ;
return TUSB_ERROR_NONE;
}
@ -137,11 +137,11 @@ bool tud_hid_mouse_is_busy(uint8_t port)
tusb_error_t tud_hid_mouse_send(uint8_t port, hid_mouse_report_t const *p_report)
{
ASSERT(tud_mounted(), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
VERIFY(tud_mounted(), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
hidd_interface_t * p_mouse = &moused_data; // TODO &keyboardd_data[port];
ASSERT_STATUS( tusb_dcd_edpt_xfer(port, p_mouse->edpt_addr, (void*) p_report, sizeof(hid_mouse_report_t), true) ) ;
TU_ASSERT( tusb_dcd_edpt_xfer(port, p_mouse->edpt_addr, (void*) p_report, sizeof(hid_mouse_report_t), true), TUSB_ERROR_DCD_EDPT_XFER ) ;
return TUSB_ERROR_NONE;
}

View File

@ -116,7 +116,7 @@ tusb_error_t mscd_open(uint8_t port, tusb_descriptor_interface_t const * p_inter
(*p_length) += sizeof(tusb_descriptor_interface_t) + 2*sizeof(tusb_descriptor_endpoint_t);
//------------- Queue Endpoint OUT for Command Block Wrapper -------------//
ASSERT_STATUS( tusb_dcd_edpt_xfer(port, p_msc->edpt_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cmd_block_wrapper_t), true) );
TU_ASSERT( tusb_dcd_edpt_xfer(port, p_msc->edpt_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cmd_block_wrapper_t), true), TUSB_ERROR_DCD_EDPT_XFER );
return TUSB_ERROR_NONE;
}
@ -197,7 +197,7 @@ tusb_error_t mscd_xfer_cb(uint8_t port, uint8_t edpt_addr, tusb_event_t event, u
}else
{
memcpy(p_msc->scsi_data, p_buffer, actual_length);
ASSERT_STATUS( tusb_dcd_edpt_queue_xfer(port, edpt_data, p_msc->scsi_data, actual_length ) );
TU_ASSERT( tusb_dcd_edpt_queue_xfer(port, edpt_data, p_msc->scsi_data, actual_length), TUSB_ERROR_DCD_EDPT_XFER );
}
}
}
@ -213,10 +213,10 @@ tusb_error_t mscd_xfer_cb(uint8_t port, uint8_t edpt_addr, tusb_event_t event, u
// Either bulk in & out can be stalled in the data phase, dcd must make sure these queued transfer will be resumed after host clear stall
if (!is_waiting_read10_write10)
{
ASSERT_STATUS( tusb_dcd_edpt_xfer(port, p_msc->edpt_in , (uint8_t*) p_csw, sizeof(msc_cmd_status_wrapper_t), false) );
TU_ASSERT( tusb_dcd_edpt_xfer(port, p_msc->edpt_in , (uint8_t*) p_csw, sizeof(msc_cmd_status_wrapper_t), false), TUSB_ERROR_DCD_EDPT_XFER );
//------------- Queue the next CBW -------------//
ASSERT_STATUS( tusb_dcd_edpt_xfer(port, p_msc->edpt_out, (uint8_t*) p_cbw, sizeof(msc_cmd_block_wrapper_t), true) );
TU_ASSERT( tusb_dcd_edpt_xfer(port, p_msc->edpt_out, (uint8_t*) p_cbw, sizeof(msc_cmd_block_wrapper_t), true), TUSB_ERROR_DCD_EDPT_XFER );
}
return TUSB_ERROR_NONE;
@ -252,7 +252,7 @@ static bool read10_write10_data_xfer(uint8_t port, mscd_interface_t* p_msc)
return true;
} else if (xferred_block < block_count)
{
ASSERT_STATUS( tusb_dcd_edpt_xfer(port, edpt_addr, p_buffer, xferred_byte, true) );
TU_ASSERT( tusb_dcd_edpt_xfer(port, edpt_addr, p_buffer, xferred_byte, true), TUSB_ERROR_DCD_EDPT_XFER );
// adjust lba, block_count, xfer_bytes for the next call
p_readwrite->lba = __n2be(lba+xferred_block);
@ -263,7 +263,7 @@ static bool read10_write10_data_xfer(uint8_t port, mscd_interface_t* p_msc)
}else
{
p_csw->status = MSC_CSW_STATUS_PASSED;
ASSERT_STATUS( tusb_dcd_edpt_queue_xfer(port, edpt_addr, p_buffer, xferred_byte) );
TU_ASSERT( tusb_dcd_edpt_queue_xfer(port, edpt_addr, p_buffer, xferred_byte), TUSB_ERROR_DCD_EDPT_XFER );
return true;
}
}

View File

@ -86,6 +86,7 @@
ENTRY(TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT )\
ENTRY(TUSB_ERROR_DCD_NOT_ENOUGH_QTD )\
ENTRY(TUSB_ERROR_DCD_OPEN_PIPE_FAILED )\
ENTRY(TUSB_ERROR_DCD_EDPT_XFER )\
ENTRY(TUSB_ERROR_NOT_SUPPORTED_YET )\
ENTRY(TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED )\
ENTRY(TUSB_ERROR_NOT_ENOUGH_MEMORY )\

View File

@ -88,7 +88,7 @@ typedef enum
TUSB_DESC_DEBUG = 0x0A ,
TUSB_DESC_INTERFACE_ASSOCIATION = 0x0B ,
TUSB_DESC_CLASS_SPECIFIC = 0x24
}tusb_std_descriptor_type_t;
}tusb_desc_type_t;
typedef enum
{

View File

@ -60,11 +60,11 @@
// VERIFY Helper
//--------------------------------------------------------------------+
#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 _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 _VERIFY_MESS(_status)
#define _ASSERT_MESS()
#endif
@ -82,13 +82,13 @@
#define VERIFY_STS_1ARGS(sts) \
do { \
uint32_t _status = (uint32_t)(sts); \
if ( 0 != _status ) { VERIFY_MESS(_status) return _status; } \
if ( 0 != _status ) { _VERIFY_MESS(_status) return _status; } \
} while(0)
#define VERIFY_STS_2ARGS(sts, _error) \
do { \
uint32_t _status = (uint32_t)(sts); \
if ( 0 != _status ) { VERIFY_MESS(_status) return _error; }\
if ( 0 != _status ) { _VERIFY_MESS(_status) return _error; }\
} while(0)
/**
@ -106,13 +106,13 @@
#define VERIFY_STS_HDLR_2ARGS(sts, _handler) \
do { \
uint32_t _status = (uint32_t)(sts); \
if ( 0 != _status ) { VERIFY_MESS(_status) _handler; return _status; }\
if ( 0 != _status ) { _VERIFY_MESS(_status) _handler; return _status; }\
} while(0)
#define VERIFY_STS_HDLR_3ARGS(sts, _handler, _error) \
do { \
uint32_t _status = (uint32_t)(sts); \
if ( 0 != _status ) { VERIFY_MESS(_status) _handler; return _error; }\
if ( 0 != _status ) { _VERIFY_MESS(_status) _handler; return _error; }\
} while(0)
#define VERIFY_STATUS_HDLR(...) GET_4TH_ARG(__VA_ARGS__, VERIFY_STS_HDLR_3ARGS, VERIFY_STS_HDLR_2ARGS)(__VA_ARGS__)

View File

@ -401,7 +401,7 @@ static tusb_error_t usbd_set_configure_received(uint8_t port, uint8_t config_num
static tusb_error_t get_descriptor(uint8_t port, tusb_control_request_t const * const p_request, uint8_t const ** pp_buffer, uint16_t * p_length)
{
tusb_std_descriptor_type_t const desc_type = (tusb_std_descriptor_type_t) u16_high_u8(p_request->wValue);
tusb_desc_type_t const desc_type = (tusb_desc_type_t) u16_high_u8(p_request->wValue);
uint8_t const desc_index = u16_low_u8( p_request->wValue );
uint8_t const * p_data = NULL ;

View File

@ -62,37 +62,38 @@ typedef enum
/*------------------------------------------------------------------*/
/* Controller API
*------------------------------------------------------------------*/
bool tusb_dcd_init (uint8_t port);
void tusb_dcd_connect (uint8_t port);
void tusb_dcd_disconnect (uint8_t port);
void tusb_dcd_set_address (uint8_t port, uint8_t dev_addr);
void tusb_dcd_set_config (uint8_t port, uint8_t config_num);
bool tusb_dcd_init (uint8_t port);
void tusb_dcd_connect (uint8_t port);
void tusb_dcd_disconnect (uint8_t port);
void tusb_dcd_set_address (uint8_t port, uint8_t dev_addr);
void tusb_dcd_set_config (uint8_t port, uint8_t config_num);
/*------------------------------------------------------------------*/
/* Event Function
* Called by DCD to notify USBD
*------------------------------------------------------------------*/
void tusb_dcd_bus_event(uint8_t port, usbd_bus_event_type_t bus_event);
void tusb_dcd_setup_received(uint8_t port, uint8_t const* p_request);
void tusb_dcd_xfer_complete(uint8_t port, uint8_t edpt_addr, uint32_t xferred_bytes, bool succeeded);
void tusb_dcd_bus_event (uint8_t port, usbd_bus_event_type_t bus_event);
void tusb_dcd_setup_received (uint8_t port, uint8_t const* p_request);
void tusb_dcd_xfer_complete (uint8_t port, uint8_t edpt_addr, uint32_t xferred_bytes, bool succeeded);
/*------------------------------------------------------------------*/
/* Endpoint API
*------------------------------------------------------------------*/
//------------- Control Endpoint -------------//
bool tusb_dcd_control_xfer(uint8_t port, tusb_dir_t dir, uint8_t * p_buffer, uint16_t length, bool int_on_complete);
void tusb_dcd_control_stall(uint8_t port);
bool tusb_dcd_control_xfer (uint8_t port, tusb_dir_t dir, uint8_t * p_buffer, uint16_t length, bool int_on_complete);
void tusb_dcd_control_stall (uint8_t port);
//------------- Other Endpoints -------------//
bool tusb_dcd_edpt_open(uint8_t port, tusb_descriptor_endpoint_t const * p_endpoint_desc);
tusb_error_t tusb_dcd_edpt_queue_xfer(uint8_t port, uint8_t edpt_addr, uint8_t * buffer, uint16_t total_bytes); // only queue, not transferring yet
tusb_error_t tusb_dcd_edpt_xfer(uint8_t port, uint8_t edpt_addr, uint8_t * buffer, uint16_t total_bytes, bool int_on_complete);
bool tusb_dcd_edpt_open (uint8_t port, tusb_descriptor_endpoint_t const * p_endpoint_desc);
bool tusb_dcd_edpt_xfer (uint8_t port, uint8_t edpt_addr, uint8_t * buffer, uint16_t total_bytes, bool int_on_complete);
bool tusb_dcd_edpt_queue_xfer (uint8_t port, uint8_t edpt_addr, uint8_t * buffer, uint16_t total_bytes); // only queue, not transferring yet
bool tusb_dcd_edpt_busy(uint8_t port, uint8_t edpt_addr);
void tusb_dcd_edpt_stall (uint8_t port, uint8_t edpt_addr);
void tusb_dcd_edpt_clear_stall (uint8_t port, uint8_t edpt_addr);
void tusb_dcd_edpt_stall(uint8_t port, uint8_t edpt_addr);
void tusb_dcd_edpt_clear_stall(uint8_t port, uint8_t edpt_addr);
// TODO may remove
bool tusb_dcd_edpt_busy (uint8_t port, uint8_t edpt_addr);
#ifdef __cplusplus
}