From 295612b48f396fa2234c109be4b73294e5c6c27c Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 21 Sep 2013 00:42:39 +0700 Subject: [PATCH] remove ATTR_WEAK for all necessary driver callback fix ceedling tests --- demos/host/host_os_none/host_os_none.uvopt | 22 ++--- .../lpc18xx_43xx/test/host/cdc/cdc_callback.h | 5 +- .../test/host/hid/hidh_callback.h | 12 +-- .../test/host/hid/test_hid_host.c | 3 +- .../test/host/hid/test_hidh_generic.c | 93 +++++++++++++++++++ .../test/host/usbh/test_enum_task.c | 2 + tinyusb/class/cdc_host.h | 12 +-- tinyusb/class/cdc_rndis_host.c | 8 +- tinyusb/class/hid_host.c | 8 +- tinyusb/class/hid_host.h | 14 +-- tinyusb/host/usbh.c | 4 +- 11 files changed, 137 insertions(+), 46 deletions(-) create mode 100644 tests/lpc18xx_43xx/test/host/hid/test_hidh_generic.c diff --git a/demos/host/host_os_none/host_os_none.uvopt b/demos/host/host_os_none/host_os_none.uvopt index 47780250f..b9da97852 100644 --- a/demos/host/host_os_none/host_os_none.uvopt +++ b/demos/host/host_os_none/host_os_none.uvopt @@ -403,10 +403,10 @@ 1 0 0 - 43 + 3 0 - 164 - 171 + 165 + 192 0 ..\src\main.c main.c @@ -525,7 +525,7 @@ 0 2 0 - 140 + 141 146 0 ..\..\bsp\boards\embedded_artists\board_ea4357.c @@ -541,7 +541,7 @@ 0 1 0 - 102 + 96 106 0 ..\..\bsp\boards\printf_retarget.c @@ -677,7 +677,7 @@ 0 0 0 - 57 + 23 69 0 ..\..\..\tinyusb\tusb.c @@ -741,8 +741,8 @@ 0 0 0 - 370 - 375 + 1 + 1 0 ..\..\..\tinyusb\host\usbh.c usbh.c @@ -757,7 +757,7 @@ 0 25 0 - 141 + 142 147 0 ..\..\..\tinyusb\host\ehci\ehci.c @@ -805,7 +805,7 @@ 0 7 0 - 101 + 67 112 0 ..\..\..\tinyusb\hal\hal_lpc43xx.c @@ -917,7 +917,7 @@ 0 15 0 - 86 + 87 90 0 ..\..\..\tinyusb\class\msc_host.c diff --git a/tests/lpc18xx_43xx/test/host/cdc/cdc_callback.h b/tests/lpc18xx_43xx/test/host/cdc/cdc_callback.h index 8dcfc4eac..1a3c07077 100644 --- a/tests/lpc18xx_43xx/test/host/cdc/cdc_callback.h +++ b/tests/lpc18xx_43xx/test/host/cdc/cdc_callback.h @@ -55,11 +55,10 @@ void tusbh_cdc_mounted_cb(uint8_t dev_addr); void tusbh_cdc_unmounted_isr(uint8_t dev_addr); -void tusbh_cdc_isr(uint8_t dev_addr, tusb_event_t event); void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes); -void tusbh_cdc_rndis_mounted_cb(uint8_t dev_addr) ATTR_WEAK; -void tusbh_cdc_rndis_unmounted_isr(uint8_t dev_addr) ATTR_WEAK; +void tusbh_cdc_rndis_mounted_cb(uint8_t dev_addr); +void tusbh_cdc_rndis_unmounted_isr(uint8_t dev_addr); #ifdef __cplusplus diff --git a/tests/lpc18xx_43xx/test/host/hid/hidh_callback.h b/tests/lpc18xx_43xx/test/host/hid/hidh_callback.h index 44b8c0ff7..a3e001554 100644 --- a/tests/lpc18xx_43xx/test/host/hid/hidh_callback.h +++ b/tests/lpc18xx_43xx/test/host/hid/hidh_callback.h @@ -59,13 +59,13 @@ #include "common/common.h" //------------- hidh -------------// -void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK; -void tusbh_hid_keyboard_mounted_cb(uint8_t dev_addr) ATTR_WEAK; -void tusbh_hid_keyboard_unmounted_isr(uint8_t dev_addr) ATTR_WEAK; +void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event); +void tusbh_hid_keyboard_mounted_cb(uint8_t dev_addr); +void tusbh_hid_keyboard_unmounted_isr(uint8_t dev_addr); -void tusbh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK; -void tusbh_hid_mouse_mounted_cb(uint8_t dev_addr) ATTR_WEAK; -void tusbh_hid_mouse_unmounted_isr(uint8_t dev_addr) ATTR_WEAK; +void tusbh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event); +void tusbh_hid_mouse_mounted_cb(uint8_t dev_addr); +void tusbh_hid_mouse_unmounted_isr(uint8_t dev_addr); #ifdef __cplusplus } diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c b/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c index 900319e5e..7abb16428 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c @@ -47,8 +47,8 @@ #include "mock_osal.h" #include "mock_hcd.h" #include "mock_usbh.h" - #include "hid_host.h" +#include "mock_hidh_callback.h" uint8_t dev_addr; pipe_handle_t pipe_hdl; @@ -89,6 +89,7 @@ void test_hidh_close(void) keyboard_data[dev_addr-1].report_size = 8; hcd_pipe_close_ExpectAndReturn(pipe_hdl, TUSB_ERROR_NONE); + tusbh_hid_keyboard_unmounted_isr_Expect(dev_addr); //------------- Code Under TEST -------------// hidh_close(dev_addr); diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hidh_generic.c b/tests/lpc18xx_43xx/test/host/hid/test_hidh_generic.c new file mode 100644 index 000000000..0afe77596 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_generic.c @@ -0,0 +1,93 @@ +/* + * test_hidh_usbh.c + * + * Created on: May 13, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.org) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the tiny usb stack. + */ + +#include "stdlib.h" +#include "unity.h" +#include "type_helper.h" +#include "errors.h" +#include "common/common.h" + +#include "hid_host.h" +#include "mock_osal.h" +#include "mock_cdc_host.h" +#include "usbh.h" +#include "mock_hcd.h" +#include "mock_hidh_callback.h" +#include "descriptor_test.h" +#include "host_helper.h" + + +extern hidh_interface_info_t mouse_data[TUSB_CFG_HOST_DEVICE_MAX]; +hidh_interface_info_t *p_hidh_mouse; +tusb_mouse_report_t report; + +tusb_descriptor_interface_t const *p_mouse_interface_desc = &desc_configuration.mouse_interface; +tusb_descriptor_endpoint_t const *p_mouse_endpoint_desc = &desc_configuration.mouse_endpoint; + +uint8_t dev_addr; + +void setUp(void) +{ + helper_usbh_init_expect(); + usbh_init(); + + dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1; + +// uint16_t length; +// TEST_ASSERT_STATUS( hidh_open_subtask(dev_addr, p_mouse_interface_desc, &length) ); +// +// p_hidh_mouse = &mouse_data[dev_addr-1]; +// +// p_hidh_mouse->report_size = sizeof(tusb_mouse_report_t); +// p_hidh_mouse->pipe_hdl = (pipe_handle_t) { +// .dev_addr = dev_addr, +// .xfer_type = TUSB_XFER_INTERRUPT, +// .index = 1 +// }; +} + +void tearDown(void) +{ + +} + +//void test_generic_init(void) +//{ +// hidh_init(); +// +// TEST_ASSERT_MEM_ZERO(mouse_data, sizeof(hidh_interface_info_t)*TUSB_CFG_HOST_DEVICE_MAX); +//} diff --git a/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c b/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c index b6e9877c2..c7f604d39 100644 --- a/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c +++ b/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c @@ -76,8 +76,10 @@ void setUp(void) hcd_pipe_control_xfer_StubWithCallback(control_xfer_stub); hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); + osal_task_delay_Expect(200); hcd_port_reset_Expect(enum_connect.core_id); hcd_port_speed_get_ExpectAndReturn(enum_connect.core_id, device_speed); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); hcd_pipe_control_open_ExpectAndReturn(0, 8, TUSB_ERROR_NONE); diff --git a/tinyusb/class/cdc_host.h b/tinyusb/class/cdc_host.h index 393eec228..dfc1eba7b 100644 --- a/tinyusb/class/cdc_host.h +++ b/tinyusb/class/cdc_host.h @@ -70,9 +70,9 @@ tusb_error_t tusbh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t leng tusb_error_t tusbh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify); //------------- CDC Application Callback -------------// -ATTR_WEAK void tusbh_cdc_mounted_cb(uint8_t dev_addr); -ATTR_WEAK void tusbh_cdc_unmounted_isr(uint8_t dev_addr); -ATTR_WEAK void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes); +void tusbh_cdc_mounted_cb(uint8_t dev_addr); +void tusbh_cdc_unmounted_isr(uint8_t dev_addr); +void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes); #if TUSB_CFG_HOST_CDC_RNDIS @@ -83,9 +83,9 @@ bool tusbh_cdc_rndis_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RES tusb_error_t tusbh_cdc_rndis_get_mac_addr(uint8_t dev_addr, uint8_t mac_address[6]); //------------- RNDIS Application Callback (overshadow CDC callbacks) -------------// -ATTR_WEAK void tusbh_cdc_rndis_mounted_cb(uint8_t dev_addr); -ATTR_WEAK void tusbh_cdc_rndis_unmounted_isr(uint8_t dev_addr); -ATTR_WEAK void tusbh_cdc_rndis_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes); +void tusbh_cdc_rndis_mounted_cb(uint8_t dev_addr); +void tusbh_cdc_rndis_unmounted_isr(uint8_t dev_addr); +void tusbh_cdc_rndis_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes); diff --git a/tinyusb/class/cdc_rndis_host.c b/tinyusb/class/cdc_rndis_host.c index 51d6c3723..af0fe9a05 100644 --- a/tinyusb/class/cdc_rndis_host.c +++ b/tinyusb/class/cdc_rndis_host.c @@ -133,6 +133,7 @@ void rndish_init(void) void rndish_close(uint8_t dev_addr) { osal_semaphore_reset( rndish_data[dev_addr-1].sem_notification_hdl ); +// memclr_(&rndish_data[dev_addr-1], sizeof(rndish_data_t)); TODO need to move semaphore & its handle out before memclr } @@ -220,12 +221,7 @@ tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc) rndis_msg_set_cmplt_t * const p_set_cmpt = (rndis_msg_set_cmplt_t *) msg_payload; SUBTASK_ASSERT(p_set_cmpt->type == RNDIS_MSG_SET_CMPLT && p_set_cmpt->status == RNDIS_STATUS_SUCCESS); - - // - if ( tusbh_cdc_rndis_mounted_cb ) - { - tusbh_cdc_rndis_mounted_cb(dev_addr); - } + tusbh_cdc_rndis_mounted_cb(dev_addr); OSAL_SUBTASK_END } diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c index e3d74fa12..f3dff2eed 100644 --- a/tinyusb/class/hid_host.c +++ b/tinyusb/class/hid_host.c @@ -310,17 +310,17 @@ void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes void hidh_close(uint8_t dev_addr) { #if TUSB_CFG_HOST_HID_KEYBOARD - hidh_interface_close(dev_addr, &keyboard_data[dev_addr-1]); - if (tusbh_hid_keyboard_unmounted_isr) + if ( pipehandle_is_valid( keyboard_data[dev_addr-1].pipe_hdl ) ) { + hidh_interface_close(dev_addr, &keyboard_data[dev_addr-1]); tusbh_hid_keyboard_unmounted_isr(dev_addr); } #endif #if TUSB_CFG_HOST_HID_MOUSE - hidh_interface_close(dev_addr, &mouse_data[dev_addr-1]); - if( tusbh_hid_mouse_unmounted_isr ) + if( pipehandle_is_valid( mouse_data[dev_addr-1].pipe_hdl ) ) { + hidh_interface_close(dev_addr, &mouse_data[dev_addr-1]); tusbh_hid_mouse_unmounted_isr( dev_addr ); } #endif diff --git a/tinyusb/class/hid_host.h b/tinyusb/class/hid_host.h index 179e6fa25..6a8dc8a0d 100644 --- a/tinyusb/class/hid_host.h +++ b/tinyusb/class/hid_host.h @@ -63,9 +63,9 @@ bool tusbh_hid_keyboard_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WAR tusb_error_t tusbh_hid_keyboard_get_report(uint8_t dev_addr, void * report) /*ATTR_WARN_UNUSED_RESULT*/; tusb_interface_status_t tusbh_hid_keyboard_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT; //------------- Application Callback -------------// -ATTR_WEAK void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event); -ATTR_WEAK void tusbh_hid_keyboard_mounted_cb(uint8_t dev_addr); -ATTR_WEAK void tusbh_hid_keyboard_unmounted_isr(uint8_t dev_addr); +void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event); +void tusbh_hid_keyboard_mounted_cb(uint8_t dev_addr); +void tusbh_hid_keyboard_unmounted_isr(uint8_t dev_addr); //--------------------------------------------------------------------+ // MOUSE Application API @@ -74,9 +74,9 @@ bool tusbh_hid_mouse_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_U tusb_error_t tusbh_hid_mouse_get_report(uint8_t dev_addr, void* report) /*ATTR_WARN_UNUSED_RESULT*/; tusb_interface_status_t tusbh_hid_mouse_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT; //------------- Application Callback -------------// -ATTR_WEAK void tusbh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event); -ATTR_WEAK void tusbh_hid_mouse_mounted_cb(uint8_t dev_addr); -ATTR_WEAK void tusbh_hid_mouse_unmounted_isr(uint8_t dev_addr); +void tusbh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event); +void tusbh_hid_mouse_mounted_cb(uint8_t dev_addr); +void tusbh_hid_mouse_unmounted_isr(uint8_t dev_addr); //--------------------------------------------------------------------+ // GENERIC Application API @@ -87,7 +87,7 @@ tusb_error_t tusbh_hid_generic_set_report(uint8_t dev_addr, void* report, bool tusb_interface_status_t tusbh_hid_generic_get_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT; tusb_interface_status_t tusbh_hid_generic_set_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT; //------------- Application Callback -------------// -ATTR_WEAK void tusbh_hid_generic_isr(uint8_t dev_addr, tusb_event_t event); +void tusbh_hid_generic_isr(uint8_t dev_addr, tusb_event_t event); //--------------------------------------------------------------------+ // USBH-CLASS DRIVER API diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index e95012f01..1016ebd0d 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -348,7 +348,7 @@ tusb_error_t enumeration_body_subtask(void) osal_task_delay(200); // wait for device is stable hcd_port_reset( usbh_devices[0].core_id ); // port must be reset to have correct speed operation - osal_task_delay(50); // reset is recommended to last 50 ms +// osal_task_delay(50); // TODO reset is recommended to last 50 ms (NXP EHCI passes this) usbh_devices[0].speed = hcd_port_speed_get( usbh_devices[0].core_id ); SUBTASK_ASSERT_STATUS( usbh_pipe_control_open(0, 8) ); @@ -364,7 +364,7 @@ tusb_error_t enumeration_body_subtask(void) SUBTASK_ASSERT_STATUS(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(50); // reset is recommended to last 50 ms +// osal_task_delay(50); // TODO reset is recommended to last 50 ms (NXP EHCI passes this) //------------- Set new address -------------// new_addr = get_new_address();