From 1d33d4e07247107af6e8a14467852ed56734924c Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 29 Mar 2018 13:11:36 +0700 Subject: [PATCH] assert clean up --- tinyusb/class/hid/hid_device.c | 2 +- tinyusb/class/hid/hid_host.c | 4 +-- tinyusb/class/msc/msc_host.c | 12 +++---- tinyusb/common/assertion.h | 4 --- tinyusb/device/usbd.c | 6 ++-- tinyusb/host/hub.c | 12 +++---- tinyusb/host/usbh.c | 32 +++++++++---------- tinyusb/osal/osal.h | 12 +++---- tinyusb/osal/osal_none.h | 8 ++--- tinyusb/portable/nxp/lpc17xx/dcd_lpc175x_6x.c | 4 +-- tinyusb/tusb.c | 4 +-- 11 files changed, 48 insertions(+), 52 deletions(-) diff --git a/tinyusb/class/hid/hid_device.c b/tinyusb/class/hid/hid_device.c index 47aa55abf..cd40dd86c 100644 --- a/tinyusb/class/hid/hid_device.c +++ b/tinyusb/class/hid/hid_device.c @@ -234,7 +234,7 @@ tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t cons // return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; // TODO test STALL control out endpoint (with mouse+keyboard) // wValue = Report Type | Report ID STASK_INVOKE( usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, m_hid_buffer, p_request->wLength), err ); - STASK_ASSERT_STATUS(err); + STASK_ASSERT_ERR(err); p_driver->set_report_cb(rhport, u16_high_u8(p_request->wValue), m_hid_buffer, p_request->wLength); } diff --git a/tinyusb/class/hid/hid_host.c b/tinyusb/class/hid/hid_host.c index b0537875a..a65783182 100644 --- a/tinyusb/class/hid/hid_host.c +++ b/tinyusb/class/hid/hid_host.c @@ -225,7 +225,7 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ #if TUSB_CFG_HOST_HID_KEYBOARD if ( HID_PROTOCOL_KEYBOARD == p_interface_desc->bInterfaceProtocol) { - STASK_ASSERT_STATUS ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &keyboardh_data[dev_addr-1]) ); + STASK_ASSERT_ERR ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &keyboardh_data[dev_addr-1]) ); tuh_hid_keyboard_mounted_cb(dev_addr); } else #endif @@ -233,7 +233,7 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ #if TUSB_CFG_HOST_HID_MOUSE if ( HID_PROTOCOL_MOUSE == p_interface_desc->bInterfaceProtocol) { - STASK_ASSERT_STATUS ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &mouseh_data[dev_addr-1]) ); + STASK_ASSERT_ERR ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &mouseh_data[dev_addr-1]) ); tuh_hid_mouse_mounted_cb(dev_addr); } else #endif diff --git a/tinyusb/class/msc/msc_host.c b/tinyusb/class/msc/msc_host.c index 65d51b5bf..bcaf840d9 100644 --- a/tinyusb/class/msc/msc_host.c +++ b/tinyusb/class/msc/msc_host.c @@ -351,7 +351,7 @@ tusb_error_t msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ //------------- SCSI Inquiry -------------// tusbh_msc_inquiry(dev_addr, 0, msch_buffer); osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT, &error); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); 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); @@ -359,7 +359,7 @@ tusb_error_t msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ //------------- SCSI Read Capacity 10 -------------// tusbh_msc_read_capacity10(dev_addr, 0, msch_buffer); osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT, &error); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); // NOTE: my toshiba thumb-drive stall the first Read Capacity and require the sequence // Read Capacity --> Stalled --> Clear Stall --> Request Sense --> Read Capacity (2) to work @@ -371,21 +371,21 @@ tusb_error_t msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ 0, NULL ), error ); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); hcd_pipe_clear_stall(msch_data[dev_addr-1].bulk_in); osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT, &error); // wait for SCSI status - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); //------------- SCSI Request Sense -------------// (void) tuh_msc_request_sense(dev_addr, 0, msch_buffer); osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT, &error); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); //------------- Re-read SCSI Read Capactity -------------// tusbh_msc_read_capacity10(dev_addr, 0, msch_buffer); osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT, &error); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); } msch_data[dev_addr-1].last_lba = __be2n( ((scsi_read_capacity10_data_t*)msch_buffer)->last_lba ); diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h index 8a132d5b1..6689d66e8 100644 --- a/tinyusb/common/assertion.h +++ b/tinyusb/common/assertion.h @@ -81,10 +81,6 @@ extern "C" //--------------------------------------------------------------------+ // tusb_error_t Status Assert TODO use ASSERT_DEFINE //--------------------------------------------------------------------+ -#define ASSERT_STATUS_MESSAGE(sts, message) \ - ASSERT_DEFINE(tusb_error_t status = (tusb_error_t)(sts),\ - TUSB_ERROR_NONE == status, status, "%s: %s", tusb_strerr[status], message) - #define ASSERT_STATUS(sts) \ ASSERT_DEFINE(tusb_error_t status = (tusb_error_t)(sts),\ TUSB_ERROR_NONE == status, status, "%s", tusb_strerr[status]) diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c index e745addd9..3c637de1a 100644 --- a/tinyusb/device/usbd.c +++ b/tinyusb/device/usbd.c @@ -257,7 +257,7 @@ static tusb_error_t usbd_main_stk(void) #if 1 osal_queue_receive(usbd_queue_hdl, &event, OSAL_TIMEOUT_WAIT_FOREVER, &error); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); #else enum { ROUTINE_INTERVAL_MS = 10 }; osal_queue_receive(usbd_queue_hdl, &event, ROUTINE_INTERVAL_MS, &error); @@ -322,7 +322,7 @@ tusb_error_t usbd_control_xfer_st(uint8_t rhport, tusb_dir_t dir, uint8_t * buff dcd_control_xfer(rhport, dir, buffer, length); osal_semaphore_wait( usbd_control_xfer_sem_hdl, 100, &error ); - STASK_ASSERT_STATUS( error ); + STASK_ASSERT_ERR( error ); } // Status opposite direction with Zero Length @@ -458,7 +458,7 @@ static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number) usbd_devices[rhport].interface2class[p_desc_interface->bInterfaceNumber] = class_index; uint16_t length=0; - ASSERT_STATUS( usbd_class_drivers[class_index].open( rhport, p_desc_interface, &length ) ); + ASSERT_ERR( usbd_class_drivers[class_index].open( rhport, p_desc_interface, &length ) ); TU_ASSERT( length >= sizeof(tusb_desc_interface_t), TUSB_ERROR_FAILED ); p_desc += length; diff --git a/tinyusb/host/hub.c b/tinyusb/host/hub.c index 7bcd009e8..9b4f03634 100644 --- a/tinyusb/host/hub.c +++ b/tinyusb/host/hub.c @@ -83,7 +83,7 @@ tusb_error_t hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, 0, NULL ), error ); - STASK_ASSERT_STATUS( error ); + STASK_ASSERT_ERR( error ); //------------- Get Port Status to check if feature is cleared -------------// STASK_INVOKE( @@ -92,7 +92,7 @@ tusb_error_t hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, 4, hub_enum_buffer ), error ); - STASK_ASSERT_STATUS( error ); + STASK_ASSERT_ERR( error ); //------------- Check if feature is cleared -------------// hub_port_status_response_t * p_port_status; @@ -117,7 +117,7 @@ tusb_error_t hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port) 0, NULL ), error ); - STASK_ASSERT_STATUS( error ); + STASK_ASSERT_ERR( error ); osal_task_delay(RESET_DELAY); // TODO Hub wait for Status Endpoint on Reset Change @@ -128,7 +128,7 @@ tusb_error_t hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port) 4, hub_enum_buffer ), error ); - STASK_ASSERT_STATUS( error ); + STASK_ASSERT_ERR( error ); hub_port_status_response_t * p_port_status; p_port_status = (hub_port_status_response_t *) hub_enum_buffer; @@ -185,7 +185,7 @@ tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_i sizeof(descriptor_hub_desc_t), hub_enum_buffer ), error ); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); // only care about this field in hub descriptor hub_data[dev_addr-1].port_number = ((descriptor_hub_desc_t*) hub_enum_buffer)->bNbrPorts; @@ -203,7 +203,7 @@ tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_i } //------------- Queue the initial Status endpoint transfer -------------// - STASK_ASSERT_STATUS ( hcd_pipe_xfer(hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true) ); + STASK_ASSERT_ERR ( hcd_pipe_xfer(hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true) ); OSAL_SUBTASK_END } diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index a491988c3..e0be32e3f 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -186,7 +186,7 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, uint8_t bmRequestType, OSAL_SUBTASK_BEGIN osal_mutex_wait(usbh_devices[dev_addr].control.mutex_hdl, OSAL_TIMEOUT_NORMAL, &error); - STASK_ASSERT_STATUS_HDLR(error, osal_mutex_release(usbh_devices[dev_addr].control.mutex_hdl)); + STASK_ASSERT_ERR_HDLR(error, osal_mutex_release(usbh_devices[dev_addr].control.mutex_hdl)); usbh_devices[dev_addr].control.request = (tusb_control_request_t) { {.bmRequestType = bmRequestType}, @@ -206,7 +206,7 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, uint8_t bmRequestType, if ( TUSB_ERROR_NONE == error ) osal_semaphore_wait(usbh_devices[dev_addr].control.sem_hdl, OSAL_TIMEOUT_NORMAL, &error); osal_mutex_release(usbh_devices[dev_addr].control.mutex_hdl); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); if (TUSB_EVENT_XFER_STALLED == usbh_devices[dev_addr].control.pipe_status) STASK_RETURN(TUSB_ERROR_USBH_XFER_STALLED); if (TUSB_EVENT_XFER_ERROR == usbh_devices[dev_addr].control.pipe_status) STASK_RETURN(TUSB_ERROR_USBH_XFER_FAILED); @@ -374,7 +374,7 @@ tusb_error_t enumeration_body_subtask(void) OSAL_SUBTASK_BEGIN osal_queue_receive(enum_queue_hdl, &enum_entry, OSAL_TIMEOUT_WAIT_FOREVER, &error); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); usbh_devices[0].core_id = enum_entry.core_id; // TODO refractor integrate to device_pool usbh_devices[0].hub_addr = enum_entry.hub_addr; @@ -412,8 +412,8 @@ tusb_error_t enumeration_body_subtask(void) 4, enum_data_buffer ), error ); -// STASK_ASSERT_STATUS( error ); - STASK_ASSERT_STATUS_HDLR(error, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor +// STASK_ASSERT_ERR( error ); + STASK_ASSERT_ERR_HDLR(error, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor // Acknowledge Port Connection Change STASK_INVOKE( hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_CONNECTION_CHANGE), error ); @@ -433,8 +433,8 @@ tusb_error_t enumeration_body_subtask(void) else { // Connection Event STASK_INVOKE ( hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port), error ); -// STASK_ASSERT_STATUS( error ); - STASK_ASSERT_STATUS_HDLR(error, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor +// STASK_ASSERT_ERR( error ); + STASK_ASSERT_ERR_HDLR(error, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor usbh_devices[0].speed = hub_port_get_speed(); @@ -444,7 +444,7 @@ tusb_error_t enumeration_body_subtask(void) } #endif - STASK_ASSERT_STATUS( usbh_pipe_control_open(0, 8) ); + STASK_ASSERT_ERR( usbh_pipe_control_open(0, 8) ); usbh_devices[0].state = TUSB_DEVICE_STATE_ADDRESSED; //------------- Get first 8 bytes of device descriptor to get Control Endpoint Size -------------// @@ -458,14 +458,14 @@ tusb_error_t enumeration_body_subtask(void) //------------- Reset device again before Set Address -------------// if (usbh_devices[0].hub_addr == 0) { // connected directly to roothub - STASK_ASSERT_STATUS(error); // TODO some slow device is observed to fail the very fist controller xfer, can try more times + STASK_ASSERT_ERR(error); // TODO some slow device is observed to fail the very fist controller xfer, can try more times hcd_port_reset( usbh_devices[0].core_id ); // reset port after 8 byte descriptor osal_task_delay(RESET_DELAY); } #if TUSB_CFG_HOST_HUB else { // connected via a hub - STASK_ASSERT_STATUS_HDLR(error, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor + STASK_ASSERT_ERR_HDLR(error, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor STASK_INVOKE ( hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port), error ); if ( TUSB_ERROR_NONE == error ) @@ -487,7 +487,7 @@ tusb_error_t enumeration_body_subtask(void) 0, NULL ), error ); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); //------------- update port info & close control pipe of addr0 -------------// usbh_devices[new_addr].core_id = usbh_devices[0].core_id; @@ -500,7 +500,7 @@ tusb_error_t enumeration_body_subtask(void) usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG; // open control pipe for new address - STASK_ASSERT_STATUS ( usbh_pipe_control_open(new_addr, ((tusb_desc_device_t*) enum_data_buffer)->bMaxPacketSize0 ) ); + STASK_ASSERT_ERR ( usbh_pipe_control_open(new_addr, ((tusb_desc_device_t*) enum_data_buffer)->bMaxPacketSize0 ) ); //------------- Get full device descriptor -------------// STASK_INVOKE( @@ -509,7 +509,7 @@ tusb_error_t enumeration_body_subtask(void) 18, enum_data_buffer ), error ); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); // update device info TODO alignment issue usbh_devices[new_addr].vendor_id = ((tusb_desc_device_t*) enum_data_buffer)->idVendor; @@ -526,7 +526,7 @@ tusb_error_t enumeration_body_subtask(void) 9, enum_data_buffer ), error ); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); STASK_ASSERT_HDLR( TUSB_CFG_HOST_ENUM_BUFFER_SIZE >= ((tusb_desc_configuration_t*)enum_data_buffer)->wTotalLength, tuh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_CONFIG_DESC_TOO_LONG, NULL) ); @@ -537,7 +537,7 @@ tusb_error_t enumeration_body_subtask(void) TUSB_CFG_HOST_ENUM_BUFFER_SIZE, enum_data_buffer ), error ); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); // update configuration info usbh_devices[new_addr].interface_count = ((tusb_desc_configuration_t*) enum_data_buffer)->bNumInterfaces; @@ -549,7 +549,7 @@ tusb_error_t enumeration_body_subtask(void) 0, NULL ), error ); - STASK_ASSERT_STATUS(error); + STASK_ASSERT_ERR(error); usbh_devices[new_addr].state = TUSB_DEVICE_STATE_CONFIGURED; diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h index 83f2573a8..e74929de7 100644 --- a/tinyusb/osal/osal.h +++ b/tinyusb/osal/osal.h @@ -74,15 +74,15 @@ #define OSAL_SUBTASK_BEGIN #define OSAL_SUBTASK_END return TUSB_ERROR_NONE; - #define STASK_RETURN(_error) return _error; - #define STASK_INVOKE(_subtask, _status) (_status) = _subtask + #define STASK_RETURN(_error) return _error; + #define STASK_INVOKE(_subtask, _status) (_status) = _subtask //------------- Sub Task Assert -------------// - #define STASK_ASSERT_STATUS(sts) VERIFY_STATUS(sts) - #define STASK_ASSERT(condition) VERIFY(condition, TUSB_ERROR_OSAL_TASK_FAILED) + #define STASK_ASSERT_ERR(_err) VERIFY_STATUS(_err) + #define STASK_ASSERT_ERR_HDLR(_err, _func) VERIFY_STATUS_HDLR(_err, _func) - #define STASK_ASSERT_STATUS_HDLR(sts, func_call) VERIFY_STATUS_HDLR(sts, func_call) - #define STASK_ASSERT_HDLR(condition, func_call) VERIFY_HDLR(condition, func_call) + #define STASK_ASSERT(_cond) VERIFY(_cond, TUSB_ERROR_OSAL_TASK_FAILED) + #define STASK_ASSERT_HDLR(_cond, _func) VERIFY_HDLR(_cond, _func) #endif #ifdef __cplusplus diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index 3dad86183..414352df1 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -125,11 +125,11 @@ static inline osal_task_t osal_task_create(osal_func_t code, const char* name, u //------------- Sub Task Assert -------------// #define STASK_RETURN(error) do { TASK_RESTART; return error; } while(0) -#define STASK_ASSERT_STATUS(sts) VERIFY_STATUS_HDLR(sts, TASK_RESTART) -#define STASK_ASSERT_STATUS_HDLR(sts, func_call) VERIFY_STATUS_HDLR(sts, func_call; TASK_RESTART ) +#define STASK_ASSERT_ERR(_err) VERIFY_STATUS_HDLR(_err, TASK_RESTART) +#define STASK_ASSERT_ERR_HDLR(_err, _func) VERIFY_STATUS_HDLR(_err, _func; TASK_RESTART ) -#define STASK_ASSERT(condition) VERIFY_HDLR(condition, TASK_RESTART) -#define STASK_ASSERT_HDLR(condition, func_call) VERIFY_HDLR(condition, func_call; TASK_RESTART) +#define STASK_ASSERT(_cond) VERIFY_HDLR(_cond, TASK_RESTART) +#define STASK_ASSERT_HDLR(_cond, _func) VERIFY_HDLR(_cond, _func; TASK_RESTART) //--------------------------------------------------------------------+ // QUEUE API diff --git a/tinyusb/portable/nxp/lpc17xx/dcd_lpc175x_6x.c b/tinyusb/portable/nxp/lpc17xx/dcd_lpc175x_6x.c index 7285d1461..aee001c50 100644 --- a/tinyusb/portable/nxp/lpc17xx/dcd_lpc175x_6x.c +++ b/tinyusb/portable/nxp/lpc17xx/dcd_lpc175x_6x.c @@ -316,10 +316,10 @@ static tusb_error_t pipe_control_xfer(uint8_t ep_id, uint8_t* p_buffer, uint16_t if (ep_id) { - ASSERT_STATUS ( pipe_control_write(p_buffer, packet_len) ); + ASSERT_ERR ( pipe_control_write(p_buffer, packet_len) ); }else { - ASSERT_STATUS ( pipe_control_read(p_buffer, packet_len) ); + ASSERT_ERR ( pipe_control_read(p_buffer, packet_len) ); } dcd_data.control_dma.remaining_bytes -= packet_len; diff --git a/tinyusb/tusb.c b/tinyusb/tusb.c index 309fcc249..2bbba8471 100644 --- a/tinyusb/tusb.c +++ b/tinyusb/tusb.c @@ -46,11 +46,11 @@ tusb_error_t tusb_init(void) VERIFY( tusb_hal_init(), TUSB_ERROR_FAILED ) ; // hardware init #if MODE_HOST_SUPPORTED - ASSERT_STATUS( usbh_init() ); // host stack init + ASSERT_ERR( usbh_init() ); // host stack init #endif #if MODE_DEVICE_SUPPORTED - ASSERT_STATUS ( usbd_init() ); // device stack init + ASSERT_ERR ( usbd_init() ); // device stack init #endif return TUSB_ERROR_NONE;