usbhost: used wd timer to process loop event

used wdt thread process event

Signed-off-by: yezhonghui <yezhonghui@xiaomi.com>
This commit is contained in:
yezhonghui
2025-04-14 15:55:56 +08:00
committed by Xiang Xiao
parent bb304441db
commit 0e6afae4f2
3 changed files with 76 additions and 88 deletions
-11
View File
@@ -219,17 +219,6 @@ static int sim_loop_task(int argc, char **argv)
{
while (1)
{
irqstate_t flags = up_irq_save();
sched_lock();
sched_unlock();
up_irq_restore(flags);
#ifdef CONFIG_SIM_USB_HOST
sim_usbhost_loop();
#endif
/* Sleep minimal time, let the idle run */
usleep(CONFIG_SIM_LOOPTASK_INTERVAL);
-1
View File
@@ -495,7 +495,6 @@ void sim_usbdev_initialize(void);
#ifdef CONFIG_SIM_USB_HOST
int sim_usbhost_initialize(void);
int sim_usbhost_loop(void);
#endif
/* sim_canchar.c ************************************************************/
+76 -76
View File
@@ -52,6 +52,7 @@
****************************************************************************/
#define SIM_USBHOST_BUFSIZE 256
#define SIM_USBHOST_PERIOD MSEC2TICK(CONFIG_SIM_LOOP_INTERVAL)
#define RHPNDX(rh) ((rh)->hport.hport.port)
#define RHPORT(rh) (RHPNDX(rh)+1)
@@ -110,6 +111,7 @@ struct sim_usbhost_s
sem_t pscsem; /* Semaphore to wait for port status change events */
struct usbhost_devaddr_s devgen; /* Address generation data */
struct wdog_s wdog;
};
/****************************************************************************
@@ -657,6 +659,79 @@ static void sim_usbhost_rqcomplete(struct sim_usbhost_s *drvr)
}
}
/****************************************************************************
* Name: sim_usbhost_interrupt
****************************************************************************/
static void sim_usbhost_interrupt(wdparm_t arg)
{
struct sim_usbhost_s *priv = (struct sim_usbhost_s *)arg;
struct usbhost_hubport_s *hport;
bool connect;
/* Handle root hub status change on each root port */
connect = host_usbhost_getconnstate();
/* Check current connect status */
if (connect)
{
/* Connected ... Did we just become connected? */
if (!priv->connected)
{
host_usbhost_open();
/* Yes.. connected. */
priv->connected = true;
/* Notify any waiters */
nxsem_post(&priv->pscsem);
priv->pscwait = false;
}
sim_usbhost_rqcomplete(priv);
}
else
{
/* Disconnected... Did we just become disconnected? */
if (priv->connected)
{
sim_usbhost_rqcomplete(priv);
host_usbhost_close();
/* Yes.. disconnect the device */
priv->connected = false;
/* Are we bound to a class instance? */
hport = &priv->hport.hport;
if (hport->devclass)
{
/* Yes.. Disconnect the class */
CLASS_DISCONNECTED(hport->devclass);
hport->devclass = NULL;
}
/* Notify any waiters for the Root Hub Status change
* event.
*/
nxsem_post(&priv->pscsem);
priv->pscwait = false;
}
}
wd_start_next(&priv->wdog, SIM_USBHOST_PERIOD, sim_usbhost_interrupt, arg);
}
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -724,82 +799,7 @@ int sim_usbhost_initialize(void)
return -ENODEV;
}
return OK;
}
/****************************************************************************
* Name: sim_usbhost_loop
*
* Description:
* USB host loop process.
*
****************************************************************************/
int sim_usbhost_loop(void)
{
struct sim_usbhost_s *priv = &g_sim_usbhost;
struct usbhost_hubport_s *hport;
bool connect;
/* Handle root hub status change on each root port */
connect = host_usbhost_getconnstate();
/* Check current connect status */
if (connect)
{
/* Connected ... Did we just become connected? */
if (!priv->connected)
{
host_usbhost_open();
/* Yes.. connected. */
priv->connected = true;
/* Notify any waiters */
nxsem_post(&priv->pscsem);
priv->pscwait = false;
}
sim_usbhost_rqcomplete(priv);
}
else
{
/* Disconnected... Did we just become disconnected? */
if (priv->connected)
{
sim_usbhost_rqcomplete(priv);
host_usbhost_close();
/* Yes.. disconnect the device */
priv->connected = false;
/* Are we bound to a class instance? */
hport = &priv->hport.hport;
if (hport->devclass)
{
/* Yes.. Disconnect the class */
CLASS_DISCONNECTED(hport->devclass);
hport->devclass = NULL;
}
/* Notify any waiters for the Root Hub Status change
* event.
*/
nxsem_post(&priv->pscsem);
priv->pscwait = false;
}
}
wd_start(&priv->wdog, 0, sim_usbhost_interrupt, (wdparm_t)priv);
return OK;
}