forked from xuos/xiuos
peripheral interface validation work about xidatong-arm
This commit is contained in:
commit
1a6f47cf49
|
@ -111,3 +111,6 @@ int Adapter4GTest(void)
|
|||
return 0;
|
||||
}
|
||||
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, Adapter4GTest, Adapter4GTest, show adapter 4G information);
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
MSH_CMD_EXPORT(Adapter4GTestRTThread,a 4G adpter sample);
|
||||
#endif
|
|
@ -39,13 +39,31 @@ if ADD_NUTTX_FETURES
|
|||
endif
|
||||
|
||||
if ADD_RTTHREAD_FETURES
|
||||
config ADAPTER_EC200T_DRIVER
|
||||
string "EC200T device uart driver path"
|
||||
default "/dev/uart2"
|
||||
config ADAPTER_EC200T_PIN_DRIVER
|
||||
string "EC200T device pin driver path"
|
||||
default "/dev/pin"
|
||||
config ADAPTER_EC200T_PWRKEY
|
||||
int "EC200T PWRKEY pin number"
|
||||
default "97"
|
||||
default "97"
|
||||
config ADAPTER_EC200T_PIN_DRIVER
|
||||
string "EC200T device pin driver path"
|
||||
default "/dev/pin_dev"
|
||||
|
||||
config ADAPTER_EC200T_DRIVER_EXTUART
|
||||
bool "Using extra uart to support 4G"
|
||||
default n
|
||||
|
||||
config ADAPTER_EC200T_DRIVER
|
||||
string "EC200T device uart driver path"
|
||||
default "/dev/usart8"
|
||||
depends on !ADAPTER_EC200T_DRIVER_EXTUART
|
||||
|
||||
if ADAPTER_EC200T_DRIVER_EXTUART
|
||||
config ADAPTER_EC200T_DRIVER
|
||||
string "EC200T device extra uart driver path"
|
||||
default "/dev/extuart_dev5"
|
||||
|
||||
config ADAPTER_EC200T_DRIVER_EXT_PORT
|
||||
int "if EC200T device using extuart, choose port"
|
||||
default "5"
|
||||
endif
|
||||
|
||||
|
||||
endif
|
||||
|
|
|
@ -40,10 +40,12 @@
|
|||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
static void Ec200tPowerSet(void){ return; }
|
||||
#else
|
||||
static void Ec200tPowerSet(void)
|
||||
{
|
||||
#ifdef ADAPTER_EC200T_USING_PWRKEY
|
||||
#else
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
static void Ec200tPowerSet(void){ return; }
|
||||
#else
|
||||
static void Ec200tPowerSet(void)
|
||||
{
|
||||
int pin_fd;
|
||||
pin_fd = PrivOpen(ADAPTER_EC200T_PIN_DRIVER, O_RDWR);
|
||||
if (pin_fd < 0) {
|
||||
|
@ -74,8 +76,8 @@ static void Ec200tPowerSet(void)
|
|||
PrivClose(pin_fd);
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int Ec200tOpen(struct Adapter *adapter)
|
||||
|
@ -150,6 +152,9 @@ out:
|
|||
#ifdef ADD_NUTTX_FETURES
|
||||
static int Ec200tIoctl(struct Adapter *adapter, int cmd, void *args){ return 0;}
|
||||
#else
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
static int Ec200tIoctl(struct Adapter *adapter, int cmd, void *args){ return 0;}
|
||||
#else
|
||||
static int Ec200tIoctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
if (OPE_INT != cmd) {
|
||||
|
@ -177,12 +182,14 @@ static int Ec200tIoctl(struct Adapter *adapter, int cmd, void *args)
|
|||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||
ioctl_cfg.args = &serial_cfg;
|
||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
|
||||
Ec200tPowerSet();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int Ec200tConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
{
|
||||
|
|
|
@ -199,6 +199,9 @@ int wifiopen(void)
|
|||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, wifiopen, wifiopen, open adapter wifi );
|
||||
#endif
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
MSH_CMD_EXPORT(wifiopen,a wifi adpter sample);
|
||||
#endif
|
||||
int wificlose(void)
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
|
@ -207,6 +210,9 @@ int wificlose(void)
|
|||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, wificlose, wificlose, close adapter wifi );
|
||||
#endif
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
MSH_CMD_EXPORT(wificlose,a wifi adpter sample);
|
||||
#endif
|
||||
int wifisetup(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
|
@ -222,6 +228,9 @@ int wifisetup(int argc, char *argv[])
|
|||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisetup, wifisetup, setup adapter wifi );
|
||||
#endif
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
MSH_CMD_EXPORT(wifisetup,a wifi adpter sample:wifisetup <server|client>);
|
||||
#endif
|
||||
int wifiaddrset(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
|
@ -236,6 +245,9 @@ int wifiaddrset(int argc, char *argv[])
|
|||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wifiaddrset, wifiaddrset, addrset adapter wifi);
|
||||
#endif
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
MSH_CMD_EXPORT(wifiaddrset,a wifi adpter sample:wifiaddrset <server|client>);
|
||||
#endif
|
||||
int wifiping(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
|
@ -245,6 +257,9 @@ int wifiping(int argc, char *argv[])
|
|||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3), wifiping, wifiping, wifiping adapter );
|
||||
#endif
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
MSH_CMD_EXPORT(wifiping,a wifi adpter sample:wifiping <server|client>);
|
||||
#endif
|
||||
int wificonnect(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
|
@ -266,6 +281,9 @@ int wificonnect(int argc, char *argv[])
|
|||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wificonnect, wificonnect, wificonnect adapter);
|
||||
#endif
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
MSH_CMD_EXPORT(wificonnect,a wifi adpter sample:wificonnect <server|client>);
|
||||
#endif
|
||||
int wifisend(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
|
@ -281,6 +299,9 @@ int wifisend(int argc, char *argv[])
|
|||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisend, wifisend, wifisend adapter wifi information);
|
||||
#endif
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
MSH_CMD_EXPORT(wifisend,a wifi adpter sample:wifisend <server|client>);
|
||||
#endif
|
||||
int wifirecv(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
|
@ -295,6 +316,9 @@ int wifirecv(int argc, char *argv[])
|
|||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifirecv, wifirecv, wifirecv adapter wifi information);
|
||||
#endif
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
MSH_CMD_EXPORT(wifirecv,a wifi adpter sample:wifirecv <server|client>);
|
||||
#endif
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
|
||||
|
|
|
@ -46,5 +46,25 @@ if ADD_NUTTX_FETURES
|
|||
endif
|
||||
|
||||
if ADD_RTTHREAD_FETURES
|
||||
if ADD_RTTHREAD_FETURES
|
||||
config ADAPTER_ESP07S_DRIVER_EXTUART
|
||||
bool "Using extra uart to support wifi"
|
||||
default n
|
||||
|
||||
config ADAPTER_ESP07S_DRIVER
|
||||
string "ESP07S device uart driver path"
|
||||
default "/dev/uart2"
|
||||
depends on !ADAPTER_ESP07S_DRIVER_EXTUART
|
||||
|
||||
if ADAPTER_ESP07S_DRIVER_EXTUART_RT
|
||||
config ADAPTER_ESP07S_DRIVER
|
||||
string "ESP07S device extra uart driver path"
|
||||
default "/dev/extuart_dev6_rt"
|
||||
|
||||
config ADAPTER_ESP07S_DRIVER_EXT_PORT
|
||||
int "if ESP07S device using extuart, choose port"
|
||||
default "6"
|
||||
endif
|
||||
endif
|
||||
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
from building import *
|
||||
import os
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = []
|
||||
if GetDepend(['ADAPTER_ESP07S_WIFI']):
|
||||
src += ['esp07s_wifi.c']
|
||||
|
||||
group = DefineGroup('connection wifi esp07s', src, depend = [], CPPPATH = [cwd])
|
||||
|
||||
|
||||
Return('group')
|
|
@ -48,3 +48,68 @@ static void sdram_test2(void)
|
|||
}
|
||||
MSH_CMD_EXPORT(sdram_test2, sdram test2);
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USB1_HOST
|
||||
#include <dfs_posix.h>
|
||||
static char test_data[120], buffer[120];
|
||||
#define TEST_FN "/testusb.c"
|
||||
void readwrite(const char* filename)
|
||||
{
|
||||
int fd;
|
||||
int index, length;
|
||||
|
||||
fd = open(TEST_FN, O_WRONLY | O_CREAT | O_TRUNC, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
rt_kprintf("open file for write failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (index = 0; index < sizeof(test_data); index ++)
|
||||
{
|
||||
test_data[index] = index + 27;
|
||||
}
|
||||
|
||||
length = write(fd, test_data, sizeof(test_data));
|
||||
if (length != sizeof(test_data))
|
||||
{
|
||||
rt_kprintf("write data failed\n");
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
fd = open(TEST_FN, O_RDONLY, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
rt_kprintf("check: open file for read failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
length = read(fd, buffer, sizeof(buffer));
|
||||
if (length != sizeof(buffer))
|
||||
{
|
||||
rt_kprintf("check: read file failed\n");
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
for (index = 0; index < sizeof(test_data); index ++)
|
||||
{
|
||||
if (test_data[index] != buffer[index])
|
||||
{
|
||||
rt_kprintf("check: check data failed at %d\n", index);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
rt_kprintf("usb host read/write udisk successful\r\n");
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT(readwrite, usb host read write test);
|
||||
|
||||
#endif
|
|
@ -221,6 +221,14 @@ menu "Onboard Peripheral Drivers"
|
|||
select RT_USING_DFS
|
||||
select RT_USING_DFS_ELMFAT
|
||||
default n
|
||||
|
||||
config BSP_USB0_HOST
|
||||
bool "Enable USB0 Host"
|
||||
default n
|
||||
|
||||
config BSP_USB1_HOST
|
||||
bool "Enable USB1 Host"
|
||||
default n
|
||||
|
||||
menuconfig BSP_USING_ETH
|
||||
bool "Enable Ethernet"
|
||||
|
|
|
@ -9,7 +9,7 @@ MCUX_Config/clock_config.c
|
|||
MCUX_Config/pin_mux.c
|
||||
""")
|
||||
|
||||
CPPPATH = [cwd,cwd + '/MCUX_Config',cwd + '/ports']
|
||||
CPPPATH = [cwd,cwd + '/MCUX_Config',cwd + '/ports',cwd + '/usb']
|
||||
CPPDEFINES = ['CPU_MIMXRT1052CVL5B', 'SKIP_SYSCLK_INIT', 'EVK_MCIMXRM', 'FSL_SDK_ENABLE_DRIVER_CACHE_CONTROL=1','XIP_EXTERNAL_FLASH=1']
|
||||
if GetDepend('BSP_USING_PHY') and GetDepend('PHY_USING_8720A'):
|
||||
src += ['./ports/LAN8720A.c']
|
||||
|
@ -18,6 +18,8 @@ if GetDepend('BSP_USING_SDCARD'):
|
|||
if GetDepend(['RT_USING_DFS_ROMFS']):
|
||||
src += ['ports/romfs.c']
|
||||
src += ['ports/mnt_romfs.c']
|
||||
if GetDepend('RT_USING_USB_HOST'):
|
||||
src += ['usb/drv_usbh.c']
|
||||
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)
|
||||
|
||||
Return('group')
|
||||
|
|
|
@ -0,0 +1,732 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-10-30 ZYH the first version
|
||||
* 2019-12-19 tyustli port to stm32 series
|
||||
* 2021-01-19 Leslie Lee port to imxrt series
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
|
||||
#if defined(BSP_USB0_HOST) || defined(BSP_USB1_HOST)
|
||||
#include "drv_usbh.h"
|
||||
#include <usb/include/usb_host_config.h>
|
||||
#include <usb/include/usb.h>
|
||||
#include <usb/phy/usb_phy.h>
|
||||
#include <usb/host/usb_host.h>
|
||||
#include <usb/host/usb_host_hci.h>
|
||||
#include <usb/host/usb_host_ehci.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
|
||||
/* USB PHY configuration */
|
||||
#ifndef BOARD_USB_PHY_D_CAL
|
||||
#define BOARD_USB_PHY_D_CAL (0x0CU)
|
||||
#endif
|
||||
#ifndef BOARD_USB_PHY_TXCAL45DP
|
||||
#define BOARD_USB_PHY_TXCAL45DP (0x06U)
|
||||
#endif
|
||||
#ifndef BOARD_USB_PHY_TXCAL45DM
|
||||
#define BOARD_USB_PHY_TXCAL45DM (0x06U)
|
||||
#endif
|
||||
|
||||
#define USB_HOST_INTERRUPT_PRIORITY 3
|
||||
|
||||
enum
|
||||
{
|
||||
#ifdef BSP_USB0_HOST
|
||||
USBH0_INDEX,
|
||||
#endif
|
||||
#ifdef BSP_USB1_HOST
|
||||
USBH1_INDEX,
|
||||
#endif
|
||||
};
|
||||
|
||||
struct imxrt_usb_host_pipe
|
||||
{
|
||||
usb_host_pipe_handle pipe_handle;
|
||||
struct rt_completion urb_completion;
|
||||
usb_status_t transfer_status;
|
||||
};
|
||||
|
||||
struct imxrt_usb_host
|
||||
{
|
||||
struct uhcd uhcd;
|
||||
usb_host_handle host_handle;
|
||||
usb_device_handle device_handle;
|
||||
struct imxrt_usb_host_pipe pipes[16];
|
||||
volatile rt_bool_t connect_status;
|
||||
char *name;
|
||||
};
|
||||
|
||||
static struct imxrt_usb_host imxrt_usb_host_obj[] =
|
||||
{
|
||||
#ifdef BSP_USB0_HOST
|
||||
{
|
||||
.connect_status = RT_FALSE,
|
||||
.name = "usbh0"
|
||||
},
|
||||
#endif
|
||||
#ifdef BSP_USB1_HOST
|
||||
{
|
||||
.connect_status = RT_FALSE,
|
||||
.name = "usbh1"
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
static void _imxrt_usb_host_send_callback(void *param, usb_host_transfer_t *transfer, usb_status_t status)
|
||||
{
|
||||
struct imxrt_usb_host_pipe *pipe = (struct imxrt_usb_host_pipe *)param;
|
||||
pipe->transfer_status = status;
|
||||
rt_completion_done(&pipe->urb_completion);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* @brief Initializes USB specific setting that was not set by the Clocks tool.
|
||||
*/
|
||||
static void USB_HostClockInit(usb_controller_index_t controller_id)
|
||||
{
|
||||
usb_phy_config_struct_t phyConfig = {
|
||||
BOARD_USB_PHY_D_CAL, BOARD_USB_PHY_TXCAL45DP, BOARD_USB_PHY_TXCAL45DM,
|
||||
};
|
||||
uint32_t notUsed = 0;
|
||||
|
||||
if (controller_id == kUSB_ControllerEhci0)
|
||||
{
|
||||
CLOCK_EnableUsbhs0PhyPllClock(kCLOCK_Usbphy480M, 480000000U);
|
||||
CLOCK_EnableUsbhs0Clock(kCLOCK_Usb480M, 480000000U);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLOCK_EnableUsbhs1PhyPllClock(kCLOCK_Usbphy480M, 480000000U);
|
||||
CLOCK_EnableUsbhs1Clock(kCLOCK_Usb480M, 480000000U);
|
||||
}
|
||||
|
||||
USB_EhciPhyInit(controller_id, 24000000U, &phyConfig);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Enables interrupt service routines for device.
|
||||
*/
|
||||
void USB_HostIsrEnable(usb_controller_index_t controller_id)
|
||||
{
|
||||
uint8_t irqNumber;
|
||||
#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI > 0U))
|
||||
IRQn_Type usbHOSTEhciIrq[] = USBHS_IRQS;
|
||||
irqNumber = usbHOSTEhciIrq[controller_id - kUSB_ControllerEhci0];
|
||||
#endif
|
||||
/* Install isr, set priority, and enable IRQ. */
|
||||
#if defined(__GIC_PRIO_BITS)
|
||||
GIC_SetPriority((IRQn_Type)irqNumber, USB_HOST_INTERRUPT_PRIORITY);
|
||||
#else
|
||||
NVIC_SetPriority((IRQn_Type)irqNumber, USB_HOST_INTERRUPT_PRIORITY);
|
||||
#endif
|
||||
EnableIRQ((IRQn_Type)irqNumber);
|
||||
}
|
||||
|
||||
#ifdef BSP_USB0_HOST
|
||||
void USB_OTG1_IRQHandler(void)
|
||||
{
|
||||
/* enter interrupt */
|
||||
rt_interrupt_enter();
|
||||
|
||||
USB_HostEhciIsrFunction(imxrt_usb_host_obj[USBH0_INDEX].host_handle);
|
||||
/* leave interrupt */
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
|
||||
static rt_err_t _ehci0_reset_port(rt_uint8_t port)
|
||||
{
|
||||
// No reset port function available
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static uint8_t _ehci0_pipe_buf[64];
|
||||
static uint8_t _ehci0_pipe_idx;
|
||||
|
||||
static int _ehci0_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbytes, int timeouts)
|
||||
{
|
||||
int timeout = timeouts;
|
||||
|
||||
if (!imxrt_usb_host_obj[USBH0_INDEX].connect_status)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
usb_host_transfer_t *transfer;
|
||||
if (imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].pipe_handle == NULL)
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("error operation on null pipe\n"));
|
||||
return -1;
|
||||
}
|
||||
if (USB_HostMallocTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, &transfer) != kStatus_USB_Success)
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("error to get transfer\n"));
|
||||
return -1;
|
||||
}
|
||||
transfer->transferBuffer = buffer;
|
||||
transfer->transferLength = nbytes;
|
||||
transfer->transferSofar = 0;
|
||||
transfer->callbackFn = _imxrt_usb_host_send_callback;
|
||||
transfer->callbackParam = &(imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index]);
|
||||
transfer->direction = (pipe->ep.bEndpointAddress & USB_DIR_IN) ? USB_IN : USB_OUT;
|
||||
if (pipe->ep.bmAttributes == USB_ENDPOINT_CONTROL)
|
||||
{
|
||||
if (token == USBH_PID_SETUP)
|
||||
{
|
||||
struct urequest *setup = (struct urequest *)buffer;
|
||||
transfer->setupStatus = 0;
|
||||
transfer->setupPacket->bmRequestType = setup->request_type;
|
||||
transfer->setupPacket->bRequest = setup->bRequest;
|
||||
transfer->setupPacket->wIndex = setup->wIndex;
|
||||
transfer->setupPacket->wLength = setup->wLength;
|
||||
transfer->setupPacket->wValue = setup->wValue;
|
||||
transfer->transferBuffer = RT_NULL;
|
||||
transfer->transferLength = 0;
|
||||
transfer->next = RT_NULL;
|
||||
if ((transfer->setupPacket->bmRequestType & USB_REQUEST_TYPE_DIR_MASK) == USB_REQUEST_TYPE_DIR_IN)
|
||||
{
|
||||
transfer->direction = USB_IN;
|
||||
transfer->transferBuffer = _ehci0_pipe_buf;
|
||||
transfer->transferLength = setup->wLength;
|
||||
_ehci0_pipe_idx = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
transfer->direction = USB_OUT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_memcpy(buffer, _ehci0_pipe_buf + _ehci0_pipe_idx, nbytes);
|
||||
imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].transfer_status = kStatus_USB_Success;
|
||||
transfer->transferSofar = nbytes;
|
||||
_ehci0_pipe_idx += nbytes;
|
||||
if (_ehci0_pipe_idx >= 64)
|
||||
{
|
||||
_ehci0_pipe_idx = 0;
|
||||
}
|
||||
goto _ehci0_pipe_xfer_finish;
|
||||
}
|
||||
|
||||
}
|
||||
rt_completion_init(&(imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].urb_completion));
|
||||
if (USB_HostEhciWritePipe(((usb_host_instance_t *)imxrt_usb_host_obj[USBH0_INDEX].host_handle)->controllerHandle, imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].pipe_handle, transfer) != kStatus_USB_Success)
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb host failed to send\n"));
|
||||
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
|
||||
return -1;
|
||||
}
|
||||
if (-RT_ETIMEOUT == rt_completion_wait(&(imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].urb_completion), RT_WAITING_FOREVER))
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb transfer timeout\n"));
|
||||
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
|
||||
return -1;
|
||||
}
|
||||
_ehci0_pipe_xfer_finish:
|
||||
switch (imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].transfer_status)
|
||||
{
|
||||
case kStatus_USB_Success:
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("ok\n"));
|
||||
pipe->status = UPIPE_STATUS_OK;
|
||||
if (pipe->callback != RT_NULL)
|
||||
{
|
||||
pipe->callback(pipe);
|
||||
}
|
||||
size_t size = transfer->transferSofar;
|
||||
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
|
||||
if (pipe->ep.bEndpointAddress & 0x80)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
else if (pipe->ep.bEndpointAddress & 0x00)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
return nbytes;
|
||||
break;
|
||||
}
|
||||
case kStatus_USB_TransferStall:
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("stall\n"));
|
||||
pipe->status = UPIPE_STATUS_STALL;
|
||||
if (pipe->callback != RT_NULL)
|
||||
{
|
||||
pipe->callback(pipe);
|
||||
}
|
||||
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
case kStatus_USB_TransferFailed:
|
||||
default:
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("error\n"));
|
||||
pipe->status = UPIPE_STATUS_ERROR;
|
||||
if (pipe->callback != RT_NULL)
|
||||
{
|
||||
pipe->callback(pipe);
|
||||
}
|
||||
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static rt_uint16_t _ehci0_pipe_index = 0;
|
||||
static rt_uint8_t _ehci0_get_free_pipe_index(void)
|
||||
{
|
||||
rt_uint8_t idx;
|
||||
for (idx = 1; idx < 16; idx++)
|
||||
{
|
||||
if (!(_ehci0_pipe_index & (0x01 << idx)))
|
||||
{
|
||||
_ehci0_pipe_index |= (0x01 << idx);
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
static void _ehci0_free_pipe_index(rt_uint8_t index)
|
||||
{
|
||||
_ehci0_pipe_index &= ~(0x01 << index);
|
||||
}
|
||||
|
||||
static rt_err_t _ehci0_open_pipe(upipe_t pipe)
|
||||
{
|
||||
pipe->pipe_index = _ehci0_get_free_pipe_index();
|
||||
if (pipe->pipe_index == 0xFF)
|
||||
{
|
||||
return -RT_ERROR;
|
||||
}
|
||||
usb_host_pipe_init_t pipe_init =
|
||||
{
|
||||
.devInstance = imxrt_usb_host_obj[USBH0_INDEX].device_handle,
|
||||
.pipeType = pipe->ep.bmAttributes,
|
||||
.direction = (pipe->ep.bEndpointAddress & USB_DIR_IN) ? USB_IN : USB_OUT,
|
||||
.endpointAddress = (pipe->ep.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_NUMBER_MASK),
|
||||
.interval = pipe->ep.bInterval,
|
||||
.maxPacketSize = (uint16_t)(pipe->ep.wMaxPacketSize & USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_SIZE_MASK),
|
||||
.numberPerUframe = (uint8_t)(pipe->ep.wMaxPacketSize & USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_MULT_TRANSACTIONS_MASK),
|
||||
.nakCount = USB_HOST_CONFIG_MAX_NAK,
|
||||
};
|
||||
USB_HostOpenPipe(imxrt_usb_host_obj[USBH0_INDEX].host_handle, &imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].pipe_handle, &pipe_init);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t _ehci0_close_pipe(upipe_t pipe)
|
||||
{
|
||||
(void)USB_HostClosePipe(imxrt_usb_host_obj[USBH0_INDEX].host_handle, imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].pipe_handle);
|
||||
_ehci0_free_pipe_index(pipe->pipe_index);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static struct uhcd_ops _ehci0_uhcd_ops =
|
||||
{
|
||||
_ehci0_reset_port,
|
||||
_ehci0_pipe_xfer,
|
||||
_ehci0_open_pipe,
|
||||
_ehci0_close_pipe,
|
||||
};
|
||||
|
||||
static usb_status_t usb0_host_callback(usb_device_handle handle, usb_host_configuration_handle config_handle, rt_uint32_t event_code)
|
||||
{
|
||||
usb_status_t status = kStatus_USB_Success;
|
||||
|
||||
switch (event_code)
|
||||
{
|
||||
case kUSB_HostEventAttach:
|
||||
if (!imxrt_usb_host_obj[USBH0_INDEX].connect_status)
|
||||
{
|
||||
imxrt_usb_host_obj[USBH0_INDEX].connect_status = RT_TRUE;
|
||||
imxrt_usb_host_obj[USBH0_INDEX].device_handle = handle;
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb connected\n"));
|
||||
rt_usbh_root_hub_connect_handler(&(imxrt_usb_host_obj[USBH0_INDEX].uhcd), OTG_PORT, RT_TRUE);
|
||||
}
|
||||
break;
|
||||
|
||||
case kUSB_HostEventNotSupported:
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb device not supported\n"));
|
||||
break;
|
||||
|
||||
case kUSB_HostEventEnumerationDone:
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("enumeration done\n"));
|
||||
break;
|
||||
|
||||
case kUSB_HostEventDetach:
|
||||
if (imxrt_usb_host_obj[USBH0_INDEX].connect_status)
|
||||
{
|
||||
imxrt_usb_host_obj[USBH0_INDEX].connect_status = RT_FALSE;
|
||||
imxrt_usb_host_obj[USBH0_INDEX].device_handle = handle;
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb disconnnect\n"));
|
||||
rt_usbh_root_hub_disconnect_handler(&(imxrt_usb_host_obj[USBH0_INDEX].uhcd), OTG_PORT);
|
||||
(void)USB_HostCloseDeviceInterface(handle, NULL);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
rt_thread_t usbh0_thread;
|
||||
|
||||
static void _ehci0_usbh_thread(void* param)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
USB_HostEhciTaskFunction(imxrt_usb_host_obj[USBH0_INDEX].host_handle);
|
||||
}
|
||||
}
|
||||
|
||||
static rt_err_t _ehci0_usbh_init(rt_device_t device)
|
||||
{
|
||||
USB_HostClockInit(kUSB_ControllerEhci0);
|
||||
|
||||
if (kStatus_USB_Success == USB_HostInit(kUSB_ControllerEhci0, &imxrt_usb_host_obj[USBH0_INDEX].host_handle, usb0_host_callback))
|
||||
{
|
||||
usbh0_thread = rt_thread_create("ehci0", _ehci0_usbh_thread, RT_NULL, 500, 4, 9999999);
|
||||
rt_thread_startup(usbh0_thread);
|
||||
USB_HostIsrEnable(kUSB_ControllerEhci0);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("USB_HostInit ehci0 error\r\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USB1_HOST
|
||||
void USB_OTG2_IRQHandler(void)
|
||||
{
|
||||
/* enter interrupt */
|
||||
rt_interrupt_enter();
|
||||
|
||||
USB_HostEhciIsrFunction(imxrt_usb_host_obj[USBH1_INDEX].host_handle);
|
||||
/* leave interrupt */
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
|
||||
static rt_err_t _ehci1_reset_port(rt_uint8_t port)
|
||||
{
|
||||
// No reset port function available
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static uint8_t _ehci1_pipe_buf[64];
|
||||
static uint8_t _ehci1_pipe_idx;
|
||||
|
||||
static int _ehci1_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbytes, int timeouts)
|
||||
{
|
||||
int timeout = timeouts;
|
||||
|
||||
if (!imxrt_usb_host_obj[USBH1_INDEX].connect_status)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
usb_host_transfer_t *transfer;
|
||||
if (imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].pipe_handle == NULL)
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("error operation on null pipe\n"));
|
||||
return -1;
|
||||
}
|
||||
if (USB_HostMallocTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, &transfer) != kStatus_USB_Success)
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("error to get transfer\n"));
|
||||
return -1;
|
||||
}
|
||||
transfer->transferBuffer = buffer;
|
||||
transfer->transferLength = nbytes;
|
||||
transfer->transferSofar = 0;
|
||||
transfer->callbackFn = _imxrt_usb_host_send_callback;
|
||||
transfer->callbackParam = &(imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index]);
|
||||
transfer->direction = (pipe->ep.bEndpointAddress & USB_DIR_IN) ? USB_IN : USB_OUT;
|
||||
if (pipe->ep.bmAttributes == USB_ENDPOINT_CONTROL)
|
||||
{
|
||||
if (token == USBH_PID_SETUP)
|
||||
{
|
||||
struct urequest *setup = (struct urequest *)buffer;
|
||||
transfer->setupStatus = 0;
|
||||
transfer->setupPacket->bmRequestType = setup->request_type;
|
||||
transfer->setupPacket->bRequest = setup->bRequest;
|
||||
transfer->setupPacket->wIndex = setup->wIndex;
|
||||
transfer->setupPacket->wLength = setup->wLength;
|
||||
transfer->setupPacket->wValue = setup->wValue;
|
||||
transfer->transferBuffer = RT_NULL;
|
||||
transfer->transferLength = 0;
|
||||
transfer->next = RT_NULL;
|
||||
if ((transfer->setupPacket->bmRequestType & USB_REQUEST_TYPE_DIR_MASK) == USB_REQUEST_TYPE_DIR_IN)
|
||||
{
|
||||
transfer->direction = USB_IN;
|
||||
transfer->transferBuffer = _ehci1_pipe_buf;
|
||||
transfer->transferLength = setup->wLength;
|
||||
_ehci1_pipe_idx = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
transfer->direction = USB_OUT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_memcpy(buffer, _ehci1_pipe_buf + _ehci1_pipe_idx, nbytes);
|
||||
imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].transfer_status = kStatus_USB_Success;
|
||||
transfer->transferSofar = nbytes;
|
||||
_ehci1_pipe_idx += nbytes;
|
||||
if (_ehci1_pipe_idx >= 64)
|
||||
{
|
||||
_ehci1_pipe_idx = 0;
|
||||
}
|
||||
goto _ehci1_pipe_xfer_finish;
|
||||
}
|
||||
|
||||
}
|
||||
rt_completion_init(&(imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].urb_completion));
|
||||
if (USB_HostEhciWritePipe(((usb_host_instance_t *)imxrt_usb_host_obj[USBH1_INDEX].host_handle)->controllerHandle, imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].pipe_handle, transfer) != kStatus_USB_Success)
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb host failed to send\n"));
|
||||
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
|
||||
return -1;
|
||||
}
|
||||
if (-RT_ETIMEOUT == rt_completion_wait(&(imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].urb_completion), RT_WAITING_FOREVER))
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb transfer timeout\n"));
|
||||
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
|
||||
return -1;
|
||||
}
|
||||
// rt_thread_mdelay(1);
|
||||
_ehci1_pipe_xfer_finish:
|
||||
switch (imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].transfer_status)
|
||||
{
|
||||
case kStatus_USB_Success:
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("ok\n"));
|
||||
pipe->status = UPIPE_STATUS_OK;
|
||||
if (pipe->callback != RT_NULL)
|
||||
{
|
||||
pipe->callback(pipe);
|
||||
}
|
||||
size_t size = transfer->transferSofar;
|
||||
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
|
||||
if (pipe->ep.bEndpointAddress & 0x80)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
else if (pipe->ep.bEndpointAddress & 0x00)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
return nbytes;
|
||||
break;
|
||||
}
|
||||
case kStatus_USB_TransferStall:
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("stall\n"));
|
||||
pipe->status = UPIPE_STATUS_STALL;
|
||||
if (pipe->callback != RT_NULL)
|
||||
{
|
||||
pipe->callback(pipe);
|
||||
}
|
||||
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
case kStatus_USB_TransferFailed:
|
||||
default:
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("error\n"));
|
||||
pipe->status = UPIPE_STATUS_ERROR;
|
||||
if (pipe->callback != RT_NULL)
|
||||
{
|
||||
pipe->callback(pipe);
|
||||
}
|
||||
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static rt_uint16_t _ehci1_pipe_index = 0;
|
||||
static rt_uint8_t _ehci1_get_free_pipe_index(void)
|
||||
{
|
||||
rt_uint8_t idx;
|
||||
for (idx = 1; idx < 16; idx++)
|
||||
{
|
||||
if (!(_ehci1_pipe_index & (0x01 << idx)))
|
||||
{
|
||||
_ehci1_pipe_index |= (0x01 << idx);
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
static void _ehci1_free_pipe_index(rt_uint8_t index)
|
||||
{
|
||||
_ehci1_pipe_index &= ~(0x01 << index);
|
||||
}
|
||||
|
||||
static rt_err_t _ehci1_open_pipe(upipe_t pipe)
|
||||
{
|
||||
pipe->pipe_index = _ehci1_get_free_pipe_index();
|
||||
if (pipe->pipe_index == 0xFF)
|
||||
{
|
||||
return -RT_ERROR;
|
||||
}
|
||||
usb_host_pipe_init_t pipe_init =
|
||||
{
|
||||
.devInstance = imxrt_usb_host_obj[USBH1_INDEX].device_handle,
|
||||
.pipeType = pipe->ep.bmAttributes,
|
||||
.direction = (pipe->ep.bEndpointAddress & USB_DIR_IN) ? USB_IN : USB_OUT,
|
||||
.endpointAddress = (pipe->ep.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_NUMBER_MASK),
|
||||
.interval = pipe->ep.bInterval,
|
||||
.maxPacketSize = (uint16_t)(pipe->ep.wMaxPacketSize & USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_SIZE_MASK),
|
||||
.numberPerUframe = (uint8_t)(pipe->ep.wMaxPacketSize & USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_MULT_TRANSACTIONS_MASK),
|
||||
.nakCount = USB_HOST_CONFIG_MAX_NAK,
|
||||
};
|
||||
USB_HostOpenPipe(imxrt_usb_host_obj[USBH1_INDEX].host_handle, &imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].pipe_handle, &pipe_init);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t _ehci1_close_pipe(upipe_t pipe)
|
||||
{
|
||||
(void)USB_HostClosePipe(imxrt_usb_host_obj[USBH1_INDEX].host_handle, imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].pipe_handle);
|
||||
_ehci1_free_pipe_index(pipe->pipe_index);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static struct uhcd_ops _ehci1_uhcd_ops =
|
||||
{
|
||||
_ehci1_reset_port,
|
||||
_ehci1_pipe_xfer,
|
||||
_ehci1_open_pipe,
|
||||
_ehci1_close_pipe,
|
||||
};
|
||||
|
||||
static usb_status_t usb1_host_callback(usb_device_handle handle, usb_host_configuration_handle config_handle, rt_uint32_t event_code)
|
||||
{
|
||||
usb_status_t status = kStatus_USB_Success;
|
||||
|
||||
switch (event_code)
|
||||
{
|
||||
case kUSB_HostEventAttach:
|
||||
if (!imxrt_usb_host_obj[USBH1_INDEX].connect_status)
|
||||
{
|
||||
imxrt_usb_host_obj[USBH1_INDEX].connect_status = RT_TRUE;
|
||||
imxrt_usb_host_obj[USBH1_INDEX].device_handle = handle;
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb connected\n"));
|
||||
rt_usbh_root_hub_connect_handler(&(imxrt_usb_host_obj[USBH1_INDEX].uhcd), OTG_PORT, RT_TRUE);
|
||||
}
|
||||
break;
|
||||
|
||||
case kUSB_HostEventNotSupported:
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb device not supported\n"));
|
||||
break;
|
||||
|
||||
case kUSB_HostEventEnumerationDone:
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("enumeration done\n"));
|
||||
break;
|
||||
|
||||
case kUSB_HostEventDetach:
|
||||
if (imxrt_usb_host_obj[USBH1_INDEX].connect_status)
|
||||
{
|
||||
imxrt_usb_host_obj[USBH1_INDEX].connect_status = RT_FALSE;
|
||||
imxrt_usb_host_obj[USBH1_INDEX].device_handle = handle;
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb disconnnect\n"));
|
||||
rt_usbh_root_hub_disconnect_handler(&(imxrt_usb_host_obj[USBH1_INDEX].uhcd), OTG_PORT);
|
||||
(void)USB_HostCloseDeviceInterface(handle, NULL);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
rt_thread_t usbh1_thread;
|
||||
|
||||
static void _ehci1_usbh_thread(void* param)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
USB_HostEhciTaskFunction(imxrt_usb_host_obj[USBH1_INDEX].host_handle);
|
||||
}
|
||||
}
|
||||
|
||||
static rt_err_t _ehci1_usbh_init(rt_device_t device)
|
||||
{
|
||||
USB_HostClockInit(kUSB_ControllerEhci1);
|
||||
|
||||
if (kStatus_USB_Success == USB_HostInit(kUSB_ControllerEhci1, &imxrt_usb_host_obj[USBH1_INDEX].host_handle, usb1_host_callback))
|
||||
{
|
||||
usbh1_thread = rt_thread_create("ehci1", _ehci1_usbh_thread, RT_NULL, 500, 4, 9999999);
|
||||
rt_thread_startup(usbh1_thread);
|
||||
USB_HostIsrEnable(kUSB_ControllerEhci1);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("USB_HostInit ehci1 error\r\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
#endif
|
||||
|
||||
int imxrt_usbh_register(void)
|
||||
{
|
||||
rt_kprintf("register usbh1\r\n");
|
||||
rt_err_t res = -RT_ERROR;
|
||||
struct imxrt_usb_host *usb_host_obj;
|
||||
|
||||
#ifdef BSP_USB0_HOST
|
||||
usb_host_obj = &(imxrt_usb_host_obj[USBH0_INDEX]);
|
||||
rt_memset((void *)(&(usb_host_obj->uhcd)), 0, sizeof(struct uhcd));
|
||||
usb_host_obj->uhcd.parent.type = RT_Device_Class_USBHost;
|
||||
usb_host_obj->uhcd.parent.init = _ehci0_usbh_init;
|
||||
usb_host_obj->uhcd.parent.user_data = usb_host_obj;
|
||||
usb_host_obj->uhcd.ops = &_ehci0_uhcd_ops;
|
||||
usb_host_obj->uhcd.num_ports = OTG_PORT;
|
||||
res = rt_device_register(&(usb_host_obj->uhcd.parent), usb_host_obj->name, RT_DEVICE_FLAG_DEACTIVATE);
|
||||
if (res != RT_EOK)
|
||||
{
|
||||
rt_kprintf("register usb0 host failed res = %d\r\n", res);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
/*modify by zjr*/
|
||||
rt_usb_host_init();
|
||||
#endif
|
||||
#ifdef BSP_USB1_HOST
|
||||
usb_host_obj = &(imxrt_usb_host_obj[USBH1_INDEX]);
|
||||
rt_memset((void *)(&(usb_host_obj->uhcd)), 0, sizeof(struct uhcd));
|
||||
usb_host_obj->uhcd.parent.type = RT_Device_Class_USBHost;
|
||||
usb_host_obj->uhcd.parent.init = _ehci1_usbh_init;
|
||||
usb_host_obj->uhcd.parent.user_data = usb_host_obj;
|
||||
usb_host_obj->uhcd.ops = &_ehci1_uhcd_ops;
|
||||
usb_host_obj->uhcd.num_ports = OTG_PORT;
|
||||
res = rt_device_register(&(usb_host_obj->uhcd.parent), usb_host_obj->name, RT_DEVICE_FLAG_DEACTIVATE);
|
||||
if (res != RT_EOK)
|
||||
{
|
||||
rt_kprintf("register usb0 host failed res = %d\r\n", res);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
/*modify by zjr*/
|
||||
rt_usb_host_init();
|
||||
// rt_usb_host_init(usb_host_obj->name);
|
||||
#endif
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_DEVICE_EXPORT(imxrt_usbh_register);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-12-12 ZYH the first version
|
||||
* 2019-12-19 tyustli port to stm32 series
|
||||
* 2021-01-19 Leslie Lee port to imxrt series
|
||||
*/
|
||||
#ifndef __DRV_USBH_H__
|
||||
#define __DRV_USBH_H__
|
||||
#include <rtthread.h>
|
||||
|
||||
#define OTG_PORT 1
|
||||
|
||||
int imxrt_usbh_register(void);
|
||||
|
||||
#endif
|
||||
|
||||
/************* end of file ************/
|
Binary file not shown.
After Width: | Height: | Size: 163 KiB |
Binary file not shown.
After Width: | Height: | Size: 84 KiB |
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Loading…
Reference in New Issue