Add pulse encoder and usb host to imxrt (not tested)

This commit is contained in:
LeeChunHei 2021-01-22 11:13:08 +08:00 committed by LeeChunHei
parent 0fb6a82223
commit 7c151557c3
9 changed files with 1877 additions and 1562 deletions

View File

@ -76,7 +76,17 @@ if GetDepend(['BSP_USING_DMA']):
src += ['MIMXRT1052/drivers/fsl_edma.c']
src += ['MIMXRT1052/drivers/fsl_lpuart_edma.c']
src += ['MIMXRT1052/drivers/fsl_lpspi_edma.c']
if GetDepend(['BSP_USING_PULSE_ENCODER']):
src += ['MIMXRT1052/drivers/fsl_enc.c']
#Adding this as XBAR is used in pin mux
src += ['MIMXRT1052/drivers/fsl_xbara.c']
src += ['MIMXRT1052/drivers/fsl_xbarb.c']
#fsl os abstract files
src += ['MIMXRT1052/drivers/fsl_os_abstraction_rtthread.c']
src += ['MIMXRT1052/drivers/generic_list.c']
group = DefineGroup('Libraries', src, depend = [''], CPPPATH = path)

View File

@ -54,15 +54,22 @@ if GetDepend('BSP_USING_AUDIO'):
if GetDepend('BSP_USING_SDIO'):
src += ['drv_sdio.c']
if GetDepend('BSP_USING_USB_DEVICE'):
if GetDepend('BSP_USING_PULSE_ENCODER'):
src += ['drv_pulse_encoder.c']
if GetDepend('RT_USING_USB_DEVICE'):
src += ['drv_usbd.c']
src += Glob('usb/device/*.c')
if GetDepend('BSP_USING_USB_DEVICE'):
if GetDepend('RT_USING_USB_DEVICE') or GetDepend('RT_USING_USB_HOST'):
src += Glob('usb/phy/*.c')
CPPDEFINES += ['ENDIANNESS']
if GetDepend('RT_USING_USB_HOST'):
src += ['drv_usbh.c']
src += Glob('usb/host/*.c')
path = [cwd,cwd + '/config']
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES=CPPDEFINES)

View File

