15 Commits

Author SHA1 Message Date
sakumisu
7c0ef50bb3 release v0.10.1 2023-08-30 20:05:04 +08:00
sakumisu
0f2cb9f900 fix warning 2023-08-30 20:03:18 +08:00
sakumisu
7c1fae04b2 fix video packet caculation 2023-08-30 17:43:13 +08:00
sakimisu
14f5dd2dd3 implement msc device thread,remove other unused os thread 2023-08-29 14:40:03 +08:00
sakimisu
9029f8c5b1 fix warning 2023-08-27 13:38:13 +08:00
Zhihong Chen
b9915e0e1b port: hpmicro: separate host and device USB instance config
- separate host and device USB instance config

Signed-off-by: Zhihong Chen <zhihong.chen@hpmicro.com>
2023-08-26 12:45:31 +08:00
sakimisu
1387790744 add config for hpmicro usb instance and irq 2023-08-26 01:09:33 +08:00
sakimisu
c5fc9f338e fix macro spelling 2023-08-25 21:37:14 +08:00
sakimisu
4d61e5e053 copy bouffalo ehci glue from official sdk 2023-08-25 21:36:58 +08:00
sakimisu
1a7259649b standardize video control api 2023-08-25 21:36:27 +08:00
sakimisu
628e4ee928 improve ehci driver, enable iaad feature 2023-08-25 21:36:14 +08:00
sakimisu
749369b6fc remove usb_phy_init, because hpm sdk v1.2 implement it 2023-08-25 21:35:42 +08:00
Fan YANG
89cd77374c common: Add support for IAR for risc-v toolchain
- Added support for the IAR for risc-v toolchain

Signed-off-by: Fan YANG <fan.yang@hpmicro.com>
2023-08-18 23:33:02 +08:00
sakumisu
3792ad4905 add test scripts 2023-08-15 14:33:54 +08:00
heyuanjie87
2789633b50 [hub 修正] 快速断开的情况下无法处理断开事件 2023-08-13 09:40:01 +08:00
19 changed files with 715 additions and 345 deletions

View File

@@ -6,7 +6,7 @@
#ifndef CHERRYUSB_CONFIG_H
#define CHERRYUSB_CONFIG_H
#define CHERRYUSB_VERSION 0x001000
#define CHERRYUSB_VERSION 0x001001
/* ================ USB common Configuration ================ */
@@ -44,27 +44,6 @@
/* Enable test mode */
// #define CONFIG_USBDEV_TEST_MODE
//#define CONFIG_USBDEV_TX_THREAD
//#define CONFIG_USBDEV_RX_THREAD
#ifdef CONFIG_USBDEV_TX_THREAD
#ifndef CONFIG_USBDEV_TX_PRIO
#define CONFIG_USBDEV_TX_PRIO 4
#endif
#ifndef CONFIG_USBDEV_TX_STACKSIZE
#define CONFIG_USBDEV_TX_STACKSIZE 2048
#endif
#endif
#ifdef CONFIG_USBDEV_RX_THREAD
#ifndef CONFIG_USBDEV_RX_PRIO
#define CONFIG_USBDEV_RX_PRIO 4
#endif
#ifndef CONFIG_USBDEV_RX_STACKSIZE
#define CONFIG_USBDEV_RX_STACKSIZE 2048
#endif
#endif
#ifndef CONFIG_USBDEV_MSC_BLOCK_SIZE
#define CONFIG_USBDEV_MSC_BLOCK_SIZE 512
#endif
@@ -81,6 +60,16 @@
#define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
#endif
// #define CONFIG_USBDEV_MSC_THREAD
#ifndef CONFIG_USBDEV_MSC_PRIO
#define CONFIG_USBDEV_MSC_PRIO 4
#endif
#ifndef CONFIG_USBDEV_MSC_STACKSIZE
#define CONFIG_USBDEV_MSC_STACKSIZE 2048
#endif
#ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
#define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
#endif
@@ -153,7 +142,7 @@
#define CONFIG_USB_EHCI_HCOR_BASE (0x20072000 + 0x10)
#define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
// #define CONFIG_USB_EHCI_INFO_ENABLE
// #define CONFIG_USB_ECHI_HCOR_RESERVED_DISABLE
// #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
// #define CONFIG_USB_EHCI_CONFIGFLAG
// #define CONFIG_USB_EHCI_PORT_POWER

View File

