update version to v2.0.4

This commit is contained in:
Artery-MCU
2022-04-11 19:32:28 +08:00
parent 07d7347ba4
commit ccd0f1e108
1470 changed files with 213761 additions and 13939 deletions

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usb_core.h
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb core header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -31,12 +31,12 @@
#ifdef __cplusplus
extern "C" {
#endif
#include "usb_std.h"
#include "usb_conf.h"
#ifdef USE_OTG_DEVICE_MODE
#ifdef USE_OTG_DEVICE_MODE
#include "usbd_core.h"
#endif
#ifdef USE_OTG_HOST_MODE
@@ -46,7 +46,7 @@ extern "C" {
/** @addtogroup AT32F415_middlewares_usb_drivers
* @{
*/
/** @addtogroup USB_drivers_core
* @{
*/
@@ -74,7 +74,7 @@ typedef struct
uint8_t dma_en; /*!< dma enable state, not use*/
uint8_t hc_num; /*!< the otg host support number of channel */
uint8_t ept_num; /*!< the otg device support number of endpoint */
uint16_t max_size; /*!< support max packet size */
uint16_t fifo_size; /*!< the usb otg total file size */
uint8_t phy_itface; /*!< usb phy select */
@@ -82,7 +82,7 @@ typedef struct
uint8_t low_power; /*!< the usb otg low power option */
uint8_t sof_out; /*!< the sof signal output */
uint8_t usb_id; /*!< select otgfs1 or otgfs2 */
uint8_t vbusig; /*!< ignore vbus detection, only available in at32f415xx revision C.
at32f415xx revision B: (not support)
the vbus detection pin (pa9) can not be used for other functionality.
@@ -91,7 +91,7 @@ typedef struct
at32f415xx revision C: (support)
ignore vbus detection, the internal vbus is always valid.
the vbus pin (pa9) can be used for other functionality.
*/
*/
} usb_core_cfg;
/**
@@ -100,43 +100,43 @@ typedef struct
typedef struct
{
usb_reg_type *usb_reg; /*!< the usb otg register type */
#ifdef USE_OTG_DEVICE_MODE
#ifdef USE_OTG_DEVICE_MODE
usbd_core_type dev; /*!< the usb device core type */
#endif
#ifdef USE_OTG_HOST_MODE
#ifdef USE_OTG_HOST_MODE
usbh_core_type host; /*!< the usb host core type */
#endif
usb_core_cfg cfg; /*!< the usb otg core config type */
} otg_core_type;
usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id);
#ifdef USE_OTG_DEVICE_MODE
usb_sts_type usbd_init(otg_core_type *udev,
uint8_t core_id, uint8_t usb_id,
#ifdef USE_OTG_DEVICE_MODE
usb_sts_type usbd_init(otg_core_type *udev,
uint8_t core_id, uint8_t usb_id,
usbd_class_handler *class_handler,
usbd_desc_handler *desc_handler);
#endif
#ifdef USE_OTG_HOST_MODE
usb_sts_type usbh_init(otg_core_type *hdev,
uint8_t core_id, uint8_t usb_id,
#ifdef USE_OTG_HOST_MODE
usb_sts_type usbh_init(otg_core_type *hdev,
uint8_t core_id, uint8_t usb_id,
usbh_class_handler_type *class_handler,
usbh_user_handler_type *user_handler);
#endif
/**
* @}
*/
*/
/**
* @}
*/
/**
* @}
*/
*/
#ifdef __cplusplus
}
#endif

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usb_std.h
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb standard header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -39,7 +39,7 @@ extern "C" {
/** @addtogroup AT32F415_middlewares_usb_drivers
* @{
*/
/** @addtogroup USB_standard
* @{
*/
@@ -130,7 +130,7 @@ typedef enum
USB_CONN_STATE_ADDRESSED, /*!< usb device connect state address */
USB_CONN_STATE_CONFIGURED, /*!< usb device connect state configured */
USB_CONN_STATE_SUSPENDED /*!< usb device connect state suspend */
}usbd_conn_state;
}usbd_conn_state;
/**
* @brief endpoint 0 state
@@ -141,7 +141,7 @@ typedef enum
#define USB_EPT0_DATA_OUT 3 /*!< usb endpoint state data out */
#define USB_EPT0_STATUS_IN 4 /*!< usb endpoint state status in */
#define USB_EPT0_STATUS_OUT 5 /*!< usb endpoint state status out */
#define USB_EPT0_STALL 6 /*!< usb endpoint state stall */
#define USB_EPT0_STALL 6 /*!< usb endpoint state stall */
/**
* @brief usb descriptor length
@@ -209,7 +209,7 @@ typedef enum
/**
* @brief usb cdc class set line coding struct
*/
typedef struct
typedef struct
{
uint32_t bitrate; /* line coding baud rate */
uint8_t format; /* line coding foramt */
@@ -272,7 +272,7 @@ typedef enum
}usb_sts_type;
/**
/**
* @brief format of usb setup data
*/
typedef struct
@@ -280,12 +280,12 @@ typedef struct
uint8_t bmRequestType; /*!< characteristics of request */
uint8_t bRequest; /*!< specific request */
uint16_t wValue; /*!< word-sized field that varies according to request */
uint16_t wIndex; /*!< word-sized field that varies according to request
uint16_t wIndex; /*!< word-sized field that varies according to request
typically used to pass an index or offset */
uint16_t wLength; /*!< number of bytes to transfer if there is a data stage */
} usb_setup_type;
/**
/**
* @brief format of standard device descriptor
*/
typedef struct
@@ -306,28 +306,28 @@ typedef struct
uint8_t bNumConfigurations; /*!< number of possible configurations */
} usb_device_desc_type;
/**
/**
* @brief format of standard configuration descriptor
*/
typedef struct
{
uint8_t bLength; /*!< size of this descriptor in bytes */
uint8_t bDescriptorType; /*!< configuration descriptor type */
uint8_t bDescriptorType; /*!< configuration descriptor type */
uint16_t wTotalLength; /*!< total length of data returned for this configuration */
uint8_t bNumInterfaces; /*!< number of interfaces supported by this configuration */
uint8_t bConfigurationValue; /*!< value to use as an argument to the SetConfiguration() request */
uint8_t iConfiguration; /*!< index of string descriptor describing this configuration */
uint8_t bmAttributes; /*!< configuration characteristics
uint8_t bmAttributes; /*!< configuration characteristics
D7 reserved
D6 self-powered
D5 remote wakeup
D4~D0 reserved */
D4~D0 reserved */
uint8_t bMaxPower; /*!< maximum power consumption of the usb device from the bus */
}usb_configuration_desc_type;
/**
/**
* @brief format of standard interface descriptor
*/
typedef struct
@@ -336,14 +336,14 @@ typedef struct
uint8_t bDescriptorType; /*!< interface descriptor type */
uint8_t bInterfaceNumber; /*!< number of this interface */
uint8_t bAlternateSetting; /*!< value used to select this alternate setting for the interface */
uint8_t bNumEndpoints; /*!< number of endpoints used by this interface */
uint8_t bNumEndpoints; /*!< number of endpoints used by this interface */
uint8_t bInterfaceClass; /*!< class code (assigned by the usb-if) */
uint8_t bInterfaceSubClass; /*!< subclass code (assigned by the usb-if) */
uint8_t bInterfaceProtocol; /*!< protocol code (assigned by the usb-if) */
uint8_t iInterface; /*!< index of string descriptor describing this interface */
} usb_interface_desc_type;
/**
/**
* @brief format of standard endpoint descriptor
*/
typedef struct
@@ -353,10 +353,10 @@ typedef struct
uint8_t bEndpointAddress; /*!< the address of the endpoint on the usb device described by this descriptor */
uint8_t bmAttributes; /*!< describes the endpoints attributes when it is configured using bConfiguration value */
uint16_t wMaxPacketSize; /*!< maximum packet size this endpoint */
uint8_t bInterval; /*!< interval for polling endpoint for data transfers */
uint8_t bInterval; /*!< interval for polling endpoint for data transfers */
} usb_endpoint_desc_type;
/**
/**
* @brief format of header
*/
typedef struct
@@ -373,7 +373,7 @@ typedef struct
/**
* @}
*/
/**
* @}
*/

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usbd_core.h
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb device core header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -39,7 +39,7 @@ extern "C" {
/** @addtogroup AT32F415_middlewares_usbd_drivers
* @{
*/
/** @addtogroup USBD_drivers_core
* @{
*/
@@ -66,7 +66,7 @@ typedef enum
}usbd_event_type;
/**
* @brief usb device descriptor struct
* @brief usb device descriptor struct
*/
typedef struct
{
@@ -75,7 +75,7 @@ typedef struct
}usbd_desc_t;
/**
* @brief usb device descriptor handler
* @brief usb device descriptor handler
*/
typedef struct
{
@@ -114,23 +114,23 @@ typedef struct
typedef struct
{
usb_reg_type *usb_reg; /*!< usb register pointer */
usbd_class_handler *class_handler; /*!< usb device class handler pointer */
usbd_desc_handler *desc_handler; /*!< usb device descriptor handler pointer */
usb_ept_info ept_in[USB_EPT_MAX_NUM]; /*!< usb in endpoint infomation struct */
usb_ept_info ept_out[USB_EPT_MAX_NUM]; /*!< usb out endpoint infomation struct */
usb_setup_type setup; /*!< usb setup type struct */
uint8_t setup_buffer[12]; /*!< usb setup request buffer */
uint8_t ept0_sts; /*!< usb control endpoint 0 state */
uint8_t speed; /*!< usb speed */
uint16_t ept0_wlength; /*!< usb endpoint 0 transfer length */
usbd_conn_state conn_state; /*!< usb current connect state */
usbd_conn_state old_conn_state; /*!< usb save the previous connect state */
uint8_t device_addr; /*!< device address */
uint8_t remote_wakup; /*!< remote wakeup state */
uint8_t default_config; /*!< usb default config state */
@@ -162,20 +162,20 @@ void usbd_remote_wakeup(usbd_core_type *udev);
void usbd_enter_suspend(usbd_core_type *udev);
void usbd_flush_tx_fifo(usbd_core_type *udev, uint8_t ept_num);
void usbd_fifo_alloc(usbd_core_type *udev);
usb_sts_type usbd_core_init(usbd_core_type *udev,
usb_sts_type usbd_core_init(usbd_core_type *udev,
usb_reg_type *usb_reg,
usbd_class_handler *class_handler,
usbd_desc_handler *desc_handler,
usbd_desc_handler *desc_handler,
uint8_t core_id);
#endif
/**
* @}
*/
*/
/**
* @}
*/
*/
/**
* @}

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usbd_int.h
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb interrupt header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -35,7 +35,7 @@ extern "C" {
/** @addtogroup AT32F415_middlewares_usbd_drivers
* @{
*/
/** @addtogroup USBD_drivers_int
* @{
*/
@@ -64,11 +64,11 @@ void usb_write_empty_txfifo(usbd_core_type *udev, uint32_t ept_num);
/**
* @}
*/
*/
/**
* @}
*/
*/
/**
* @}

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usb_sdr.h
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -39,7 +39,7 @@ extern "C" {
/** @addtogroup AT32F415_middlewares_usbd_drivers
* @{
*/
/** @addtogroup USBD_drivers_standard_request
* @{
*/
@@ -57,11 +57,11 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev);
/**
* @}
*/
*/
/**
* @}
*/
*/
/**
* @}

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usbh_core.h
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb host core header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -38,7 +38,7 @@ extern "C" {
/** @addtogroup AT32F415_middlewares_usbh_drivers
* @{
*/
/** @addtogroup USBH_drivers_core
* @{
*/
@@ -234,7 +234,7 @@ typedef struct
/**
* @brief usb host control struct type
*/
typedef struct
typedef struct
{
uint8_t hch_in; /*!< in channel number */
uint8_t hch_out; /*!< out channel number */
@@ -285,24 +285,24 @@ typedef struct
typedef struct
{
usb_reg_type *usb_reg; /*!< usb register pointer */
uint8_t global_state; /*!< usb host global state machine */
uint8_t enum_state; /*!< usb host enumeration state machine */
uint8_t req_state; /*!< usb host request state machine */
usbh_dev_desc_type dev; /*!< usb device descriptor */
usbh_ctrl_type ctrl; /*!< usb host control transfer struct */
usbh_class_handler_type *class_handler; /*!< usb host class handler pointer */
usbh_user_handler_type *user_handler; /*!< usb host user handler pointer */
usb_hch_type hch[USB_HOST_CHANNEL_NUM]; /*!< usb host channel array */
uint8_t rx_buffer[USB_MAX_DATA_LENGTH]; /*!< usb host rx buffer */
uint32_t conn_sts; /*!< connect status */
uint32_t conn_sts; /*!< connect status */
uint32_t port_enable; /*!< port enable status */
uint32_t timer; /*!< sof timer */
uint32_t err_cnt[USB_HOST_CHANNEL_NUM]; /*!< error counter */
uint32_t xfer_cnt[USB_HOST_CHANNEL_NUM]; /*!< xfer counter */
hch_sts_type hch_state[USB_HOST_CHANNEL_NUM];/*!< channel state */
@@ -333,8 +333,8 @@ void usbh_resume(usbh_core_type *uhost);
uint16_t usbh_alloc_channel(usbh_core_type *uhost, uint8_t ept_addr);
urb_sts_type usbh_get_urb_status(usbh_core_type *uhost, uint8_t ch_num);
usb_sts_type usbh_ctrl_result_check(usbh_core_type *uhost,
ctrl_ept0_sts_type next_ctrl_state,
usb_sts_type usbh_ctrl_result_check(usbh_core_type *uhost,
ctrl_ept0_sts_type next_ctrl_state,
uint8_t next_enum_state);
uint8_t usbh_alloc_address(void);
void usbh_reset_port(usbh_core_type *uhost);
@@ -342,10 +342,10 @@ usb_sts_type usbh_loop_handler(usbh_core_type *uhost);
void usbh_ch_disable(usbh_core_type *uhost, uint8_t chn);
void usbh_hc_open(usbh_core_type *uhost,
uint8_t chn,
uint8_t ept_num,
uint8_t ept_num,
uint8_t dev_address,
uint8_t type,
uint16_t maxpacket,
uint8_t type,
uint16_t maxpacket,
uint8_t speed);
void usbh_active_vbus(usbh_core_type *uhost, confirm_state state);
@@ -359,11 +359,11 @@ usb_sts_type usbh_core_init(usbh_core_type *uhost,
/**
* @}
*/
*/
/**
* @}
*/
*/
/**
* @}

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usbh_ctrl.h
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -40,7 +40,7 @@ extern "C" {
/** @addtogroup AT32F415_middlewares_usbh_drivers
* @{
*/
/** @addtogroup USBH_drivers_control
* @{
*/
@@ -93,11 +93,11 @@ usb_sts_type usbh_clear_ept_feature(usbh_core_type *uhost, uint8_t ept_num, uint
/**
* @}
*/
*/
/**
* @}
*/
*/
/**
* @}

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usbh_int.h
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -35,7 +35,7 @@ extern "C" {
/** @addtogroup AT32F415_middlewares_usbh_drivers
* @{
*/
/** @addtogroup USBH_drivers_int
* @{
*/
@@ -59,11 +59,11 @@ void usbh_sof_handler(usbh_core_type *uhost);
/**
* @}
*/
*/
/**
* @}
*/
*/
/**
* @}

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usb_core.c
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb driver
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -28,11 +28,11 @@
/** @addtogroup AT32F415_middlewares_usb_drivers
* @{
*/
/** @defgroup USB_drivers_core
* @brief usb global drivers core
* @{
*/
*/
/** @defgroup USB_core_private_functions
* @{
@@ -41,24 +41,24 @@
usb_sts_type usb_core_config(otg_core_type *udev, uint8_t core_id);
/**
* @brief usb core config
* @brief usb core config
* @param otgdev: to the structure of otg_core_type
* @param core_id: usb core id number (USB_FULL_SPEED_CORE_ID)
* @retval usb_sts_type
*/
usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id)
usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id)
{
/* set usb speed and core id */
otgdev->cfg.speed = core_id;
otgdev->cfg.core_id = core_id;
/* default sof out and vbus ignore */
otgdev->cfg.sof_out = FALSE;
otgdev->cfg.vbusig = FALSE;
/* set max size */
otgdev->cfg.max_size = 64;
/* set support number of channel and endpoint */
#ifdef USE_OTG_HOST_MODE
otgdev->cfg.hc_num = USB_HOST_CHANNEL_NUM;
@@ -87,7 +87,7 @@ usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id)
* the vbus pin (pa9) can be used for other functionality.
*/
otgdev->cfg.vbusig = TRUE;
#endif
#endif
return USB_OK;
}
@@ -105,24 +105,24 @@ usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id)
* @param desc_handler: device config callback handler
* @retval usb_sts_type
*/
usb_sts_type usbd_init(otg_core_type *otgdev,
uint8_t core_id, uint8_t usb_id,
usb_sts_type usbd_init(otg_core_type *otgdev,
uint8_t core_id, uint8_t usb_id,
usbd_class_handler *class_handler,
usbd_desc_handler *desc_handler)
{
usb_sts_type usb_sts = USB_OK;
/* select use OTG1 or OTG2 */
otgdev->usb_reg = usb_global_select_core(usb_id);
/* usb device core config */
usb_core_config(otgdev, core_id);
if(otgdev->cfg.sof_out)
{
otgdev->usb_reg->gccfg_bit.sofouten = TRUE;
}
if(otgdev->cfg.vbusig)
{
/**
@@ -137,13 +137,13 @@ usb_sts_type usbd_init(otg_core_type *otgdev,
*/
otgdev->usb_reg->gccfg_bit.vbusig = TRUE;
}
/* usb device core init */
usbd_core_init(&(otgdev->dev), otgdev->usb_reg,
usbd_core_init(&(otgdev->dev), otgdev->usb_reg,
class_handler,
desc_handler,
desc_handler,
core_id);
return usb_sts;
}
#endif
@@ -162,8 +162,8 @@ usb_sts_type usbd_init(otg_core_type *otgdev,
* @param user_handler: user callback handler
* @retval usb_sts_type
*/
usb_sts_type usbh_init(otg_core_type *otgdev,
uint8_t core_id, uint8_t usb_id,
usb_sts_type usbh_init(otg_core_type *otgdev,
uint8_t core_id, uint8_t usb_id,
usbh_class_handler_type *class_handler,
usbh_user_handler_type *user_handler)
{
@@ -171,15 +171,15 @@ usb_sts_type usbh_init(otg_core_type *otgdev,
/* select use otg1 or otg2 */
otgdev->usb_reg = usb_global_select_core(usb_id);
/* usb core config */
usb_core_config(otgdev, core_id);
if(otgdev->cfg.sof_out)
{
otgdev->usb_reg->gccfg_bit.sofouten = TRUE;
}
if(otgdev->cfg.vbusig)
{
/**
@@ -194,25 +194,25 @@ usb_sts_type usbh_init(otg_core_type *otgdev,
*/
otgdev->usb_reg->gccfg_bit.vbusig = TRUE;
}
/* usb host core init */
usbh_core_init(&otgdev->host, otgdev->usb_reg,
class_handler,
user_handler,
core_id);
return status;
}
#endif
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
*/
/**
* @}
*/

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usbd_core.c
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb device driver
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -23,7 +23,7 @@
*
**************************************************************************
*/
#include "usb_core.h"
#include "usbd_core.h"
#include "usbd_sdr.h"
@@ -31,11 +31,11 @@
/** @addtogroup AT32F415_middlewares_usbd_drivers
* @{
*/
/** @defgroup USBD_drivers_core
* @brief usb device drivers core
* @{
*/
*/
/** @defgroup USBD_core_private_functions
* @{
@@ -51,20 +51,21 @@ void usbd_core_in_handler(usbd_core_type *udev, uint8_t ept_addr)
{
/* get endpoint info*/
usb_ept_info *ept_info = &udev->ept_in[ept_addr & 0x7F];
if(ept_addr == 0)
{
if(udev->ept0_sts == USB_EPT0_DATA_IN)
{
if(ept_info->ept0_slen > ept_info->maxpacket)
if(ept_info->rem0_len > ept_info->maxpacket)
{
ept_info->ept0_slen -= ept_info->maxpacket;
usbd_ept_send(udev, 0, ept_info->trans_buf,
MIN(ept_info->ept0_slen, ept_info->maxpacket));
ept_info->rem0_len -= ept_info->maxpacket;
usbd_ept_send(udev, 0, ept_info->trans_buf,
MIN(ept_info->rem0_len, ept_info->maxpacket));
}
/* endpoint 0 */
else if(ept_info->last_len == ept_info->maxpacket
&& ept_info->ept0_slen <= udev->ept0_wlength)
&& ept_info->ept0_slen >= ept_info->maxpacket
&& ept_info->ept0_slen < udev->ept0_wlength)
{
ept_info->last_len = 0;
usbd_ept_send(udev, 0, 0, 0);
@@ -72,16 +73,18 @@ void usbd_core_in_handler(usbd_core_type *udev, uint8_t ept_addr)
}
else
{
if(udev->class_handler->ept0_tx_handler != 0 &&
if(udev->class_handler->ept0_tx_handler != 0 &&
udev->conn_state == USB_CONN_STATE_CONFIGURED)
{
udev->class_handler->ept0_tx_handler(udev);
}
usbd_ctrl_recv_status(udev);
{
udev->class_handler->ept0_tx_handler(udev);
}
usbd_ctrl_recv_status(udev);
}
}
}
else if(udev->class_handler->in_handler != 0 &&
else if(udev->class_handler->in_handler != 0 &&
udev->conn_state == USB_CONN_STATE_CONFIGURED)
{
/* other user define endpoint */
@@ -99,17 +102,17 @@ void usbd_core_out_handler(usbd_core_type *udev, uint8_t ept_addr)
{
/* get endpoint info*/
usb_ept_info *ept_info = &udev->ept_out[ept_addr & 0x7F];
if(ept_addr == 0)
{
/* endpoint 0 */
if(udev->ept0_sts == USB_EPT0_DATA_OUT)
{
if(ept_info->ept0_slen > ept_info->maxpacket)
if(ept_info->rem0_len > ept_info->maxpacket)
{
ept_info->ept0_slen -= ept_info->maxpacket;
usbd_ept_recv(udev, ept_addr, ept_info->trans_buf,
MIN(ept_info->ept0_slen, ept_info->maxpacket));
ept_info->rem0_len -= ept_info->maxpacket;
usbd_ept_recv(udev, ept_addr, ept_info->trans_buf,
MIN(ept_info->rem0_len, ept_info->maxpacket));
}
else
{
@@ -121,7 +124,7 @@ void usbd_core_out_handler(usbd_core_type *udev, uint8_t ept_addr)
}
}
}
else if(udev->class_handler->out_handler != 0 &&
else if(udev->class_handler->out_handler != 0 &&
udev->conn_state == USB_CONN_STATE_CONFIGURED)
{
/* other user define endpoint */
@@ -139,11 +142,11 @@ void usbd_core_setup_handler(usbd_core_type *udev, uint8_t ept_num)
{
/* setup parse */
usbd_setup_request_parse(&udev->setup, udev->setup_buffer);
/* set ept0 status */
udev->ept0_sts = USB_EPT0_SETUP;
udev->ept0_wlength = udev->setup.wLength;
switch(udev->setup.bmRequestType & USB_REQ_RECIPIENT_MASK)
{
case USB_REQ_RECIPIENT_DEVICE:
@@ -174,10 +177,11 @@ void usbd_core_setup_handler(usbd_core_type *udev, uint8_t ept_num)
void usbd_ctrl_send(usbd_core_type *udev, uint8_t *buffer, uint16_t len)
{
usb_ept_info *ept_info = &udev->ept_in[0];
ept_info->ept0_slen = len;
ept_info->rem0_len = len;
udev->ept0_sts = USB_EPT0_DATA_IN;
usbd_ept_send(udev, 0, buffer, len);
}
@@ -194,8 +198,9 @@ void usbd_ctrl_recv(usbd_core_type *udev, uint8_t *buffer, uint16_t len)
usb_ept_info *ept_info = &udev->ept_out[0];
ept_info->ept0_slen = len;
ept_info->rem0_len = len;
udev->ept0_sts = USB_EPT0_DATA_OUT;
usbd_ept_recv(udev, 0, buffer, len);
}
@@ -207,7 +212,7 @@ void usbd_ctrl_recv(usbd_core_type *udev, uint8_t *buffer, uint16_t len)
void usbd_ctrl_send_status(usbd_core_type *udev)
{
udev->ept0_sts = USB_EPT0_STATUS_IN;
usbd_ept_send(udev, 0, 0, 0);
}
@@ -219,7 +224,7 @@ void usbd_ctrl_send_status(usbd_core_type *udev)
void usbd_ctrl_recv_status(usbd_core_type *udev)
{
udev->ept0_sts = USB_EPT0_STATUS_OUT;
usbd_ept_recv(udev, 0, 0, 0);
}
@@ -233,8 +238,8 @@ void usbd_clear_stall(usbd_core_type *udev, uint8_t ept_addr)
{
usb_ept_info *ept_info;
usb_reg_type *usbx = udev->usb_reg;
if(ept_addr & 0x80)
if(ept_addr & 0x80)
{
/* in endpoint */
ept_info = &udev->ept_in[ept_addr & 0x7F];
@@ -270,7 +275,7 @@ void usbd_set_stall(usbd_core_type *udev, uint8_t ept_addr)
ept_info = &udev->ept_out[ept_addr & 0x7F];
}
usb_ept_stall(usbx, ept_info);
ept_info->stall = 1;
}
@@ -310,7 +315,7 @@ void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uin
{
usb_reg_type *usbx = udev->usb_reg;
usb_ept_info *ept_info;
if((ept_addr & 0x80) == 0)
{
/* out endpoint info */
@@ -323,11 +328,11 @@ void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uin
ept_info = &udev->ept_in[ept_addr & 0x7F];
ept_info->inout = EPT_DIR_IN;
}
/* set endpoint maxpacket and type */
ept_info->maxpacket = maxpacket;
ept_info->trans_type = ept_type;
/* open endpoint */
usb_ept_open(usbx, ept_info);
}
@@ -340,7 +345,7 @@ void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uin
*/
void usbd_ept_close(usbd_core_type *udev, uint8_t ept_addr)
{
usb_ept_info *ept_info;
usb_ept_info *ept_info;
if(ept_addr & 0x80)
{
/* in endpoint */
@@ -351,7 +356,7 @@ void usbd_ept_close(usbd_core_type *udev, uint8_t ept_addr)
/* out endpoint */
ept_info = &udev->ept_out[ept_addr & 0x7F];
}
/* close endpoint */
usb_ept_close(udev->usb_reg, ept_info);
}
@@ -405,7 +410,7 @@ void usb_ept_default_init(usbd_core_type *udev)
udev->ept_in[i_index].trans_buf = 0;
udev->ept_in[i_index].total_len = 0;
}
/* init out endpoint info structure */
for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++)
{
@@ -434,12 +439,12 @@ void usbd_ept_send(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint
otg_eptin_type *ept_in = USB_INEPT(usbx, ept_info->eptn);
otg_device_type *dev = OTG_DEVICE(usbx);
uint32_t pktcnt;
/* set send data buffer and length */
ept_info->trans_buf = buffer;
ept_info->total_len = len;
ept_info->trans_len = 0;
/* transfer data len is zero */
if(ept_info->total_len == 0)
{
@@ -455,35 +460,35 @@ void usbd_ept_send(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint
{
ept_info->total_len = ept_info->maxpacket;
}
/* set transfer size */
ept_in->dieptsiz_bit.xfersize = ept_info->total_len;
/* set packet count */
ept_in->dieptsiz_bit.pktcnt = 1;
ept_info->last_len = ept_info->total_len;
}
else
{
{
/* other endpoint */
/* packet count */
pktcnt = (ept_info->total_len + ept_info->maxpacket - 1) / ept_info->maxpacket;
/* set transfer size */
ept_in->dieptsiz_bit.xfersize = ept_info->total_len;
/* set packet count */
ept_in->dieptsiz_bit.pktcnt = pktcnt;
if(ept_info->trans_type == EPT_ISO_TYPE)
{
ept_in->dieptsiz_bit.mc = 1;
}
}
}
if(ept_info->trans_type != EPT_ISO_TYPE)
{
if(ept_info->total_len > 0)
@@ -492,7 +497,7 @@ void usbd_ept_send(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint
dev->diepempmsk |= 1 << ept_info->eptn;
}
}
if(ept_info->trans_type == EPT_ISO_TYPE)
{
if((dev->dsts_bit.soffn & 0x1) == 0)
@@ -504,18 +509,18 @@ void usbd_ept_send(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint
ept_in->diepctl_bit.setd0pid = TRUE;
}
}
/* clear endpoint nak */
ept_in->diepctl_bit.cnak = TRUE;
/* endpoint enable */
ept_in->diepctl_bit.eptena = TRUE;
if(ept_info->trans_type == EPT_ISO_TYPE)
{
/* write data to fifo */
usb_write_packet(usbx, ept_info->trans_buf, ept_info->eptn, ept_info->total_len);
}
usb_write_packet(usbx, ept_info->trans_buf, ept_info->eptn, ept_info->total_len);
}
}
/**
@@ -534,37 +539,37 @@ void usbd_ept_recv(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint
otg_eptout_type *ept_out = USB_OUTEPT(usbx, ept_info->eptn);
otg_device_type *dev = OTG_DEVICE(usbx);
uint32_t pktcnt;
/* set receive data buffer and length */
ept_info->trans_buf = buffer;
ept_info->total_len = len;
ept_info->trans_len = 0;
if((ept_addr & 0x7F) == 0)
{
/* endpoint 0 */
ept_info->total_len = ept_info->maxpacket;
}
if(ept_info->total_len == 0 || ((ept_addr & 0x7F) == 0))
{
/* set transfer size */
ept_out->doeptsiz_bit.xfersize = ept_info->maxpacket;
/* set packet count */
ept_out->doeptsiz_bit.pktcnt = 1;
}
else
{
pktcnt = (ept_info->total_len + ept_info->maxpacket - 1) / ept_info->maxpacket;
/* set transfer size */
ept_out->doeptsiz_bit.xfersize = ept_info->maxpacket * pktcnt;
/* set packet count */
ept_out->doeptsiz_bit.pktcnt = pktcnt;
}
if(ept_info->trans_type == EPT_ISO_TYPE)
{
if((dev->dsts_bit.soffn & 0x01) == 0)
@@ -576,10 +581,10 @@ void usbd_ept_recv(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint
ept_out->doepctl_bit.setd0pid = TRUE;
}
}
/* clear endpoint nak */
ept_out->doepctl_bit.cnak = TRUE;
/* endpoint enable */
ept_out->doepctl_bit.eptena = TRUE;
}
@@ -603,19 +608,19 @@ void usbd_remote_wakeup(usbd_core_type *udev)
{
/* check device is in suspend mode */
if(usb_suspend_status_get(udev->usb_reg) == 1)
{
{
/* set connect state */
udev->conn_state = udev->old_conn_state;
/* open phy clock */
usb_open_phy_clk(udev->usb_reg);
/* set remote wakeup */
usb_remote_wkup_set(udev->usb_reg);
/* delay 10 ms */
usb_delay_ms(10);
/* clear remote wakup */
usb_remote_wkup_clear(udev->usb_reg);
}
@@ -656,35 +661,35 @@ void usbd_flush_tx_fifo(usbd_core_type *udev, uint8_t ept_num)
void usbd_fifo_alloc(usbd_core_type *udev)
{
usb_reg_type *usbx = udev->usb_reg;
if(usbx == OTG1_GLOBAL)
{
/* set receive fifo size */
usb_set_rx_fifo(usbx, USBD_RX_SIZE);
/* set endpoint0 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT0, USBD_EP0_TX_SIZE);
/* set endpoint1 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT1, USBD_EP1_TX_SIZE);
/* set endpoint2 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT2, USBD_EP2_TX_SIZE);
/* set endpoint3 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT3, USBD_EP3_TX_SIZE);
#if (USB_EPT_MAX_NUM == 8)
#if (USB_EPT_MAX_NUM == 8)
if(USB_EPT_MAX_NUM == 8)
{
/* set endpoint4 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT4, USBD_EP4_TX_SIZE);
/* set endpoint5 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT5, USBD_EP5_TX_SIZE);
/* set endpoint6 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT6, USBD_EP6_TX_SIZE);
/* set endpoint7 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT7, USBD_EP7_TX_SIZE);
}
@@ -695,30 +700,30 @@ void usbd_fifo_alloc(usbd_core_type *udev)
{
/* set receive fifo size */
usb_set_rx_fifo(usbx, USBD2_RX_SIZE);
/* set endpoint0 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT0, USBD2_EP0_TX_SIZE);
/* set endpoint1 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT1, USBD2_EP1_TX_SIZE);
/* set endpoint2 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT2, USBD2_EP2_TX_SIZE);
/* set endpoint3 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT3, USBD2_EP3_TX_SIZE);
if(USB_EPT_MAX_NUM == 8)
{
/* set endpoint4 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT4, USBD2_EP4_TX_SIZE);
/* set endpoint5 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT5, USBD2_EP5_TX_SIZE);
/* set endpoint6 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT6, USBD2_EP6_TX_SIZE);
/* set endpoint7 tx fifo size */
usb_set_tx_fifo(usbx, USB_EPT7, USBD2_EP7_TX_SIZE);
}
@@ -737,10 +742,10 @@ void usbd_fifo_alloc(usbd_core_type *udev)
* @param core_id: usb core id number
* @retval usb_sts_type
*/
usb_sts_type usbd_core_init(usbd_core_type *udev,
usb_sts_type usbd_core_init(usbd_core_type *udev,
usb_reg_type *usb_reg,
usbd_class_handler *class_handler,
usbd_desc_handler *desc_handler,
usbd_desc_handler *desc_handler,
uint8_t core_id)
{
usb_reg_type *usbx;
@@ -748,63 +753,63 @@ usb_sts_type usbd_core_init(usbd_core_type *udev,
otg_eptin_type *ept_in;
otg_eptout_type *ept_out;
uint32_t i_index;
udev->usb_reg = usb_reg;
usbx = usb_reg;
dev = OTG_DEVICE(usbx);
/* set connect state */
udev->conn_state = USB_CONN_STATE_DEFAULT;
/* device class config */
udev->device_addr = 0;
udev->class_handler = class_handler;
udev->desc_handler = desc_handler;
/* set device disconnect */
usbd_disconnect(udev);
/* set endpoint to default status */
usb_ept_default_init(udev);
/* disable usb global interrupt */
usb_interrupt_disable(usbx);
/* init global register */
usb_global_init(usbx);
/* set device mode */
usb_global_set_mode(usbx, OTG_DEVICE_MODE);
/* open phy clock */
usb_open_phy_clk(udev->usb_reg);
/* set periodic frame interval */
dev->dcfg_bit.perfrint = DCFG_PERFRINT_80;
/* set device speed to full-speed */
dev->dcfg_bit.devspd = USB_DCFG_FULL_SPEED;
/* flush all tx fifo */
usb_flush_tx_fifo(usbx, 16);
/* flush share rx fifo */
usb_flush_rx_fifo(usbx);
/* clear all endpoint interrupt flag and mask */
dev->daint = 0xFFFFFFFF;
dev->daintmsk = 0;
dev->diepmsk = 0;
dev->doepmsk = 0;
for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++)
{
usbx->dieptxfn[i_index] = 0;
}
/* endpoint fifo alloc */
usbd_fifo_alloc(udev);
/* disable all in endpoint */
for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++)
{
@@ -822,7 +827,7 @@ usb_sts_type usbd_core_init(usbd_core_type *udev,
ept_in->dieptsiz = 0;
ept_in->diepint = 0xFF;
}
/* disable all out endpoint */
for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++)
{
@@ -841,32 +846,32 @@ usb_sts_type usbd_core_init(usbd_core_type *udev,
ept_out->doepint = 0xFF;
}
dev->diepmsk_bit.txfifoudrmsk = TRUE;
/* clear global interrupt and mask */
usbx->gintmsk = 0;
usbx->gintsts = 0xBFFFFFFF;
/* enable global interrupt mask */
usbx->gintmsk = USB_OTG_SOF_INT | USB_OTG_RXFLVL_INT |
USB_OTG_USBSUSP_INT | USB_OTG_USBRST_INT |
USB_OTG_ENUMDONE_INT | USB_OTG_IEPT_INT |
USB_OTG_OEPT_INT | USB_OTG_INCOMISOIN_INT |
usbx->gintmsk = USB_OTG_SOF_INT | USB_OTG_RXFLVL_INT |
USB_OTG_USBSUSP_INT | USB_OTG_USBRST_INT |
USB_OTG_ENUMDONE_INT | USB_OTG_IEPT_INT |
USB_OTG_OEPT_INT | USB_OTG_INCOMISOIN_INT |
USB_OTG_INCOMPIP_INCOMPISOOUT_INT | USB_OTG_WKUP_INT |
USB_OTG_OTGINT_INT;
/* usb connect */
usbd_connect(udev);
usbd_connect(udev);
/* enable global interrupt */
usb_interrupt_enable(usbx);
return USB_OK;
}
/**
* @}
*/
*/
/**
* @}

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usbd_int.c
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb interrupt request
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -28,11 +28,11 @@
/** @addtogroup AT32F415_middlewares_usbd_drivers
* @{
*/
/** @defgroup USBD_drivers_interrupt
* @brief usb device interrupt
* @{
*/
*/
/** @defgroup USBD_int_private_functions
* @{
@@ -48,7 +48,7 @@ void usbd_irq_handler(otg_core_type *otgdev)
otg_global_type *usbx = otgdev->usb_reg;
usbd_core_type *udev = &otgdev->dev;
uint32_t intsts = usb_global_get_all_interrupt(usbx);
/* check current device mode */
if(usbx->gintsts_bit.curmode == 0)
{
@@ -57,54 +57,54 @@ void usbd_irq_handler(otg_core_type *otgdev)
{
usb_global_clear_interrupt(usbx, USB_OTG_MODEMIS_FLAG);
}
/* in endpoint interrupt */
if(intsts & USB_OTG_IEPT_FLAG)
{
usbd_inept_handler(udev);
}
/* out endpoint interrupt */
if(intsts & USB_OTG_OEPT_FLAG)
{
usbd_outept_handler(udev);
}
/* usb reset interrupt */
if(intsts & USB_OTG_USBRST_FLAG)
{
usbd_reset_handler(udev);
usb_global_clear_interrupt(usbx, USB_OTG_USBRST_FLAG);
}
/* sof interrupt */
if(intsts & USB_OTG_SOF_FLAG)
{
usbd_sof_handler(udev);
usb_global_clear_interrupt(usbx, USB_OTG_SOF_FLAG);
usb_global_clear_interrupt(usbx, USB_OTG_SOF_FLAG);
}
/* enumeration done interrupt */
if(intsts & USB_OTG_ENUMDONE_FLAG)
{
usbd_enumdone_handler(udev);
usb_global_clear_interrupt(usbx, USB_OTG_ENUMDONE_FLAG);
}
/* rx non-empty interrupt, indicates that there is at least one
data packet pending to be read in rx fifo */
if(intsts & USB_OTG_RXFLVL_FLAG)
{
usbd_rxflvl_handler(udev);
}
/* incomplete isochronous in transfer interrupt */
if(intsts & USB_OTG_INCOMISOIN_FLAG)
{
usbd_incomisioin_handler(udev);
usb_global_clear_interrupt(usbx, USB_OTG_INCOMISOIN_FLAG);
}
#ifndef USB_VBUS_IGNORE
#ifndef USB_VBUS_IGNORE
/* disconnect detected interrupt */
if(intsts & USB_OTG_OTGINT_FLAG)
{
@@ -114,21 +114,21 @@ void usbd_irq_handler(otg_core_type *otgdev)
udev->usb_reg->gotgint = tmp;
usb_global_clear_interrupt(usbx, USB_OTG_OTGINT_FLAG);
}
#endif
#endif
/* incomplete isochronous out transfer interrupt */
if(intsts & USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG)
{
usbd_incomisoout_handler(udev);
usb_global_clear_interrupt(usbx, USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG);
}
/* resume/remote wakeup interrupt */
if(intsts & USB_OTG_WKUP_FLAG)
{
usbd_wakeup_handler(udev);
usb_global_clear_interrupt(usbx, USB_OTG_WKUP_FLAG);
}
/* usb suspend interrupt */
if(intsts & USB_OTG_USBSUSP_FLAG)
{
@@ -150,14 +150,14 @@ void usb_write_empty_txfifo(usbd_core_type *udev, uint32_t ept_num)
usb_ept_info *ept_info = &udev->ept_in[ept_num];
uint32_t length = ept_info->total_len - ept_info->trans_len;
uint32_t wlen = 0;
if(length > ept_info->maxpacket)
{
length = ept_info->maxpacket;
}
wlen = (length + 3) / 4;
while((USB_INEPT(usbx, ept_num)->dtxfsts & USB_OTG_DTXFSTS_INEPTFSAV) > wlen &&
while((USB_INEPT(usbx, ept_num)->dtxfsts & USB_OTG_DTXFSTS_INEPTFSAV) > wlen &&
(ept_info->trans_len < ept_info->total_len) && (ept_info->total_len != 0))
{
length = ept_info->total_len - ept_info->trans_len;
@@ -167,10 +167,10 @@ void usb_write_empty_txfifo(usbd_core_type *udev, uint32_t ept_num)
}
wlen = (length + 3) / 4;
usb_write_packet(usbx, ept_info->trans_buf, ept_num, length);
ept_info->trans_buf += length;
ept_info->trans_len += length;
}
if(length <= 0)
{
@@ -189,7 +189,7 @@ void usbd_inept_handler(usbd_core_type *udev)
otg_global_type *usbx = udev->usb_reg;
uint32_t ept_num = 0, ept_int;
uint32_t intsts;
/*get all endpoint interrut */
intsts = usb_get_all_in_interrupt(usbx);
while(intsts)
@@ -198,7 +198,7 @@ void usbd_inept_handler(usbd_core_type *udev)
{
/* get endpoint interrupt flag */
ept_int = usb_ept_in_interrupt(usbx, ept_num);
/* transfer completed interrupt */
if(ept_int & USB_OTG_DIEPINT_XFERC_FLAG)
{
@@ -206,31 +206,31 @@ void usbd_inept_handler(usbd_core_type *udev)
usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_XFERC_FLAG);
usbd_core_in_handler(udev, ept_num);
}
/* timeout condition interrupt */
if(ept_int & USB_OTG_DIEPINT_TIMEOUT_FLAG)
{
usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_TIMEOUT_FLAG);
}
/* in token received when tx fifo is empty */
if(ept_int & USB_OTG_DIEPINT_INTKNTXFEMP_FLAG)
{
usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_INTKNTXFEMP_FLAG);
}
/* in endpoint nak effective */
if(ept_int & USB_OTG_DIEPINT_INEPTNAK_FLAG)
{
usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_INEPTNAK_FLAG);
}
/* endpoint disable interrupt */
if(ept_int & USB_OTG_DIEPINT_EPTDISD_FLAG)
{
usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_EPTDISD_FLAG);
}
/* transmit fifo empty interrupt */
if(ept_int & USB_OTG_DIEPINT_TXFEMP_FLAG)
{
@@ -252,24 +252,24 @@ void usbd_outept_handler(usbd_core_type *udev)
otg_global_type *usbx = udev->usb_reg;
uint32_t ept_num = 0, ept_int;
uint32_t intsts;
/* get all out endpoint interrupt */
intsts = usb_get_all_out_interrupt(usbx);
while(intsts)
{
if(intsts & 0x1)
{
/* get out endpoint interrupt */
ept_int = usb_ept_out_interrupt(usbx, ept_num);
/* transfer completed interrupt */
if(ept_int & USB_OTG_DOEPINT_XFERC_FLAG)
{
usb_ept_out_clear(usbx, ept_num , USB_OTG_DOEPINT_XFERC_FLAG);
usbd_core_out_handler(udev, ept_num);
}
/* setup phase done interrupt */
if(ept_int & USB_OTG_DOEPINT_SETUP_FLAG)
{
@@ -281,7 +281,7 @@ void usbd_outept_handler(usbd_core_type *udev)
udev->device_addr = 0;
}
}
/* endpoint disable interrupt */
if(ept_int & USB_OTG_DOEPINT_OUTTEPD_FLAG)
{
@@ -301,20 +301,20 @@ void usbd_outept_handler(usbd_core_type *udev)
void usbd_enumdone_handler(usbd_core_type *udev)
{
otg_global_type *usbx = udev->usb_reg;
usb_ept0_setup(usbx);
usbx->gusbcfg_bit.usbtrdtim = USB_TRDTIM_16;
/* open endpoint 0 out */
usbd_ept_open(udev, 0x00, EPT_CONTROL_TYPE, 0x40);
/* open endpoint 0 in */
usbd_ept_open(udev, 0x80, EPT_CONTROL_TYPE, 0x40);
/* usb connect state set to default */
udev->conn_state = USB_CONN_STATE_DEFAULT;
/* clear callback */
if(udev->class_handler->clear_handler != 0)
udev->class_handler->clear_handler(udev);
@@ -331,23 +331,23 @@ void usbd_rxflvl_handler(usbd_core_type *udev)
uint32_t stsp;
uint32_t count;
uint32_t pktsts;
usb_ept_info *ept_info;
usb_ept_info *ept_info;
/* disable rxflvl interrupt */
usb_global_interrupt_enable(usbx, USB_OTG_RXFLVL_INT, FALSE);
/* get rx status */
stsp = usbx->grxstsp;
/*get the byte count of receive */
count = (stsp & USB_OTG_GRXSTSP_BCNT) >> 4;
/* get packet status */
pktsts = (stsp &USB_OTG_GRXSTSP_PKTSTS) >> 17;
/* get endpoint infomation struct */
ept_info = &udev->ept_out[stsp & USB_OTG_GRXSTSP_EPTNUM];
/* received out data packet */
if(pktsts == USB_OUT_STS_DATA)
{
@@ -357,7 +357,7 @@ void usbd_rxflvl_handler(usbd_core_type *udev)
usb_read_packet(usbx, ept_info->trans_buf, (stsp & USB_OTG_GRXSTSP_EPTNUM), count);
ept_info->trans_buf += count;
ept_info->trans_len += count;
}
}
/* setup data received */
@@ -367,10 +367,10 @@ void usbd_rxflvl_handler(usbd_core_type *udev)
usb_read_packet(usbx, udev->setup_buffer, (stsp & USB_OTG_GRXSTSP_EPTNUM), count);
ept_info->trans_len += count;
}
/* enable rxflvl interrupt */
usb_global_interrupt_enable(usbx, USB_OTG_RXFLVL_INT, TRUE);
}
/**
@@ -418,48 +418,48 @@ void usbd_reset_handler(usbd_core_type *udev)
otg_global_type *usbx = udev->usb_reg;
otg_device_type *dev = OTG_DEVICE(usbx);
uint32_t i_index = 0;
/* disable remote wakeup singal */
dev->dctl_bit.rwkupsig = FALSE;
/* endpoint fifo alloc */
usbd_fifo_alloc(udev);
/* flush all tx fifo */
usb_flush_tx_fifo(usbx, 0x10);
/* clear in and out endpoint interrupt flag */
for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++)
{
USB_INEPT(usbx, i_index)->diepint = 0xFF;
USB_OUTEPT(usbx, i_index)->doepint = 0xFF;
}
/* clear endpoint flag */
dev->daint = 0xFFFFFFFF;
/*clear endpoint interrupt mask */
dev->daintmsk = 0x10001;
/* enable out endpoint xfer, eptdis, setup interrupt mask */
dev->doepmsk_bit.xfercmsk = TRUE;
dev->doepmsk_bit.eptdismsk = TRUE;
dev->doepmsk_bit.setupmsk = TRUE;
/* enable in endpoint xfer, eptdis, timeout interrupt mask */
dev->diepmsk_bit.xfercmsk = TRUE;
dev->diepmsk_bit.eptdismsk = TRUE;
dev->diepmsk_bit.timeoutmsk = TRUE;
/* set device address to 0 */
usb_set_address(usbx, 0);
/* enable endpoint 0 */
usb_ept0_start(usbx);
/* usb connect state set to default */
udev->conn_state = USB_CONN_STATE_DEFAULT;
/* user define reset event */
if(udev->class_handler->event_handler)
udev->class_handler->event_handler(udev, USBD_RESET_EVENT);
@@ -485,18 +485,18 @@ void usbd_sof_handler(usbd_core_type *udev)
void usbd_suspend_handler(usbd_core_type *udev)
{
otg_global_type *usbx = udev->usb_reg;
if(OTG_DEVICE(usbx)->dsts_bit.suspsts)
{
{
/* save connect state */
udev->old_conn_state = udev->conn_state;
/* set current state to suspend */
udev->conn_state = USB_CONN_STATE_SUSPENDED;
/* enter suspend mode */
usbd_enter_suspend(udev);
/* user suspend handler */
if(udev->class_handler->event_handler != 0)
udev->class_handler->event_handler(udev, USBD_SUSPEND_EVENT);
@@ -511,23 +511,23 @@ void usbd_suspend_handler(usbd_core_type *udev)
void usbd_wakeup_handler(usbd_core_type *udev)
{
otg_global_type *usbx = udev->usb_reg;
/* clear remote wakeup bit */
OTG_DEVICE(usbx)->dctl_bit.rwkupsig = FALSE;
/* exit suspend mode */
usb_open_phy_clk(udev->usb_reg);
/* restore connect state */
udev->conn_state = udev->old_conn_state;
/* user suspend handler */
if(udev->class_handler->event_handler != 0)
udev->class_handler->event_handler(udev, USBD_WAKEUP_EVENT);
}
/**
* @}
*/
*/
/**
* @}
@@ -535,4 +535,4 @@ void usbd_wakeup_handler(usbd_core_type *udev)
/**
* @}
*/
*/

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usbd_sdr.c
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb standard device request
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -28,11 +28,11 @@
/** @addtogroup AT32F415_middlewares_usbd_drivers
* @{
*/
/** @defgroup USBD_drivers_standard_request
* @brief usb device standard_request
* @{
*/
*/
/** @defgroup USBD_sdr_private_functions
* @{
@@ -50,7 +50,7 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev);
* @brief usb parse standard setup request
* @param setup: setup structure
* @param buf: setup buffer
* @retval none
* @retval none
*/
void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf)
{
@@ -64,7 +64,7 @@ void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf)
/**
* @brief get usb standard device description request
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
* @retval status of usb_sts_type
*/
static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
{
@@ -104,7 +104,7 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
desc = udev->desc_handler->get_device_interface_string();
break;
default:
usbd_ctrl_unsupport(udev);
udev->class_handler->setup_handler(udev, &udev->setup);
return ret;
}
break;
@@ -119,7 +119,7 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
usbd_ctrl_unsupport(udev);
return ret;
}
if(desc != NULL)
{
if((desc->length != 0) && (udev->setup.wLength != 0))
@@ -134,22 +134,22 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
/**
* @brief this request sets the device address
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
* @retval status of usb_sts_type
*/
static usb_sts_type usbd_set_address(usbd_core_type *udev)
{
usb_sts_type ret = USB_OK;
usb_setup_type *setup = &udev->setup;
uint8_t dev_addr;
/* if wIndex or wLength are non-zero, then the behavior of
the device is not specified
*/
if(setup->wIndex == 0 && setup->wLength == 0)
{
dev_addr = (uint8_t)(setup->wValue) & 0x7f;
/* device behavior when this request is received
/* device behavior when this request is received
while the device is in the configured state is not specified.*/
if(udev->conn_state == USB_CONN_STATE_CONFIGURED )
{
@@ -158,7 +158,7 @@ static usb_sts_type usbd_set_address(usbd_core_type *udev)
else
{
udev->device_addr = dev_addr;
if(dev_addr != 0)
{
udev->conn_state = USB_CONN_STATE_ADDRESSED;
@@ -180,7 +180,7 @@ static usb_sts_type usbd_set_address(usbd_core_type *udev)
/**
* @brief get usb status request
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
* @retval status of usb_sts_type
*/
static usb_sts_type usbd_get_status(usbd_core_type *udev)
{
@@ -205,7 +205,7 @@ static usb_sts_type usbd_get_status(usbd_core_type *udev)
/**
* @brief clear usb feature request
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
* @retval status of usb_sts_type
*/
static usb_sts_type usbd_clear_feature(usbd_core_type *udev)
{
@@ -233,7 +233,7 @@ static usb_sts_type usbd_clear_feature(usbd_core_type *udev)
/**
* @brief set usb feature request
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
* @retval status of usb_sts_type
*/
static usb_sts_type usbd_set_feature(usbd_core_type *udev)
{
@@ -251,7 +251,7 @@ static usb_sts_type usbd_set_feature(usbd_core_type *udev)
/**
* @brief get usb configuration request
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
* @retval status of usb_sts_type
*/
static usb_sts_type usbd_get_configuration(usbd_core_type *udev)
{
@@ -283,7 +283,7 @@ static usb_sts_type usbd_get_configuration(usbd_core_type *udev)
/**
* @brief sets the usb device configuration request
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
* @retval status of usb_sts_type
*/
static usb_sts_type usbd_set_configuration(usbd_core_type *udev)
{
@@ -291,7 +291,7 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev)
static uint8_t config_value;
usb_setup_type *setup = &udev->setup;
config_value = (uint8_t)setup->wValue;
if(setup->wIndex == 0 && setup->wLength == 0)
{
switch(udev->conn_state)
@@ -308,7 +308,7 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev)
{
usbd_ctrl_send_status(udev);
}
break;
case USB_CONN_STATE_CONFIGURED:
if(config_value == 0)
@@ -316,11 +316,11 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev)
udev->conn_state = USB_CONN_STATE_ADDRESSED;
udev->dev_config = config_value;
udev->class_handler->clear_handler(udev);
usbd_ctrl_send_status(udev);
usbd_ctrl_send_status(udev);
}
else if(config_value == udev->dev_config)
{
udev->class_handler->clear_handler(udev);
udev->class_handler->clear_handler(udev);
udev->dev_config = config_value;
udev->class_handler->init_handler(udev);
usbd_ctrl_send_status(udev);
@@ -345,7 +345,7 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev)
/**
* @brief standard usb device requests
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
* @retval status of usb_sts_type
*/
usb_sts_type usbd_device_request(usbd_core_type *udev)
{
@@ -389,7 +389,7 @@ usb_sts_type usbd_device_request(usbd_core_type *udev)
/**
* @brief standard usb interface requests
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
* @retval status of usb_sts_type
*/
usb_sts_type usbd_interface_request(usbd_core_type *udev)
{
@@ -414,7 +414,7 @@ usb_sts_type usbd_interface_request(usbd_core_type *udev)
/**
* @brief standard usb endpoint requests
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
* @retval status of usb_sts_type
*/
usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
{
@@ -422,7 +422,7 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
usb_setup_type *setup = &udev->setup;
uint8_t ept_addr = LBYTE(setup->wIndex);
usb_ept_info *ept_info;
if((setup->bmRequestType & USB_REQ_TYPE_RESERVED) == USB_REQ_TYPE_CLASS)
{
udev->class_handler->setup_handler(udev, &udev->setup);
@@ -442,11 +442,11 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
{
if((ept_addr & 0x80) != 0)
{
ept_info = &udev->ept_in[ept_addr & 0x7F];
ept_info = &udev->ept_in[ept_addr & 0x7F];
}
else
{
ept_info = &udev->ept_out[ept_addr & 0x7F];
ept_info = &udev->ept_out[ept_addr & 0x7F];
}
if(ept_info->stall == 1)
{
@@ -504,7 +504,7 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
if((ept_addr != 0x00) && (ept_addr != 0x80))
{
usbd_set_stall(udev, ept_addr);
}
}
}
udev->class_handler->setup_handler(udev, &udev->setup);
usbd_ctrl_send_status(udev);
@@ -522,7 +522,7 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
}
/**
* @}
*/
*/
/**
* @}

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usbh_core.c
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb host driver
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -31,16 +31,16 @@
/** @addtogroup AT32F415_middlewares_usbh_drivers
* @{
*/
/** @defgroup USBH_drivers_core
* @brief usb host drivers core
* @{
*/
*/
/** @defgroup USBH_core_private_functions
* @{
*/
static void usbh_attached(usbh_core_type *uhost);
static void usbh_enumeration(usbh_core_type *uhost);
static void usbh_class_request(usbh_core_type *uhost);
@@ -51,7 +51,7 @@ static void usbh_disconnect(usbh_core_type *uhost);
/**
* @brief usb host free channel
* @param uhost: to the structure of usbh_core_type
* @param index: channle number
* @param index: channle number
* @retval none
*/
void usbh_free_channel(usbh_core_type *uhost, uint8_t index)
@@ -120,13 +120,14 @@ usb_sts_type usbh_in_out_request(usbh_core_type *uhost, uint8_t hc_num)
uint32_t tmp;
otg_global_type *usbx = uhost->usb_reg;
otg_hchannel_type *ch = USB_CHL(uhost->usb_reg, hc_num);
/* set usb request block to idle */
uhost->urb_state[hc_num] = URB_IDLE;
uhost->hch[hc_num].state = HCH_IDLE;
/* set usb channel transmit count to zero */
uhost->hch[hc_num].trans_count = 0;
/* check transmit data len */
if(uhost->hch[hc_num].trans_len > 0)
{
@@ -134,7 +135,7 @@ usb_sts_type usbh_in_out_request(usbh_core_type *uhost, uint8_t hc_num)
n_packet = (uhost->hch[hc_num].trans_len + \
uhost->hch[hc_num].maxpacket - 1) / \
uhost->hch[hc_num].maxpacket;
/* packet count max 256 */
if(n_packet > 256)
{
@@ -147,29 +148,29 @@ usb_sts_type usbh_in_out_request(usbh_core_type *uhost, uint8_t hc_num)
/* zero data len */
n_packet = 1;
}
/* direction is in */
if(uhost->hch[hc_num].dir)
{
uhost->hch[hc_num].trans_len = n_packet * uhost->hch[hc_num].maxpacket;
}
/* set transfer information to channel register */
ch->hctsiz = (uhost->hch[hc_num].trans_len & USB_OTG_HCTSIZ_XFERSIZE) |
((n_packet << 19) & USB_OTG_HCTSIZ_PKTCNT) |
((uhost->hch[hc_num].data_pid << 29) & USB_OTG_HCTSIZ_PID);
/* set odd frame */
ch->hcchar_bit.oddfrm = !(OTG_HOST(uhost->usb_reg)->hfnum & 0x1);
/* clear channel disable bit and enable channel */
tmp = ch->hcchar;
tmp &= ~(USB_OTG_HCCHAR_CHDIS);
tmp |= USB_OTG_HCCHAR_CHENA;
ch->hcchar = tmp;
/* channel direction is out and transfer len > 0 */
if((uhost->hch[hc_num].dir == 0) &&
if((uhost->hch[hc_num].dir == 0) &&
(uhost->hch[hc_num].trans_len > 0 ))
{
switch(uhost->hch[hc_num].ept_type)
@@ -177,8 +178,8 @@ usb_sts_type usbh_in_out_request(usbh_core_type *uhost, uint8_t hc_num)
case EPT_CONTROL_TYPE:
case EPT_BULK_TYPE:
num_words = (uhost->hch[hc_num].trans_len + 3) / 4;
/* non-periodic transfer */
/* non-periodic transfer */
if(num_words > usbx->gnptxsts_bit.nptxfspcavail)
{
usbx->gintmsk_bit.nptxfempmsk = 1;
@@ -187,21 +188,21 @@ usb_sts_type usbh_in_out_request(usbh_core_type *uhost, uint8_t hc_num)
case EPT_ISO_TYPE:
case EPT_INT_TYPE:
num_words = (uhost->hch[hc_num].trans_len + 3) / 4;
/* periodic transfer */
/* periodic transfer */
if(num_words > OTG_HOST(usbx)->hptxsts_bit.ptxfspcavil)
{
usbx->gintmsk_bit.nptxfempmsk = 1;
usbx->gintmsk_bit.ptxfempmsk = 1;
}
break;
default:
break;
}
/* write data to fifo */
usb_write_packet(usbx, uhost->hch[hc_num].trans_buf,
usb_write_packet(usbx, uhost->hch[hc_num].trans_buf,
hc_num, uhost->hch[hc_num].trans_len);
}
return status;
}
@@ -218,13 +219,13 @@ usb_sts_type usbh_interrupt_recv(usbh_core_type *uhost, uint8_t hc_num,
{
/* set direction is in */
uhost->hch[hc_num].dir = 1;
/* set transfer buffer */
uhost->hch[hc_num].trans_buf = buffer;
/* set transfer len*/
uhost->hch[hc_num].trans_len = length;
if(uhost->hch[hc_num].toggle_in == 0)
{
/* pid: data0 */
@@ -235,7 +236,7 @@ usb_sts_type usbh_interrupt_recv(usbh_core_type *uhost, uint8_t hc_num,
/* pid: data1 */
uhost->hch[hc_num].data_pid = HCH_PID_DATA1;
}
return usbh_in_out_request(uhost, hc_num);
}
@@ -252,13 +253,13 @@ usb_sts_type usbh_interrupt_send(usbh_core_type *uhost, uint8_t hc_num,
{
/* set direction is out */
uhost->hch[hc_num].dir = 0;
/* set transfer buffer */
uhost->hch[hc_num].trans_buf = buffer;
/* set transfer len*/
uhost->hch[hc_num].trans_len = length;
if(uhost->hch[hc_num].toggle_out == 0)
{
/* pid: data0 */
@@ -269,7 +270,7 @@ usb_sts_type usbh_interrupt_send(usbh_core_type *uhost, uint8_t hc_num,
/* pid: data1 */
uhost->hch[hc_num].data_pid = HCH_PID_DATA1;
}
return usbh_in_out_request(uhost, hc_num);
}
@@ -287,13 +288,13 @@ usb_sts_type usbh_bulk_recv(usbh_core_type *uhost, uint8_t hc_num,
{
/* set direction is in */
uhost->hch[hc_num].dir = 1;
/* set transfer buffer */
uhost->hch[hc_num].trans_buf = buffer;
/* set transfer len*/
uhost->hch[hc_num].trans_len = length;
if(uhost->hch[hc_num].toggle_in == 0)
{
/* pid: data0 */
@@ -304,7 +305,7 @@ usb_sts_type usbh_bulk_recv(usbh_core_type *uhost, uint8_t hc_num,
/* pid: data1 */
uhost->hch[hc_num].data_pid = HCH_PID_DATA1;
}
return usbh_in_out_request(uhost, hc_num);
}
@@ -322,13 +323,13 @@ usb_sts_type usbh_bulk_send(usbh_core_type *uhost, uint8_t hc_num,
{
/* set direction is out */
uhost->hch[hc_num].dir = 0;
/* set transfer buffer */
uhost->hch[hc_num].trans_buf = buffer;
/* set transfer len*/
uhost->hch[hc_num].trans_len = length;
if(uhost->hch[hc_num].toggle_out == 0)
{
/* pid: data0 */
@@ -339,7 +340,7 @@ usb_sts_type usbh_bulk_send(usbh_core_type *uhost, uint8_t hc_num,
/* pid: data1 */
uhost->hch[hc_num].data_pid = HCH_PID_DATA1;
}
return usbh_in_out_request(uhost, hc_num);
}
@@ -357,16 +358,16 @@ usb_sts_type usbh_isoc_send(usbh_core_type *uhost, uint8_t hc_num,
{
/* set direction is out */
uhost->hch[hc_num].dir = 0;
/* set transfer buffer */
uhost->hch[hc_num].trans_buf = buffer;
/* set transfer len*/
uhost->hch[hc_num].trans_len = length;
/* pid: data0 */
uhost->hch[hc_num].data_pid = HCH_PID_DATA0;
return usbh_in_out_request(uhost, hc_num);
}
@@ -383,19 +384,19 @@ usb_sts_type usbh_isoc_recv(usbh_core_type *uhost, uint8_t hc_num,
{
/* set direction is in */
uhost->hch[hc_num].dir = 1;
/* set transfer buffer */
uhost->hch[hc_num].trans_buf = buffer;
/* set transfer len*/
uhost->hch[hc_num].trans_len = length;
/* pid: data0 */
uhost->hch[hc_num].data_pid = HCH_PID_DATA0;
return usbh_in_out_request(uhost, hc_num);
}
/**
* @brief usb host cfg default init
* @param uhost: to the structure of usbh_core_type
@@ -405,29 +406,29 @@ usb_sts_type usbh_cfg_default_init(usbh_core_type *uhost)
{
/* set global state to idle */
uhost->global_state = USBH_IDLE;
/* enumeration state to get description */
uhost->enum_state = ENUM_GET_MIN_DESC;
/* request state send */
uhost->req_state = CMD_SEND;
/* control transfer state is idle*/
uhost->ctrl.state = CONTROL_IDLE;
/* defaut endpoint 0 max size is 8byte */
uhost->ctrl.ept0_size = 8;
/* default device address is 0 */
uhost->dev.address = 0;
/* default speed is full speed */
uhost->dev.speed = USB_FULL_SPEED_CORE_ID;
uhost->timer = 0;
uhost->ctrl.err_cnt = 0;
/* free all channel */
usbh_free_channel(uhost, uhost->ctrl.hch_in);
usbh_free_channel(uhost, uhost->ctrl.hch_out);
@@ -443,16 +444,16 @@ void usbh_enter_suspend(usbh_core_type *uhost)
{
otg_host_type *host = OTG_HOST(uhost->usb_reg);
uint32_t hprt_val = host->hprt;
hprt_val &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
hprt_val &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET);
/* set port suspend */
host->hprt = hprt_val | USB_OTG_HPRT_PRTSUSP;
/* stop phy clock */
usb_stop_phy_clk(uhost->usb_reg);
}
/**
@@ -464,22 +465,22 @@ void usbh_resume(usbh_core_type *uhost)
{
otg_host_type *host = OTG_HOST(uhost->usb_reg);
uint32_t temp = host->hprt;
/* open phy clock */
usb_open_phy_clk(uhost->usb_reg);
/* clear port suspend and set port resume*/
temp &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
temp &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET
| USB_OTG_HPRT_PRTSUSP);
host->hprt = temp | USB_OTG_HPRT_PRTRES;
/* delay 20 ms */
usb_delay_ms(20);
/*clear port resume */
temp = host->hprt;
temp &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
temp &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET
| USB_OTG_HPRT_PRTRES);
host->hprt = temp;
@@ -508,58 +509,58 @@ usb_sts_type usbh_core_init(usbh_core_type *uhost,
otg_global_type *usbx = usb_reg;
otg_host_type *host = OTG_HOST(usbx);
uhost->usb_reg = usb_reg;
/* host class handler */
uhost->class_handler = class_handler;
uhost->user_handler = user_handler;
/* host user handler */
uhost->user_handler->user_init();
uhost->timer = 0;
/* usb host cfg default init */
usbh_cfg_default_init(uhost);
/* clear host config to default value */
for(i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++)
{
uhost->err_cnt[i_index] = 0;
uhost->xfer_cnt[i_index] = 0;
uhost->hch_state[i_index] = HCH_IDLE;
uhost->hch[0].maxpacket = 8;
uhost->hch[0].maxpacket = 8;
}
/* no device connect */
uhost->conn_sts = 0;
/* disable usb interrupt */
usb_interrupt_disable(usbx);
/* usb global init */
usb_global_init(usbx);
/* set usb host mode */
usb_global_set_mode(usbx, OTG_HOST_MODE);
/* open usb phy clock*/
usb_open_phy_clk(usbx);
/* clock select */
usbh_fsls_clksel(usbx, USB_HCFG_CLK_48M);
/* set support ls and fs device */
host->hcfg_bit.fslssupp = 0;
/* set receive fifo size */
usbx->grxfsiz = USBH_RX_FIFO_SIZE;
if(usbx == OTG1_GLOBAL)
{
/* set non-periodic transmit fifo start address and depth */
usbx->gnptxfsiz_ept0tx_bit.nptxfstaddr = USBH_RX_FIFO_SIZE;
usbx->gnptxfsiz_ept0tx_bit.nptxfdep = USBH_NP_TX_FIFO_SIZE;
/* set periodic transmit fifo start address and depth */
usbx->hptxfsiz_bit.ptxfstaddr = USBH_RX_FIFO_SIZE + USBH_NP_TX_FIFO_SIZE;
usbx->hptxfsiz_bit.ptxfsize = USBH_P_TX_FIFO_SIZE;
@@ -570,7 +571,7 @@ usb_sts_type usbh_core_init(usbh_core_type *uhost,
/* set non-periodic transmit fifo start address and depth */
usbx->gnptxfsiz_ept0tx_bit.nptxfstaddr = USBH2_RX_FIFO_SIZE;
usbx->gnptxfsiz_ept0tx_bit.nptxfdep = USBH2_NP_TX_FIFO_SIZE;
/* set periodic transmit fifo start address and depth */
usbx->hptxfsiz_bit.ptxfstaddr = USBH2_RX_FIFO_SIZE + USBH2_NP_TX_FIFO_SIZE;
usbx->hptxfsiz_bit.ptxfsize = USBH2_P_TX_FIFO_SIZE;
@@ -578,34 +579,34 @@ usb_sts_type usbh_core_init(usbh_core_type *uhost,
#endif
/* flush tx fifo */
usb_flush_tx_fifo(usbx, 16);
/* flush rx fifo */
usb_flush_rx_fifo(usbx);
/* clear host channel interrut mask and status */
for(i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++)
{
USB_CHL(usbx, i_index)->hcintmsk = 0;
USB_CHL(usbx, i_index)->hcint = 0xFFFFFFFF;
}
/* power on to this port */
usb_port_power_on(usbx, TRUE);
/* clear global interrupt mask and status */
usbx->gintmsk = 0;
usbx->gintsts = 0xBFFFFFFF;
/* set global interrut mask */
usbx->gintmsk = USB_OTG_SOF_INT | USB_OTG_RXFLVL_INT |
USB_OTG_USBSUSP_INT | USB_OTG_PRT_INT |
USB_OTG_HCH_INT | USB_OTG_INCOMISOIN_INT |
USB_OTG_INCOMPIP_INCOMPISOOUT_INT | USB_OTG_WKUP_INT |
usbx->gintmsk = USB_OTG_SOF_INT | USB_OTG_RXFLVL_INT |
USB_OTG_USBSUSP_INT | USB_OTG_PRT_INT |
USB_OTG_HCH_INT | USB_OTG_INCOMISOIN_INT |
USB_OTG_INCOMPIP_INCOMPISOOUT_INT | USB_OTG_WKUP_INT |
USB_OTG_DISCON_INT;
/* enable usb global interrupt */
usb_interrupt_enable(usbx);
/* active vbus */
usbh_active_vbus(uhost, TRUE);
return status;
@@ -618,14 +619,14 @@ usb_sts_type usbh_core_init(usbh_core_type *uhost,
* @param ept_num: devvice endpoint number
* @param dev_address: device address
* @param type: channel transfer type
* this parameter can be one of the following values:
* this parameter can be one of the following values:
* - EPT_CONTROL_TYPE
* - EPT_BULK_TYPE
* - EPT_INT_TYPE
* - EPT_ISO_TYPE
* @param maxpacket: support max packe size for this channel
* @param speed: device speed
* this parameter can be one of the following values:
* this parameter can be one of the following values:
* - USB_PRTSPD_FULL_SPEED
* - USB_PRTSPD_LOW_SPEED
* @param ept_addr: endpoint address
@@ -633,33 +634,33 @@ usb_sts_type usbh_core_init(usbh_core_type *uhost,
*/
void usbh_hc_open(usbh_core_type *uhost,
uint8_t chn,
uint8_t ept_num,
uint8_t ept_num,
uint8_t dev_address,
uint8_t type,
uint16_t maxpacket,
uint8_t type,
uint16_t maxpacket,
uint8_t speed)
{
/* device address */
uhost->hch[chn].address = dev_address;
/* device speed */
uhost->hch[chn].speed = speed;
/* endpoint transfer type */
uhost->hch[chn].ept_type = type;
/* endpoint support maxpacket */
uhost->hch[chn].maxpacket = maxpacket;
/* endpoint direction in or out */
uhost->hch[chn].dir = (ept_num & 0x80)?1:0;;
/* host channel number */
uhost->hch[chn].ch_num = chn;
/* device endpoint number */
uhost->hch[chn].ept_num = ept_num;
/* enable channel */
usb_hc_enable(uhost->usb_reg, chn,
ept_num, dev_address,
@@ -671,10 +672,10 @@ void usbh_hc_open(usbh_core_type *uhost,
* @brief disable host channel
* @param usbx: to select the otgfs peripheral.
* this parameter can be one of the following values:
* - OTG1_GLOBAL
* - OTG1_GLOBAL
* - OTG2_GLOBAL
* @param chn: channel number
* @retval none
* @retval none
*/
void usbh_ch_disable(usbh_core_type *uhost, uint8_t chn)
{
@@ -691,10 +692,10 @@ uint16_t usbh_alloc_channel(usbh_core_type *uhost, uint8_t ept_addr)
{
/* get one free channel */
uint16_t ch_num = usbh_get_free_channel(uhost);
if(ch_num == HCH_ERROR)
return USB_FAIL;
/* set channel to used */
uhost->channel[ch_num] = HCH_USED | ept_addr;
return ch_num;
@@ -711,7 +712,7 @@ urb_sts_type usbh_get_urb_status(usbh_core_type *uhost, uint8_t ch_num)
return uhost->urb_state[ch_num];
}
/**
* @brief usb wait control setup complete
* @brief usb wait control setup complete
* @param uhost: to the structure of usbh_core_type
* @param next_ctrl_state: next ctrl state when setup complete
* @param next_enum_state: next enum state when setup complete
@@ -720,10 +721,10 @@ urb_sts_type usbh_get_urb_status(usbh_core_type *uhost, uint8_t ch_num)
usb_sts_type usbh_ctrl_result_check(usbh_core_type *uhost, ctrl_ept0_sts_type next_ctrl_state, uint8_t next_enum_state)
{
usb_sts_type status;
/* control transfer loop */
status = usbh_ctrl_transfer_loop(uhost);
if(status == USB_OK)
{
uhost->ctrl.state = next_ctrl_state;
@@ -745,7 +746,7 @@ usb_sts_type usbh_ctrl_result_check(usbh_core_type *uhost, ctrl_ept0_sts_type ne
}
/**
* @brief auto alloc address (1...20)
* @brief auto alloc address (1...20)
* @param none
* @retval address (1...20)
*/
@@ -779,24 +780,24 @@ usb_sts_type usbh_enum_handler(usbh_core_type *uhost)
if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_FULL_DESC) == USB_OK)
{
usbh_parse_dev_desc(uhost, uhost->rx_buffer, 8);
/* set new control endpoint maxpacket size */
uhost->ctrl.ept0_size = (uhost->dev).dev_desc.bMaxPacketSize0;
/* enable channel */
usbh_hc_open(uhost, uhost->ctrl.hch_in,0x80,
uhost->dev.address, EPT_CONTROL_TYPE,
uhost->ctrl.ept0_size,
uhost->ctrl.ept0_size,
uhost->dev.speed);
/* enable channel */
usbh_hc_open(uhost, uhost->ctrl.hch_out,0x00,
uhost->dev.address, EPT_CONTROL_TYPE,
uhost->ctrl.ept0_size,
uhost->ctrl.ept0_size,
uhost->dev.speed);
}
break;
case ENUM_GET_FULL_DESC:
/* get description */
if(uhost->ctrl.state == CONTROL_IDLE)
@@ -810,102 +811,102 @@ usb_sts_type usbh_enum_handler(usbh_core_type *uhost)
USBH_DEBUG("PID: %xh", uhost->dev.dev_desc.idProduct);
}
break;
case ENUM_SET_ADDR:
/* set device address */
if(uhost->ctrl.state == CONTROL_IDLE)
{
uhost->dev.address = usbh_alloc_address();
USBH_DEBUG("Set Address: %d", uhost->dev.address);
usbh_set_address(uhost, uhost->dev.address);
usbh_set_address(uhost, uhost->dev.address);
}
if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_CFG) == USB_OK)
{
/* enable channel */
usbh_hc_open(uhost, uhost->ctrl.hch_in,0x80,
uhost->dev.address, EPT_CONTROL_TYPE,
uhost->ctrl.ept0_size,
uhost->ctrl.ept0_size,
uhost->dev.speed);
/* enable channel */
usbh_hc_open(uhost, uhost->ctrl.hch_out,0x00,
uhost->dev.address, EPT_CONTROL_TYPE,
uhost->ctrl.ept0_size,
uhost->ctrl.ept0_size,
uhost->dev.speed);
}
break;
case ENUM_GET_CFG:
/* get device confiuration */
if(uhost->ctrl.state == CONTROL_IDLE)
{
usbh_get_configure_descriptor(uhost, 9);
}
if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_FULL_CFG) == USB_OK)
{
usbh_parse_configure_desc(uhost, uhost->rx_buffer, 9);
}
break;
case ENUM_GET_FULL_CFG:
/* get device confiuration */
if(uhost->ctrl.state == CONTROL_IDLE)
{
usbh_get_configure_descriptor(uhost, uhost->dev.cfg_desc.cfg.wTotalLength);
}
if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_MFC_STRING) == USB_OK)
{
usbh_parse_configure_desc(uhost, uhost->rx_buffer, uhost->dev.cfg_desc.cfg.wTotalLength);
}
break;
case ENUM_GET_MFC_STRING:
/* get device mfc string */
if(uhost->ctrl.state == CONTROL_IDLE)
{
usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iManufacturer,
usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iManufacturer,
uhost->rx_buffer, 0xFF);
}
if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_PRODUCT_STRING) == USB_OK)
{
usbh_parse_string_desc(uhost->rx_buffer, uhost->rx_buffer, 0xFF);
uhost->user_handler->user_mfc_string(uhost->rx_buffer);
}
break;
case ENUM_GET_PRODUCT_STRING:
/* get device product string */
if(uhost->ctrl.state == CONTROL_IDLE)
{
usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iProduct,
usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iProduct,
uhost->rx_buffer, 0xFF);
}
if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_SERIALNUM_STRING) == USB_OK)
{
usbh_parse_string_desc(uhost->rx_buffer, uhost->rx_buffer, 0xFF);
uhost->user_handler->user_product_string(uhost->rx_buffer);
}
break;
case ENUM_GET_SERIALNUM_STRING:
/* get device serial string */
if(uhost->ctrl.state == CONTROL_IDLE)
{
usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iSerialNumber,
usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iSerialNumber,
uhost->rx_buffer, 0xFF);
}
if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_SET_CONFIG) == USB_OK)
{
usbh_parse_string_desc(uhost->rx_buffer, uhost->rx_buffer, 0xFF);
uhost->user_handler->user_serial_string(uhost->rx_buffer);
}
break;
case ENUM_SET_CONFIG:
/* set device config */
if(uhost->ctrl.state == CONTROL_IDLE)
@@ -913,9 +914,9 @@ usb_sts_type usbh_enum_handler(usbh_core_type *uhost)
usbh_set_configuration(uhost, uhost->dev.cfg_desc.cfg.bConfigurationValue);
}
usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_COMPLETE);
break;
case ENUM_COMPLETE:
/* enum complete */
status = USB_OK;
@@ -940,26 +941,26 @@ void usbh_active_vbus(usbh_core_type *uhost, confirm_state state)
/**
* @brief reset usb port
* @param usbx: to the structure of otg_global_type
* @retval none
* @retval none
*/
void usbh_reset_port(usbh_core_type *uhost)
{
otg_host_type *usb_host = OTG_HOST(uhost->usb_reg);
uint32_t hprt_val = usb_host->hprt;
hprt_val &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
hprt_val &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET);
/* set port reset */
usb_host->hprt = hprt_val | USB_OTG_HPRT_PRTRST;
usb_delay_ms(100);
/* clear port reset */
usb_host->hprt = hprt_val & (~USB_OTG_HPRT_PRTRST);
usb_delay_ms(20);
}
/**
@@ -972,31 +973,31 @@ static void usbh_attached(usbh_core_type *uhost)
/* get free channel */
uhost->ctrl.hch_in = usbh_alloc_channel(uhost, 0x80);
uhost->ctrl.hch_out = usbh_alloc_channel(uhost, 0x00);
/* user reset callback handler */
uhost->user_handler->user_reset();
/* get device speed */
uhost->dev.speed = OTG_HOST(uhost->usb_reg)->hprt_bit.prtspd;
uhost->global_state = USBH_ENUMERATION;
uhost->user_handler->user_speed(uhost->dev.speed);
/* enable channel */
usbh_hc_open(uhost, uhost->ctrl.hch_in,0x80,
uhost->dev.address, EPT_CONTROL_TYPE,
uhost->ctrl.ept0_size,
uhost->ctrl.ept0_size,
uhost->dev.speed);
/* enable channel */
usbh_hc_open(uhost, uhost->ctrl.hch_out,0x00,
uhost->dev.address, EPT_CONTROL_TYPE,
uhost->ctrl.ept0_size,
uhost->ctrl.ept0_size,
uhost->dev.speed);
usb_flush_tx_fifo(uhost->usb_reg, 0x10);
usb_flush_rx_fifo(uhost->usb_reg);
/* user attached callback */
/* user attached callback */
uhost->user_handler->user_attached();
}
@@ -1025,7 +1026,7 @@ static void usbh_enumeration(usbh_core_type *uhost)
static void usbh_class_request(usbh_core_type *uhost)
{
usb_sts_type status;
/* class request callback */
status = uhost->class_handler->request_handler((void *)uhost);
if(status == USB_OK)
@@ -1073,7 +1074,7 @@ static void usbh_suspend(usbh_core_type *uhost)
usb_delay_ms(3);
usbh_enter_suspend(uhost);
uhost->global_state = USBH_SUSPENDED;
}
}
@@ -1106,25 +1107,25 @@ static void usbh_wakeup(usbh_core_type *uhost)
static void usbh_disconnect(usbh_core_type *uhost)
{
uint8_t i_index = 0;
/* set host to default state */
usbh_cfg_default_init(uhost);
/* free host channel */
for(i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++)
{
usbh_free_channel(uhost, i_index);
}
/* call class reset handler */
if(uhost->class_handler->reset_handler != NULL)
{
uhost->class_handler->reset_handler(uhost);
}
/* set global state to idle */
uhost->global_state = USBH_IDLE;
/*call user disconnect function */
uhost->user_handler->user_disconnect();
}
@@ -1138,9 +1139,9 @@ static void usbh_disconnect(usbh_core_type *uhost)
usb_sts_type usbh_loop_handler(usbh_core_type *uhost)
{
usb_sts_type status = USB_FAIL;
if(uhost->conn_sts == 0 &&
uhost->global_state != USBH_IDLE &&
if(uhost->conn_sts == 0 &&
uhost->global_state != USBH_IDLE &&
uhost->global_state != USBH_DISCONNECT)
{
uhost->global_state = USBH_IDLE;
@@ -1151,18 +1152,18 @@ usb_sts_type usbh_loop_handler(usbh_core_type *uhost)
if(uhost->conn_sts == 1)
{
uhost->global_state = USBH_PORT_EN;
/* wait stable */
usb_delay_ms(200);
/* port reset */
usbh_reset_port(uhost);
/* user reset */
uhost->user_handler->user_reset();
}
break;
case USBH_PORT_EN:
if(uhost->port_enable)
{
@@ -1170,15 +1171,15 @@ usb_sts_type usbh_loop_handler(usbh_core_type *uhost)
usb_delay_ms(50);
}
break;
case USBH_ATTACHED:
usbh_attached(uhost);
break;
case USBH_ENUMERATION:
usbh_enumeration(uhost);
break;
case USBH_USER_HANDLER:
uhost->global_state = USBH_CLASS_REQUEST;
if( uhost->class_handler->init_handler(uhost) == USB_NOT_SUPPORT)
@@ -1186,30 +1187,30 @@ usb_sts_type usbh_loop_handler(usbh_core_type *uhost)
uhost->global_state = USBH_UNSUPPORT;
}
break;
case USBH_CLASS_REQUEST:
usbh_class_request(uhost);
break;
case USBH_CLASS:
usbh_class(uhost);
break;
case USBH_SUSPEND:
usbh_suspend(uhost);
break;
case USBH_SUSPENDED:
break;
case USBH_WAKEUP:
usbh_wakeup(uhost);
break;
case USBH_DISCONNECT:
usbh_disconnect(uhost);
break;
case USBH_ERROR_STATE:
usbh_cfg_default_init(uhost);
uhost->class_handler->reset_handler(uhost);
@@ -1220,13 +1221,13 @@ usb_sts_type usbh_loop_handler(usbh_core_type *uhost)
default:
break;
}
return status;
}
/**
* @}
*/
*/
/**
* @}

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usbh_ctrl.c
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb host control request
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -30,17 +30,17 @@
/** @addtogroup AT32F415_middlewares_usbh_drivers
* @{
*/
/** @defgroup USBH_drivers_control
* @brief usb host drivers control
* @{
*/
*/
/** @defgroup USBH_ctrl_private_functions
* @{
*/
/* control timeout 5s */
/* control timeout 5s */
#define CTRL_TIMEOUT 5000
/**
@@ -56,7 +56,7 @@ usb_sts_type usbh_ctrl_send_setup(usbh_core_type *uhost, uint8_t *buffer, uint8_
uhost->hch[hc_num].data_pid = HCH_PID_SETUP;
uhost->hch[hc_num].trans_buf = buffer;
uhost->hch[hc_num].trans_len = 8; /*setup */
return usbh_in_out_request(uhost, hc_num);
}
@@ -68,14 +68,14 @@ usb_sts_type usbh_ctrl_send_setup(usbh_core_type *uhost, uint8_t *buffer, uint8_
* @param hc_num: channel number
* @retval status: usb_sts_type status
*/
usb_sts_type usbh_ctrl_recv_data(usbh_core_type *uhost, uint8_t *buffer,
usb_sts_type usbh_ctrl_recv_data(usbh_core_type *uhost, uint8_t *buffer,
uint8_t length, uint16_t hc_num)
{
uhost->hch[hc_num].dir = 1;
uhost->hch[hc_num].data_pid = HCH_PID_DATA1;
uhost->hch[hc_num].trans_buf = buffer;
uhost->hch[hc_num].trans_len = length;
uhost->hch[hc_num].trans_len = length;
return usbh_in_out_request(uhost, hc_num);
}
@@ -87,13 +87,13 @@ usb_sts_type usbh_ctrl_recv_data(usbh_core_type *uhost, uint8_t *buffer,
* @param hc_num: channel number
* @retval status: usb_sts_type status
*/
usb_sts_type usbh_ctrl_send_data(usbh_core_type *uhost, uint8_t *buffer,
usb_sts_type usbh_ctrl_send_data(usbh_core_type *uhost, uint8_t *buffer,
uint8_t length, uint16_t hc_num)
{
uhost->hch[hc_num].dir = 0;
uhost->hch[hc_num].trans_buf = buffer;
uhost->hch[hc_num].trans_len = length;
if(length == 0)
{
uhost->hch[uhost->ctrl.hch_out].toggle_out = 1;
@@ -116,7 +116,7 @@ usb_sts_type usbh_ctrl_send_data(usbh_core_type *uhost, uint8_t *buffer,
*/
usb_sts_type usbh_ctrl_setup_handler(usbh_core_type *uhost)
{
usbh_ctrl_send_setup(uhost, (uint8_t *)(&uhost->ctrl.setup),
usbh_ctrl_send_setup(uhost, (uint8_t *)(&uhost->ctrl.setup),
uhost->ctrl.hch_out);
uhost->ctrl.state = CONTROL_SETUP_WAIT;
return USB_OK;
@@ -190,11 +190,11 @@ usb_sts_type usbh_ctrl_setup_wait_handler(usbh_core_type *uhost, uint32_t *timeo
usb_sts_type usbh_ctrl_data_in_handler(usbh_core_type *uhost)
{
usb_sts_type status = USB_OK;
usbh_ctrl_recv_data(uhost, uhost->ctrl.buffer,
usbh_ctrl_recv_data(uhost, uhost->ctrl.buffer,
uhost->ctrl.len,
uhost->ctrl.hch_in);
uhost->ctrl.state = CONTROL_DATA_IN_WAIT;
return status;
}
@@ -209,7 +209,7 @@ usb_sts_type usbh_ctrl_data_in_wait_handler(usbh_core_type *uhost, uint32_t time
usb_sts_type status = USB_OK;
urb_sts_type urb_state;
urb_state = uhost->urb_state[uhost->ctrl.hch_in];
if(urb_state == URB_DONE)
{
uhost->ctrl.state = CONTROL_STATUS_OUT;
@@ -231,7 +231,7 @@ usb_sts_type usbh_ctrl_data_in_wait_handler(usbh_core_type *uhost, uint32_t time
uhost->ctrl.sts = CTRL_XACTERR;
status = USB_ERROR;
}
}
return status;
}
@@ -245,12 +245,12 @@ usb_sts_type usbh_ctrl_data_out_handler(usbh_core_type *uhost)
{
usb_sts_type status = USB_OK;
uhost->hch[uhost->ctrl.hch_out].toggle_out = 1;
usbh_ctrl_send_data(uhost, uhost->ctrl.buffer,
usbh_ctrl_send_data(uhost, uhost->ctrl.buffer,
uhost->ctrl.len,
uhost->ctrl.hch_out);
uhost->ctrl.state = CONTROL_DATA_OUT_WAIT;
return status;
}
@@ -305,8 +305,8 @@ usb_sts_type usbh_ctrl_status_in_handler(usbh_core_type *uhost)
usbh_ctrl_recv_data(uhost, 0, 0,
uhost->ctrl.hch_in);
uhost->ctrl.state = CONTROL_STATUS_IN_WAIT;
return status;
}
@@ -356,10 +356,10 @@ usb_sts_type usbh_ctrl_status_out_handler(usbh_core_type *uhost)
{
usb_sts_type status = USB_OK;
uhost->hch[uhost->ctrl.hch_out].toggle_out ^= 1;
usbh_ctrl_send_data(uhost, 0, 0, uhost->ctrl.hch_out);
uhost->ctrl.state = CONTROL_STATUS_OUT_WAIT;
return status;
}
@@ -456,50 +456,50 @@ usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost)
usb_sts_type status = USB_WAIT;
static uint32_t timeout = 0;
uhost->ctrl.sts = CTRL_START;
switch(uhost->ctrl.state)
{
case CONTROL_SETUP:
usbh_ctrl_setup_handler(uhost);
uhost->ctrl.timer = uhost->timer;
break;
case CONTROL_SETUP_WAIT:
usbh_ctrl_setup_wait_handler(uhost, &timeout);
break;
case CONTROL_DATA_IN:
usbh_ctrl_data_in_handler(uhost);
uhost->ctrl.timer = uhost->timer;
break;
case CONTROL_DATA_IN_WAIT:
usbh_ctrl_data_in_wait_handler(uhost, timeout);
break;
case CONTROL_DATA_OUT:
usbh_ctrl_data_out_handler(uhost);
uhost->ctrl.timer = uhost->timer;
break;
case CONTROL_DATA_OUT_WAIT:
usbh_ctrl_data_out_wait_handler(uhost, timeout);
break;
case CONTROL_STATUS_IN:
usbh_ctrl_status_in_handler(uhost);
uhost->ctrl.timer = uhost->timer;
break;
case CONTROL_STATUS_IN_WAIT:
usbh_ctrl_status_in_wait_handler(uhost, timeout);
break;
case CONTROL_STATUS_OUT:
usbh_ctrl_status_out_handler(uhost);
uhost->ctrl.timer = uhost->timer;
break;
case CONTROL_STATUS_OUT_WAIT:
usbh_ctrl_status_out_wait_handler(uhost, timeout);
break;
@@ -512,11 +512,11 @@ usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost)
case CONTROL_COMPLETE:
status = usbh_ctrl_complete_handler(uhost);
break;
default:
break;
}
return status;
}
@@ -550,7 +550,7 @@ usb_sts_type usbh_ctrl_request(usbh_core_type *uhost, uint8_t *buffer, uint16_t
* @retval status: usb_sts_type status
*/
usb_sts_type usbh_get_descriptor(usbh_core_type *uhost, uint16_t length,
uint8_t req_type, uint16_t wvalue,
uint8_t req_type, uint16_t wvalue,
uint8_t *buffer)
{
usb_sts_type status;
@@ -558,16 +558,16 @@ usb_sts_type usbh_get_descriptor(usbh_core_type *uhost, uint16_t length,
uhost->ctrl.setup.bRequest = USB_STD_REQ_GET_DESCRIPTOR;
uhost->ctrl.setup.wValue = wvalue;
uhost->ctrl.setup.wLength = length;
if((wvalue & 0xFF00) == ((USB_DESCIPTOR_TYPE_STRING << 8) & 0xFF00))
{
uhost->ctrl.setup.wIndex = 0x0409;
}
else
else
{
uhost->ctrl.setup.wIndex = 0;
}
status = usbh_ctrl_request(uhost, buffer, length);
return status;
}
@@ -582,7 +582,7 @@ usb_sts_type usbh_get_descriptor(usbh_core_type *uhost, uint16_t length,
void usbh_parse_dev_desc(usbh_core_type *uhost, uint8_t *buffer, uint16_t length)
{
usbh_dev_desc_type *desc = &(uhost->dev);
desc->dev_desc.bLength = *(uint8_t *)(buffer + 0);
desc->dev_desc.bDescriptorType = *(uint8_t *)(buffer + 1);
desc->dev_desc.bcdUSB = SWAPBYTE(buffer + 2);
@@ -590,7 +590,7 @@ void usbh_parse_dev_desc(usbh_core_type *uhost, uint8_t *buffer, uint16_t length
desc->dev_desc.bDeviceSubClass = *(uint8_t *)(buffer + 5);
desc->dev_desc.bDeviceProtocol = *(uint8_t *)(buffer + 6);
desc->dev_desc.bMaxPacketSize0 = *(uint8_t *)(buffer + 7);
if(length > 8)
{
desc->dev_desc.idVendor = SWAPBYTE(buffer + 8);
@@ -658,7 +658,7 @@ void usbh_parse_endpoint_desc(usb_endpoint_desc_type *ept_desc, uint8_t *buf)
* @param length: configure length
* @retval status: usb_sts_type status
*/
usb_sts_type usbh_parse_configure_desc(usbh_core_type *uhost,
usb_sts_type usbh_parse_configure_desc(usbh_core_type *uhost,
uint8_t *buffer, uint16_t length)
{
usb_cfg_desc_type *cfg_desc = &(uhost->dev.cfg_desc);
@@ -668,7 +668,7 @@ usb_sts_type usbh_parse_configure_desc(usbh_core_type *uhost,
uint16_t index_len;
uint8_t index_intf = 0;
uint8_t index_ept = 0;
desc = (usb_header_desc_type *)buffer;
cfg_desc->cfg.bLength = *(uint8_t *)buffer;
cfg_desc->cfg.bDescriptorType = *(uint8_t *)(buffer + 1);
@@ -678,11 +678,11 @@ usb_sts_type usbh_parse_configure_desc(usbh_core_type *uhost,
cfg_desc->cfg.iConfiguration = *(uint8_t *)(buffer + 6);
cfg_desc->cfg.bmAttributes = *(uint8_t *)(buffer + 7);
cfg_desc->cfg.bMaxPower = *(uint8_t *)(buffer + 8);
if(length > USB_DEVICE_CFG_DESC_LEN)
{
index_len = USB_DEVICE_CFG_DESC_LEN;
while((index_intf < USBH_MAX_INTERFACE) && index_len < cfg_desc->cfg.wTotalLength)
{
desc = usbh_get_next_header((uint8_t *)desc, &index_len);
@@ -691,7 +691,7 @@ usb_sts_type usbh_parse_configure_desc(usbh_core_type *uhost,
index_ept = 0;
intf_desc = &cfg_desc->interface[index_intf].interface;
usbh_parse_interface_desc(intf_desc, (uint8_t *)desc);
while(index_ept < intf_desc->bNumEndpoints && index_len < cfg_desc->cfg.wTotalLength)
{
desc = usbh_get_next_header((uint8_t *)desc, &index_len);
@@ -746,7 +746,7 @@ void usbh_parse_string_desc(uint8_t *src, uint8_t *dest, uint16_t length)
{
uint16_t len;
uint16_t i_index;
if(src[1] == USB_DESCIPTOR_TYPE_STRING)
{
len = ((src[0] - 2) <= length ? (src[0] - 2) : length);
@@ -771,11 +771,11 @@ usb_sts_type usbh_get_device_descriptor(usbh_core_type *uhost, uint16_t length)
usb_sts_type status = USB_WAIT;
uint8_t bm_req;
uint16_t wvalue;
bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD;
wvalue = (USB_DESCIPTOR_TYPE_DEVICE << 8) & 0xFF00;
status = usbh_get_descriptor(uhost, length, bm_req,
status = usbh_get_descriptor(uhost, length, bm_req,
wvalue, uhost->rx_buffer);
return status;
}
@@ -791,13 +791,13 @@ usb_sts_type usbh_get_configure_descriptor(usbh_core_type *uhost, uint16_t lengt
usb_sts_type status = USB_WAIT;
uint8_t bm_req;
uint16_t wvalue;
bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD;
wvalue = (USB_DESCIPTOR_TYPE_CONFIGURATION << 8) & 0xFF00;
status = usbh_get_descriptor(uhost, length, bm_req,
status = usbh_get_descriptor(uhost, length, bm_req,
wvalue, uhost->rx_buffer);
return status;
}
@@ -815,11 +815,11 @@ usb_sts_type usbh_get_sting_descriptor(usbh_core_type *uhost, uint8_t string_id,
usb_sts_type status = USB_WAIT;
uint8_t bm_req;
uint16_t wvalue;
bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD;
wvalue = (USB_DESCIPTOR_TYPE_STRING << 8) | string_id;
status = usbh_get_descriptor(uhost, length, bm_req,
status = usbh_get_descriptor(uhost, length, bm_req,
wvalue, uhost->rx_buffer);
return status;
@@ -836,7 +836,7 @@ usb_sts_type usbh_set_configuration(usbh_core_type *uhost, uint16_t config)
usb_sts_type status = USB_WAIT;
uint8_t bm_req;
bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD;
uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req;
uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_CONFIGURATION;
uhost->ctrl.setup.wValue = config;
@@ -857,7 +857,7 @@ usb_sts_type usbh_set_address(usbh_core_type *uhost, uint8_t address)
usb_sts_type status = USB_WAIT;
uint8_t bm_req;
bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD;
uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req;
uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_ADDRESS;
uhost->ctrl.setup.wValue = (uint16_t)address;
@@ -879,7 +879,7 @@ usb_sts_type usbh_set_interface(usbh_core_type *uhost, uint8_t ept_num, uint8_t
usb_sts_type status = USB_WAIT;
uint8_t bm_req;
bm_req = USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD;
uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req;
uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_INTERFACE;
uhost->ctrl.setup.wValue = (uint16_t)altsetting;
@@ -901,7 +901,7 @@ usb_sts_type usbh_set_feature(usbh_core_type *uhost, uint8_t feature, uint16_t i
usb_sts_type status = USB_WAIT;
uint8_t bm_req;
bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD;
uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req;
uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_FEATURE;
uhost->ctrl.setup.wValue = (uint16_t)feature;
@@ -924,7 +924,7 @@ usb_sts_type usbh_clear_dev_feature(usbh_core_type *uhost, uint8_t feature, uint
usb_sts_type status = USB_WAIT;
uint8_t bm_req;
bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD;
uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req;
uhost->ctrl.setup.bRequest = USB_STD_REQ_CLEAR_FEATURE;
uhost->ctrl.setup.wValue = (uint16_t)feature;
@@ -948,7 +948,7 @@ usb_sts_type usbh_clear_ept_feature(usbh_core_type *uhost, uint8_t ept_num, uint
if(uhost->ctrl.state == CONTROL_IDLE )
{
bm_req = USB_REQ_RECIPIENT_ENDPOINT | USB_REQ_TYPE_STANDARD;
uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req;
uhost->ctrl.setup.bRequest = USB_STD_REQ_CLEAR_FEATURE;
uhost->ctrl.setup.wValue = USB_FEATURE_EPT_HALT;
@@ -965,7 +965,7 @@ usb_sts_type usbh_clear_ept_feature(usbh_core_type *uhost, uint8_t ept_num, uint
/**
* @}
*/
*/
/**
* @}

View File

@@ -1,17 +1,17 @@
/**
**************************************************************************
* @file usbh_int.c
* @version v2.0.3
* @date 2022-02-11
* @version v2.0.4
* @date 2022-04-02
* @brief usb host interrupt request
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
@@ -29,11 +29,11 @@
/** @addtogroup AT32F415_middlewares_usbh_drivers
* @{
*/
/** @defgroup USBH_drivers_interrupt
* @brief usb host interrupt
* @{
*/
*/
/** @defgroup USBH_int_private_functions
* @{
@@ -49,7 +49,7 @@ void usbh_irq_handler(otg_core_type *otgdev)
otg_global_type *usbx = otgdev->usb_reg;
usbh_core_type *uhost = &otgdev->host;
uint32_t intsts = usb_global_get_all_interrupt(usbx);
if(usbx->gintsts_bit.curmode == 1)
{
if(intsts & USB_OTG_HCH_FLAG)
@@ -101,7 +101,7 @@ void usbh_irq_handler(otg_core_type *otgdev)
{
usb_global_clear_interrupt(usbx, USB_OTG_ISOOUTDROP_FLAG);
}
}
}
@@ -135,13 +135,13 @@ void usbh_disconnect_handler(usbh_core_type *uhost)
otg_global_type *usbx = uhost->usb_reg;
uint8_t i_index;
usb_host_disable(usbx);
uhost->conn_sts = 0;
uhost->global_state = USBH_DISCONNECT;
for(i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++)
{
usbh_free_channel(uhost, i_index);
@@ -160,7 +160,7 @@ void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn)
otg_global_type *usbx = uhost->usb_reg;
otg_hchannel_type *usb_chh = USB_CHL(usbx, chn);
uint32_t hcint_value = usb_chh->hcint & usb_chh->hcintmsk;
if( hcint_value & USB_OTG_HC_ACK_FLAG)
{
usb_chh->hcint = USB_OTG_HC_ACK_FLAG;
@@ -184,13 +184,13 @@ void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn)
{
usb_chh->hcintmsk_bit.chhltdmsk = TRUE;
usb_hch_halt(usbx, chn);
usb_chh->hcint = USB_OTG_HC_FRMOVRRUN_FLAG;
usb_chh->hcint = USB_OTG_HC_FRMOVRRUN_FLAG;
}
else if(hcint_value & USB_OTG_HC_XFERC_FLAG)
{
uhost->hch[chn].state = HCH_XFRC;
usb_chh->hcint = USB_OTG_HC_XFERC_FLAG;
usb_chh->hcint = USB_OTG_HC_XFERC_FLAG;
if(usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE || usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE)
{
usb_chh->hcintmsk_bit.chhltdmsk = TRUE;
@@ -219,7 +219,7 @@ void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn)
{
uhost->urb_state[chn] = URB_STALL;
}
else if(uhost->hch[chn].state == HCH_XACTERR ||
else if(uhost->hch[chn].state == HCH_XACTERR ||
uhost->hch[chn].state == HCH_DATATGLERR)
{
uhost->err_cnt[chn] ++;
@@ -241,7 +241,7 @@ void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn)
usb_chh->hcchar_bit.chena = TRUE;
uhost->urb_state[chn] = URB_NOTREADY;
}
usb_chh->hcint = USB_OTG_HC_CHHLTD_FLAG;
usb_chh->hcint = USB_OTG_HC_CHHLTD_FLAG;
}
else if(hcint_value & USB_OTG_HC_XACTERR_FLAG)
{
@@ -249,7 +249,7 @@ void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn)
uhost->hch[chn].state = HCH_XACTERR;
usb_hch_halt(usbx, chn);
uhost->err_cnt[chn] ++;
usb_chh->hcint = USB_OTG_HC_XACTERR_FLAG;
usb_chh->hcint = USB_OTG_HC_XACTERR_FLAG;
}
else if(hcint_value & USB_OTG_HC_NAK_FLAG)
{
@@ -268,12 +268,12 @@ void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn)
usb_chh->hcchar_bit.chena = TRUE;
}
uhost->hch[chn].state = HCH_NAK;
usb_chh->hcint = USB_OTG_HC_NAK_FLAG;
usb_chh->hcint = USB_OTG_HC_NAK_FLAG;
}
else if(hcint_value & USB_OTG_HC_BBLERR_FLAG)
{
usb_chh->hcint = USB_OTG_HC_BBLERR_FLAG;
}
usb_chh->hcint = USB_OTG_HC_BBLERR_FLAG;
}
}
/**
@@ -287,7 +287,7 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn)
otg_global_type *usbx = uhost->usb_reg;
otg_hchannel_type *usb_chh = USB_CHL(usbx, chn);
uint32_t hcint_value = usb_chh->hcint & usb_chh->hcintmsk;
if( hcint_value & USB_OTG_HC_ACK_FLAG)
{
usb_chh->hcint = USB_OTG_HC_ACK_FLAG;
@@ -303,7 +303,7 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn)
usb_chh->hcintmsk_bit.chhltdmsk = TRUE;
usb_hch_halt(usbx, chn);
uhost->hch[chn].state = HCH_XFRC;
usb_chh->hcint = USB_OTG_HC_XFERC_FLAG;
usb_chh->hcint = USB_OTG_HC_XFERC_FLAG;
}
else if( hcint_value & USB_OTG_HC_STALL_FLAG)
{
@@ -325,7 +325,7 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn)
if(uhost->hch[chn].state == HCH_XFRC)
{
uhost->urb_state[chn] = URB_DONE;
if(uhost->hch[chn].ept_type == EPT_BULK_TYPE ||
if(uhost->hch[chn].ept_type == EPT_BULK_TYPE ||
uhost->hch[chn].ept_type == EPT_INT_TYPE)
{
uhost->hch[chn].toggle_out ^= 1;
@@ -339,7 +339,7 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn)
{
uhost->hch[chn].urb_sts = URB_STALL;
}
else if(uhost->hch[chn].state == HCH_XACTERR ||
else if(uhost->hch[chn].state == HCH_XACTERR ||
uhost->hch[chn].state == HCH_DATATGLERR)
{
uhost->err_cnt[chn] ++;
@@ -352,11 +352,11 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn)
{
uhost->urb_state[chn] = URB_NOTREADY;
}
usb_chh->hcchar_bit.chdis = FALSE;
usb_chh->hcchar_bit.chena = TRUE;
}
usb_chh->hcint = USB_OTG_HC_CHHLTD_FLAG;
usb_chh->hcint = USB_OTG_HC_CHHLTD_FLAG;
}
else if( hcint_value & USB_OTG_HC_XACTERR_FLAG)
{
@@ -364,7 +364,7 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn)
uhost->err_cnt[chn] ++;
uhost->hch[chn].state = HCH_XACTERR;
usb_hch_halt(usbx, chn);
usb_chh->hcint = USB_OTG_HC_XACTERR_FLAG | USB_OTG_HC_NAK_FLAG;
usb_chh->hcint = USB_OTG_HC_XACTERR_FLAG | USB_OTG_HC_NAK_FLAG;
}
else if( hcint_value & USB_OTG_HC_NAK_FLAG)
{
@@ -372,7 +372,7 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn)
uhost->err_cnt[chn] = 0;
usb_hch_halt(usbx, chn);
uhost->hch[chn].state = HCH_NAK;
usb_chh->hcint = USB_OTG_HC_NAK_FLAG;
usb_chh->hcint = USB_OTG_HC_NAK_FLAG;
}
}
@@ -386,7 +386,7 @@ void usbh_hch_handler(usbh_core_type *uhost)
otg_global_type *usbx = uhost->usb_reg;
otg_host_type *usb_host = OTG_HOST(usbx);
uint32_t intsts, i_index;
intsts = usb_host->haint & 0xFFFF;
for(i_index = 0; i_index < 16; i_index ++)
{
@@ -419,9 +419,9 @@ void usbh_rx_qlvl_handler(usbh_core_type *uhost)
uint32_t tmp;
otg_hchannel_type *ch;
otg_global_type *usbx = uhost->usb_reg;
usbx->gintmsk_bit.rxflvlmsk = 0;
tmp = usbx->grxstsp;
chn = tmp & 0xF;
pktsts = (tmp >> 17) & 0xF;
@@ -435,7 +435,7 @@ void usbh_rx_qlvl_handler(usbh_core_type *uhost)
usb_read_packet(usbx, uhost->hch[chn].trans_buf, chn, pktcnt);
uhost->hch[chn].trans_buf += pktcnt;
uhost->hch[chn].trans_count += pktcnt;
if(ch->hctsiz_bit.pktcnt > 0)
{
ch->hcchar_bit.chdis = FALSE;
@@ -452,7 +452,7 @@ void usbh_rx_qlvl_handler(usbh_core_type *uhost)
break;
default:
break;
}
usbx->gintmsk_bit.rxflvlmsk = 1;
}
@@ -466,13 +466,13 @@ void usbh_port_handler(usbh_core_type *uhost)
{
otg_global_type *usbx = uhost->usb_reg;
otg_host_type *usb_host = OTG_HOST(usbx);
uint32_t prt = 0, prt_0;
prt = usb_host->hprt;
prt_0 = prt;
prt_0 &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
prt_0 &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET);
if(prt & USB_OTG_HPRT_PRTCONDET)
{
@@ -483,11 +483,11 @@ void usbh_port_handler(usbh_core_type *uhost)
}
prt_0 |= USB_OTG_HPRT_PRTCONDET;
}
if(prt & USB_OTG_HPRT_PRTENCHNG)
{
prt_0 |= USB_OTG_HPRT_PRTENCHNG;
if(prt & USB_OTG_HPRT_PRTENA)
{
if((prt & USB_OTG_HPRT_PRTSPD) == (USB_PRTSPD_LOW_SPEED << 17))
@@ -507,24 +507,24 @@ void usbh_port_handler(usbh_core_type *uhost)
uhost->port_enable = 0;
}
}
if(prt & USB_OTG_HPRT_PRTOVRCACT)
{
prt_0 |= USB_OTG_HPRT_PRTOVRCACT;
}
usb_host->hprt = prt_0;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
*/
/**
* @}
*/