@ -1,31 +1,9 @@
/*
* Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* Copyright 2016 - 2019 NXP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o 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.
*
* o Neither the name of the copyright holder 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 AND CONTRIBUTORS "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 OR CONTRIBUTORS 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.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _USB_HOST_H_
@ -34,6 +12,7 @@
#include <usb/include/usb.h>
#include <usb/include/usb_misc.h>
#include <usb/include/usb_spec.h>
#include <usb/include/usb_host_config.h>
/*******************************************************************************
* Definitions
@ -68,6 +47,16 @@ typedef enum _usb_host_event
kUSB_HostEventDetach, /*!< Device is detached */
kUSB_HostEventEnumerationDone, /*!< Device's enumeration is done and the device is supported */
kUSB_HostEventNotSupported, /*!< Device's enumeration is done and the device is not supported */
/*! Device's enumeration failed due to errors
* fail reason is put in the high 2 bytes of callback event code.
* kStatus_USB_TransferFailed - the transfer failed.
* kStatus_USB_TransferCancel - transfer is canceled by application.
* kStatus_USB_Error - parsing descriptor failed, the power cannot satisfy device's requirement,
* device addresss allocation failed, transfer is not enough
* or the transfer API failed.
* kStatus_USB_AllocFail - malloc failed.
*/
kUSB_HostEventEnumerationFail,
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
kUSB_HostEventNotSuspended, /*!< Suspend failed */
kUSB_HostEventSuspended, /*!< Suspend successful */
@ -103,7 +92,60 @@ typedef enum _usb_host_dev_info
kUSB_HostGetConfigurationDes, /*!< Device's configuration descriptor pointer */
kUSB_HostGetConfigurationLength, /*!< Device's configuration descriptor pointer */
} usb_host_dev_info_t;
/*! @brief Request type */
typedef enum _usb_host_request_type
{
kRequestDevice = 1U, /*!< Control request object is device */
kRequestInterface, /*!< Control request object is interface */
kRequestEndpoint, /*!< Control request object is endpoint */
} usb_host_request_type_t;
/*! @brief For USB_REQUEST_STANDARD_GET_DESCRIPTOR and USB_REQUEST_STANDARD_SET_DESCRIPTOR */
typedef struct _usb_host_process_descriptor_param
{
uint8_t descriptorType; /*!< See the usb_spec.h, such as the USB_DESCRIPTOR_TYPE_DEVICE */
uint8_t descriptorIndex; /*!< The descriptor index is used to select a specific descriptor (only for configuration
and string descriptors) when several descriptors of the same type are implemented in a
device */
uint8_t languageId; /*!< It specifies the language ID for string descriptors or is reset to zero for other
descriptors */
uint8_t *descriptorBuffer; /*!< Buffer pointer */
uint16_t descriptorLength; /*!< Buffer data length */
} usb_host_process_descriptor_param_t;
/*! @brief For USB_REQUEST_STANDARD_CLEAR_FEATURE and USB_REQUEST_STANDARD_SET_FEATURE */
typedef struct _usb_host_process_feature_param
{
uint8_t requestType; /*!< See the #usb_host_request_type_t */
uint8_t featureSelector; /*!< Set/cleared feature */
uint8_t interfaceOrEndpoint; /*!< Interface or end pointer */
} usb_host_process_feature_param_t;
/*! @brief For USB_REQUEST_STANDARD_GET_INTERFACE */
typedef struct _usb_host_get_interface_param
{
uint8_t interface; /*!< Interface number */
uint8_t *alternateInterfaceBuffer; /*!< Save the transfer result */
} usb_host_get_interface_param_t;
/*! @brief For USB_REQUEST_STANDARD_GET_STATUS */
typedef struct _usb_host_get_status_param
{
uint16_t statusSelector; /*!< Interface number, the end pointer number or OTG status selector */
uint8_t requestType; /*!< See the #usb_host_request_type_t */
uint8_t *statusBuffer; /*!< Save the transfer result */
} usb_host_get_status_param_t;
/*! @brief For USB_REQUEST_STANDARD_SET_INTERFACE */
typedef struct _usb_host_set_interface_param
{
uint8_t alternateSetting; /*!< Alternate setting value */
uint8_t interface; /*!< Interface number */
} usb_host_set_interface_param_t;
/*! @brief For USB_REQUEST_STANDARD_SYNCH_FRAME */
typedef struct _usb_host_synch_frame_param
{
uint8_t endpoint; /*!< Endpoint number */
uint8_t *frameNumberBuffer; /*!< Frame number data buffer */
} usb_host_synch_frame_param_t;
/*!
* @brief Host callback function typedef.
*
@ -243,8 +285,8 @@ typedef struct _usb_host_pipe_init
/*! @brief Cancel transfer parameter structure */
typedef struct _usb_host_cancel_param
{
usb_host_pipe_handle pipeHandle; /*!< Cancelling pipe handle*/
usb_host_transfer_t *transfer; /*!< Cancelling transfer*/
usb_host_pipe_handle pipeHandle; /*!< Canceling pipe handle*/
usb_host_transfer_t *transfer; /*!< Canceling transfer*/
} usb_host_cancel_param_t;
/*******************************************************************************
@ -342,7 +384,7 @@ extern usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handl
* @retval kStatus_USB_InvalidParameter The deviceHandle instance don't belong to hostHandle instance.
*/
extern usb_status_t USB_HostRemoveDevice(usb_host_handle hostHandle, usb_device_handle deviceHandle);
#if (defined(USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI > 0U))
/*!
* @brief KHCI task function.
*
@ -353,7 +395,8 @@ extern usb_status_t USB_HostRemoveDevice(usb_host_handle hostHandle, usb_device_
* @param[in] hostHandle The host handle.
*/
extern void USB_HostKhciTaskFunction(void *hostHandle);
#endif
#if (defined(USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI > 0U))
/*!
* @brief EHCI task function.
*
@ -364,7 +407,8 @@ extern void USB_HostKhciTaskFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostEhciTaskFunction(void *hostHandle);
#endif
#if (defined(USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI > 0U))
/*!
* @brief OHCI task function.
*
@ -375,7 +419,8 @@ extern void USB_HostEhciTaskFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostOhciTaskFunction(void *hostHandle);
#endif
#if (defined(USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
/*!
* @brief IP3516HS task function.
*
@ -386,7 +431,8 @@ extern void USB_HostOhciTaskFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostIp3516HsTaskFunction(void *hostHandle);
#endif
#if (defined(USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI > 0U))
/*!
* @brief Device KHCI ISR function.
*
@ -395,7 +441,8 @@ extern void USB_HostIp3516HsTaskFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostKhciIsrFunction(void *hostHandle);
#endif
#if (defined(USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI > 0U))
/*!
* @brief Device EHCI ISR function.
*
@ -404,7 +451,8 @@ extern void USB_HostKhciIsrFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostEhciIsrFunction(void *hostHandle);
#endif
#if (defined(USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI > 0U))
/*!
* @brief Device OHCI ISR function.
*
@ -413,7 +461,8 @@ extern void USB_HostEhciIsrFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostOhciIsrFunction(void *hostHandle);
#endif
#if (defined(USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
/*!
* @brief Device IP3516HS ISR function.
*
@ -422,7 +471,7 @@ extern void USB_HostOhciIsrFunction(void *hostHandle);
* @param[in] hostHandle The host handle.
*/
extern void USB_HostIp3516HsIsrFunction(void *hostHandle);
#endif
/*! @}*/
/*!
@ -566,7 +615,7 @@ extern usb_status_t USB_HostFreeTransfer(usb_host_handle hostHandle, usb_host_tr
* This function sends the USB standard request packet.
*
* @param[in] deviceHandle The device handle for control transfer.
* @param[in] usbRequest A USB standard request code. Se the usb_spec.h.
* @param[in] usbRequest A USB standard request code. See the usb_spec.h.
* @param[in] transfer The used transfer.
* @param[in] param The parameter structure is different for different request, see
* usb_host_framework.h.
@ -694,10 +743,10 @@ extern usb_status_t USB_HostL1ResumeDeviceResquest(usb_host_handle hostHandle,
/*!
* @brief Update the lpm param.
*
* The function is used to configuure the lpm token.
* The function is used to configure the lpm token.
*
* @param[in] hostHandle The host handle.
* @param[in] lpmParam HIRD vaule and whether enable remotewakeup.
* @param[in] lpmParam HIRD value and whether enable remotewakeup.
*
*/
extern usb_status_t USB_HostL1SleepDeviceResquestConfig(usb_host_handle hostHandle, uint8_t *lpmParam);
@ -715,6 +764,19 @@ extern usb_status_t USB_HostUpdateHwTick(usb_host_handle hostHandle, uint64_t ti
#endif
#if ((defined(USB_HOST_CONFIG_BATTERY_CHARGER)) && (USB_HOST_CONFIG_BATTERY_CHARGER > 0U))
/*!
* @brief Set the charger type. It is only supported on RT600 currently.
*
* The set charger type becomes valid in next attach.
*
* @param[in] hostHandle The host handle.
* @param[in] type.
*
*/
extern usb_status_t USB_HostSetChargerType(usb_host_handle hostHandle, uint8_t type);
#endif
/*! @}*/
#ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -1,31 +1,9 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o 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.
*
* o Neither the name of the copyright holder 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 AND CONTRIBUTORS "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 OR CONTRIBUTORS 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.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _USB_HOST_DEV_MNG_H_
@ -79,11 +57,11 @@ typedef struct _usb_host_device_instance
usb_descriptor_device_t *deviceDescriptor; /*!< Standard device descriptor */
usb_host_pipe_handle controlPipe; /*!< Device's control pipe */
uint8_t *configurationDesc; /*!< Configuration descriptor pointer */
uint8_t *enumBuffer; /*!< Buffer for enumeration */
uint16_t configurationLen; /*!< Configuration descriptor length */
uint16_t configurationValue; /*!< Configuration index */
uint8_t interfaceStatus[USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE]; /*!< Interfaces' status, please reference to
#usb_host_interface_state_t */
uint8_t *enumBuffer; /*!< Buffer for enumeration */
uint8_t configurationValue; /*!< Configuration index */
uint8_t state; /*!< Device state for enumeration */
uint8_t enumRetries; /*!< Re-enumeration when error in control transfer */
uint8_t stallRetries; /*!< Re-transfer when stall */
@ -104,11 +82,10 @@ typedef struct _usb_host_device_instance
typedef struct _usb_host_enum_process_entry
{
uint8_t successState; /*!< When the last step is successful, the next state value */
uint8_t retryState; /*!< When the last step need retry, the next state value */
usb_status_t (*process)(usb_host_device_instance_t *deviceInstance); /*!< When the last step transfer is done, the
function is used to process the transfer
data */
usb_host_device_enumeration_status_t successState; /*!< When the last step is successful, the next state value */
usb_host_device_enumeration_status_t retryState; /*!< When the last step need retry, the next state value */
/*! When the last step transfer is done, the function is used to process the transfer data */
usb_status_t (*process)(usb_host_device_instance_t *deviceInstance, uint32_t dataLength);
} usb_host_enum_process_entry_t;
/*******************************************************************************

File diff suppressed because it is too large Load Diff

View File

@ -1,31 +1,9 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* Copyright 2016,2019 NXP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o 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.
*
* o Neither the name of the copyright holder 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 AND CONTRIBUTORS "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 OR CONTRIBUTORS 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.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _USB_HOST_CONTROLLER_EHCI_H_
@ -39,95 +17,95 @@
* Definitions
******************************************************************************/
/* EHCI host macros */
#define EHCI_HOST_T_INVALID_VALUE (1U)
#define EHCI_HOST_POINTER_TYPE_ITD (0x00U)
#define EHCI_HOST_POINTER_TYPE_QH (0x00000002U)
#define EHCI_HOST_POINTER_TYPE_SITD (0x00000004U)
#define EHCI_HOST_POINTER_TYPE_FSTN (0x00000006U)
#define EHCI_HOST_POINTER_TYPE_MASK (0x00000006U)
#define EHCI_HOST_T_INVALID_VALUE (1U)
#define EHCI_HOST_POINTER_TYPE_ITD (0x00U)
#define EHCI_HOST_POINTER_TYPE_QH (0x00000002U)
#define EHCI_HOST_POINTER_TYPE_SITD (0x00000004U)
#define EHCI_HOST_POINTER_TYPE_FSTN (0x00000006U)
#define EHCI_HOST_POINTER_TYPE_MASK (0x00000006U)
#define EHCI_HOST_POINTER_ADDRESS_MASK (0xFFFFFFE0U)
#define EHCI_HOST_PID_OUT (0U)
#define EHCI_HOST_PID_IN (1U)
#define EHCI_HOST_PID_SETUP (2U)
#define EHCI_HOST_PID_OUT (0UL)
#define EHCI_HOST_PID_IN (1UL)
#define EHCI_HOST_PID_SETUP (2UL)
#define EHCI_HOST_QH_RL_SHIFT (28U)
#define EHCI_HOST_QH_RL_MASK (0xF0000000U)
#define EHCI_HOST_QH_C_SHIFT (27U)
#define EHCI_HOST_QH_MAX_PACKET_LENGTH_SHIFT (16U)
#define EHCI_HOST_QH_MAX_PACKET_LENGTH_MASK (0x07FF0000U)
#define EHCI_HOST_QH_H_SHIFT (15U)
#define EHCI_HOST_QH_DTC_SHIFT (14U)
#define EHCI_HOST_QH_EPS_SHIFT (12U)
#define EHCI_HOST_QH_ENDPT_SHIFT (8U)
#define EHCI_HOST_QH_I_SHIFT (7U)
#define EHCI_HOST_QH_DEVICE_ADDRESS_SHIFT (0U)
#define EHCI_HOST_QH_MULT_SHIFT (30U)
#define EHCI_HOST_QH_PORT_NUMBER_SHIFT (23U)
#define EHCI_HOST_QH_HUB_ADDR_SHIFT (16U)
#define EHCI_HOST_QH_UFRAME_CMASK_SHIFT (8U)
#define EHCI_HOST_QH_UFRAME_SMASK_SHIFT (0U)
#define EHCI_HOST_QH_STATUS_ERROR_MASK (0x0000007EU)
#define EHCI_HOST_QH_RL_SHIFT (28U)
#define EHCI_HOST_QH_RL_MASK (0xF0000000U)
#define EHCI_HOST_QH_C_SHIFT (27U)
#define EHCI_HOST_QH_MAX_PACKET_LENGTH_SHIFT (16U)
#define EHCI_HOST_QH_MAX_PACKET_LENGTH_MASK (0x07FF0000U)
#define EHCI_HOST_QH_H_SHIFT (15U)
#define EHCI_HOST_QH_DTC_SHIFT (14U)
#define EHCI_HOST_QH_EPS_SHIFT (12U)
#define EHCI_HOST_QH_ENDPT_SHIFT (8U)
#define EHCI_HOST_QH_I_SHIFT (7U)
#define EHCI_HOST_QH_DEVICE_ADDRESS_SHIFT (0U)
#define EHCI_HOST_QH_MULT_SHIFT (30U)
#define EHCI_HOST_QH_PORT_NUMBER_SHIFT (23U)
#define EHCI_HOST_QH_HUB_ADDR_SHIFT (16U)
#define EHCI_HOST_QH_UFRAME_CMASK_SHIFT (8U)
#define EHCI_HOST_QH_UFRAME_SMASK_SHIFT (0U)
#define EHCI_HOST_QH_STATUS_ERROR_MASK (0x0000007EU)
#define EHCI_HOST_QH_STATUS_NOSTALL_ERROR_MASK (0x0000003EU)
#define EHCI_HOST_QTD_DT_SHIFT (31U)
#define EHCI_HOST_QTD_DT_MASK (0x80000000U)
#define EHCI_HOST_QTD_TOTAL_BYTES_SHIFT (16U)
#define EHCI_HOST_QTD_TOTAL_BYTES_MASK (0x7FFF0000U)
#define EHCI_HOST_QTD_IOC_MASK (0x00008000U)
#define EHCI_HOST_QTD_C_PAGE_SHIFT (12U)
#define EHCI_HOST_QTD_CERR_SHIFT (10U)
#define EHCI_HOST_QTD_CERR_MAX_VALUE (0x00000003U)
#define EHCI_HOST_QTD_PID_CODE_SHIFT (8U)
#define EHCI_HOST_QTD_STATUS_SHIFT (0U)
#define EHCI_HOST_QTD_CURRENT_OFFSET_MASK (0x00000FFFU)
#define EHCI_HOST_QTD_BUFFER_POINTER_SHIFT (12U)
#define EHCI_HOST_QTD_STATUS_ACTIVE_MASK (0x00000080U)
#define EHCI_HOST_QTD_STATUS_MASK (0x000000ffU)
#define EHCI_HOST_QTD_STATUS_ERROR_MASK (0x0000007EU)
#define EHCI_HOST_QTD_DT_SHIFT (31U)
#define EHCI_HOST_QTD_DT_MASK (0x80000000U)
#define EHCI_HOST_QTD_TOTAL_BYTES_SHIFT (16U)
#define EHCI_HOST_QTD_TOTAL_BYTES_MASK (0x7FFF0000U)
#define EHCI_HOST_QTD_IOC_MASK (0x00008000U)
#define EHCI_HOST_QTD_C_PAGE_SHIFT (12U)
#define EHCI_HOST_QTD_CERR_SHIFT (10U)
#define EHCI_HOST_QTD_CERR_MAX_VALUE (0x00000003UL)
#define EHCI_HOST_QTD_PID_CODE_SHIFT (8U)
#define EHCI_HOST_QTD_STATUS_SHIFT (0U)
#define EHCI_HOST_QTD_CURRENT_OFFSET_MASK (0x00000FFFU)
#define EHCI_HOST_QTD_BUFFER_POINTER_SHIFT (12U)
#define EHCI_HOST_QTD_STATUS_ACTIVE_MASK (0x00000080U)
#define EHCI_HOST_QTD_STATUS_MASK (0x000000ffU)
#define EHCI_HOST_QTD_STATUS_ERROR_MASK (0x0000007EU)
#define EHCI_HOST_QTD_STATUS_STALL_ERROR_MASK (0x00000040U)
#define EHCI_HOST_ITD_STATUS_ACTIVE_MASK (0x80000000U)
#define EHCI_HOST_ITD_TRANSACTION_LEN_SHIFT (16U)
#define EHCI_HOST_ITD_TRANSACTION_LEN_MASK (0x0FFF0000U)
#define EHCI_HOST_ITD_IOC_SHIFT (15U)
#define EHCI_HOST_ITD_PG_SHIFT (12U)
#define EHCI_HOST_ITD_STATUS_ACTIVE_MASK (0x80000000U)
#define EHCI_HOST_ITD_TRANSACTION_LEN_SHIFT (16U)
#define EHCI_HOST_ITD_TRANSACTION_LEN_MASK (0x0FFF0000U)
#define EHCI_HOST_ITD_IOC_SHIFT (15U)
#define EHCI_HOST_ITD_PG_SHIFT (12U)
#define EHCI_HOST_ITD_TRANSACTION_OFFSET_SHIFT (0U)
#define EHCI_HOST_ITD_TRANSACTION_OFFSET_MASK (0x00000FFFU)
#define EHCI_HOST_ITD_BUFFER_POINTER_SHIFT (12U)
#define EHCI_HOST_ITD_ENDPT_SHIFT (8U)
#define EHCI_HOST_ITD_DEVICE_ADDRESS_SHIFT (0U)
#define EHCI_HOST_ITD_MAX_PACKET_SIZE_SHIFT (0U)
#define EHCI_HOST_ITD_MULT_SHIFT (0U)
#define EHCI_HOST_ITD_DIRECTION_SHIFT (11U)
#define EHCI_HOST_ITD_TRANSACTION_OFFSET_MASK (0x00000FFFU)
#define EHCI_HOST_ITD_BUFFER_POINTER_SHIFT (12U)
#define EHCI_HOST_ITD_ENDPT_SHIFT (8U)
#define EHCI_HOST_ITD_DEVICE_ADDRESS_SHIFT (0U)
#define EHCI_HOST_ITD_MAX_PACKET_SIZE_SHIFT (0U)
#define EHCI_HOST_ITD_MULT_SHIFT (0U)
#define EHCI_HOST_ITD_DIRECTION_SHIFT (11U)
#define EHCI_HOST_SITD_STATUS_ACTIVE_MASK (0x00000080U)
#define EHCI_HOST_SITD_DIRECTION_SHIFT (31U)
#define EHCI_HOST_SITD_PORT_NUMBER_SHIFT (24U)
#define EHCI_HOST_SITD_HUB_ADDR_SHIFT (16U)
#define EHCI_HOST_SITD_ENDPT_SHIFT (8U)
#define EHCI_HOST_SITD_STATUS_ACTIVE_MASK (0x00000080U)
#define EHCI_HOST_SITD_DIRECTION_SHIFT (31U)
#define EHCI_HOST_SITD_PORT_NUMBER_SHIFT (24U)
#define EHCI_HOST_SITD_HUB_ADDR_SHIFT (16U)
#define EHCI_HOST_SITD_ENDPT_SHIFT (8U)
#define EHCI_HOST_SITD_DEVICE_ADDRESS_SHIFT (0U)
#define EHCI_HOST_SITD_CMASK_SHIFT (8U)
#define EHCI_HOST_SITD_SMASK_SHIFT (0U)
#define EHCI_HOST_SITD_TOTAL_BYTES_SHIFT (16U)
#define EHCI_HOST_SITD_TOTAL_BYTES_MASK (0x03FF0000U)
#define EHCI_HOST_SITD_TP_SHIFT (3U)
#define EHCI_HOST_SITD_TCOUNT_SHIFT (0U)
#define EHCI_HOST_SITD_IOC_SHIFT (31U)
#define EHCI_HOST_SITD_CMASK_SHIFT (8U)
#define EHCI_HOST_SITD_SMASK_SHIFT (0U)
#define EHCI_HOST_SITD_TOTAL_BYTES_SHIFT (16U)
#define EHCI_HOST_SITD_TOTAL_BYTES_MASK (0x03FF0000U)
#define EHCI_HOST_SITD_TP_SHIFT (3U)
#define EHCI_HOST_SITD_TCOUNT_SHIFT (0U)
#define EHCI_HOST_SITD_IOC_SHIFT (31U)
/* register related MACROs */
#define EHCI_PORTSC1_W1_BITS (0x0000002AU)
#define EHCI_PORTSC1_W1_BITS (0x0000002AU)
#define EHCI_MAX_UFRAME_VALUE (0x00003FFFU)
/* task event */
#define EHCI_TASK_EVENT_DEVICE_ATTACH (0x01U)
#define EHCI_TASK_EVENT_DEVICE_ATTACH (0x01U)
#define EHCI_TASK_EVENT_TRANSACTION_DONE (0x02U)
#define EHCI_TASK_EVENT_DEVICE_DETACH (0x04U)
#define EHCI_TASK_EVENT_PORT_CHANGE (0x08U)
#define EHCI_TASK_EVENT_TIMER0 (0x10U)
#define EHCI_TASK_EVENT_TIMER1 (0x20U)
#define EHCI_TASK_EVENT_DEVICE_DETACH (0x04U)
#define EHCI_TASK_EVENT_PORT_CHANGE (0x08U)
#define EHCI_TASK_EVENT_TIMER0 (0x10U)
#define EHCI_TASK_EVENT_TIMER1 (0x20U)
#define USB_HostEhciLock() USB_OsaMutexLock(ehciInstance->ehciMutex)
#define USB_HostEhciUnlock() USB_OsaMutexUnlock(ehciInstance->ehciMutex)
#define USB_HostEhciLock() (void)OSA_MutexLock(ehciInstance->ehciMutex, USB_OSA_WAIT_TIMEOUT)
#define USB_HostEhciUnlock() (void)OSA_MutexUnlock(ehciInstance->ehciMutex)
/*******************************************************************************
* KHCI driver public structures, enumerations, macros, functions
@ -144,6 +122,8 @@
#define USB_HOST_EHCI_PORT_CONNECT_DEBOUNCE_DELAY (101U)
/*! @brief Delay for port reset */
#define USB_HOST_EHCI_PORT_RESET_DELAY (11U)
/*! @brief The MAX continuous transfers that application can send. */
#define USB_HOST_EHCI_ISO_MAX_CONTINUOUS_TRANSFER (8U)
/*! @brief The SITD inserts a frame interval for putting more SITD continuously.
* There is an interval when an application sends two FS/LS ISO transfers.
* When the interval is less than the macro, the two transfers are continuous in the frame list. Otherwise, the two
@ -171,7 +151,7 @@
*/
#define USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER (16U)
/*! @brief Control or bulk transaction timeout value (unit: 100 ms) */
#define USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE (20U)
#define USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE (50U)
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
typedef enum _bus_ehci_suspend_request_state
@ -323,8 +303,10 @@ typedef struct _usb_host_ehci_instance
usb_host_ehci_pipe_t *ehciPipeIndexBase; /*!< Pipe buffer's start pointer*/
usb_host_ehci_pipe_t *ehciPipeList; /*!< Idle pipe list pointer*/
usb_host_ehci_pipe_t *ehciRunningPipeList; /*!< Running pipe list pointer*/
usb_osa_mutex_handle ehciMutex; /*!< EHCI mutex*/
usb_osa_event_handle taskEventHandle; /*!< EHCI task event*/
osa_mutex_handle_t ehciMutex; /*!< EHCI mutex*/
uint32_t mutexBuffer[(OSA_MUTEX_HANDLE_SIZE + 3) / 4]; /*!< The mutex buffer. */
osa_event_handle_t taskEventHandle; /*!< EHCI task event*/
uint32_t taskEventHandleBuffer[(OSA_EVENT_HANDLE_SIZE + 3) / 4]; /*!< EHCI task event handle buffer*/
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
uint64_t matchTick;
USBPHY_Type *registerPhyBase; /*!< The base address of the PHY register */
@ -355,6 +337,10 @@ typedef struct _usb_host_ehci_data
#endif
#if ((defined(USB_HOST_CONFIG_EHCI_MAX_ITD)) && (USB_HOST_CONFIG_EHCI_MAX_ITD > 0U))
usb_host_ehci_itd_t ehciItd[USB_HOST_CONFIG_EHCI_MAX_ITD]; /*!< Idle ITD list array*/
/* add additional 32bytes because the itd cannot cross over 4K boundary,
* If one ITD cross over 4K boundary, the code will move 32 bytes for ITD.
*/
uint32_t reserved[8];
#endif
#if ((defined(USB_HOST_CONFIG_EHCI_MAX_SITD)) && (USB_HOST_CONFIG_EHCI_MAX_SITD > 0U))
usb_host_ehci_sitd_t ehciSitd[USB_HOST_CONFIG_EHCI_MAX_SITD]; /*!< Idle SITD list array*/

View File

@ -1,34 +1,13 @@
/*
* Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* Copyright 2016 - 2019 NXP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o 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.
*
* o Neither the name of the copyright holder 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 AND CONTRIBUTORS "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 OR CONTRIBUTORS 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.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <usb/include/usb_device_config.h>
#include <usb/include/usb_host_config.h>
#include <fsl_os_abstraction.h>
#include "fsl_common.h"
#include "usb_host.h"
#include "usb_host_hci.h"
@ -42,16 +21,24 @@
* Definitions
******************************************************************************/
/* Component ID definition, used by tools. */
#ifndef FSL_COMPONENT_ID
#define FSL_COMPONENT_ID "middleware.usb.host_stack"
#endif
#if defined __CORTEX_M && (__CORTEX_M == 7U)
#if (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE > 0U))
#warning USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE is not supported.
#endif
#endif
/*******************************************************************************
* Prototypes
******************************************************************************/
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
extern uint32_t USB_HostHubGetTotalThinkTime(usb_host_handle hostHandle, uint8_t parentHubNo);
extern usb_status_t USB_HostHubSuspendDevice(usb_host_handle hostHandle);
extern usb_status_t USB_HostHubResumeDevice(usb_host_handle hostHandle);
#include "usb_host_hub.h"
#include "usb_host_hub_app.h"
#endif
/*!
@ -77,15 +64,6 @@ static void USB_HostReleaseInstance(usb_host_instance_t *hostInstance);
static void USB_HostGetControllerInterface(uint8_t controllerId,
const usb_host_controller_interface_t **controllerTable);
#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI))
extern void USB_HostEhciTestModeInit(usb_device_handle devHandle);
#endif /* USB_HOST_CONFIG_COMPLIANCE_TEST */
#if ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS))
extern void USB_HostIp3516HsTestModeInit(usb_device_handle devHandle);
#endif /* USB_HOST_CONFIG_COMPLIANCE_TEST */
#endif /* USB_HOST_CONFIG_EHCI */
/*******************************************************************************
* Variables
******************************************************************************/
@ -94,8 +72,7 @@ usb_host_instance_t g_UsbHostInstance[USB_HOST_CONFIG_MAX_HOST];
#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI))
#include "usb_host_ehci.h"
static const usb_host_controller_interface_t s_EhciInterface = \
{
static const usb_host_controller_interface_t s_EhciInterface = {
USB_HostEhciCreate, USB_HostEhciDestory, USB_HostEhciOpenPipe, USB_HostEhciClosePipe,
USB_HostEhciWritePipe, USB_HostEhciReadpipe, USB_HostEhciIoctl,
};
@ -103,8 +80,7 @@ static const usb_host_controller_interface_t s_EhciInterface = \
#if ((defined USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI))
#include "usb_host_khci.h"
static const usb_host_controller_interface_t s_KhciInterface = \
{
static const usb_host_controller_interface_t s_KhciInterface = {
USB_HostKhciCreate, USB_HostKhciDestory, USB_HostKhciOpenPipe, USB_HostKhciClosePipe,
USB_HostKhciWritePipe, USB_HostKhciReadpipe, USB_HostKciIoctl,
};
@ -112,8 +88,7 @@ static const usb_host_controller_interface_t s_KhciInterface = \
#if ((defined USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI > 0U))
#include "usb_host_ohci.h"
static const usb_host_controller_interface_t s_OhciInterface = \
{
static const usb_host_controller_interface_t s_OhciInterface = {
USB_HostOhciCreate, USB_HostOhciDestory, USB_HostOhciOpenPipe, USB_HostOhciClosePipe,
USB_HostOhciWritePipe, USB_HostOhciReadPipe, USB_HostOhciIoctl,
};
@ -121,65 +96,67 @@ static const usb_host_controller_interface_t s_OhciInterface = \
#if ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
#include "usb_host_ip3516hs.h"
static const usb_host_controller_interface_t s_Ip3516HsInterface = \
{
static const usb_host_controller_interface_t s_Ip3516HsInterface = {
USB_HostIp3516HsCreate, USB_HostIp3516HsDestory, USB_HostIp3516HsOpenPipe, USB_HostIp3516HsClosePipe,
USB_HostIp3516HsWritePipe, USB_HostIp3516HsReadPipe, USB_HostIp3516HsIoctl,
};
#endif /* USB_HOST_CONFIG_IP3516HS */
USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE) static uint8_t s_Setupbuffer[USB_HOST_CONFIG_MAX_HOST][USB_HOST_CONFIG_MAX_TRANSFERS][USB_DATA_ALIGN_SIZE_MULTIPLE(8)];
USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
static uint8_t s_Setupbuffer[USB_HOST_CONFIG_MAX_HOST][USB_HOST_CONFIG_MAX_TRANSFERS][USB_DATA_ALIGN_SIZE_MULTIPLE(8)];
/*******************************************************************************
* Code
******************************************************************************/
* Code
******************************************************************************/
#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : usb_test_mode_init
* Returned Value : None
* Comments :
* This function is called by common class to initialize the class driver. It
* is called in response to a select interface call by application
*
*END*--------------------------------------------------------------------*/
*
* Function Name : usb_test_mode_init
* Returned Value : None
* Comments :
* This function is called by common class to initialize the class driver. It
* is called in response to a select interface call by application
*
*END*--------------------------------------------------------------------*/
usb_status_t USB_HostTestModeInit(usb_device_handle deviceHandle)
{
#if (((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI)) || \
((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS)))
usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)deviceInstance->hostHandle;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)deviceInstance->hostHandle;
#endif
uint32_t productId;
uint32_t vendorId;
usb_echo("usb host test init\r\n");
USB_HostHelperGetPeripheralInformation(deviceHandle, kUSB_HostGetDevicePID, &productId);
USB_HostHelperGetPeripheralInformation(deviceHandle, kUSB_HostGetDeviceVID, &vendorId);
usb_echo(" vendor id :0x%x product id:0x%x \r\n", vendorId, productId);
(void)usb_echo("usb host test init\r\n");
(void)USB_HostHelperGetPeripheralInformation(deviceHandle, (uint32_t)kUSB_HostGetDevicePID, &productId);
(void)USB_HostHelperGetPeripheralInformation(deviceHandle, (uint32_t)kUSB_HostGetDeviceVID, &vendorId);
(void)usb_echo(" vendor id :0x%x product id:0x%x \r\n", vendorId, productId);
if ((productId != 0x0200U) && (productId != 0x0101) && (productId != 0x0102) && (productId != 0x0103) &&
(productId != 0x0104) && (productId != 0x0105) && (productId != 0x0106) && (productId != 0x0107) &&
(productId != 0x0108))
if ((productId != 0x0200U) && (productId != 0x0101U) && (productId != 0x0102U) && (productId != 0x0103U) &&
(productId != 0x0104U) && (productId != 0x0105U) && (productId != 0x0106U) && (productId != 0x0107U) &&
(productId != 0x0108U))
{
usb_echo("Unsupported Device\r\n");
(void)usb_echo("Unsupported Device\r\n");
}
if (productId == 0x0200U)
{
usb_echo("PET test device attached\r\n");
(void)usb_echo("PET test device attached\r\n");
}
else
{
#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI))
if (hostInstance->controllerTable == &s_EhciInterface)
{
USB_HostEhciTestModeInit(deviceHandle);
(void)hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostTestModeInit,
(void *)deviceHandle);
}
#elif((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS))
#elif ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS))
if (hostInstance->controllerTable == &s_Ip3516HsInterface)
{
USB_HostIp3516HsTestModeInit(deviceHandle);
(void)hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostTestModeInit,
(void *)deviceHandle);
}
#endif
}
@ -190,13 +167,14 @@ usb_status_t USB_HostTestModeInit(usb_device_handle deviceHandle)
static usb_host_instance_t *USB_HostGetInstance(void)
{
uint8_t i = 0;
uint8_t i = 0;
uint32_t index = 0;
USB_OSA_SR_ALLOC();
USB_OSA_ENTER_CRITICAL();
void *temp;
OSA_SR_ALLOC();
OSA_ENTER_CRITICAL();
for (; i < USB_HOST_CONFIG_MAX_HOST; i++)
{
if (g_UsbHostInstance[i].occupied != 1)
if (g_UsbHostInstance[i].occupied != 1U)
{
uint8_t *buffer = (uint8_t *)&g_UsbHostInstance[i];
for (uint32_t j = 0U; j < sizeof(usb_host_instance_t); j++)
@ -204,53 +182,53 @@ static usb_host_instance_t *USB_HostGetInstance(void)
buffer[j] = 0x00U;
}
g_UsbHostInstance[i].occupied = 1;
USB_OSA_EXIT_CRITICAL();
OSA_EXIT_CRITICAL();
for (index = 0; index < USB_HOST_CONFIG_MAX_TRANSFERS; ++index)
{
g_UsbHostInstance[i].transferList[index].setupPacket =
(usb_setup_struct_t *)&(s_Setupbuffer[i][index][0]);
temp = (void *)&(s_Setupbuffer[i][index][0]);
g_UsbHostInstance[i].transferList[index].setupPacket = (usb_setup_struct_t *)temp;
}
return &g_UsbHostInstance[i];
}
}
USB_OSA_EXIT_CRITICAL();
OSA_EXIT_CRITICAL();
return NULL;
}
static void USB_HostReleaseInstance(usb_host_instance_t *hostInstance)
{
USB_OSA_SR_ALLOC();
USB_OSA_ENTER_CRITICAL();
OSA_SR_ALLOC();
OSA_ENTER_CRITICAL();
hostInstance->occupied = 0;
USB_OSA_EXIT_CRITICAL();
OSA_EXIT_CRITICAL();
}
static void USB_HostGetControllerInterface(uint8_t controllerId,
const usb_host_controller_interface_t **controllerTable)
{
#if ((defined USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI))
if (controllerId == kUSB_ControllerKhci0)
if (controllerId == (uint8_t)kUSB_ControllerKhci0)
{
*controllerTable = &s_KhciInterface;
}
#endif /* USB_HOST_CONFIG_KHCI */
#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI))
if ((controllerId == kUSB_ControllerEhci0) || (controllerId == kUSB_ControllerEhci1))
if ((controllerId == (uint8_t)kUSB_ControllerEhci0) || (controllerId == (uint8_t)kUSB_ControllerEhci1))
{
*controllerTable = &s_EhciInterface;
}
#endif /* USB_HOST_CONFIG_EHCI */
#if ((defined USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI > 0U))
if (controllerId == kUSB_ControllerOhci0)
if (controllerId == (uint8_t)kUSB_ControllerOhci0)
{
*controllerTable = &s_OhciInterface;
}
#endif /* USB_HOST_CONFIG_OHCI */
#if ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
if (controllerId == kUSB_ControllerIp3516Hs0)
if (controllerId == (uint8_t)kUSB_ControllerIp3516Hs0)
{
*controllerTable = &s_Ip3516HsInterface;
}
@ -259,10 +237,10 @@ static void USB_HostGetControllerInterface(uint8_t controllerId,
usb_status_t USB_HostInit(uint8_t controllerId, usb_host_handle *hostHandle, host_callback_t callbackFn)
{
usb_status_t status = kStatus_USB_Success;
usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = NULL;
usb_host_transfer_t *transferPrev = NULL;
uint8_t i = 0;
uint8_t i = 0;
hostInstance = USB_HostGetInstance(); /* get one host instance */
if (hostInstance == NULL)
@ -291,10 +269,11 @@ usb_status_t USB_HostInit(uint8_t controllerId, usb_host_handle *hostHandle, hos
}
/* HOST instance init*/
hostInstance->controllerId = controllerId;
hostInstance->controllerId = controllerId;
hostInstance->deviceCallback = callbackFn;
hostInstance->deviceList = NULL;
if (kStatus_USB_OSA_Success != USB_OsaMutexCreate(&hostInstance->hostMutex))
hostInstance->deviceList = NULL;
hostInstance->hostMutex = (osa_mutex_handle_t)(&hostInstance->mutexBuffer[0]);
if (KOSA_StatusSuccess != OSA_MutexCreate(hostInstance->hostMutex))
{
USB_HostReleaseInstance(hostInstance);
#ifdef HOST_ECHO
@ -306,19 +285,19 @@ usb_status_t USB_HostInit(uint8_t controllerId, usb_host_handle *hostHandle, hos
/* initialize transfer list */
hostInstance->transferHead = &hostInstance->transferList[0];
transferPrev = hostInstance->transferHead;
transferPrev = hostInstance->transferHead;
for (i = 1; i < USB_HOST_CONFIG_MAX_TRANSFERS; ++i)
{
transferPrev->next = &hostInstance->transferList[i];
transferPrev = transferPrev->next;
transferPrev = transferPrev->next;
}
/* controller create */
/* controller create, the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerCreate(controllerId, hostInstance, &(hostInstance->controllerHandle));
if ((status != kStatus_USB_Success) || (hostInstance->controllerHandle == NULL))
{
USB_OsaMutexDestroy(hostInstance->hostMutex);
(void)OSA_MutexDestroy(hostInstance->hostMutex);
USB_HostReleaseInstance(hostInstance);
#ifdef HOST_ECHO
usb_echo("host init: controller init fail\r\n");
@ -332,8 +311,8 @@ usb_status_t USB_HostInit(uint8_t controllerId, usb_host_handle *hostHandle, hos
usb_status_t USB_HostDeinit(usb_host_handle hostHandle)
{
usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
usb_host_device_instance_t *deviceInstance = NULL;
if (hostHandle == NULL)
@ -346,23 +325,23 @@ usb_status_t USB_HostDeinit(usb_host_handle hostHandle)
while (deviceInstance != NULL)
{
deviceInstance = (usb_host_device_instance_t *)hostInstance->deviceList;
USB_HostDetachDeviceInternal(hostHandle, deviceInstance);
(void)USB_HostDetachDeviceInternal(hostHandle, deviceInstance);
}
/* controller instance destory */
status = hostInstance->controllerTable->controllerDestory(hostInstance->controllerHandle);
/* controller instance destroy, the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerDestory(hostInstance->controllerHandle);
hostInstance->controllerHandle = NULL;
if (status != kStatus_USB_Success)
{
#ifdef HOST_ECHO
usb_echo("host controller destory fail\r\n");
usb_echo("host controller destroy fail\r\n");
#endif
}
/* resource release */
if (hostInstance->hostMutex)
if (NULL != hostInstance->hostMutex)
{
USB_OsaMutexDestroy(hostInstance->hostMutex);
(void)OSA_MutexDestroy(hostInstance->hostMutex);
hostInstance->hostMutex = NULL;
}
USB_HostReleaseInstance(hostInstance);
@ -374,7 +353,7 @@ usb_status_t USB_HostOpenPipe(usb_host_handle hostHandle,
usb_host_pipe_handle *pipeHandle,
usb_host_pipe_init_t *pipeInit)
{
usb_status_t status = kStatus_USB_Success;
usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if ((hostHandle == NULL) || (pipeInit == NULL))
@ -382,7 +361,7 @@ usb_status_t USB_HostOpenPipe(usb_host_handle hostHandle,
return kStatus_USB_InvalidHandle;
}
/* call controller open pipe interface */
/* call controller open pipe interface, the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerOpenPipe(hostInstance->controllerHandle, pipeHandle, pipeInit);
return status;
@ -390,7 +369,7 @@ usb_status_t USB_HostOpenPipe(usb_host_handle hostHandle,
usb_status_t USB_HostClosePipe(usb_host_handle hostHandle, usb_host_pipe_handle pipeHandle)
{
usb_status_t status = kStatus_USB_Success;
usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if ((hostHandle == NULL) || (pipeHandle == NULL))
@ -398,7 +377,7 @@ usb_status_t USB_HostClosePipe(usb_host_handle hostHandle, usb_host_pipe_handle
return kStatus_USB_InvalidHandle;
}
/* call controller close pipe interface */
/* call controller close pipe interface, the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerClosePipe(hostInstance->controllerHandle, pipeHandle);
return status;
@ -406,7 +385,7 @@ usb_status_t USB_HostClosePipe(usb_host_handle hostHandle, usb_host_pipe_handle
usb_status_t USB_HostSend(usb_host_handle hostHandle, usb_host_pipe_handle pipeHandle, usb_host_transfer_t *transfer)
{
usb_status_t status = kStatus_USB_Success;
usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if ((hostHandle == NULL) || (pipeHandle == NULL) || (transfer == NULL))
@ -416,9 +395,9 @@ usb_status_t USB_HostSend(usb_host_handle hostHandle, usb_host_pipe_handle pipeH
/* initialize transfer */
transfer->transferSofar = 0;
transfer->direction = USB_OUT;
transfer->direction = USB_OUT;
USB_HostLock(); /* This api can be called by host task and app task */
(void)USB_HostLock(); /* This api can be called by host task and app task */
/* keep this code: in normal situation application will guarantee the device is attached when call send/receive function
*/
#if 0
@ -435,9 +414,10 @@ usb_status_t USB_HostSend(usb_host_handle hostHandle, usb_host_pipe_handle pipeH
DCACHE_CleanByRange((uint32_t)transfer->transferBuffer, transfer->transferLength);
}
#endif
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerWritePipe(hostInstance->controllerHandle, pipeHandle, transfer);
USB_HostUnlock();
(void)USB_HostUnlock();
return status;
}
@ -445,7 +425,7 @@ usb_status_t USB_HostSendSetup(usb_host_handle hostHandle,
usb_host_pipe_handle pipeHandle,
usb_host_transfer_t *transfer)
{
usb_status_t status = kStatus_USB_Success;
usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if ((hostHandle == NULL) || (pipeHandle == NULL) || (transfer == NULL))
@ -455,8 +435,8 @@ usb_status_t USB_HostSendSetup(usb_host_handle hostHandle,
/* initialize transfer */
transfer->transferSofar = 0;
transfer->next = NULL;
transfer->setupStatus = 0;
transfer->next = NULL;
transfer->setupStatus = 0;
if ((transfer->setupPacket->bmRequestType & USB_REQUEST_TYPE_DIR_MASK) == USB_REQUEST_TYPE_DIR_IN)
{
transfer->direction = USB_IN;
@ -466,7 +446,7 @@ usb_status_t USB_HostSendSetup(usb_host_handle hostHandle,
transfer->direction = USB_OUT;
}
USB_HostLock(); /* This API can be called by host task and application task */
(void)USB_HostLock(); /* This API can be called by host task and application task */
/* keep this code: in normal situation application will guarantee the device is attached when call send/receive function
*/
#if 0
@ -484,15 +464,16 @@ usb_status_t USB_HostSendSetup(usb_host_handle hostHandle,
DCACHE_CleanInvalidateByRange((uint32_t)transfer->transferBuffer, transfer->transferLength);
}
#endif
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerWritePipe(hostInstance->controllerHandle, pipeHandle, transfer);
USB_HostUnlock();
(void)USB_HostUnlock();
return status;
}
usb_status_t USB_HostRecv(usb_host_handle hostHandle, usb_host_pipe_handle pipeHandle, usb_host_transfer_t *transfer)
{
usb_status_t status = kStatus_USB_Success;
usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
if ((hostHandle == NULL) || (pipeHandle == NULL) || (transfer == NULL))
@ -502,9 +483,9 @@ usb_status_t USB_HostRecv(usb_host_handle hostHandle, usb_host_pipe_handle pipeH
/* initialize transfer */
transfer->transferSofar = 0;
transfer->direction = USB_IN;
transfer->direction = USB_IN;
USB_HostLock(); /* This API can be called by host task and application task */
(void)USB_HostLock(); /* This API can be called by host task and application task */
/* keep this code: in normal situation application will guarantee the device is attached when call send/receive function
*/
#if 0
@ -521,9 +502,10 @@ usb_status_t USB_HostRecv(usb_host_handle hostHandle, usb_host_pipe_handle pipeH
DCACHE_CleanInvalidateByRange((uint32_t)transfer->transferBuffer, transfer->transferLength);
}
#endif
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerReadPipe(hostInstance->controllerHandle, pipeHandle, transfer);
USB_HostUnlock();
(void)USB_HostUnlock();
return status;
}
@ -531,7 +513,7 @@ usb_status_t USB_HostCancelTransfer(usb_host_handle hostHandle,
usb_host_pipe_handle pipeHandle,
usb_host_transfer_t *transfer)
{
usb_status_t status = kStatus_USB_Success;
usb_status_t status = kStatus_USB_Success;
usb_host_instance_t *hostInstance = (usb_host_instance_t *)hostHandle;
usb_host_cancel_param_t cancelParam;
@ -542,9 +524,10 @@ usb_status_t USB_HostCancelTransfer(usb_host_handle hostHandle,
/* initialize cancel parameter */
cancelParam.pipeHandle = pipeHandle;
cancelParam.transfer = transfer;
cancelParam.transfer = transfer;
/* USB_HostLock(); This api can be called by host task and app task */
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostCancelTransfer,
&cancelParam);
/* USB_HostUnlock(); */
@ -562,18 +545,18 @@ usb_status_t USB_HostMallocTransfer(usb_host_handle hostHandle, usb_host_transfe
}
/* get one from the transfer_head */
USB_HostLock();
(void)USB_HostLock();
if (hostInstance->transferHead != NULL)
{
*transfer = hostInstance->transferHead;
*transfer = hostInstance->transferHead;
hostInstance->transferHead = hostInstance->transferHead->next;
USB_HostUnlock();
(void)USB_HostUnlock();
return kStatus_USB_Success;
}
else
{
*transfer = NULL;
USB_HostUnlock();
(void)USB_HostUnlock();
return kStatus_USB_Error;
}
}
@ -592,10 +575,10 @@ usb_status_t USB_HostFreeTransfer(usb_host_handle hostHandle, usb_host_transfer_
}
/* release one to the transfer_head */
USB_HostLock();
transfer->next = hostInstance->transferHead;
(void)USB_HostLock();
transfer->next = hostInstance->transferHead;
hostInstance->transferHead = transfer;
USB_HostUnlock();
(void)USB_HostUnlock();
return kStatus_USB_Success;
}
@ -604,23 +587,28 @@ usb_status_t USB_HostHelperGetPeripheralInformation(usb_device_handle deviceHand
uint32_t *infoValue)
{
usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle;
uint32_t *temp;
usb_host_dev_info_t devInfo;
if ((deviceHandle == NULL) || (infoValue == NULL))
{
return kStatus_USB_InvalidParameter;
}
switch (infoCode)
devInfo = (usb_host_dev_info_t)infoCode;
switch (devInfo)
{
case kUSB_HostGetDeviceAddress: /* device address */
*infoValue = (uint32_t)deviceInstance->setAddress;
break;
case kUSB_HostGetDeviceControlPipe: /* device control pipe */
*infoValue = (uint32_t)deviceInstance->controlPipe;
temp = (uint32_t *)deviceInstance->controlPipe;
*infoValue = (uint32_t)temp;
break;
case kUSB_HostGetHostHandle: /* device host handle */
*infoValue = (uint32_t)deviceInstance->hostHandle;
temp = (uint32_t *)deviceInstance->hostHandle;
*infoValue = (uint32_t)temp;
break;
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
@ -685,7 +673,8 @@ usb_status_t USB_HostHelperGetPeripheralInformation(usb_device_handle deviceHand
break;
default:
return kStatus_USB_Error;
/*no action*/
break;
}
return kStatus_USB_Success;
@ -698,26 +687,27 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter
uint32_t endPosition;
usb_descriptor_union_t *unionDes;
usb_host_ep_t *epParse;
void *temp;
if (interfaceHandle == NULL)
{
return kStatus_USB_InvalidHandle;
}
if (alternateSetting == 0)
if (alternateSetting == 0U)
{
return kStatus_USB_InvalidParameter;
}
/* parse configuration descriptor */
unionDes = (usb_descriptor_union_t *)((usb_host_interface_t *)interfaceHandle)
->interfaceDesc; /* interface extend descriptor start */
temp = (void *)((usb_host_interface_t *)interfaceHandle)->interfaceDesc;
;
unionDes = (usb_descriptor_union_t *)temp; /* interface extend descriptor start */
endPosition =
(uint32_t)unionDes +
((usb_host_interface_t *)interfaceHandle)->interfaceExtensionLength; /* interface extend descriptor end */
unionDes = (usb_descriptor_union_t *)((uint32_t)unionDes + unionDes->common.bLength);
/* search for the alternate setting interface descritpor */
/* search for the alternate setting interface descriptor */
while ((uint32_t)unionDes < endPosition)
{
if (unionDes->interface.bDescriptorType == USB_DESCRIPTOR_TYPE_INTERFACE)
@ -742,12 +732,12 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter
}
/* initialize interface handle structure instance */
interface->interfaceDesc = &unionDes->interface;
interface->alternateSettingNumber = 0;
interface->epCount = 0;
interface->interfaceExtension = NULL;
interface->interfaceExtensionLength = 0;
interface->interfaceIndex = unionDes->interface.bInterfaceNumber;
interface->interfaceDesc = &unionDes->interface;
interface->alternateSettingNumber = 0U;
interface->epCount = 0U;
interface->interfaceExtension = NULL;
interface->interfaceExtensionLength = 0U;
interface->interfaceIndex = unionDes->interface.bInterfaceNumber;
/* search for endpoint descriptor start position */
unionDes = (usb_descriptor_union_t *)((uint32_t)unionDes + unionDes->common.bLength);
@ -770,7 +760,7 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter
}
/* parse endpoint descriptor */
if (interface->interfaceDesc->bNumEndpoints != 0)
if (interface->interfaceDesc->bNumEndpoints != 0U)
{
if ((unionDes->common.bDescriptorType != USB_DESCRIPTOR_TYPE_ENDPOINT) ||
(interface->interfaceDesc->bNumEndpoints > USB_HOST_CONFIG_INTERFACE_MAX_EP))
@ -790,11 +780,12 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter
#endif
return kStatus_USB_Error;
}
epParse = (usb_host_ep_t *)&interface->epList[interface->epCount];
epParse->epDesc = (usb_descriptor_endpoint_t *)unionDes;
epParse = (usb_host_ep_t *)&interface->epList[interface->epCount];
temp = (void *)unionDes;
epParse->epDesc = (usb_descriptor_endpoint_t *)temp;
epParse->epExtensionLength = 0;
epParse->epExtension = NULL;
unionDes = (usb_descriptor_union_t *)((uint32_t)unionDes + unionDes->common.bLength);
epParse->epExtension = NULL;
unionDes = (usb_descriptor_union_t *)((uint32_t)unionDes + unionDes->common.bLength);
while ((uint32_t)unionDes < endPosition)
{
if ((unionDes->common.bDescriptorType != USB_DESCRIPTOR_TYPE_ENDPOINT) &&
@ -820,7 +811,7 @@ usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle inter
void USB_HostGetVersion(uint32_t *version)
{
if (version)
if (NULL != version)
{
*version =
(uint32_t)USB_MAKE_VERSION(USB_STACK_VERSION_MAJOR, USB_STACK_VERSION_MINOR, USB_STACK_VERSION_BUGFIX);
@ -828,12 +819,12 @@ void USB_HostGetVersion(uint32_t *version)
}
#if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
/* Send BUS or specific device suepend request */
/* Send BUS or specific device suspend request */
usb_status_t USB_HostSuspendDeviceResquest(usb_host_handle hostHandle, usb_device_handle deviceHandle)
{
usb_host_instance_t *hostInstance;
usb_host_device_instance_t *deviceInstance;
usb_status_t status = kStatus_USB_Error;
usb_status_t status = kStatus_USB_Error;
usb_host_bus_control_t type = kUSB_HostBusSuspend;
if (hostHandle == NULL)
@ -849,6 +840,7 @@ usb_status_t USB_HostSuspendDeviceResquest(usb_host_handle hostHandle, usb_devic
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
status = USB_HostHubSuspendDevice(hostInstance);
#else
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl, &type);
#endif
@ -857,11 +849,12 @@ usb_status_t USB_HostSuspendDeviceResquest(usb_host_handle hostHandle, usb_devic
{
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
deviceInstance = (usb_host_device_instance_t *)deviceHandle;
if (0 == deviceInstance->hubNumber)
if (0U == deviceInstance->hubNumber)
{
#endif
if (hostInstance->deviceList == deviceHandle)
{
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle,
kUSB_HostBusControl, &type);
}
@ -888,7 +881,7 @@ usb_status_t USB_HostResumeDeviceResquest(usb_host_handle hostHandle, usb_device
{
usb_host_instance_t *hostInstance;
usb_host_device_instance_t *deviceInstance;
usb_status_t status = kStatus_USB_Error;
usb_status_t status = kStatus_USB_Error;
usb_host_bus_control_t type = kUSB_HostBusResume;
if (hostHandle == NULL)
@ -905,6 +898,7 @@ usb_status_t USB_HostResumeDeviceResquest(usb_host_handle hostHandle, usb_device
if (NULL == deviceHandle)
{
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl, &type);
}
@ -912,11 +906,12 @@ usb_status_t USB_HostResumeDeviceResquest(usb_host_handle hostHandle, usb_device
{
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
deviceInstance = (usb_host_device_instance_t *)deviceHandle;
if (0 == deviceInstance->hubNumber)
if (0U == deviceInstance->hubNumber)
{
#endif
if (hostInstance->deviceList == deviceHandle)
{
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle,
kUSB_HostBusControl, &type);
}
@ -935,13 +930,13 @@ usb_status_t USB_HostResumeDeviceResquest(usb_host_handle hostHandle, usb_device
return status;
}
#if ((defined(USB_HOST_CONFIG_LPM_L1)) && (USB_HOST_CONFIG_LPM_L1 > 0U))
/* Send BUS or specific device suepend request */
/* Send BUS or specific device suspend request */
usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle,
usb_device_handle deviceHandle,
uint8_t sleepType)
{
usb_host_instance_t *hostInstance;
usb_status_t status = kStatus_USB_Error;
usb_status_t status = kStatus_USB_Error;
usb_host_bus_control_t type = kUSB_HostBusL1Sleep;
if (hostHandle == NULL)
@ -955,8 +950,9 @@ usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle,
if (1U == sleepType)
{
/*#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))*/
/*To do, implete hub L1 suspend device*/
/*To do, incomplete hub L1 suspend device*/
/*#else*/
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl, &type);
/*#endif*/
@ -968,6 +964,7 @@ usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle,
#endif
if (hostInstance->deviceList == deviceHandle)
{
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl,
&type);
}
@ -978,7 +975,7 @@ usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle,
}
return status;
}
/* Send BUS or specific device suepend request */
/* Send BUS or specific device suspend request */
usb_status_t USB_HostL1SleepDeviceResquestConfig(usb_host_handle hostHandle, uint8_t *lpmParam)
{
usb_host_instance_t *hostInstance;
@ -989,7 +986,7 @@ usb_status_t USB_HostL1SleepDeviceResquestConfig(usb_host_handle hostHandle, uin
return kStatus_USB_InvalidHandle;
}
hostInstance = (usb_host_instance_t *)hostHandle;
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostL1Config, lpmParam);
@ -1003,7 +1000,7 @@ usb_status_t USB_HostL1ResumeDeviceResquest(usb_host_handle hostHandle,
{
usb_host_instance_t *hostInstance;
usb_status_t status = kStatus_USB_Error;
usb_status_t status = kStatus_USB_Error;
usb_host_bus_control_t type = kUSB_HostBusL1Resume;
if (hostHandle == NULL)
@ -1014,17 +1011,19 @@ usb_status_t USB_HostL1ResumeDeviceResquest(usb_host_handle hostHandle,
if (1U == sleepType)
{
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status =
hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl, &type);
}
else
{
#if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
/*To do, if device hub number is 0, need suspend the bus ,else suspend the corresponding device*/
/*To do, if device hub number is 0, need suspend the bus ,else suspend the corresponding device*/
#endif
if (hostInstance->deviceList == deviceHandle)
{
/* the callbackFn is initialized in USB_HostGetControllerInterface */
status = hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostBusControl,
&type);
}
@ -1050,3 +1049,18 @@ usb_status_t USB_HostUpdateHwTick(usb_host_handle hostHandle, uint64_t tick)
return status;
}
#endif
#if ((defined(USB_HOST_CONFIG_BATTERY_CHARGER)) && (USB_HOST_CONFIG_BATTERY_CHARGER > 0U))
usb_status_t USB_HostSetChargerType(usb_host_handle hostHandle, uint8_t type)
{
usb_host_instance_t *hostInstance;
if (hostHandle == NULL)
{
return kStatus_USB_InvalidHandle;
}
hostInstance = (usb_host_instance_t *)hostHandle;
return hostInstance->controllerTable->controllerIoctl(hostInstance->controllerHandle, kUSB_HostSetChargerType,
&type);
}
#endif

View File

@ -1,31 +1,9 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* Copyright 2016 - 2019 NXP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o 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.
*
* o Neither the name of the copyright holder 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 AND CONTRIBUTORS "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 OR CONTRIBUTORS 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.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _USB_HOST_HCI_H_
@ -36,9 +14,9 @@
******************************************************************************/
/*! @brief USB host lock */
#define USB_HostLock() USB_OsaMutexLock(hostInstance->hostMutex)
#define USB_HostLock() OSA_MutexLock(hostInstance->hostMutex, RT_WAITING_FOREVER)
/*! @brief USB host unlock */
#define USB_HostUnlock() USB_OsaMutexUnlock(hostInstance->hostMutex)
#define USB_HostUnlock() OSA_MutexUnlock(hostInstance->hostMutex)
/*!
* @addtogroup usb_host_controller_driver
@ -56,6 +34,10 @@ typedef enum _usb_host_controller_control
kUSB_HostPortAttachDisable, /*!< Disable the port attach event */
kUSB_HostPortAttachEnable, /*!< Enable the port attach event */
kUSB_HostL1Config, /*!< L1 suspend Bus control code */
kUSB_HostSetChargerType, /*!< set charger type */
#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
kUSB_HostTestModeInit, /*!< intialize charger type */
#endif
} usb_host_controller_control_t;
/*! @brief USB host controller bus control code */
@ -97,7 +79,9 @@ typedef struct _usb_host_controller_interface
uint32_t ioctlEvent,
void *ioctlParam); /*!< Control a controller function prototype*/
} usb_host_controller_interface_t;
#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
usb_status_t USB_HostTestModeInit(usb_device_handle deviceHandle);
#endif
/*! @}*/
/*!
@ -110,7 +94,8 @@ typedef struct _usb_host_instance
{
void *controllerHandle; /*!< The low level controller handle*/
host_callback_t deviceCallback; /*!< Device attach/detach callback*/
usb_osa_mutex_handle hostMutex; /*!< Host layer mutex*/
osa_mutex_handle_t hostMutex; /*!< Host layer mutex*/
uint32_t mutexBuffer[(OSA_MUTEX_HANDLE_SIZE + 3) / 4]; /*!< Host layer mutex*/
usb_host_transfer_t transferList[USB_HOST_CONFIG_MAX_TRANSFERS]; /*!< Transfer resource*/
usb_host_transfer_t *transferHead; /*!< Idle transfer head*/
const usb_host_controller_interface_t *controllerTable; /*!< KHCI/EHCI interface*/
@ -126,6 +111,7 @@ typedef struct _usb_host_instance
uint8_t controllerId; /*!< The controller ID*/
} usb_host_instance_t;
extern usb_host_instance_t g_UsbHostInstance[USB_HOST_CONFIG_MAX_HOST];
/*! @}*/
#endif /* _USB_HOST_HCI_H_ */