From e20025b54d16deccbd6e86433f31d80f5a976fd4 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 6 Feb 2013 12:03:01 +0700 Subject: [PATCH] refractor move test enum to its own file add assert with handler add task assert with error catcher --- .cproject | 861 +++++++++------------------ tests/project.yml | 3 +- tests/test/host/test_enum_task.c | 191 ++++++ tests/test/host/test_usbh.c | 116 +--- tests/test/support/descriptor_test.c | 2 +- tests/test/support/descriptor_test.h | 3 +- tests/test/support/tusb_callback.h | 71 +++ tinyusb/class/hid_host.c | 2 +- tinyusb/common/assertion.h | 14 +- tinyusb/common/common.h | 3 + tinyusb/common/errors.h | 1 + tinyusb/host/hcd.h | 6 +- tinyusb/host/usbh.c | 10 +- tinyusb/host/usbh.h | 10 +- tinyusb/osal/osal.h | 7 + tinyusb/osal/osal_none.h | 16 +- 16 files changed, 591 insertions(+), 725 deletions(-) create mode 100644 tests/test/host/test_enum_task.c create mode 100644 tests/test/support/tusb_callback.h diff --git a/.cproject b/.cproject index 074b5a576..81fb8ff3c 100644 --- a/.cproject +++ b/.cproject @@ -11,34 +11,39 @@ + + - + - - - - - @@ -98,571 +103,6 @@ </infoList> </TargetConfig> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -718,5 +158,266 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/project.yml b/tests/project.yml index 54da541dd..54a07be6f 100644 --- a/tests/project.yml +++ b/tests/project.yml @@ -88,6 +88,7 @@ :load_paths: - vendor/ceedling/plugins :enabled: - - stdout_pretty_tests_report + #- stdout_pretty_tests_report + - stdout_ide_tests_report - module_generator ... diff --git a/tests/test/host/test_enum_task.c b/tests/test/host/test_enum_task.c new file mode 100644 index 000000000..8c57cc85b --- /dev/null +++ b/tests/test/host/test_enum_task.c @@ -0,0 +1,191 @@ +/* + * test_enum_task.c + * + * Created on: Feb 5, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * 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 "unity.h" +#include "errors.h" +#include "usbh.h" +#include "descriptor_test.h" +#include "mock_osal.h" +#include "mock_hcd.h" +#include "mock_usbh_hcd.h" +#include "mock_tusb_callback.h" + +extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; +extern usbh_device_addr0_t device_addr0; +tusb_handle_device_t dev_hdl; +pipe_handle_t pipe_addr0 = 12; + +usbh_enumerate_t const enum_connect = { + .core_id = 0, + .hub_addr = 0, + .hub_port = 0, + .connect_status = 1 +}; + +void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call); +void semaphore_wait_success_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call); +tusb_error_t control_xfer_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call); + +void setUp(void) +{ + memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); + + osal_queue_receive_StubWithCallback(queue_recv_stub); + osal_semaphore_wait_StubWithCallback(semaphore_wait_success_stub); + hcd_pipe_control_xfer_StubWithCallback(control_xfer_stub); + + hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); + hcd_port_speed_ExpectAndReturn(enum_connect.core_id, TUSB_SPEED_FULL); + + hcd_addr0_open_IgnoreAndReturn(TUSB_ERROR_NONE); + hcd_addr0_close_IgnoreAndReturn(TUSB_ERROR_NONE); +} + +void tearDown(void) +{ +} + +//--------------------------------------------------------------------+ +// STUB & HELPER +//--------------------------------------------------------------------+ +void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call) +{ + (*p_data) = ( *((uint32_t*) &enum_connect) ); + (*p_error) = TUSB_ERROR_NONE; +} + +void semaphore_wait_success_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) +{ + (*p_error) = TUSB_ERROR_NONE; +} + +#define semaphore_wait_timeout_stub(n) semaphore_wait_timeout_##n +#define semaphore_wait_timeout(n) \ + void semaphore_wait_timeout_##n(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) {\ + if (num_call >= n)\ + (*p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ + else \ + (*p_error) = TUSB_ERROR_NONE;\ + } + +semaphore_wait_timeout(0) +semaphore_wait_timeout(1) +semaphore_wait_timeout(2) +semaphore_wait_timeout(3) +semaphore_wait_timeout(4) + +tusb_error_t control_xfer_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call) +{ + switch (num_call) + { + case 0: // get 8 bytes of device descriptor + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_DEVICE, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(8, p_request->wLength); + memcpy(data, &desc_device, p_request->wLength); + break; + + case 1: // set device address + TEST_ASSERT_EQUAL(TUSB_REQUEST_SET_ADDRESS, p_request->bRequest); + TEST_ASSERT_EQUAL(p_request->wValue, 1); + break; + + case 2: // get full device decriptor for new address + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_DEVICE, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(18, p_request->wLength); + memcpy(data, &desc_device, p_request->wLength); + break; + + case 3: // get 9 bytes of configuration descriptor + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_CONFIGURATION, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(9, p_request->wLength); + memcpy(data, &desc_configuration, p_request->wLength); + break; + + case 4: // get full-length configuration descriptor + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_CONFIGURATION, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(desc_configuration.configuration.wTotalLength, p_request->wLength); + memcpy(data, &desc_configuration, p_request->wLength); + break; + } + + return TUSB_ERROR_NONE; +} + +//--------------------------------------------------------------------+ +// enum connect directed +//--------------------------------------------------------------------+ +void test_failed_get_first_dev_desc(void) +{ + osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(0)); + tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_FAILED, NULL); + + usbh_enumeration_task(); +} + +void test_enum_task_connect(void) +{ + + usbh_enumeration_task(); + + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_ADDRESSED, usbh_device_info_pool[0].status); + TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_device_info_pool[0].speed); + TEST_ASSERT_EQUAL(enum_connect.core_id, usbh_device_info_pool[0].core_id); + TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_device_info_pool[0].hub_addr); + TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_device_info_pool[0].hub_port); + +// hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); + +} + +void test_enum_task_disconnect(void) +{ + TEST_IGNORE(); +} + +void test_enum_task_connect_via_hub(void) +{ + TEST_IGNORE(); +} + +void test_enum_task_disconnect_via_hub(void) +{ + TEST_IGNORE(); +} diff --git a/tests/test/host/test_usbh.c b/tests/test/host/test_usbh.c index 911756ede..e0fc003ee 100644 --- a/tests/test/host/test_usbh.c +++ b/tests/test/host/test_usbh.c @@ -38,7 +38,6 @@ #include "unity.h" #include "errors.h" #include "usbh.h" -#include "descriptor_test.h" #include "mock_osal.h" #include "mock_hcd.h" #include "mock_usbh_hcd.h" @@ -83,13 +82,12 @@ void test_usbh_init_queue_create_failed(void) TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init()); } - void test_usbh_init_ok(void) { uint32_t dummy; usbh_device_info_t device_info_zero[TUSB_CFG_HOST_DEVICE_MAX]; - memset(device_info_zero, 0, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); + memclr_(device_info_zero, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); for(uint32_t i=0; ibRequest); - TEST_ASSERT_EQUAL(TUSB_DESC_DEVICE, p_request->wValue >> 8); - - memcpy(data, &desc_device, p_request->wLength); - - return TUSB_ERROR_NONE; -} - -tusb_error_t set_device_addr_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call) -{ - TEST_ASSERT_EQUAL(TUSB_REQUEST_SET_ADDRESS, p_request->bRequest); - TEST_ASSERT_EQUAL(p_request->wValue, 1); - return TUSB_ERROR_NONE; -} - -tusb_error_t get_configuration_desc_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call) -{ - TEST_ASSERT(num_call < 2); - - TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); - TEST_ASSERT_EQUAL(TUSB_DESC_CONFIGURATION, p_request->wValue >> 8); - - memcpy(data, &desc_device, p_request->wLength); - - return TUSB_ERROR_NONE; -} - -void test_enum_task_connect(void) -{ - pipe_handle_t pipe_addr0 = 12; - - osal_queue_receive_StubWithCallback(queue_recv_stub); - hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); - hcd_port_speed_ExpectAndReturn(enum_connect.core_id, TUSB_SPEED_FULL); - - { - hcd_addr0_open_IgnoreAndReturn(TUSB_ERROR_NONE); - - // get 8-byte of device descriptor - hcd_pipe_control_xfer_StubWithCallback(get_device_desc_stub); - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); - // set device address - hcd_pipe_control_xfer_StubWithCallback(set_device_addr_stub); - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); - - hcd_addr0_close_IgnoreAndReturn(TUSB_ERROR_NONE); - } - - usbh_enumeration_task(); - - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_ADDRESSED, usbh_device_info_pool[0].status); - TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_device_info_pool[0].speed); - TEST_ASSERT_EQUAL(enum_connect.core_id, usbh_device_info_pool[0].core_id); - TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_device_info_pool[0].hub_addr); - TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_device_info_pool[0].hub_port); - - hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); - - hcd_pipe_control_xfer_StubWithCallback(get_device_desc_stub); // get full device descriptor - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); - - hcd_pipe_control_xfer_StubWithCallback(get_configuration_desc_stub); // get 9 bytes of configuration descriptor - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); - - hcd_pipe_control_xfer_StubWithCallback(get_configuration_desc_stub); // get full-length configuration descriptor - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); -} - -void test_enum_task_disconnect(void) -{ - TEST_IGNORE(); -} - -void test_enum_task_connect_via_hub(void) -{ - TEST_IGNORE(); -} - -void test_enum_task_disconnect_via_hub(void) -{ - TEST_IGNORE(); -} diff --git a/tests/test/support/descriptor_test.c b/tests/test/support/descriptor_test.c index bbc5c72c6..7851716ad 100644 --- a/tests/test/support/descriptor_test.c +++ b/tests/test/support/descriptor_test.c @@ -39,7 +39,7 @@ #include "descriptor_test.h" TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) -tusb_descriptor_device_t desc_device = +tusb_descriptor_device_t const desc_device = { .bLength = sizeof(tusb_descriptor_device_t), .bDescriptorType = TUSB_DESC_DEVICE, diff --git a/tests/test/support/descriptor_test.h b/tests/test/support/descriptor_test.h index 71f6351c9..70694b1b7 100644 --- a/tests/test/support/descriptor_test.h +++ b/tests/test/support/descriptor_test.h @@ -98,7 +98,8 @@ typedef struct unsigned char ConfigDescTermination; } app_configuration_desc_t; -extern tusb_descriptor_device_t desc_device; +extern tusb_descriptor_device_t const desc_device; +extern app_configuration_desc_t const desc_configuration; #ifdef __cplusplus } diff --git a/tests/test/support/tusb_callback.h b/tests/test/support/tusb_callback.h new file mode 100644 index 000000000..5a6e11eb5 --- /dev/null +++ b/tests/test/support/tusb_callback.h @@ -0,0 +1,71 @@ +/* + * tusb_callback.h + * + * Created on: Feb 5, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * 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. + */ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_TUSB_CALLBACK_H_ +#define _TUSB_TUSB_CALLBACK_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#include "common/common.h" +#include "usbh.h" + +uint8_t tusbh_device_attached_cb (tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK ATTR_WARN_UNUSED_RESULT; +void tusbh_device_mounted_cb (tusb_handle_device_t device_hdl) ATTR_WEAK; +void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK; + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_TUSB_CALLBACK_H_ */ + +/** @} */ diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c index eeed7cb0b..07abb7e6a 100644 --- a/tinyusb/class/hid_host.c +++ b/tinyusb/class/hid_host.c @@ -91,7 +91,7 @@ uint8_t tusbh_hid_keyboard_no_instances(tusb_handle_device_t const device_hdl) //--------------------------------------------------------------------+ void class_hid_keyboard_init(void) { - memset(&keyboard_info_pool, 0, sizeof(class_hid_keyboard_info_t)*TUSB_CFG_HOST_DEVICE_MAX); + memclr_(&keyboard_info_pool, sizeof(class_hid_keyboard_info_t)*TUSB_CFG_HOST_DEVICE_MAX); } tusb_error_t class_hid_keyboard_install(uint8_t const dev_addr, uint8_t const *descriptor) diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h index f6aff004e..e8ce24c0a 100644 --- a/tinyusb/common/assertion.h +++ b/tinyusb/common/assertion.h @@ -69,25 +69,25 @@ extern "C" // Assert Helper //--------------------------------------------------------------------+ #define ASSERT_MESSAGE(format, ...)\ - _PRINTF("Assert at %s: %s:%d: " format "\n", __FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) + _PRINTF("Assert at %s %s %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) #ifndef _TEST_ASSERT_ - #define ASSERT_ERROR_HANDLER(x) return (x) + #define ASSERT_ERROR_HANDLER(x, para) return (x) #else - #define ASSERT_ERROR_HANDLER(x) Throw(x) + #define ASSERT_ERROR_HANDLER(x, para) Throw(x) #endif -#define ASSERT_DEFINE(...) ASSERT_DEFINE_WITH_HANDLER(ASSERT_ERROR_HANDLER, __VA_ARGS__) - -#define ASSERT_DEFINE_WITH_HANDLER(error_handler, setup_statement, condition, error, format, ...) \ +#define ASSERT_DEFINE_WITH_HANDLER(error_handler, handler_para, setup_statement, condition, error, format, ...) \ do{\ setup_statement;\ if (!(condition)) {\ ASSERT_MESSAGE(format, __VA_ARGS__);\ - error_handler(error);\ + error_handler(error, handler_para);\ }\ }while(0) +#define ASSERT_DEFINE(...) ASSERT_DEFINE_WITH_HANDLER(ASSERT_ERROR_HANDLER, NULL, __VA_ARGS__) + //--------------------------------------------------------------------+ // tusb_error_t Status Assert TODO use ASSERT_DEFINE //--------------------------------------------------------------------+ diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h index 403ca5d6c..a3c8cfef5 100644 --- a/tinyusb/common/common.h +++ b/tinyusb/common/common.h @@ -98,6 +98,9 @@ #define U32_TO_U8S_BE(u32) U32_B1_U8(u32), U32_B2_U8(u32), U32_B3_U8(u32), U32_B4_U8(u32) #define U32_TO_U8S_LE(u32) U32_B4_U8(u32), U32_B3_U8(u32), U32_B2_U8(u32), U32_B1_U8(u32) + +#define memclr_(buffer, size) memset(buffer, 0, size) + /// form an uint32_t from 4 x uint8_t static inline uint32_t u32_from_u8(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) ATTR_ALWAYS_INLINE ATTR_CONST; static inline uint32_t u32_from_u8(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h index 2d8a80e22..42a7a3975 100644 --- a/tinyusb/common/errors.h +++ b/tinyusb/common/errors.h @@ -66,6 +66,7 @@ ENTRY(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT)\ ENTRY(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE)\ ENTRY(TUSB_ERROR_HCD_FAILED)\ + ENTRY(TUSB_ERROR_USBH_MOUNT_FAILED)\ ENTRY(TUSB_ERROR_OSAL_TIMEOUT)\ ENTRY(TUSB_ERROR_OSAL_TASK_FAILED)\ ENTRY(TUSB_ERROR_OSAL_QUEUE_FAILED)\ diff --git a/tinyusb/host/hcd.h b/tinyusb/host/hcd.h index db16ce869..079a0c4f3 100644 --- a/tinyusb/host/hcd.h +++ b/tinyusb/host/hcd.h @@ -71,9 +71,9 @@ tusb_error_t hcd_init(uint8_t hostid) ATTR_WARN_UNUSED_RESULT; //--------------------------------------------------------------------+ // PIPE API //--------------------------------------------------------------------+ -pipe_handle_t hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size); -tusb_error_t hcd_pipe_control_xfer(pipe_handle_t pipe_hdl, tusb_std_request_t const * p_request, uint8_t data[]); -pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const * endpoint_desc); +pipe_handle_t hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) ATTR_WARN_UNUSED_RESULT; +tusb_error_t hcd_pipe_control_xfer(pipe_handle_t pipe_hdl, tusb_std_request_t const * p_request, uint8_t data[]) ATTR_WARN_UNUSED_RESULT; +pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const * endpoint_desc) ATTR_WARN_UNUSED_RESULT; #if 0 //tusb_error_t hcd_pipe_open( diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index ffdb2769f..371514748 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -89,16 +89,14 @@ void usbh_enumeration_task(void) OSAL_TASK_LOOP_BEGIN - osal_queue_receive(enum_queue_hdl, (uint32_t*)(&device_addr0.enum_entry), OSAL_TIMEOUT_NORMAL, &error); - TASK_ASSERT_STATUS(error); + osal_queue_receive(enum_queue_hdl, (uint32_t*)(&device_addr0.enum_entry), OSAL_TIMEOUT_WAIT_FOREVER, &error); if (device_addr0.enum_entry.hub_addr == 0) // direct connection { TASK_ASSERT(device_addr0.enum_entry.connect_status == hcd_port_connect_status(device_addr0.enum_entry.core_id)); // there chances the event is out-dated device_addr0.speed = hcd_port_speed(device_addr0.enum_entry.core_id); - error = hcd_addr0_open(&device_addr0); - TASK_ASSERT_STATUS(error); + TASK_ASSERT_STATUS( hcd_addr0_open(&device_addr0) ); { // Get first 8 bytes of device descriptor to get Control Endpoint Size tusb_std_request_t request_device_desc = { @@ -110,7 +108,7 @@ void usbh_enumeration_task(void) hcd_pipe_control_xfer(device_addr0.pipe_hdl, &request_device_desc, enum_data_buffer); osal_semaphore_wait(device_addr0.sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static - TASK_ASSERT_STATUS(error); + TASK_ASSERT_STATUS_HANDLER(error, tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_FAILED, NULL)); } new_addr = get_new_address(); @@ -158,7 +156,7 @@ tusb_error_t usbh_init(void) { uint32_t i; - memset(usbh_device_info_pool, 0, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); + memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); for(i=0; i count == 0 ) {\ - if ( timeout + osal_tick_from_msec(msec) < osal_tick_get() ) /* time out */ \ + if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( timeout + osal_tick_from_msec(msec) < osal_tick_get() )) /* time out */ \ *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ else\ return;\