summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-12-05 20:39:52 +0700
committerhathach <[email protected]>2018-12-05 20:39:52 +0700
commit2fa32bd949cab0991a55f1e06f842c1d9edb3c93 (patch)
tree1a7becdf973d340a05e433b5341d2eb5b470918b /src
parent4537ba66e536eb1d40c73f80ab150d92c2393397 (diff)
able to build host lpc18xx
Diffstat (limited to 'src')
-rw-r--r--src/host/ehci/ehci.c4
-rw-r--r--src/host/hcd.h3
-rw-r--r--src/host/usbh.c102
-rw-r--r--src/portable/nxp/lpc18_43/hcd_lpc18_43.c58
4 files changed, 103 insertions, 64 deletions
diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c
index 491651f5c..1dbf03682 100644
--- a/src/host/ehci/ehci.c
+++ b/src/host/ehci/ehci.c
@@ -956,7 +956,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si
{
if (TUSB_SPEED_HIGH == p_qhd->endpoint_speed)
{
- TU_ASSERT( interval <= 16, VOID_RETURN);
+ TU_ASSERT( interval <= 16, );
if ( interval < 4) // sub milisecond interval
{
p_qhd->interval_ms = 0;
@@ -969,7 +969,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si
}
}else
{
- TU_ASSERT( 0 != interval, VOID_RETURN);
+ TU_ASSERT( 0 != interval, );
// Full/Low: 4.12.2.1 (EHCI) case 1 schedule start split at 1 us & complete split at 2,3,4 uframes
p_qhd->interrupt_smask = 0x01;
p_qhd->non_hs_interrupt_cmask = BIN8(11100);
diff --git a/src/host/hcd.h b/src/host/hcd.h
index b9f6a1ff7..420b8a001 100644
--- a/src/host/hcd.h
+++ b/src/host/hcd.h
@@ -87,6 +87,9 @@ static inline bool pipehandle_is_equal(pipe_handle_t x, pipe_handle_t y)
tusb_error_t hcd_init(void) ATTR_WARN_UNUSED_RESULT;
void hal_hcd_isr(uint8_t hostid);
+void hcd_int_enable (uint8_t rhport);
+void hcd_int_disable(uint8_t rhport);
+
//--------------------------------------------------------------------+
// PIPE API
//--------------------------------------------------------------------+
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 3bb90e71d..a0df57657 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -373,8 +373,6 @@ tusb_error_t usbh_task_body(void)
static uint8_t configure_selected = 1; // TODO move
static uint8_t *p_desc = NULL; // TODO move
-// OSAL_SUBTASK_BEGIN
-
if ( !osal_queue_receive(_usbh_q, &enum_entry) ) return;
usbh_devices[0].core_id = enum_entry.core_id; // TODO refractor integrate to device_pool
@@ -386,10 +384,12 @@ tusb_error_t usbh_task_body(void)
if ( usbh_devices[0].hub_addr == 0)
{
if( hcd_port_connect_status(usbh_devices[0].core_id) )
- { // connection event
+ {
+ // connection event
osal_task_delay(POWER_STABLE_DELAY); // wait until device is stable. Increase this if the first 8 bytes is failed to get
- if ( !hcd_port_connect_status(usbh_devices[0].core_id) ) STASK_RETURN(TUSB_ERROR_NONE); // exit if device unplugged while delaying
+ // exit if device unplugged while delaying
+ if ( !hcd_port_connect_status(usbh_devices[0].core_id) ) return TUSB_ERROR_NONE;
hcd_port_reset( usbh_devices[0].core_id ); // port must be reset to have correct speed operation
osal_task_delay(RESET_DELAY);
@@ -399,7 +399,7 @@ tusb_error_t usbh_task_body(void)
else
{ // disconnection event
usbh_device_unplugged(usbh_devices[0].core_id, 0, 0);
- STASK_RETURN(TUSB_ERROR_NONE); // restart task
+ return TUSB_ERROR_NONE; // restart task
}
}
#if CFG_TUSB_HOST_HUB
@@ -445,21 +445,19 @@ tusb_error_t usbh_task_body(void)
}
#endif
- STASK_ASSERT_ERR( usbh_pipe_control_open(0, 8) );
+ TU_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 -------------//
- STASK_INVOKE(
- usbh_control_xfer_subtask( 0, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
- TUSB_REQ_GET_DESCRIPTOR, (TUSB_DESC_DEVICE << 8), 0,
- 8, enum_data_buffer ),
- error
- );
+ error = usbh_control_xfer_subtask( 0, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
+ TUSB_REQ_GET_DESCRIPTOR, (TUSB_DESC_DEVICE << 8), 0,
+ 8, enum_data_buffer );
//------------- Reset device again before Set Address -------------//
if (usbh_devices[0].hub_addr == 0)
- { // connected directly to roothub
- STASK_ASSERT_ERR(error); // TODO some slow device is observed to fail the very fist controller xfer, can try more times
+ {
+ // connected directly to roothub
+ TU_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);
}
@@ -480,15 +478,12 @@ tusb_error_t usbh_task_body(void)
//------------- Set new address -------------//
new_addr = get_new_address();
- STASK_ASSERT(new_addr <= CFG_TUSB_HOST_DEVICE_MAX); // TODO notify application we reach max devices
+ TU_ASSERT(new_addr <= CFG_TUSB_HOST_DEVICE_MAX); // TODO notify application we reach max devices
- STASK_INVOKE(
- usbh_control_xfer_subtask( 0, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
- TUSB_REQ_SET_ADDRESS, new_addr, 0,
- 0, NULL ),
- error
- );
- STASK_ASSERT_ERR(error);
+ error = usbh_control_xfer_subtask( 0, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
+ TUSB_REQ_SET_ADDRESS, new_addr, 0,
+ 0, NULL );
+ TU_ASSERT_ERR(error);
//------------- update port info & close control pipe of addr0 -------------//
usbh_devices[new_addr].core_id = usbh_devices[0].core_id;
@@ -501,16 +496,13 @@ tusb_error_t usbh_task_body(void)
usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG;
// open control pipe for new address
- STASK_ASSERT_ERR ( usbh_pipe_control_open(new_addr, ((tusb_desc_device_t*) enum_data_buffer)->bMaxPacketSize0 ) );
+ TU_ASSERT_ERR ( usbh_pipe_control_open(new_addr, ((tusb_desc_device_t*) enum_data_buffer)->bMaxPacketSize0 ) );
//------------- Get full device descriptor -------------//
- STASK_INVOKE(
- usbh_control_xfer_subtask( new_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
- TUSB_REQ_GET_DESCRIPTOR, (TUSB_DESC_DEVICE << 8), 0,
- 18, enum_data_buffer ),
- error
- );
- STASK_ASSERT_ERR(error);
+ error = usbh_control_xfer_subtask( new_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
+ TUSB_REQ_GET_DESCRIPTOR, (TUSB_DESC_DEVICE << 8), 0,
+ 18, enum_data_buffer );
+ TU_ASSERT_ERR(error);
// update device info TODO alignment issue
usbh_devices[new_addr].vendor_id = ((tusb_desc_device_t*) enum_data_buffer)->idVendor;
@@ -518,39 +510,30 @@ tusb_error_t usbh_task_body(void)
usbh_devices[new_addr].configure_count = ((tusb_desc_device_t*) enum_data_buffer)->bNumConfigurations;
configure_selected = get_configure_number_for_device((tusb_desc_device_t*) enum_data_buffer);
- STASK_ASSERT(configure_selected <= usbh_devices[new_addr].configure_count); // TODO notify application when invalid configuration
+ TU_ASSERT(configure_selected <= usbh_devices[new_addr].configure_count); // TODO notify application when invalid configuration
//------------- Get 9 bytes of configuration descriptor -------------//
- STASK_INVOKE(
- usbh_control_xfer_subtask( new_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
- TUSB_REQ_GET_DESCRIPTOR, (TUSB_DESC_CONFIGURATION << 8) | (configure_selected - 1), 0,
- 9, enum_data_buffer ),
- error
- );
- STASK_ASSERT_ERR(error);
- STASK_ASSERT_HDLR( CFG_TUSB_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) );
+ error = usbh_control_xfer_subtask( new_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
+ TUSB_REQ_GET_DESCRIPTOR, (TUSB_DESC_CONFIGURATION << 8) | (configure_selected - 1), 0,
+ 9, enum_data_buffer );
+ TU_ASSERT_ERR(error);
+ TU_VERIFY_HDLR( CFG_TUSB_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) );
//------------- Get full configuration descriptor -------------//
- STASK_INVOKE(
- usbh_control_xfer_subtask( new_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
- TUSB_REQ_GET_DESCRIPTOR, (TUSB_DESC_CONFIGURATION << 8) | (configure_selected - 1), 0,
- CFG_TUSB_HOST_ENUM_BUFFER_SIZE, enum_data_buffer ),
- error
- );
- STASK_ASSERT_ERR(error);
+ error = usbh_control_xfer_subtask( new_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
+ TUSB_REQ_GET_DESCRIPTOR, (TUSB_DESC_CONFIGURATION << 8) | (configure_selected - 1), 0,
+ CFG_TUSB_HOST_ENUM_BUFFER_SIZE, enum_data_buffer );
+ TU_ASSERT_ERR(error);
// update configuration info
usbh_devices[new_addr].interface_count = ((tusb_desc_configuration_t*) enum_data_buffer)->bNumInterfaces;
//------------- Set Configure -------------//
- STASK_INVOKE(
- usbh_control_xfer_subtask( new_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
- TUSB_REQ_SET_CONFIGURATION, configure_selected, 0,
- 0, NULL ),
- error
- );
- STASK_ASSERT_ERR(error);
+ error = usbh_control_xfer_subtask( new_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
+ TUSB_REQ_SET_CONFIGURATION, configure_selected, 0,
+ 0, NULL );
+ TU_ASSERT_ERR(error);
usbh_devices[new_addr].state = TUSB_DEVICE_STATE_CONFIGURED;
@@ -571,7 +554,7 @@ tusb_error_t usbh_task_body(void)
static uint8_t class_index; // has to be static as it is used to call class's open_subtask
class_index = std_class_code_to_index( ((tusb_desc_interface_t*) p_desc)->bInterfaceClass );
- STASK_ASSERT( class_index != 0 ); // class_index == 0 means corrupted data, abort enumeration
+ TU_ASSERT( class_index != 0 ); // class_index == 0 means corrupted data, abort enumeration
if (usbh_class_drivers[class_index].open_subtask &&
!(class_index == TUSB_CLASS_HUB && usbh_devices[new_addr].hub_addr != 0))
@@ -579,14 +562,11 @@ tusb_error_t usbh_task_body(void)
static uint16_t length;
length = 0;
- STASK_INVOKE ( // parameters in task/sub_task must be static storage (static or global)
- usbh_class_drivers[class_index].open_subtask( new_addr, (tusb_desc_interface_t*) p_desc, &length ),
- error
- );
+ error = usbh_class_drivers[class_index].open_subtask( new_addr, (tusb_desc_interface_t*) p_desc, &length );
if (error == TUSB_ERROR_NONE)
{
- STASK_ASSERT( length >= sizeof(tusb_desc_interface_t) );
+ TU_ASSERT( length >= sizeof(tusb_desc_interface_t) );
usbh_devices[new_addr].flag_supported_class |= BIT_(class_index);
p_desc += length;
}else // Interface open failed, for example a subclass is not supported
@@ -601,8 +581,6 @@ tusb_error_t usbh_task_body(void)
}
tuh_device_mount_succeed_cb(new_addr);
-
-// OSAL_SUBTASK_END
}
diff --git a/src/portable/nxp/lpc18_43/hcd_lpc18_43.c b/src/portable/nxp/lpc18_43/hcd_lpc18_43.c
new file mode 100644
index 000000000..6a5820b1a
--- /dev/null
+++ b/src/portable/nxp/lpc18_43/hcd_lpc18_43.c
@@ -0,0 +1,58 @@
+/**************************************************************************/
+/*!
+ @file hcd_lpc18_43.c
+ @author hathach (tinyusb.org)
+
+ @section LICENSE
+
+ Software License Agreement (BSD License)
+
+ Copyright (c) 2018, 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. Neither the name of the copyright holders nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
+*/
+/**************************************************************************/
+
+#include "tusb_option.h"
+
+#if TUSB_OPT_HOST_ENABLED && (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX)
+
+
+
+//--------------------------------------------------------------------+
+// MACRO TYPEDEF CONSTANT ENUM DECLARATION
+//--------------------------------------------------------------------+
+
+void hcd_int_enable(uint8_t rhport)
+{
+ NVIC_EnableIRQ(rhport ? USB1_IRQn : USB0_IRQn);
+}
+
+void hcd_int_disable(uint8_t rhport)
+{
+ NVIC_DisableIRQ(rhport ? USB1_IRQn : USB0_IRQn);
+}
+#endif