update
This commit is contained in:
@@ -333,13 +333,35 @@ static void usbh_print_hubport_info(struct usbh_hubport *hport)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBHOST_XHCI
|
||||
|
||||
static int usbh_get_default_mps(int speed)
|
||||
{
|
||||
switch (speed) {
|
||||
case USB_SPEED_LOW:
|
||||
return 8;
|
||||
case USB_SPEED_FULL:
|
||||
case USB_SPEED_HIGH:
|
||||
return 64;
|
||||
case USB_SPEED_SUPER:
|
||||
default:
|
||||
return 512;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int usbh_hport_activate_ep0(struct usbh_hubport *hport)
|
||||
{
|
||||
struct usbh_endpoint_cfg ep0_cfg = { 0 };
|
||||
|
||||
ep0_cfg.ep_addr = 0x00;
|
||||
ep0_cfg.ep_interval = 0x00;
|
||||
#ifdef CONFIG_USBHOST_XHCI
|
||||
ep0_cfg.ep_mps = usbh_get_default_mps(hport->speed);
|
||||
#else
|
||||
ep0_cfg.ep_mps = 0x08;
|
||||
#endif
|
||||
ep0_cfg.ep_type = USB_ENDPOINT_TYPE_CONTROL;
|
||||
ep0_cfg.hport = hport;
|
||||
|
||||
|
||||
@@ -43,11 +43,11 @@ static int USBCmdEntry(int argc, char *argv[])
|
||||
}
|
||||
else if (!strcmp(argv[1], "disk"))
|
||||
{
|
||||
|
||||
ret = FFreeRTOSWriteReadUsbDisk();
|
||||
}
|
||||
else if (!strcmp(argv[1], "hid"))
|
||||
{
|
||||
|
||||
ret = FFreeRTOSRecvHidInput();
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "ft_debug.h"
|
||||
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_hid.h"
|
||||
#include "usbh_msc.h"
|
||||
|
||||
#include "fmemory_pool.h"
|
||||
/************************** Constant Definitions *****************************/
|
||||
@@ -129,6 +131,91 @@ static void UsbInitTask(void * args)
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
static void UsbMscTask(void * args)
|
||||
{
|
||||
int ret;
|
||||
struct usbh_msc *msc_class;
|
||||
static uint8_t partition_table[512] = {0};
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
msc_class = (struct usbh_msc *)usbh_find_class_instance("/dev/sda");
|
||||
if (msc_class == NULL)
|
||||
{
|
||||
USB_LOG_RAW("do not find /dev/sda\r\n");
|
||||
goto err_exit;
|
||||
}
|
||||
|
||||
/* get the partition table */
|
||||
ret = usbh_msc_scsi_read10(msc_class, 0, partition_table, 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
USB_LOG_RAW("scsi_read10 error,ret:%d\r\n", ret);
|
||||
goto err_exit;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < 512; i++)
|
||||
{
|
||||
if (i % 16 == 0)
|
||||
{
|
||||
USB_LOG_RAW("\r\n");
|
||||
}
|
||||
USB_LOG_RAW("%02x ", partition_table[i]);
|
||||
}
|
||||
USB_LOG_RAW("\r\n");
|
||||
|
||||
/* write partition table */
|
||||
for (uint32_t i = 0; i < 512; i++)
|
||||
{
|
||||
partition_table[i] ^= 0xfffff;
|
||||
}
|
||||
|
||||
ret = usbh_msc_scsi_write10(msc_class, 0, partition_table, 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
USB_LOG_RAW("scsi_write10 error,ret:%d\r\n", ret);
|
||||
goto err_exit;
|
||||
}
|
||||
|
||||
vTaskDelay(10);
|
||||
}
|
||||
|
||||
err_exit:
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
static void UsbHidTask(void * args)
|
||||
{
|
||||
int ret;
|
||||
struct usbh_hid *hid_class;
|
||||
static uint8_t hid_buffer[128] = {0};
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
hid_class = (struct usbh_hid *)usbh_find_class_instance("/dev/input0");
|
||||
if (hid_class == NULL)
|
||||
{
|
||||
USB_LOG_RAW("do not find /dev/input0\r\n");
|
||||
goto err_exit;
|
||||
}
|
||||
|
||||
ret = usbh_int_transfer(hid_class->intin, hid_buffer, 8, 1000);
|
||||
if (ret < 0)
|
||||
{
|
||||
USB_LOG_RAW("intr in error,ret:%d\r\n", ret);
|
||||
goto err_exit;
|
||||
}
|
||||
USB_LOG_RAW("recv len:%d, key:[0x%x, 0x%x, 0x%x, 0x%x]\r\n",
|
||||
ret,
|
||||
hid_buffer[0], hid_buffer[1], hid_buffer[2], hid_buffer[3]);
|
||||
|
||||
vTaskDelay(10);
|
||||
}
|
||||
|
||||
err_exit:
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
BaseType_t FFreeRTOSInitUsb(void)
|
||||
{
|
||||
BaseType_t ret = pdPASS;
|
||||
@@ -146,4 +233,42 @@ BaseType_t FFreeRTOSInitUsb(void)
|
||||
taskEXIT_CRITICAL(); /* allow schedule since task created */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
BaseType_t FFreeRTOSWriteReadUsbDisk(void)
|
||||
{
|
||||
BaseType_t ret = pdPASS;
|
||||
|
||||
taskENTER_CRITICAL(); /* no schedule when create task */
|
||||
|
||||
ret = xTaskCreate((TaskFunction_t )UsbMscTask,
|
||||
(const char* )"UsbMscTask",
|
||||
(uint16_t )2048,
|
||||
NULL,
|
||||
(UBaseType_t )configMAX_PRIORITIES - 1,
|
||||
NULL);
|
||||
FASSERT_MSG(pdPASS == ret, "create task failed");
|
||||
|
||||
taskEXIT_CRITICAL(); /* allow schedule since task created */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
BaseType_t FFreeRTOSRecvHidInput(void)
|
||||
{
|
||||
BaseType_t ret = pdPASS;
|
||||
|
||||
taskENTER_CRITICAL(); /* no schedule when create task */
|
||||
|
||||
ret = xTaskCreate((TaskFunction_t )UsbHidTask,
|
||||
(const char* )"UsbHidTask",
|
||||
(uint16_t )2048,
|
||||
NULL,
|
||||
(UBaseType_t )configMAX_PRIORITIES - 1,
|
||||
NULL);
|
||||
FASSERT_MSG(pdPASS == ret, "create task failed");
|
||||
|
||||
taskEXIT_CRITICAL(); /* allow schedule since task created */
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -69,7 +69,7 @@
|
||||
#define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
|
||||
#endif
|
||||
|
||||
#define CONFIG_USBHOST_GET_STRING_DESC
|
||||
// #define CONFIG_USBHOST_GET_STRING_DESC
|
||||
|
||||
// #define CONFIG_USBDEV_MSC_THREAD
|
||||
|
||||
|
||||
@@ -463,9 +463,6 @@ enum TRBCCode {
|
||||
#define XHCI_RING(_trb) \
|
||||
((struct xhci_ring*)((unsigned long)(_trb) & ~(XHCI_RING_SIZE-1)))
|
||||
|
||||
#define XHCI_GET_FIELD(data, field) \
|
||||
(((data) >> field##_SHIFT) & field##_MASK)
|
||||
|
||||
#define BARRIER() __asm__ __volatile__("": : :"memory")
|
||||
|
||||
#ifdef XHCI_AARCH64
|
||||
|
||||
Reference in New Issue
Block a user