mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 13:27:01 +08:00
Use small lock to protect usbdev and endpoint in arch renesas.
Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sched.h>
|
||||||
|
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
@@ -45,6 +46,7 @@
|
|||||||
#include <nuttx/serial/serial.h>
|
#include <nuttx/serial/serial.h>
|
||||||
|
|
||||||
#include <nuttx/irq.h>
|
#include <nuttx/irq.h>
|
||||||
|
#include <nuttx/spinlock.h>
|
||||||
#include <arch/board/board.h>
|
#include <arch/board/board.h>
|
||||||
#include <arch/chip/types.h>
|
#include <arch/chip/types.h>
|
||||||
|
|
||||||
@@ -240,6 +242,10 @@ struct rx65n_usbdev_s
|
|||||||
/* The endpoint list */
|
/* The endpoint list */
|
||||||
|
|
||||||
struct rx65n_ep_s eplist[RX65N_NENDPOINTS];
|
struct rx65n_ep_s eplist[RX65N_NENDPOINTS];
|
||||||
|
|
||||||
|
/* Spinlock */
|
||||||
|
|
||||||
|
spinlock_t lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* For maintaining tables of endpoint info */
|
/* For maintaining tables of endpoint info */
|
||||||
@@ -1838,9 +1844,9 @@ static void rx65n_reqcomplete(struct rx65n_ep_s *privep, int16_t result)
|
|||||||
|
|
||||||
/* Remove the completed request at the head of the endpoint request list */
|
/* Remove the completed request at the head of the endpoint request list */
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = spin_lock_irqsave(&privep->dev->lock);
|
||||||
privreq = rx65n_rqdequeue(privep);
|
privreq = rx65n_rqdequeue(privep);
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&privep->dev->lock, flags);
|
||||||
|
|
||||||
if (privreq)
|
if (privreq)
|
||||||
{
|
{
|
||||||
@@ -2998,10 +3004,12 @@ static int rx65n_epdisable(struct usbdev_ep_s *ep)
|
|||||||
|
|
||||||
/* Cancel any ongoing activity */
|
/* Cancel any ongoing activity */
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = spin_lock_irqsave(&privep->dev->lock);
|
||||||
|
sched_lock();
|
||||||
rx65n_cancelrequests(privep);
|
rx65n_cancelrequests(privep);
|
||||||
|
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&privep->dev->lock, flags);
|
||||||
|
sched_unlock();
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3106,7 +3114,8 @@ static int rx65n_epsubmit(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
|
|||||||
epno = USB_EPNO(ep->eplog);
|
epno = USB_EPNO(ep->eplog);
|
||||||
req->result = -EINPROGRESS;
|
req->result = -EINPROGRESS;
|
||||||
req->xfrd = 0;
|
req->xfrd = 0;
|
||||||
flags = enter_critical_section();
|
flags = spin_lock_irqsave(&priv->lock);
|
||||||
|
sched_lock();
|
||||||
|
|
||||||
/* If we are stalled, then drop all requests on the floor */
|
/* If we are stalled, then drop all requests on the floor */
|
||||||
|
|
||||||
@@ -3133,7 +3142,8 @@ static int rx65n_epsubmit(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
|
|||||||
{
|
{
|
||||||
privreq->req.len = CDC_CLASS_DATA_LENGTH;
|
privreq->req.len = CDC_CLASS_DATA_LENGTH;
|
||||||
rx65n_rdrequest(epno, priv, privep);
|
rx65n_rdrequest(epno, priv, privep);
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
|
sched_unlock();
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3142,7 +3152,8 @@ static int rx65n_epsubmit(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
|
|||||||
if (!privep->txbusy)
|
if (!privep->txbusy)
|
||||||
{
|
{
|
||||||
ret = rx65n_wrrequest(epno, priv, privep);
|
ret = rx65n_wrrequest(epno, priv, privep);
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
|
sched_unlock();
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3156,7 +3167,8 @@ static int rx65n_epsubmit(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
|
|||||||
if (priv->ep0state == EP0STATE_RDREQUEST)
|
if (priv->ep0state == EP0STATE_RDREQUEST)
|
||||||
{
|
{
|
||||||
rx65n_rdrequest(epno, priv, privep);
|
rx65n_rdrequest(epno, priv, privep);
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
|
sched_unlock();
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3189,7 +3201,8 @@ static int rx65n_epsubmit(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
|
sched_unlock();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3230,9 +3243,11 @@ static int rx65n_epcancel(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
|
|||||||
#endif
|
#endif
|
||||||
usbtrace(TRACE_EPCANCEL, USB_EPNO(ep->eplog));
|
usbtrace(TRACE_EPCANCEL, USB_EPNO(ep->eplog));
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = spin_lock_irqsave(&privep->dev->lock);
|
||||||
|
sched_lock();
|
||||||
rx65n_cancelrequests(privep);
|
rx65n_cancelrequests(privep);
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&privep->dev->lock, flags);
|
||||||
|
sched_unlock();
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3247,7 +3262,7 @@ static inline struct rx65n_ep_s *rx65n_epreserve(struct rx65n_usbdev_s *priv,
|
|||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
int epndx = 0;
|
int epndx = 0;
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = spin_lock_irqsave(&priv->lock);
|
||||||
epset &= priv->epavail;
|
epset &= priv->epavail;
|
||||||
if (epset)
|
if (epset)
|
||||||
{
|
{
|
||||||
@@ -3272,7 +3287,7 @@ static inline struct rx65n_ep_s *rx65n_epreserve(struct rx65n_usbdev_s *priv,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
return privep;
|
return privep;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3366,9 +3381,9 @@ errout:
|
|||||||
static inline void
|
static inline void
|
||||||
rx65n_epunreserve(struct rx65n_usbdev_s *priv, struct rx65n_ep_s *privep)
|
rx65n_epunreserve(struct rx65n_usbdev_s *priv, struct rx65n_ep_s *privep)
|
||||||
{
|
{
|
||||||
irqstate_t flags = enter_critical_section();
|
irqstate_t flags = spin_lock_irqsave(&priv->lock);
|
||||||
priv->epavail |= RX65N_ENDP_BIT(USB_EPNO(privep->ep.eplog));
|
priv->epavail |= RX65N_ENDP_BIT(USB_EPNO(privep->ep.eplog));
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -6031,6 +6046,10 @@ void renesas_usbinitialize(void)
|
|||||||
int epno;
|
int epno;
|
||||||
usbtrace(TRACE_DEVINIT, 0);
|
usbtrace(TRACE_DEVINIT, 0);
|
||||||
|
|
||||||
|
/* Initialize driver lock */
|
||||||
|
|
||||||
|
spin_lock_init(&priv->lock);
|
||||||
|
|
||||||
/* Enable write to System registers */
|
/* Enable write to System registers */
|
||||||
|
|
||||||
regval = rx65n_getreg16(RX65N_PRCR_ADDR);
|
regval = rx65n_getreg16(RX65N_PRCR_ADDR);
|
||||||
|
|||||||
Reference in New Issue
Block a user