@@ -108,7 +108,7 @@ static int _usbh_hub_get_hub_descriptor(struct usbh_hub *hub, uint8_t *buffer)
memcpy(buffer, g_hub_buf, USB_SIZEOF_HUB_DESC);
return ret;
}
#if 0
static int _usbh_hub_get_status(struct usbh_hub *hub, uint8_t *buffer)
{
struct usb_setup_packet *setup;
@@ -130,6 +130,7 @@ static int _usbh_hub_get_status(struct usbh_hub *hub, uint8_t *buffer)
return ret;
}
#endif
#endif
static int _usbh_hub_get_portstatus(struct usbh_hub *hub, uint8_t port, struct hub_port_status *port_status)
{
@@ -460,9 +461,10 @@ static void usbh_hub_events(struct usbh_hub *hub)
return;
}
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
portchange_index = hub->int_buffer[0];
portchange_index = hub->int_buffer[0];
hub->int_buffer[0] = 0;
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
USB_LOG_DBG("Port change:0x%02x\r\n", portchange_index);
if (!(portchange_index & (1 << (port + 1)))) {
@@ -625,7 +627,6 @@ static void usbh_hub_events(struct usbh_hub *hub)
}
}
hub->int_buffer[0] = 0;
/* Start next hub int transfer */
if (!hub->is_roothub && hub->connected) {
usbh_submit_urb(&hub->intin_urb);

View File

@@ -6,6 +6,9 @@
#include "usbd_core.h"
#include "usbd_msc.h"
#include "usb_scsi.h"
#if defined(CONFIG_USBDEV_MSC_THREAD)
#include "usb_osal.h"
#endif
#define MSD_OUT_EP_IDX 0
#define MSD_IN_EP_IDX 1
@@ -41,6 +44,12 @@ USB_NOCACHE_RAM_SECTION struct usbd_msc_priv {
uint32_t scsi_blk_nbr;
USB_MEM_ALIGNX uint8_t block_buffer[CONFIG_USBDEV_MSC_BLOCK_SIZE];
#if defined(CONFIG_USBDEV_MSC_THREAD)
usb_osal_mq_t usbd_msc_mq;
usb_osal_thread_t usbd_msc_thread;
uint32_t nbytes;
#endif
} g_usbd_msc;
static void usbd_msc_reset(void)
@@ -481,7 +490,12 @@ static bool SCSI_read10(uint8_t **data, uint32_t *len)
return false;
}
g_usbd_msc.stage = MSC_DATA_IN;
#ifdef CONFIG_USBDEV_MSC_THREAD
usb_osal_mq_send(g_usbd_msc.usbd_msc_mq, MSC_DATA_IN);
return true;
#else
return SCSI_processRead();
#endif
}
static bool SCSI_read12(uint8_t **data, uint32_t *len)
@@ -508,7 +522,12 @@ static bool SCSI_read12(uint8_t **data, uint32_t *len)
return false;
}
g_usbd_msc.stage = MSC_DATA_IN;
#ifdef CONFIG_USBDEV_MSC_THREAD
usb_osal_mq_send(g_usbd_msc.usbd_msc_mq, MSC_DATA_IN);
return true;
#else
return SCSI_processRead();
#endif
}
static bool SCSI_write10(uint8_t **data, uint32_t *len)
@@ -764,9 +783,14 @@ void mass_storage_bulk_out(uint8_t ep, uint32_t nbytes)
switch (g_usbd_msc.cbw.CB[0]) {
case SCSI_CMD_WRITE10:
case SCSI_CMD_WRITE12:
#ifdef CONFIG_USBDEV_MSC_THREAD
g_usbd_msc.nbytes = nbytes;
usb_osal_mq_send(g_usbd_msc.usbd_msc_mq, MSC_DATA_OUT);
#else
if (SCSI_processWrite(nbytes) == false) {
usbd_msc_send_csw(CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
}
#endif
break;
default:
break;
@@ -784,10 +808,14 @@ void mass_storage_bulk_in(uint8_t ep, uint32_t nbytes)
switch (g_usbd_msc.cbw.CB[0]) {
case SCSI_CMD_READ10:
case SCSI_CMD_READ12:
#ifdef CONFIG_USBDEV_MSC_THREAD
usb_osal_mq_send(g_usbd_msc.usbd_msc_mq, MSC_DATA_IN);
#else
if (SCSI_processRead() == false) {
usbd_msc_send_csw(CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
return;
}
#endif
break;
default:
break;
@@ -810,6 +838,32 @@ void mass_storage_bulk_in(uint8_t ep, uint32_t nbytes)
}
}
#ifdef CONFIG_USBDEV_MSC_THREAD
static void usbdev_msc_thread(void *argument)
{
uintptr_t event;
int ret;
while (1) {
ret = usb_osal_mq_recv(g_usbd_msc.usbd_msc_mq, (uintptr_t *)&event, 0xffffffff);
if (ret < 0) {
continue;
}
USB_LOG_DBG("%d\r\n", event);
if (event == MSC_DATA_OUT) {
if (SCSI_processWrite(g_usbd_msc.nbytes) == false) {
usbd_msc_send_csw(CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
}
} else if (event == MSC_DATA_IN) {
if (SCSI_processRead() == false) {
usbd_msc_send_csw(CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
}
} else {
}
}
}
#endif
struct usbd_interface *usbd_msc_init_intf(struct usbd_interface *intf, const uint8_t out_ep, const uint8_t in_ep)
{
intf->class_interface_handler = msc_storage_class_interface_request_handler;
@@ -834,6 +888,16 @@ struct usbd_interface *usbd_msc_init_intf(struct usbd_interface *intf, const uin
return NULL;
}
#ifdef CONFIG_USBDEV_MSC_THREAD
g_usbd_msc.usbd_msc_mq = usb_osal_mq_create(1);
if (g_usbd_msc.usbd_msc_mq == NULL) {
return NULL;
}
g_usbd_msc.usbd_msc_thread = usb_osal_thread_create("usbd_msc", CONFIG_USBDEV_MSC_STACKSIZE, CONFIG_USBDEV_MSC_PRIO, usbdev_msc_thread, NULL);
if (g_usbd_msc.usbd_msc_thread == NULL) {
return NULL;
}
#endif
return intf;
}

View File

@@ -16,6 +16,8 @@ struct usbh_cdc_custom_air724 {
struct usbh_urb bulkout_urb; /* Bulk OUT urb */
};
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_air724_buf[32];
static inline int usbh_air724_bulk_out_transfer(struct usbh_cdc_custom_air724 *cdc_custom_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout)
{
int ret;
@@ -30,12 +32,26 @@ static inline int usbh_air724_bulk_out_transfer(struct usbh_cdc_custom_air724 *c
return ret;
}
static inline int usbh_air724_bulk_in_transfer(struct usbh_cdc_custom_air724 *cdc_custom_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout)
{
int ret;
struct usbh_urb *urb = &cdc_custom_class->bulkin_urb;
memset(urb, 0, sizeof(struct usbh_urb));
usbh_bulk_urb_fill(urb, cdc_custom_class->bulkin, buffer, buflen, timeout, NULL, NULL);
ret = usbh_submit_urb(urb);
if (ret == 0) {
ret = urb->actual_length;
}
return ret;
}
int usbh_air724_connect(struct usbh_hubport *hport, uint8_t intf)
{
struct usbh_endpoint_cfg ep_cfg = { 0 };
struct usb_endpoint_descriptor *ep_desc;
int ret;
/* interface 3 is AT command */
if (intf != 3) {
USB_LOG_WRN("ignore intf:%d\r\n", intf);
return 0;
@@ -65,20 +81,22 @@ int usbh_air724_connect(struct usbh_hubport *hport, uint8_t intf)
USB_LOG_INFO("Register air724 Class:%s\r\n", hport->config.intf[intf].devname);
uint8_t cdc_buffer[32] = { 0x41, 0x54, 0x0d, 0x0a };
ret = usbh_air724_bulk_out_transfer(cdc_custom_class->bulkout, cdc_buffer, 4, 3000);
const uint8_t AT[4] = { 0x41, 0x54, 0x0d, 0x0a };
memcpy(g_air724_buf, AT, 4);
ret = usbh_air724_bulk_out_transfer(cdc_custom_class, g_air724_buf, 4, 3000);
if (ret < 0) {
USB_LOG_ERR("bulk out error,ret:%d\r\n", ret);
} else {
USB_LOG_RAW("send over:%d\r\n", ret);
}
ret = usbh_air724_bulk_out_transfer(cdc_custom_class->bulkin, cdc_buffer, 10, 3000);
ret = usbh_air724_bulk_in_transfer(cdc_custom_class, g_air724_buf, 10, 3000);
if (ret < 0) {
USB_LOG_ERR("bulk in error,ret:%d\r\n", ret);
} else {
USB_LOG_RAW("recv over:%d\r\n", ret);
for (size_t i = 0; i < ret; i++) {
USB_LOG_RAW("0x%02x ", cdc_buffer[i]);
USB_LOG_RAW("0x%02x ", g_air724_buf[i]);
}
}

View File

@@ -769,14 +769,14 @@ uint32_t usbd_video_mjpeg_payload_fill(uint8_t *input, uint32_t input_len, uint8
uint32_t picture_pos = 0;
static uint8_t uvc_header[2] = { 0x02, 0x80 };
packets = input_len / g_usbd_video.probe.dwMaxPayloadTransferSize + 1;
last_packet_size = input_len - ((packets - 1) * (g_usbd_video.probe.dwMaxPayloadTransferSize - 2)) + 2;
packets = (input_len + (g_usbd_video.probe.dwMaxPayloadTransferSize - 2) ) / (g_usbd_video.probe.dwMaxPayloadTransferSize - 2);
last_packet_size = input_len - ((packets - 1) * (g_usbd_video.probe.dwMaxPayloadTransferSize - 2));
for (size_t i = 0; i < packets; i++) {
output[g_usbd_video.probe.dwMaxPayloadTransferSize * i] = uvc_header[0];
output[g_usbd_video.probe.dwMaxPayloadTransferSize * i + 1] = uvc_header[1];
if (i == (packets - 1)) {
memcpy(&output[2 + g_usbd_video.probe.dwMaxPayloadTransferSize * i], &input[picture_pos], last_packet_size - 2);
memcpy(&output[2 + g_usbd_video.probe.dwMaxPayloadTransferSize * i], &input[picture_pos], last_packet_size);
output[g_usbd_video.probe.dwMaxPayloadTransferSize * i + 1] |= (1 << 1);
} else {
memcpy(&output[2 + g_usbd_video.probe.dwMaxPayloadTransferSize * i], &input[picture_pos], g_usbd_video.probe.dwMaxPayloadTransferSize - 2);

View File

@@ -53,32 +53,45 @@ static void usbh_video_class_free(struct usbh_video *video_class)
memset(video_class, 0, sizeof(struct usbh_video));
}
int usbh_video_get_cur(struct usbh_video *video_class, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len)
int usbh_video_get(struct usbh_video *video_class, uint8_t request, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len)
{
struct usb_setup_packet *setup = video_class->hport->setup;
int ret;
uint8_t retry;
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
setup->bRequest = VIDEO_REQUEST_GET_CUR;
setup->bRequest = request;
setup->wValue = cs << 8;
setup->wIndex = (entity_id << 8) | intf;
setup->wLength = len;
ret = usbh_control_transfer(video_class->hport->ep0, setup, g_video_buf);
if (ret < 0) {
return ret;
retry = 0;
while (1) {
ret = usbh_control_transfer(video_class->hport->ep0, setup, g_video_buf);
if (ret > 0) {
break;
}
retry++;
if (retry == 3) {
return ret;
}
}
memcpy(buf, g_video_buf, len);
if (buf) {
memcpy(buf, g_video_buf, len);
}
return ret;
}
int usbh_video_set_cur(struct usbh_video *video_class, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len)
int usbh_video_set(struct usbh_video *video_class, uint8_t request, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len)
{
struct usb_setup_packet *setup = video_class->hport->setup;
int ret;
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
setup->bRequest = VIDEO_REQUEST_SET_CUR;
setup->bRequest = request;
setup->wValue = cs << 8;
setup->wIndex = (entity_id << 8) | intf;
setup->wLength = len;
@@ -86,13 +99,13 @@ int usbh_video_set_cur(struct usbh_video *video_class, uint8_t intf, uint8_t ent
memcpy(g_video_buf, buf, len);
ret = usbh_control_transfer(video_class->hport->ep0, setup, g_video_buf);
usb_osal_msleep(5);
usb_osal_msleep(50);
return ret;
}
int usbh_videostreaming_get_cur_probe(struct usbh_video *video_class)
{
return usbh_video_get_cur(video_class, video_class->data_intf, 0x00, VIDEO_VS_PROBE_CONTROL, (uint8_t *)&video_class->probe, 26);
return usbh_video_get(video_class, VIDEO_REQUEST_GET_CUR, video_class->data_intf, 0x00, VIDEO_VS_PROBE_CONTROL, (uint8_t *)&video_class->probe, 26);
}
int usbh_videostreaming_set_cur_probe(struct usbh_video *video_class, uint8_t formatindex, uint8_t frameindex)
@@ -100,7 +113,8 @@ int usbh_videostreaming_set_cur_probe(struct usbh_video *video_class, uint8_t fo
video_class->probe.bFormatIndex = formatindex;
video_class->probe.bFrameIndex = frameindex;
video_class->probe.dwMaxPayloadTransferSize = 0;
return usbh_video_set_cur(video_class, video_class->data_intf, 0x00, VIDEO_VS_PROBE_CONTROL, (uint8_t *)&video_class->probe, 26);
video_class->probe.dwFrameInterval = 333333;
return usbh_video_set(video_class, VIDEO_REQUEST_SET_CUR, video_class->data_intf, 0x00, VIDEO_VS_PROBE_CONTROL, (uint8_t *)&video_class->probe, 26);
}
int usbh_videostreaming_set_cur_commit(struct usbh_video *video_class, uint8_t formatindex, uint8_t frameindex)
@@ -108,7 +122,8 @@ int usbh_videostreaming_set_cur_commit(struct usbh_video *video_class, uint8_t f
memcpy(&video_class->commit, &video_class->probe, sizeof(struct video_probe_and_commit_controls));
video_class->commit.bFormatIndex = formatindex;
video_class->commit.bFrameIndex = frameindex;
return usbh_video_set_cur(video_class, video_class->data_intf, 0x00, VIDEO_VS_COMMIT_CONTROL, (uint8_t *)&video_class->commit, 26);
video_class->commit.dwFrameInterval = 333333;
return usbh_video_set(video_class, VIDEO_REQUEST_SET_CUR, video_class->data_intf, 0x00, VIDEO_VS_COMMIT_CONTROL, (uint8_t *)&video_class->commit, 26);
}
int usbh_video_open(struct usbh_video *video_class,
@@ -125,6 +140,7 @@ int usbh_video_open(struct usbh_video *video_class,
bool found = false;
uint8_t formatidx = 0;
uint8_t frameidx = 0;
uint8_t step;
if (video_class->is_opened) {
return -EMFILE;
@@ -152,31 +168,65 @@ int usbh_video_open(struct usbh_video *video_class,
return -EINVAL;
}
/* Open video step:
* Get CUR request (probe)
* Set CUR request (probe)
* Get CUR request (probe)
* Get MAX request (probe)
* Get MIN request (probe)
* Get CUR request (probe)
* Set CUR request (commit)
*
*/
step = 0;
ret = usbh_videostreaming_get_cur_probe(video_class);
if (ret < 0) {
return ret;
}
ret = usbh_videostreaming_set_cur_probe(video_class, formatidx, frameidx);
if (ret < 0) {
return ret;
}
ret = usbh_videostreaming_get_cur_probe(video_class);
if (ret < 0) {
return ret;
}
ret = usbh_videostreaming_set_cur_probe(video_class, formatidx, frameidx);
if (ret < 0) {
return ret;
}
ret = usbh_videostreaming_get_cur_probe(video_class);
if (ret < 0) {
return ret;
}
ret = usbh_videostreaming_set_cur_commit(video_class, formatidx, frameidx);
if (ret < 0) {
return ret;
goto errout;
}
step = 1;
ret = usbh_videostreaming_set_cur_probe(video_class, formatidx, frameidx);
if (ret < 0) {
goto errout;
}
step = 2;
ret = usbh_videostreaming_get_cur_probe(video_class);
if (ret < 0) {
goto errout;
}
step = 3;
ret = usbh_video_get(video_class, VIDEO_REQUEST_GET_MAX, video_class->data_intf, 0x00, VIDEO_VS_PROBE_CONTROL, NULL, 26);
if (ret < 0) {
goto errout;
}
step = 4;
ret = usbh_video_get(video_class, VIDEO_REQUEST_GET_MIN, video_class->data_intf, 0x00, VIDEO_VS_PROBE_CONTROL, NULL, 26);
if (ret < 0) {
goto errout;
}
step = 5;
ret = usbh_videostreaming_set_cur_probe(video_class, formatidx, frameidx);
if (ret < 0) {
goto errout;
}
step = 6;
ret = usbh_videostreaming_get_cur_probe(video_class);
if (ret < 0) {
goto errout;
}
step = 7;
ret = usbh_videostreaming_set_cur_commit(video_class, formatidx, frameidx);
if (ret < 0) {
goto errout;
}
step = 8;
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_INTERFACE;
setup->bRequest = USB_REQUEST_SET_INTERFACE;
setup->wValue = altsetting;
@@ -185,7 +235,7 @@ int usbh_video_open(struct usbh_video *video_class,
ret = usbh_control_transfer(video_class->hport->ep0, setup, NULL);
if (ret < 0) {
return ret;
goto errout;
}
ep_desc = &video_class->hport->config.intf[video_class->data_intf].altsetting[altsetting].ep[0].ep_desc;
@@ -203,6 +253,10 @@ int usbh_video_open(struct usbh_video *video_class,
video_class->is_opened = true;
video_class->current_format = format_type;
return ret;
errout:
USB_LOG_ERR("Fail to open video in step %u\r\n", step);
return ret;
}
int usbh_video_close(struct usbh_video *video_class)

View File

@@ -25,6 +25,8 @@ struct usbh_video_format {
struct usbh_videostreaming {
uint32_t bufoffset;
uint32_t buflen;
uint16_t width;
uint16_t heigth;
void (*video_one_frame_callback)(struct usbh_videostreaming *stream);
};
@@ -52,11 +54,8 @@ struct usbh_video {
extern "C" {
#endif
int usbh_video_get_cur(struct usbh_video *video_class, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len);
int usbh_video_set_cur(struct usbh_video *video_class, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len);
int usbh_videostreaming_get_cur_probe(struct usbh_video *video_class);
int usbh_videostreaming_set_cur_probe(struct usbh_video *video_class, uint8_t formatindex, uint8_t frameindex);
int usbh_videostreaming_set_cur_commit(struct usbh_video *video_class, uint8_t formatindex, uint8_t frameindex);
int usbh_video_get_cur(struct usbh_video *video_class, uint8_t request, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len);
int usbh_video_set_cur(struct usbh_video *video_class, uint8_t request, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len);
int usbh_video_open(struct usbh_video *video_class,
uint8_t format_type,

View File

@@ -394,7 +394,7 @@ static int rndis_set_cmd_handler(uint8_t *data, uint32_t len)
static int rndis_reset_cmd_handler(uint8_t *data, uint32_t len)
{
rndis_reset_msg_t *cmd = (rndis_reset_msg_t *)data;
// rndis_reset_msg_t *cmd = (rndis_reset_msg_t *)data;
rndis_reset_cmplt_t *resp;
resp = ((rndis_reset_cmplt_t *)rndis_encapsulated_resp_buffer);

View File

@@ -260,7 +260,6 @@ int usbh_rndis_keepalive(struct usbh_rndis *rndis_class)
static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
{
struct usbh_endpoint_cfg ep_cfg = { 0 };
struct usb_endpoint_descriptor *ep_desc;
int ret;
uint32_t *oid_support_list;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, sakumisu
* Copyright (c) 2022-2023, sakumisu
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -44,9 +44,9 @@
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
#elif defined(__ICCARM__) || defined(__ICCRX__)
#elif defined(__ICCARM__) || defined(__ICCRX__) || defined(__ICCRISCV__)
#ifndef __USED
#if __ICCARM_V8
#if defined(__ICCARM_V8) || defined (__ICCRISCV__)
#define __USED __attribute__((used))
#else
#define __USED __root
@@ -54,7 +54,7 @@
#endif
#ifndef __WEAK
#if __ICCARM_V8
#if defined(__ICCARM_V8) || defined (__ICCRISCV__)
#define __WEAK __attribute__((weak))
#else
#define __WEAK _Pragma("__weak")
@@ -62,7 +62,7 @@
#endif
#ifndef __PACKED
#if __ICCARM_V8
#if defined(__ICCARM_V8) || defined (__ICCRISCV__)
#define __PACKED __attribute__((packed, aligned(1)))
#else
/* Needs IAR language extensions */
@@ -71,7 +71,7 @@
#endif
#ifndef __PACKED_STRUCT
#if __ICCARM_V8
#if defined(__ICCARM_V8) || defined (__ICCRISCV__)
#define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
#else
/* Needs IAR language extensions */
@@ -80,7 +80,7 @@
#endif
#ifndef __PACKED_UNION
#if __ICCARM_V8
#if defined(__ICCARM_V8) || defined (__ICCRISCV__)
#define __PACKED_UNION union __attribute__((packed, aligned(1)))
#else
/* Needs IAR language extensions */
@@ -89,7 +89,7 @@
#endif
#ifndef __ALIGNED
#if __ICCARM_V8
#if defined(__ICCARM_V8) || defined (__ICCRISCV__)
#define __ALIGNED(x) __attribute__((aligned(x)))
#elif (__VER__ >= 7080000)
/* Needs IAR language extensions */

View File

@@ -6,9 +6,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "usbd_core.h"
#if defined(CONFIG_USBDEV_TX_THREAD) || defined(CONFIG_USBDEV_RX_THREAD)
#include "usb_osal.h"
#endif
/* general descriptor field offsets */
#define DESC_bLength 0 /** Length offset */
@@ -68,15 +65,6 @@ USB_NOCACHE_RAM_SECTION struct usbd_core_priv {
struct usbd_tx_rx_msg rx_msg[USB_EP_OUT_NUM];
} g_usbd_core;
#if defined(CONFIG_USBDEV_TX_THREAD)
usb_osal_mq_t usbd_tx_mq;
usb_osal_thread_t usbd_tx_thread;
#endif
#if defined(CONFIG_USBDEV_RX_THREAD)
usb_osal_mq_t usbd_rx_mq;
usb_osal_thread_t usbd_rx_thread;
#endif
static void usbd_class_event_notify_handler(uint8_t event, void *arg);
static void usbd_print_setup(struct usb_setup_packet *setup)
@@ -1140,66 +1128,18 @@ void usbd_event_ep0_out_complete_handler(uint8_t ep, uint32_t nbytes)
void usbd_event_ep_in_complete_handler(uint8_t ep, uint32_t nbytes)
{
#ifndef CONFIG_USBDEV_TX_THREAD
if (g_usbd_core.tx_msg[ep & 0x7f].cb) {
g_usbd_core.tx_msg[ep & 0x7f].cb(ep, nbytes);
}
#else
g_usbd_core.tx_msg[ep & 0x7f].nbytes = nbytes;
usb_osal_mq_send(usbd_tx_mq, (uintptr_t)&g_usbd_core.tx_msg[ep & 0x7f]);
#endif
}
void usbd_event_ep_out_complete_handler(uint8_t ep, uint32_t nbytes)
{
#ifndef CONFIG_USBDEV_RX_THREAD
if (g_usbd_core.rx_msg[ep & 0x7f].cb) {
g_usbd_core.rx_msg[ep & 0x7f].cb(ep, nbytes);
}
#else
g_usbd_core.rx_msg[ep & 0x7f].nbytes = nbytes;
usb_osal_mq_send(usbd_rx_mq, (uintptr_t)&g_usbd_core.rx_msg[ep & 0x7f]);
#endif
}
#ifdef CONFIG_USBDEV_TX_THREAD
static void usbdev_tx_thread(void *argument)
{
struct usbd_tx_rx_msg *msg;
int ret;
while (1) {
ret = usb_osal_mq_recv(usbd_tx_mq, (uintptr_t *)&msg, 0xffffffff);
if (ret < 0) {
continue;
}
if (msg->cb) {
msg->cb(msg->ep, msg->nbytes);
}
}
}
#endif
#ifdef CONFIG_USBDEV_RX_THREAD
static void usbdev_rx_thread(void *argument)
{
struct usbd_tx_rx_msg *msg;
int ret;
while (1) {
ret = usb_osal_mq_recv(usbd_rx_mq, (uintptr_t *)&msg, 0xffffffff);
if (ret < 0) {
continue;
}
if (msg->cb) {
msg->cb(msg->ep, msg->nbytes);
}
}
}
#endif
#ifdef CONFIG_USBDEV_ADVANCE_DESC
void usbd_desc_register(struct usb_descriptor *desc)
{
@@ -1270,26 +1210,6 @@ bool usb_device_is_configured(void)
int usbd_initialize(void)
{
#ifdef CONFIG_USBDEV_TX_THREAD
usbd_tx_mq = usb_osal_mq_create(16);
if (usbd_tx_mq == NULL) {
return -1;
}
usbd_tx_thread = usb_osal_thread_create("usbd_tx", CONFIG_USBDEV_TX_STACKSIZE, CONFIG_USBDEV_TX_PRIO, usbdev_tx_thread, NULL);
if (usbd_tx_thread == NULL) {
return -1;
}
#endif
#ifdef CONFIG_USBDEV_RX_THREAD
usbd_rx_mq = usb_osal_mq_create(16);
if (usbd_rx_mq == NULL) {
return -1;
}
usbd_rx_thread = usb_osal_thread_create("usbd_rx", CONFIG_USBDEV_RX_STACKSIZE, CONFIG_USBDEV_RX_PRIO, usbdev_rx_thread, NULL);
if (usbd_rx_thread == NULL) {
return -1;
}
#endif
return usb_dc_init();
}
@@ -1297,8 +1217,6 @@ int usbd_deinitialize(void)
{
g_usbd_core.intf_offset = 0;
usb_dc_deinit();
#if defined(CONFIG_USBDEV_TX_THREAD) || defined(CONFIG_USBDEV_RX_THREAD)
#endif
return 0;
}

View File

@@ -9,13 +9,13 @@
#define USBH_IRQHandler USBH_IRQHandler
#endif
#define EHCI_HCCR ((struct ehci_hccr *)CONFIG_USB_EHCI_HCCR_BASE)
#define EHCI_HCOR ((struct ehci_hcor *)CONFIG_USB_EHCI_HCOR_BASE)
#define EHCI_HCCR ((struct ehci_hccr *)CONFIG_USB_EHCI_HCCR_BASE)
#define EHCI_HCOR ((struct ehci_hcor *)CONFIG_USB_EHCI_HCOR_BASE)
#define EHCI_PTR2ADDR(x) ((uint32_t)x)
#define EHCI_ADDRALIGN32(x) ((uint32_t)(x) & ~0x1F)
#define EHCI_ADDR2QH(x) ((struct ehci_qh_hw *)((uint32_t)(x) & ~0x1F))
#define EHCI_ADDR2ITD(x) ((struct ehci_itd_hw *)((uint32_t)(x) & ~0x1F))
#define EHCI_PTR2ADDR(x) ((uint32_t)(x) & ~0x1F)
#define EHCI_ADDR2QH(x) ((struct ehci_qh_hw *)((uint32_t)(x) & ~0x1F))
#define EHCI_ADDR2QTD(x) ((struct ehci_qtd_hw *)((uint32_t)(x) & ~0x1F))
#define EHCI_ADDR2ITD(x) ((struct ehci_itd_hw *)((uint32_t)(x) & ~0x1F))
#if CONFIG_USB_EHCI_FRAME_LIST_SIZE == 1024
#define EHCI_PERIOIDIC_QH_NUM 11
@@ -49,7 +49,6 @@ struct ehci_pipe {
bool waiter;
usb_osal_sem_t waitsem;
struct usbh_hubport *hport;
struct ehci_qh_hw *qh;
struct usbh_urb *urb;
uint8_t mf_unmask;
uint8_t mf_valid;
@@ -60,11 +59,14 @@ struct ehci_pipe {
struct ehci_qh_hw {
struct ehci_qh hw;
uint32_t first_qtd;
struct ehci_pipe *pipe;
struct usbh_urb *urb;
uint8_t remove_in_iaad;
} __attribute__((aligned(32)));
struct ehci_qtd_hw {
struct ehci_qtd hw;
struct usbh_urb *urb;
uint32_t total_len;
} __attribute__((aligned(32)));
struct ehci_itd_hw {

View File

@@ -0,0 +1,134 @@
#include "bflb_core.h"
#include "usbh_core.h"
#include "hardware/usb_v2_reg.h"
#ifndef CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
#error "usb host must enable CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE"
#endif
#define BLFB_USB_BASE ((uint32_t)0x20072000)
#define BFLB_PDS_BASE ((uint32_t)0x2000e000)
#define PDS_USB_CTL_OFFSET (0x500) /* usb_ctl */
#define PDS_USB_PHY_CTRL_OFFSET (0x504) /* usb_phy_ctrl */
/* 0x500 : usb_ctl */
#define PDS_REG_USB_SW_RST_N (1 << 0U)
#define PDS_REG_USB_EXT_SUSP_N (1 << 1U)
#define PDS_REG_USB_WAKEUP (1 << 2U)
#define PDS_REG_USB_L1_WAKEUP (1 << 3U)
#define PDS_REG_USB_DRVBUS_POL (1 << 4U)
#define PDS_REG_USB_IDDIG (1 << 5U)
/* 0x504 : usb_phy_ctrl */
#define PDS_REG_USB_PHY_PONRST (1 << 0U)
#define PDS_REG_USB_PHY_OSCOUTEN (1 << 1U)
#define PDS_REG_USB_PHY_XTLSEL_SHIFT (2U)
#define PDS_REG_USB_PHY_XTLSEL_MASK (0x3 << PDS_REG_USB_PHY_XTLSEL_SHIFT)
#define PDS_REG_USB_PHY_OUTCLKSEL (1 << 4U)
#define PDS_REG_USB_PHY_PLLALIV (1 << 5U)
#define PDS_REG_PU_USB20_PSW (1 << 6U)
#define USB_SOF_TIMER_MASK_AFTER_RESET_HS (0x44C)
#define USB_SOF_TIMER_MASK_AFTER_RESET_FS (0x2710)
extern void USBH_IRQHandler();
static void bflb_usb_phy_init(void)
{
uint32_t regval;
/* USB_PHY_CTRL[3:2] reg_usb_phy_xtlsel=0 */
/* 2000e504 = 0x40; #100; USB_PHY_CTRL[6] reg_pu_usb20_psw=1 (VCC33A) */
/* 2000e504 = 0x41; #500; USB_PHY_CTRL[0] reg_usb_phy_ponrst=1 */
/* 2000e500 = 0x20; #100; USB_CTL[0] reg_usb_sw_rst_n=0 */
/* 2000e500 = 0x22; #500; USB_CTL[1] reg_usb_ext_susp_n=1 */
/* 2000e500 = 0x23; #100; USB_CTL[0] reg_usb_sw_rst_n=1 */
/* #1.2ms; wait UCLK */
/* wait(soc616_b0.usb_uclk); */
regval = getreg32(BFLB_PDS_BASE + PDS_USB_PHY_CTRL_OFFSET);
regval &= ~PDS_REG_USB_PHY_XTLSEL_MASK;
putreg32(regval, BFLB_PDS_BASE + PDS_USB_PHY_CTRL_OFFSET);
regval = getreg32(BFLB_PDS_BASE + PDS_USB_PHY_CTRL_OFFSET);
regval |= PDS_REG_PU_USB20_PSW;
putreg32(regval, BFLB_PDS_BASE + PDS_USB_PHY_CTRL_OFFSET);
regval = getreg32(BFLB_PDS_BASE + PDS_USB_PHY_CTRL_OFFSET);
regval |= PDS_REG_USB_PHY_PONRST;
putreg32(regval, BFLB_PDS_BASE + PDS_USB_PHY_CTRL_OFFSET);
/* greater than 5T */
bflb_mtimer_delay_us(1);
regval = getreg32(BFLB_PDS_BASE + PDS_USB_CTL_OFFSET);
regval &= ~PDS_REG_USB_SW_RST_N;
putreg32(regval, BFLB_PDS_BASE + PDS_USB_CTL_OFFSET);
/* greater than 5T */
bflb_mtimer_delay_us(1);
regval = getreg32(BFLB_PDS_BASE + PDS_USB_CTL_OFFSET);
regval |= PDS_REG_USB_EXT_SUSP_N;
putreg32(regval, BFLB_PDS_BASE + PDS_USB_CTL_OFFSET);
/* wait UCLK 1.2ms */
bflb_mtimer_delay_ms(3);
regval = getreg32(BFLB_PDS_BASE + PDS_USB_CTL_OFFSET);
regval |= PDS_REG_USB_SW_RST_N;
putreg32(regval, BFLB_PDS_BASE + PDS_USB_CTL_OFFSET);
bflb_mtimer_delay_ms(2);
}
void usb_hc_low_level_init(void)
{
uint32_t regval;
bflb_usb_phy_init();
bflb_irq_attach(37, USBH_IRQHandler, NULL);
bflb_irq_enable(37);
/* enable device-A for host */
regval = getreg32(BFLB_PDS_BASE + PDS_USB_CTL_OFFSET);
regval &= ~PDS_REG_USB_IDDIG;
putreg32(regval, BFLB_PDS_BASE + PDS_USB_CTL_OFFSET);
regval = getreg32(BLFB_USB_BASE + USB_OTG_CSR_OFFSET);
regval |= USB_A_BUS_DROP_HOV;
regval &= ~USB_A_BUS_REQ_HOV;
putreg32(regval, BLFB_USB_BASE + USB_OTG_CSR_OFFSET);
bflb_mtimer_delay_ms(10);
/* enable vbus and bus control */
regval = getreg32(BLFB_USB_BASE + USB_OTG_CSR_OFFSET);
regval &= ~USB_A_BUS_DROP_HOV;
regval |= USB_A_BUS_REQ_HOV;
putreg32(regval, BLFB_USB_BASE + USB_OTG_CSR_OFFSET);
regval = getreg32(BLFB_USB_BASE + USB_GLB_INT_OFFSET);
regval |= USB_MDEV_INT;
regval |= USB_MOTG_INT;
regval &= ~USB_MHC_INT;
putreg32(regval, BLFB_USB_BASE + USB_GLB_INT_OFFSET);
}
uint8_t usbh_get_port_speed(const uint8_t port)
{
uint8_t speed = 3;
speed = (getreg32(BLFB_USB_BASE + USB_OTG_CSR_OFFSET) & USB_SPD_TYP_HOV_POV_MASK) >> USB_SPD_TYP_HOV_POV_SHIFT;
if (speed == 0) {
return USB_SPEED_FULL;
} else if (speed == 1) {
return USB_SPEED_LOW;
} else if (speed == 2) {
return USB_SPEED_HIGH;
}
return USB_SPEED_HIGH;
}

View File

@@ -3,39 +3,13 @@
#include "hpm_soc.h"
#include "hpm_usb_drv.h"
#define USB_PHY_INIT_DELAY_COUNT (16U) /**< a delay count for USB phy initialization */
#if !defined(CONFIG_USB_EHCI_HPMICRO) || !CONFIG_USB_EHCI_HPMICRO
#error "hpm ehci must set CONFIG_USB_EHCI_HPMICRO=1"
#endif
/* Initialize USB phy */
static void usb_phy_init(USB_Type *ptr)
{
uint32_t status;
ptr->OTG_CTRL0 |= USB_OTG_CTRL0_OTG_UTMI_RESET_SW_MASK; /* set otg_utmi_reset_sw for naneng usbphy */
ptr->OTG_CTRL0 &= ~USB_OTG_CTRL0_OTG_UTMI_SUSPENDM_SW_MASK; /* clr otg_utmi_suspend_m for naneng usbphy */
ptr->PHY_CTRL1 &= ~USB_PHY_CTRL1_UTMI_CFG_RST_N_MASK; /* clr cfg_rst_n */
do {
status = USB_OTG_CTRL0_OTG_UTMI_RESET_SW_GET(ptr->OTG_CTRL0); /* wait for reset status */
} while (status == 0);
ptr->OTG_CTRL0 |= USB_OTG_CTRL0_OTG_UTMI_SUSPENDM_SW_MASK; /* set otg_utmi_suspend_m for naneng usbphy */
for (int i = 0; i < USB_PHY_INIT_DELAY_COUNT; i++) {
ptr->PHY_CTRL0 = USB_PHY_CTRL0_GPIO_ID_SEL_N_SET(0); /* used for delay */
}
ptr->OTG_CTRL0 &= ~USB_OTG_CTRL0_OTG_UTMI_RESET_SW_MASK; /* clear otg_utmi_reset_sw for naneng usbphy */
/* otg utmi clock detection */
ptr->PHY_STATUS |= USB_PHY_STATUS_UTMI_CLK_VALID_MASK; /* write 1 to clear valid status */
do {
status = USB_PHY_STATUS_UTMI_CLK_VALID_GET(ptr->PHY_STATUS); /* get utmi clock status */
} while (status == 0);
ptr->PHY_CTRL1 |= USB_PHY_CTRL1_UTMI_CFG_RST_N_MASK; /* set cfg_rst_n */
ptr->PHY_CTRL1 |= USB_PHY_CTRL1_UTMI_OTG_SUSPENDM_MASK; /* set otg_suspendm */
}
#if !defined(CONFIG_HPM_USBH_BASE) || !defined(CONFIG_HPM_USBH_IRQn)
#error "hpm ehci must config CONFIG_HPM_USBH_BASE and CONFIG_HPM_USBH_IRQn"
#endif
static void usb_host_mode_init(USB_Type *ptr)
{
@@ -58,20 +32,20 @@ static void usb_host_mode_init(USB_Type *ptr)
void usb_hc_low_level_init()
{
usb_phy_init((USB_Type *)HPM_USB0_BASE);
intc_m_enable_irq(IRQn_USB0);
usb_phy_init((USB_Type *)CONFIG_HPM_USBH_BASE);
intc_m_enable_irq(CONFIG_HPM_USBH_IRQn);
}
void usb_hc_low_level2_init()
{
usb_host_mode_init((USB_Type *)HPM_USB0_BASE);
usb_host_mode_init((USB_Type *)CONFIG_HPM_USBH_BASE);
}
uint8_t usbh_get_port_speed(const uint8_t port)
{
uint8_t speed;
speed = usb_get_port_speed((USB_Type *)HPM_USB0_BASE);
speed = usb_get_port_speed((USB_Type *)CONFIG_HPM_USBH_BASE);
if (speed == 0x00) {
return USB_SPEED_FULL;
@@ -88,15 +62,8 @@ uint8_t usbh_get_port_speed(const uint8_t port)
extern void USBH_IRQHandler(void);
void isr_usb0(void)
void isr_usb(void)
{
USBH_IRQHandler();
}
SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usb0)
#ifdef HPM_USB1_BASE
void isr_usb1(void)
{
}
SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usb1)
#endif
SDK_DECLARE_EXT_ISR_M(CONFIG_HPM_USBH_IRQn, isr_usb)

View File

@@ -5,6 +5,12 @@
*/
#include "usb_ehci_priv.h"
#define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
#define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
#define EHCI_TUNE_RL_TT 0
#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
#define EHCI_TUNE_MULT_TT 1
struct ehci_hcd g_ehci_hcd;
USB_NOCACHE_RAM_SECTION struct ehci_qh_hw ehci_qh_pool[CONFIG_USB_EHCI_QH_NUM];
@@ -18,16 +24,17 @@ USB_NOCACHE_RAM_SECTION struct ehci_qh_hw g_periodic_qh_head[EHCI_PERIOIDIC_QH_N
/* The frame list */
USB_NOCACHE_RAM_SECTION uint32_t g_framelist[CONFIG_USB_EHCI_FRAME_LIST_SIZE] __attribute__((aligned(4096)));
static const uint8_t g_ehci_speed[4] = {
0, EHCI_LOW_SPEED, EHCI_FULL_SPEED, EHCI_HIGH_SPEED
};
static struct ehci_qh_hw *ehci_qh_alloc(void)
{
struct ehci_qh_hw *qh;
size_t flags;
for (uint32_t i = 0; i < CONFIG_USB_EHCI_QH_NUM; i++) {
if (!g_ehci_hcd.ehci_qh_used[i]) {
flags = usb_osal_enter_critical_section();
g_ehci_hcd.ehci_qh_used[i] = true;
usb_osal_leave_critical_section(flags);
qh = &ehci_qh_pool[i];
memset(qh, 0, sizeof(struct ehci_qh_hw));
qh->hw.hlp = QTD_LIST_END;
@@ -41,9 +48,15 @@ static struct ehci_qh_hw *ehci_qh_alloc(void)
static void ehci_qh_free(struct ehci_qh_hw *qh)
{
size_t flags;
for (uint32_t i = 0; i < CONFIG_USB_EHCI_QH_NUM; i++) {
if (&ehci_qh_pool[i] == qh) {
flags = usb_osal_enter_critical_section();
g_ehci_hcd.ehci_qh_used[i] = false;
usb_osal_leave_critical_section(flags);
qh->urb = NULL;
return;
}
}
@@ -52,9 +65,14 @@ static void ehci_qh_free(struct ehci_qh_hw *qh)
static struct ehci_qtd_hw *ehci_qtd_alloc(void)
{
struct ehci_qtd_hw *qtd;
size_t flags;
for (uint32_t i = 0; i < CONFIG_USB_EHCI_QTD_NUM; i++) {
if (!g_ehci_hcd.ehci_qtd_used[i]) {
flags = usb_osal_enter_critical_section();
g_ehci_hcd.ehci_qtd_used[i] = true;
usb_osal_leave_critical_section(flags);
qtd = &ehci_qtd_pool[i];
memset(qtd, 0, sizeof(struct ehci_qtd_hw));
qtd->hw.next_qtd = QTD_LIST_END;
@@ -68,9 +86,15 @@ static struct ehci_qtd_hw *ehci_qtd_alloc(void)
static void ehci_qtd_free(struct ehci_qtd_hw *qtd)
{
size_t flags;
for (uint32_t i = 0; i < CONFIG_USB_EHCI_QTD_NUM; i++) {
if (&ehci_qtd_pool[i] == qtd) {
flags = usb_osal_enter_critical_section();
g_ehci_hcd.ehci_qtd_used[i] = false;
usb_osal_leave_critical_section(flags);
qtd->urb = NULL;
return;
}
}
@@ -149,10 +173,18 @@ static struct ehci_qh_hw *ehci_get_periodic_qhead(uint8_t interval)
}
static void ehci_qh_fill(struct ehci_qh_hw *qh,
struct ehci_pipe *pipe)
uint8_t dev_addr,
uint8_t ep_addr,
uint8_t ep_type,
uint16_t ep_mps,
uint8_t ep_mult,
uint8_t ep_interval,
uint8_t speed,
uint8_t hubaddr,
uint8_t hubport)
{
struct usbh_hub *hub;
uint32_t regval;
uint32_t epchar = 0;
uint32_t epcap = 0;
/* QH endpoint characteristics:
*
@@ -167,17 +199,6 @@ static void ehci_qh_fill(struct ehci_qh_hw *qh,
* C Control endpoint
* RL NAK count reloaded
*/
regval = ((uint32_t)pipe->dev_addr << QH_EPCHAR_DEVADDR_SHIFT) |
((uint32_t)(pipe->ep_addr & 0xf) << QH_EPCHAR_ENDPT_SHIFT) |
((uint32_t)g_ehci_speed[pipe->speed] << QH_EPCHAR_EPS_SHIFT) |
((uint32_t)pipe->ep_mps << QH_EPCHAR_MAXPKT_SHIFT) |
QH_EPCHAR_DTC |
((uint32_t)0 << QH_EPCHAR_RL_SHIFT);
if (pipe->ep_type == USB_ENDPOINT_TYPE_CONTROL && (pipe->speed != USB_SPEED_HIGH)) {
regval |= QH_EPCHAR_C;
}
qh->hw.epchar = regval;
/* QH endpoint capabilities
*
@@ -189,26 +210,59 @@ static void ehci_qh_fill(struct ehci_qh_hw *qh,
* PORT Port number
* MULT High band width multiplier
*/
regval = 0;
hub = pipe->hport->parent;
epchar |= ((ep_addr & 0xf) << QH_EPCHAR_ENDPT_SHIFT);
epchar |= (dev_addr << QH_EPCHAR_DEVADDR_SHIFT);
epchar |= (ep_mps << QH_EPCHAR_MAXPKT_SHIFT);
regval |= QH_EPCAPS_HUBADDR(hub->hub_addr);
regval |= QH_EPCAPS_PORT(pipe->hport->port);
if (pipe->ep_type == USB_ENDPOINT_TYPE_INTERRUPT) {
if (pipe->speed == USB_SPEED_HIGH) {
regval |= ehci_caculate_smask(pipe->ep_interval);
} else {
regval |= QH_EPCAPS_SSMASK(2);
regval |= QH_EPCAPS_SCMASK(0x78);
}
regval |= QH_EPCAPS_MULT(1);
if (ep_type == USB_ENDPOINT_TYPE_CONTROL) {
epchar |= QH_EPCHAR_DTC; /* toggle from qtd */
}
qh->hw.epcap = regval;
switch (speed) {
case USB_SPEED_LOW:
epchar |= QH_EPCHAR_EPS_LOW;
case USB_SPEED_FULL:
if (ep_type == USB_ENDPOINT_TYPE_CONTROL) {
epchar |= QH_EPCHAR_C; /* for TT */
}
qh->pipe = pipe;
if (ep_type != USB_ENDPOINT_TYPE_INTERRUPT) {
epchar |= (EHCI_TUNE_RL_TT << QH_EPCHAR_RL_SHIFT);
}
epcap |= QH_EPCAPS_MULT(EHCI_TUNE_MULT_TT);
epcap |= QH_EPCAPS_HUBADDR(hubaddr);
epcap |= QH_EPCAPS_PORT(hubport);
if (ep_type == USB_ENDPOINT_TYPE_INTERRUPT) {
epcap |= QH_EPCAPS_SSMASK(2);
epcap |= QH_EPCAPS_SCMASK(0x78);
}
break;
case USB_SPEED_HIGH:
epchar |= QH_EPCHAR_EPS_HIGH;
if (ep_type == USB_ENDPOINT_TYPE_CONTROL) {
epchar |= (EHCI_TUNE_RL_HS << QH_EPCHAR_RL_SHIFT);
epcap |= QH_EPCAPS_MULT(EHCI_TUNE_MULT_HS);
} else if (ep_type == USB_ENDPOINT_TYPE_BULK) {
epcap |= QH_EPCAPS_MULT(EHCI_TUNE_MULT_HS);
} else {
/* only for interrupt ep */
epcap |= QH_EPCAPS_MULT(ep_mult);
epcap |= ehci_caculate_smask(ep_interval);
}
break;
default:
break;
}
qh->hw.epchar = epchar;
qh->hw.epcap = epcap;
}
static void ehci_qtd_bpl_fill(struct ehci_qtd_hw *qtd, uint32_t bufaddr, size_t buflen)
@@ -237,7 +291,7 @@ static void ehci_qtd_bpl_fill(struct ehci_qtd_hw *qtd, uint32_t bufaddr, size_t
}
}
static void ehci_qtd_fill(struct ehci_pipe *pipe, struct ehci_qtd_hw *qtd, uint32_t bufaddr, size_t buflen, uint32_t token)
static void ehci_qtd_fill(struct ehci_qtd_hw *qtd, uint32_t bufaddr, size_t buflen, uint32_t token)
{
/* qTD token
*
@@ -255,7 +309,7 @@ static void ehci_qtd_fill(struct ehci_pipe *pipe, struct ehci_qtd_hw *qtd, uint3
qtd->hw.token = token;
ehci_qtd_bpl_fill(qtd, bufaddr, buflen);
pipe->xfrd += buflen;
qtd->total_len = buflen;
}
static struct ehci_qh_hw *ehci_control_pipe_init(struct ehci_pipe *pipe, struct usb_setup_packet *setup, uint8_t *buffer, uint32_t buflen)
@@ -289,15 +343,25 @@ static struct ehci_qh_hw *ehci_control_pipe_init(struct ehci_pipe *pipe, struct
return NULL;
}
ehci_qh_fill(qh, pipe);
ehci_qh_fill(qh,
pipe->dev_addr,
pipe->ep_addr,
pipe->ep_type,
pipe->ep_mps,
0,
pipe->ep_interval,
pipe->hport->speed,
pipe->hport->parent->hub_addr,
pipe->hport->port);
/* fill setup qtd */
token = QTD_TOKEN_STATUS_ACTIVE |
QTD_TOKEN_PID_SETUP |
((uint32_t)3 << QTD_TOKEN_CERR_SHIFT) |
((uint32_t)EHCI_TUNE_CERR << QTD_TOKEN_CERR_SHIFT) |
((uint32_t)8 << QTD_TOKEN_NBYTES_SHIFT);
ehci_qtd_fill(pipe, qtd_setup, EHCI_PTR2ADDR(setup), 8, token);
ehci_qtd_fill(qtd_setup, (uintptr_t)setup, 8, token);
qtd_setup->urb = pipe->urb;
/* fill data qtd */
if (setup->wLength > 0) {
@@ -309,10 +373,11 @@ static struct ehci_qh_hw *ehci_control_pipe_init(struct ehci_pipe *pipe, struct
token |= QTD_TOKEN_STATUS_ACTIVE |
QTD_TOKEN_PID_OUT |
QTD_TOKEN_TOGGLE |
((uint32_t)3 << QTD_TOKEN_CERR_SHIFT) |
((uint32_t)EHCI_TUNE_CERR << QTD_TOKEN_CERR_SHIFT) |
((uint32_t)buflen << QTD_TOKEN_NBYTES_SHIFT);
ehci_qtd_fill(pipe, qtd_data, EHCI_PTR2ADDR(buffer), buflen, token);
ehci_qtd_fill(qtd_data, (uintptr_t)buffer, buflen, token);
qtd_data->urb = pipe->urb;
qtd_setup->hw.next_qtd = EHCI_PTR2ADDR(qtd_data);
qtd_data->hw.next_qtd = EHCI_PTR2ADDR(qtd_status);
} else {
@@ -328,13 +393,15 @@ static struct ehci_qh_hw *ehci_control_pipe_init(struct ehci_pipe *pipe, struct
token |= QTD_TOKEN_STATUS_ACTIVE |
QTD_TOKEN_TOGGLE |
QTD_TOKEN_IOC |
((uint32_t)3 << QTD_TOKEN_CERR_SHIFT) |
((uint32_t)EHCI_TUNE_CERR << QTD_TOKEN_CERR_SHIFT) |
((uint32_t)0 << QTD_TOKEN_NBYTES_SHIFT);
ehci_qtd_fill(pipe, qtd_status, 0, 0, token);
ehci_qtd_fill(qtd_status, 0, 0, token);
qtd_status->urb = pipe->urb;
qtd_status->hw.next_qtd = QTD_LIST_END;
/* update qh first qtd */
qh->hw.curr_qtd = EHCI_PTR2ADDR(qtd_setup);
qh->hw.overlay.next_qtd = EHCI_PTR2ADDR(qtd_setup);
/* record qh first qtd */
@@ -342,10 +409,12 @@ static struct ehci_qh_hw *ehci_control_pipe_init(struct ehci_pipe *pipe, struct
flags = usb_osal_enter_critical_section();
pipe->qh = qh;
qh->urb = pipe->urb;
/* add qh into async list */
ehci_qh_add_head(&g_async_qh_head, qh);
EHCI_HCOR->usbcmd |= EHCI_USBCMD_ASEN;
usb_osal_leave_critical_section(flags);
return qh;
}
@@ -377,7 +446,16 @@ static struct ehci_qh_hw *ehci_bulk_pipe_init(struct ehci_pipe *pipe, uint8_t *b
return NULL;
}
ehci_qh_fill(qh, pipe);
ehci_qh_fill(qh,
pipe->dev_addr,
pipe->ep_addr,
pipe->ep_type,
pipe->ep_mps,
0,
pipe->ep_interval,
pipe->hport->speed,
pipe->hport->parent->hub_addr,
pipe->hport->port);
while (buflen >= 0) {
qtd = ehci_qtd_alloc();
@@ -390,28 +468,22 @@ static struct ehci_qh_hw *ehci_bulk_pipe_init(struct ehci_pipe *pipe, uint8_t *b
buflen = 0;
}
/* fill qtd */
if (pipe->toggle) {
token = QTD_TOKEN_TOGGLE;
} else {
token = 0;
}
if (pipe->ep_addr & 0x80) {
token |= QTD_TOKEN_PID_IN;
token = QTD_TOKEN_PID_IN;
} else {
token |= QTD_TOKEN_PID_OUT;
token = QTD_TOKEN_PID_OUT;
}
token |= QTD_TOKEN_STATUS_ACTIVE |
((uint32_t)3 << QTD_TOKEN_CERR_SHIFT) |
((uint32_t)EHCI_TUNE_CERR << QTD_TOKEN_CERR_SHIFT) |
((uint32_t)xfer_len << QTD_TOKEN_NBYTES_SHIFT);
if (buflen == 0) {
token |= QTD_TOKEN_IOC;
}
ehci_qtd_fill(pipe, qtd, (uint32_t)buffer, xfer_len, token);
ehci_qtd_fill(qtd, (uintptr_t)buffer, xfer_len, token);
qtd->urb = pipe->urb;
qtd->hw.next_qtd = QTD_LIST_END;
buffer += xfer_len;
@@ -428,17 +500,27 @@ static struct ehci_qh_hw *ehci_bulk_pipe_init(struct ehci_pipe *pipe, uint8_t *b
}
/* update qh first qtd */
qh->hw.curr_qtd = EHCI_PTR2ADDR(first_qtd);
qh->hw.overlay.next_qtd = EHCI_PTR2ADDR(first_qtd);
/* update data toggle */
if (pipe->toggle) {
qh->hw.overlay.token = QTD_TOKEN_TOGGLE;
} else {
qh->hw.overlay.token = 0;
}
/* record qh first qtd */
qh->first_qtd = EHCI_PTR2ADDR(first_qtd);
flags = usb_osal_enter_critical_section();
pipe->qh = qh;
qh->urb = pipe->urb;
/* add qh into async list */
ehci_qh_add_head(&g_async_qh_head, qh);
EHCI_HCOR->usbcmd |= EHCI_USBCMD_ASEN;
usb_osal_leave_critical_section(flags);
return qh;
}
@@ -470,7 +552,16 @@ static struct ehci_qh_hw *ehci_intr_pipe_init(struct ehci_pipe *pipe, uint8_t *b
return NULL;
}
ehci_qh_fill(qh, pipe);
ehci_qh_fill(qh,
pipe->dev_addr,
pipe->ep_addr,
pipe->ep_type,
pipe->ep_mps,
pipe->mult + 1,
pipe->ep_interval,
pipe->hport->speed,
pipe->hport->parent->hub_addr,
pipe->hport->port);
while (buflen >= 0) {
qtd = ehci_qtd_alloc();
@@ -483,28 +574,22 @@ static struct ehci_qh_hw *ehci_intr_pipe_init(struct ehci_pipe *pipe, uint8_t *b
buflen = 0;
}
/* fill qtd */
if (pipe->toggle) {
token = QTD_TOKEN_TOGGLE;
} else {
token = 0;
}
if (pipe->ep_addr & 0x80) {
token |= QTD_TOKEN_PID_IN;
token = QTD_TOKEN_PID_IN;
} else {
token |= QTD_TOKEN_PID_OUT;
token = QTD_TOKEN_PID_OUT;
}
token |= QTD_TOKEN_STATUS_ACTIVE |
((uint32_t)3 << QTD_TOKEN_CERR_SHIFT) |
((uint32_t)EHCI_TUNE_CERR << QTD_TOKEN_CERR_SHIFT) |
((uint32_t)xfer_len << QTD_TOKEN_NBYTES_SHIFT);
if (buflen == 0) {
token |= QTD_TOKEN_IOC;
}
ehci_qtd_fill(pipe, qtd, (uint32_t)buffer, xfer_len, token);
ehci_qtd_fill(qtd, (uintptr_t)buffer, xfer_len, token);
qtd->urb = pipe->urb;
qtd->hw.next_qtd = QTD_LIST_END;
buffer += xfer_len;
@@ -521,20 +606,31 @@ static struct ehci_qh_hw *ehci_intr_pipe_init(struct ehci_pipe *pipe, uint8_t *b
}
/* update qh first qtd */
qh->hw.curr_qtd = EHCI_PTR2ADDR(first_qtd);
qh->hw.overlay.next_qtd = EHCI_PTR2ADDR(first_qtd);
/* update data toggle */
if (pipe->toggle) {
qh->hw.overlay.token = QTD_TOKEN_TOGGLE;
} else {
qh->hw.overlay.token = 0;
}
/* record qh first qtd */
qh->first_qtd = EHCI_PTR2ADDR(first_qtd);
flags = usb_osal_enter_critical_section();
pipe->qh = qh;
qh->urb = pipe->urb;
/* add qh into periodic list */
if (pipe->speed == USB_SPEED_HIGH) {
ehci_qh_add_head(ehci_get_periodic_qhead(pipe->ep_interval), qh);
} else {
ehci_qh_add_head(ehci_get_periodic_qhead(pipe->ep_interval * 8), qh);
}
EHCI_HCOR->usbcmd |= EHCI_USBCMD_PSEN;
usb_osal_leave_critical_section(flags);
return qh;
}
@@ -560,46 +656,39 @@ void ehci_pipe_waitup(struct ehci_pipe *pipe)
}
}
static void ehci_qh_scan_qtds(struct ehci_qh_hw *qh, struct ehci_pipe *pipe)
static void ehci_qh_scan_qtds(struct ehci_qh_hw *qh)
{
struct ehci_qtd_hw *qtd;
struct ehci_qtd_hw *next;
if ((qh->first_qtd & QTD_LIST_END) == 0) {
qtd = (struct ehci_qtd_hw *)qh->first_qtd;
while (qtd) {
if (qtd->hw.next_qtd & QTD_LIST_END) {
next = NULL;
} else {
next = (struct ehci_qtd_hw *)qtd->hw.next_qtd;
}
qtd = EHCI_ADDR2QTD(qh->first_qtd);
qh->first_qtd = qtd->hw.next_qtd;
while (qtd) {
// if (qtd->hw.token & QTD_TOKEN_STATUS_ACTIVE) {
// continue;
// }
if (pipe) {
pipe->xfrd -= (qtd->hw.token & QTD_TOKEN_NBYTES_MASK) >>
QTD_TOKEN_NBYTES_SHIFT;
}
qtd->urb->actual_length += (qtd->total_len - ((qtd->hw.token & QTD_TOKEN_NBYTES_MASK) >> QTD_TOKEN_NBYTES_SHIFT));
ehci_qtd_free(qtd);
qtd = next;
}
ehci_qtd_free(qtd);
qh->first_qtd = qtd->hw.next_qtd;
qtd = EHCI_ADDR2QTD(qh->first_qtd);
}
}
static void ehci_check_qh(struct ehci_qh_hw *qhead, struct ehci_qh_hw *qh, struct ehci_pipe *pipe)
static void ehci_check_qh(struct ehci_qh_hw *qhead, struct ehci_qh_hw *qh)
{
struct usbh_urb *urb;
struct ehci_pipe *pipe;
uint32_t token;
token = qh->hw.overlay.token;
if (token & QTD_TOKEN_STATUS_ACTIVE) {
} else {
urb = pipe->urb;
urb = qh->urb;
pipe = urb->pipe;
ehci_qh_scan_qtds(qh, pipe);
ehci_qh_scan_qtds(qh);
if (qh->first_qtd & QTD_LIST_END) {
/* remove qh from list */
ehci_qh_remove(qhead, qh);
@@ -623,29 +712,37 @@ static void ehci_check_qh(struct ehci_qh_hw *qhead, struct ehci_qh_hw *qh, struc
}
}
urb->actual_length = pipe->xfrd;
ehci_qh_free(qh);
pipe->qh = NULL;
qh->remove_in_iaad = 1;
ehci_pipe_waitup(pipe);
EHCI_HCOR->usbcmd |= EHCI_USBCMD_IAAD;
}
}
}
static void ehci_kill_qh(struct ehci_qh_hw *qhead, struct ehci_qh_hw *qh)
{
struct ehci_qtd_hw *qtd;
ehci_qh_remove(qhead, qh);
ehci_qh_scan_qtds(qh, NULL);
qtd = EHCI_ADDR2QTD(qh->first_qtd);
while (qtd) {
ehci_qtd_free(qtd);
qh->first_qtd = qtd->hw.next_qtd;
qtd = EHCI_ADDR2QTD(qh->first_qtd);
}
ehci_qh_free(qh);
}
static int usbh_reset_port(const uint8_t port)
{
uint32_t timeout = 0;
volatile uint32_t timeout = 0;
uint32_t regval;
#if defined(CONFIG_USB_EHCI_HPMICRO) && CONFIG_USB_EHCI_HPMICRO
if ((*(volatile uint32_t *)(CONFIG_HPM_USB_BASE + 0x224) & 0xc0) == (2 << 6)) { /* Hardcode for hpm */
if ((*(volatile uint32_t *)(CONFIG_HPM_USBH_BASE + 0x224) & 0xc0) == (2 << 6)) { /* Hardcode for hpm */
EHCI_HCOR->portsc[port - 1] |= (1 << 29);
} else {
EHCI_HCOR->portsc[port - 1] &= ~(1 << 29);
@@ -682,7 +779,7 @@ int usb_hc_init(void)
uint32_t interval;
struct ehci_qh_hw *qh;
uint32_t timeout = 0;
volatile uint32_t timeout = 0;
uint32_t regval;
memset(&g_ehci_hcd, 0, sizeof(struct ehci_hcd));
@@ -1023,9 +1120,9 @@ int usbh_pipe_alloc(usbh_pipe_t *pipe, const struct usbh_endpoint_cfg *ep_cfg)
int usbh_pipe_free(usbh_pipe_t pipe)
{
struct usbh_urb *urb;
size_t flags;
struct ehci_pipe *ppipe;
struct ehci_pipe *ppipe = (struct ehci_pipe *)pipe;
ppipe = (struct ehci_pipe *)pipe;
if (!ppipe) {
return -EINVAL;
@@ -1037,9 +1134,7 @@ int usbh_pipe_free(usbh_pipe_t pipe)
usbh_kill_urb(urb);
}
flags = usb_osal_enter_critical_section();
ehci_pipe_free(ppipe);
usb_osal_leave_critical_section(flags);
return 0;
}
@@ -1050,17 +1145,13 @@ int usbh_submit_urb(struct usbh_urb *urb)
size_t flags;
int ret = 0;
if (!urb) {
if (!urb || !urb->pipe) {
return -EINVAL;
}
pipe = urb->pipe;
if (!pipe) {
return -EINVAL;
}
if (!pipe->hport->connected) {
if (!pipe->inuse || !(EHCI_HCOR->portsc[0] & EHCI_PORTSC_CCS) || !pipe->hport->connected) {
return -ENODEV;
}
@@ -1072,7 +1163,6 @@ int usbh_submit_urb(struct usbh_urb *urb)
pipe->waiter = false;
pipe->xfrd = 0;
pipe->qh = NULL;
pipe->urb = urb;
urb->errorcode = -EBUSY;
urb->actual_length = 0;
@@ -1081,6 +1171,7 @@ int usbh_submit_urb(struct usbh_urb *urb)
pipe->waiter = true;
}
usb_osal_leave_critical_section(flags);
switch (pipe->ep_type) {
case USB_ENDPOINT_TYPE_CONTROL:
qh = ehci_control_pipe_init(pipe, urb->setup, urb->transfer_buffer, urb->transfer_buffer_length);
@@ -1149,7 +1240,7 @@ int usbh_kill_urb(struct usbh_urb *urb)
if ((pipe->ep_type == USB_ENDPOINT_TYPE_CONTROL) || (pipe->ep_type == USB_ENDPOINT_TYPE_BULK)) {
qh = EHCI_ADDR2QH(g_async_qh_head.hw.hlp);
while ((qh != &g_async_qh_head) && qh) {
if (qh == pipe->qh) {
if (qh->urb == urb) {
ehci_kill_qh(&g_async_qh_head, qh);
}
qh = EHCI_ADDR2QH(qh->hw.hlp);
@@ -1157,7 +1248,7 @@ int usbh_kill_urb(struct usbh_urb *urb)
} else if (pipe->ep_type == USB_ENDPOINT_TYPE_INTERRUPT) {
qh = EHCI_ADDR2QH(g_periodic_qh_head[EHCI_PERIOIDIC_QH_NUM - 1].hw.hlp);
while (qh) {
if (qh == pipe->qh) {
if (qh->urb == urb) {
if (pipe->speed == USB_SPEED_HIGH) {
ehci_kill_qh(ehci_get_periodic_qhead(pipe->ep_interval), qh);
} else {
@@ -1174,7 +1265,6 @@ int usbh_kill_urb(struct usbh_urb *urb)
EHCI_HCOR->usbcmd |= (EHCI_USBCMD_PSEN | EHCI_USBCMD_ASEN);
pipe->qh = NULL;
pipe->urb = NULL;
if (pipe->waiter) {
@@ -1191,13 +1281,11 @@ int usbh_kill_urb(struct usbh_urb *urb)
static void ehci_scan_async_list(void)
{
struct ehci_qh_hw *qh;
struct ehci_pipe *pipe;
qh = EHCI_ADDR2QH(g_async_qh_head.hw.hlp);
while ((qh != &g_async_qh_head) && qh) {
pipe = qh->pipe;
if (pipe) {
ehci_check_qh(&g_async_qh_head, qh, pipe);
if (qh->urb) {
ehci_check_qh(&g_async_qh_head, qh);
}
qh = EHCI_ADDR2QH(qh->hw.hlp);
}
@@ -1210,12 +1298,12 @@ static void ehci_scan_periodic_list(void)
qh = EHCI_ADDR2QH(g_periodic_qh_head[EHCI_PERIOIDIC_QH_NUM - 1].hw.hlp);
while (qh) {
pipe = qh->pipe;
if (pipe) {
if (qh->urb && qh->urb->pipe) {
pipe = (struct ehci_pipe *)qh->urb->pipe;
if (pipe->speed == USB_SPEED_HIGH) {
ehci_check_qh(ehci_get_periodic_qhead(pipe->ep_interval), qh, pipe);
ehci_check_qh(ehci_get_periodic_qhead(pipe->ep_interval), qh);
} else {
ehci_check_qh(ehci_get_periodic_qhead(pipe->ep_interval * 8), qh, pipe);
ehci_check_qh(ehci_get_periodic_qhead(pipe->ep_interval * 8), qh);
}
}
qh = EHCI_ADDR2QH(qh->hw.hlp);
@@ -1262,12 +1350,28 @@ void USBH_IRQHandler(void)
g_ehci_hcd.ehci_itd_used[index] = false;
}
}
usbh_roothub_thread_wakeup(port + 1);
}
}
}
if (usbsts & EHCI_USBSTS_IAA) {
for (uint8_t index = 0; index < CONFIG_USB_EHCI_QH_NUM; index++) {
struct ehci_qh_hw *qh = &ehci_qh_pool[index];
if (g_ehci_hcd.ehci_qh_used[index] && qh->remove_in_iaad) {
struct usbh_urb *urb;
struct ehci_pipe *pipe;
urb = qh->urb;
pipe = urb->pipe;
qh->remove_in_iaad = 0;
ehci_qh_free(qh);
ehci_pipe_waitup(pipe);
}
}
}
if (usbsts & EHCI_USBSTS_FATAL) {

View File

@@ -302,7 +302,7 @@ struct ehci_hcor {
uint32_t ctrldssegment; /* 0x10: 4G Segment Selector */
uint32_t periodiclistbase; /* 0x14: Frame List Base Address */
uint32_t asynclistaddr; /* 0x18: Next Asynchronous List Address */
#ifndef CONFIG_USB_ECHI_HCOR_RESERVED_DISABLE
#ifndef CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
uint32_t reserved[9];
#endif
uint32_t configflag; /* 0x40: Configured Flag Register */

View File

@@ -10,6 +10,10 @@
#define USB_NUM_BIDIR_ENDPOINTS USB_SOC_DCD_MAX_ENDPOINT_COUNT
#endif
#if !defined(CONFIG_HPM_USBD_BASE) || !defined(CONFIG_HPM_USBD_IRQn)
#error "hpm dcd must config CONFIG_HPM_USBD_BASE and CONFIG_HPM_USBD_IRQn"
#endif
/* USBSTS, USBINTR */
enum {
intr_usb = HPM_BITSMASK(1, 0),
@@ -62,7 +66,7 @@ int usb_dc_init(void)
memset(&g_hpm_udc, 0, sizeof(struct hpm_udc));
g_hpm_udc.handle = &usb_device_handle[0];
g_hpm_udc.handle->regs = (USB_Type *)HPM_USB0_BASE;
g_hpm_udc.handle->regs = (USB_Type *)CONFIG_HPM_USBD_BASE;
g_hpm_udc.handle->dcd_data = &_dcd_data;
uint32_t int_mask;
@@ -71,7 +75,7 @@ int usb_dc_init(void)
usb_device_init(g_hpm_udc.handle, int_mask);
intc_m_enable_irq(IRQn_USB0);
intc_m_enable_irq(CONFIG_HPM_USBD_IRQn);
return 0;
}
@@ -279,8 +283,8 @@ void USBD_IRQHandler(void)
}
}
void isr_usb0(void)
void isr_usb(void)
{
USBD_IRQHandler();
}
SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usb0)
SDK_DECLARE_EXT_ISR_M(CONFIG_HPM_USBD_IRQn, isr_usb)

View File

@@ -0,0 +1,49 @@
import serial
import time
try:
from serial.tools.list_ports import comports
except ImportError:
raise serial.serialutil.SerialException
test_comx = 'COM66'
test_baudrate = 2000000
test_maxsize = 10*1024*1024
test_data = '0xAA' * 4096
test_serial = serial.Serial(test_comx, test_baudrate, timeout = 1)
def test_cdc_out():
send_count = 0
begin = time.time()
while True:
if send_count < test_maxsize:
txdatalen = test_serial.write(test_data.encode("utf-8"))
send_count += txdatalen
else:
print("cdc out speed %f MB/s" %(send_count//1024//1024/(time.time() - begin)))
break
def test_cdc_in():
read_count = 0
begin = time.time()
while True:
if read_count < test_maxsize:
data = test_serial.read(test_maxsize).decode(encoding='utf-8',errors='ignore')
read_count += len(data)
else:
print("cdc in speed %f MB/s" %(read_count//1024//1024/(time.time() - begin)))
break
if __name__ == '__main__':
print('test cdc out speed')
test_serial.setDTR(0)
test_cdc_out()
print('test cdc in speed')
test_serial.setDTR(1)
test_cdc_in()

View File

@@ -0,0 +1,68 @@
# Copyright (c) 2021 HPMicro
# SPDX-License-Identifier: BSD-3-Clause
import pywinusb.hid as hid
import os
import time
import sys
import operator
# VID and PID customization changes here...
VID = 0xFFFF
PID = 0xFFFF
# Send buffer
buffer = [0xff]*64
# Const
TIMEOUT = -1
PASS = 0
FAIL = 1
# Result
result = TIMEOUT
def search_dev():
filter = hid.HidDeviceFilter(vendor_id = VID, product_id = PID)
hid_device = filter.get_devices()
return hid_device
def recv_data(data):
print("<=================== USB HID Read ========================>")
for i in range(0, len(data)):
print("0x{0:02x}" .format(data[i]), end=" ")
print("\n")
global result
result = (PASS if (operator.eq(data[1:-1], buffer[1:-1]) == True) else FAIL)
return None
def send_data(report):
print("<=================== USB HID Write ========================>")
buffer[0] = report[0].report_id
print("0x{0:02x}" .format(buffer[0]), end=" ")
for i in range(1,64):
buffer[i] = i % 256
print("0x{0:02x}" .format(buffer[i]), end=" ")
print("\n")
report[0].set_raw_data(buffer)
report[0].send()
return None
if __name__ == '__main__':
device = search_dev()[0]
device.open()
device.set_raw_data_handler(recv_data)
send_data(device.find_output_reports())
time.sleep(1)
if result == PASS:
print("USB hid echo passed!")
elif result == FAIL:
print("USB HID echo failed!")
else:
print("USB HID echo timed out!")