summaryrefslogtreecommitdiff
path: root/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-04-05 17:44:04 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-04-05 17:44:04 +0000
commit7d6b25e17e4a83e7fd20cec47203fa897c53113a (patch)
tree6f91b9b19d0a241c182bacdb0a621f438e2abf56 /nuttx/arch/arm/src/stm32/stm32_otgfsdev.c
parent8cd35f60598c48898e560e8488f965ac7cbb3030 (diff)
downloadpx4-nuttx-7d6b25e17e4a83e7fd20cec47203fa897c53113a.tar.gz
px4-nuttx-7d6b25e17e4a83e7fd20cec47203fa897c53113a.tar.bz2
px4-nuttx-7d6b25e17e4a83e7fd20cec47203fa897c53113a.zip
Beginning of a NuttX configuration tool
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4560 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/arm/src/stm32/stm32_otgfsdev.c')
-rwxr-xr-xnuttx/arch/arm/src/stm32/stm32_otgfsdev.c248
1 files changed, 172 insertions, 76 deletions
diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c
index 2fe7582a1..227489bb5 100755
--- a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c
+++ b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c
@@ -365,20 +365,21 @@ static bool stm32_addlast(FAR struct stm32_ep_s *privep,
/* Low level data transfers and request operations *****************************/
-static inline void stm32_ep0xfer(uint8_t epphy, uint8_t *data, uint32_t nbytes);
+static inline void stm32_ep0xfer(uint8_t epphy, FAR uint8_t *data, uint32_t nbytes);
static void stm32_ep0read(FAR uint8_t *dest, uint16_t len);
-static void stm32_flushep(struct stm32_ep_s *privep);
+static void stm32_flushep(FAR struct stm32_ep_s *privep);
-static inline void stm32_abortrequest(struct stm32_ep_s *privep,
- struct stm32_req_s *privreq, int16_t result);
-static void stm32_reqcomplete(struct stm32_ep_s *privep, int16_t result);
+static inline void stm32_abortrequest(FAR struct stm32_ep_s *privep,
+ FAR struct stm32_req_s *privreq, int16_t result);
+static void stm32_reqcomplete(FAR struct stm32_ep_s *privep, int16_t result);
-static int stm32_wrrequest(struct stm32_usbdev_s *priv,
- struct stm32_ep_s *privep);
-static int stm32_rdrequest(struct stm32_usbdev_s *priv,
- struct stm32_ep_s *privep);
-static void stm32_cancelrequests(struct stm32_ep_s *privep, int16_t status);
+static int stm32_wrrequest(FAR struct stm32_usbdev_s *priv,
+ FAR struct stm32_ep_s *privep);
+static int stm32_rdrequest(FAR struct stm32_usbdev_s *priv,
+ FAR struct stm32_ep_s *privep);
+static void stm32_cancelrequests(FAR struct stm32_ep_s *privep,
+ int16_t status);
/* Interrupt handling **********************************************************/
@@ -386,7 +387,6 @@ static struct stm32_ep_s *stm32_epfindbyaddr(struct stm32_usbdev_s *priv,
uint16_t eplog);
static int stm32_dispatchrequest(struct stm32_usbdev_s *priv,
const struct usb_ctrlreq_s *ctrl);
-static void stm32_ep0configure(struct stm32_usbdev_s *priv);
static void stm32_usbreset(struct stm32_usbdev_s *priv);
static void stm32_ep0complete(struct stm32_usbdev_s *priv, uint8_t epphy);
@@ -416,6 +416,7 @@ static inline void stm32_epininterrupt(FAR struct stm32_usbdev_s *priv);
static inline void stm32_resumeinterrupt(FAR struct stm32_usbdev_s *priv);
static inline void stm32_suspendinterrupt(FAR struct stm32_usbdev_s *priv);
static inline void stm32_rxinterrupt(FAR struct stm32_usbdev_s *priv);
+static inline void stm32_resetinterrupt(FAR struct stm32_usbdev_s *priv);
static inline void stm32_enuminterrupt(FAR struct stm32_usbdev_s *priv);
#ifdef CONFIG_USBDEV_ISOCHRONOUS
static inline void stm32_isocininterrupt(FAR struct stm32_usbdev_s *priv);
@@ -431,9 +432,16 @@ static inline void stm32_otginterrupt(FAR struct stm32_usbdev_s *priv);
static int stm32_usbinterrupt(int irq, FAR void *context);
/* Endpoint operations *********************************************************/
+/* Endpoint configuration */
+static int stm32_epoutconfigure(FAR struct usbdev_ep_s *privep,
+ uint8_t eptype, uint16_t maxpacket);
+static int stm32_epinconfigure(FAR struct usbdev_ep_s *privep,
+ uint8_t eptype, uint16_t maxpacket);
static int stm32_epconfigure(FAR struct usbdev_ep_s *ep,
- const struct usb_epdesc_s *desc, bool last);
+ FAR const struct usb_epdesc_s *desc, bool last);
+static void stm32_ep0configure(FAR struct stm32_usbdev_s *priv);
+
static int stm32_epdisable(FAR struct usbdev_ep_s *ep);
static FAR struct usbdev_req_s *stm32_epallocreq(FAR struct usbdev_ep_s *ep);
static void stm32_epfreereq(FAR struct usbdev_ep_s *ep,
@@ -1066,23 +1074,6 @@ static int stm32_dispatchrequest(struct stm32_usbdev_s *priv,
}
/*******************************************************************************
- * Name: stm32_ep0configure
- *
- * Description:
- * Reset Usb engine
- *
- *******************************************************************************/
-
-static void stm32_ep0configure(struct stm32_usbdev_s *priv)
-{
- /* Enable ep0 IN and ep0 OUT */
-#warning "Missing Logic"
-
- /* Enable EP0 */
-#warning "Missing Logic"
-}
-
-/*******************************************************************************
* Name: stm32_usbreset
*
* Description:
@@ -2226,6 +2217,30 @@ static inline void stm32_rxinterrupt(FAR struct stm32_usbdev_s *priv)
}
/*******************************************************************************
+ * Name: stm32_resetinterrupt
+ *
+ * Description:
+ * USB reset interrupt
+ *
+ *******************************************************************************/
+
+static inline void stm32_resetinterrupt(FAR struct stm32_usbdev_s *priv)
+{
+ /* Perform the device reset */
+#warning "Reset hardware?"
+
+ /* Re-configure EP0 */
+
+ stm32_ep0configure(priv);
+
+ /* And put the device back in the initial state (no address, no
+ * configuration).
+ */
+
+ priv->devstate = DEVSTATE_DEFAULT;
+}
+
+/*******************************************************************************
* Name: stm32_isocininterrupt
*
* Description:
@@ -2420,7 +2435,7 @@ static int stm32_usbinterrupt(int irq, FAR void *context)
if ((regval & OTGFS_GINT_USBRST) != 0)
{
usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_DEVRESET), (uint16_t)regval);
- stm32_usbreset(priv);
+ stm32_resetinterrupt(priv);
usbtrace(TRACE_INTEXIT(STM32_TRACEINTID_USB), 0);
return OK;
}
@@ -2483,10 +2498,10 @@ static int stm32_usbinterrupt(int irq, FAR void *context)
*******************************************************************************/
/*******************************************************************************
- * Name: stm32_epconfigure
+ * Name: stm32_epoutconfigure
*
* Description:
- * Configure endpoint, making it usable
+ * Configure an OUT endpoint, making it usable
*
* Input Parameters:
* ep - the struct usbdev_ep_s instance obtained from allocep()
@@ -2497,63 +2512,86 @@ static int stm32_usbinterrupt(int irq, FAR void *context)
*
*******************************************************************************/
-static int stm32_epconfigure(FAR struct usbdev_ep_s *ep,
- FAR const struct usb_epdesc_s *desc,
- bool last)
+static int stm32_epoutconfigure(FAR struct usbdev_ep_s *privep, uint8_t eptype,
+ uint16_t maxpacket)
{
FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep;
- uint16_t maxsize;
usbtrace(TRACE_EPCONFIGURE, privep->epphy);
DEBUGASSERT(desc->addr == ep->eplog);
- /* Initialise EP capabilities */
-
- maxsize = GETUINT16(desc->mxpacketsize);
-#warning "Missing Logic"
-
/* Setup Endpoint Control Register */
- if (privep->isin)
- {
- /* Reset the data toggles */
+ /* Reset the data toggles */
#warning "Missing logic"
- /* Set the endpoint type */
+ /* Set the endpoint type */
- switch (desc->attr & USB_EP_ATTR_XFERTYPE_MASK)
- {
- case USB_EP_ATTR_XFER_CONTROL:
- break;
- case USB_EP_ATTR_XFER_ISOC:
- break;
- case USB_EP_ATTR_XFER_BULK:
- break;
- case USB_EP_ATTR_XFER_INT:
- break;
- }
-#warning "Missing logic"
- }
- else
+ switch (eptype)
{
- /* Reset the data toggles */
+ case USB_EP_ATTR_XFER_CONTROL:
+ break;
+ case USB_EP_ATTR_XFER_ISOC:
+ break;
+ case USB_EP_ATTR_XFER_BULK:
+ break;
+ case USB_EP_ATTR_XFER_INT:
+ break;
+ }
#warning "Missing logic"
- /* Set the endpoint type */
+ /* Reset endpoint status */
+
+ privep->stalled = false;
- switch (desc->attr & USB_EP_ATTR_XFERTYPE_MASK)
- {
- case USB_EP_ATTR_XFER_CONTROL:
- break;
- case USB_EP_ATTR_XFER_ISOC:
- break;
- case USB_EP_ATTR_XFER_BULK:
- break;
- case USB_EP_ATTR_XFER_INT:
- break;
- }
+ /* Enable the endpoint */
+
+#warning "Missing logic"
+ return OK;
+}
+
+/*******************************************************************************
+ * Name: stm32_epinconfigure
+ *
+ * Description:
+ * Configure an IN endpoint, making it usable
+ *
+ * Input Parameters:
+ * ep - the struct usbdev_ep_s instance obtained from allocep()
+ * desc - A struct usb_epdesc_s instance describing the endpoint
+ * last - true if this this last endpoint to be configured. Some hardware
+ * needs to take special action when all of the endpoints have been
+ * configured.
+ *
+ *******************************************************************************/
+
+static int stm32_epinconfigure(FAR struct usbdev_ep_s *privep, uint8_t eptype,
+ uint16_t maxpacket)
+{
+ FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep;
+
+ usbtrace(TRACE_EPCONFIGURE, privep->epphy);
+ DEBUGASSERT(desc->addr == ep->eplog);
+
+ /* Setup Endpoint Control Register */
+
+ /* Reset the data toggles */
#warning "Missing logic"
+
+ /* Set the endpoint type */
+
+ switch (eptype)
+ {
+ case USB_EP_ATTR_XFER_CONTROL:
+ break;
+ case USB_EP_ATTR_XFER_ISOC:
+ break;
+ case USB_EP_ATTR_XFER_BULK:
+ break;
+ case USB_EP_ATTR_XFER_INT:
+ break;
}
+#warning "Missing logic"
/* Reset endpoint status */
@@ -2561,16 +2599,74 @@ static int stm32_epconfigure(FAR struct usbdev_ep_s *ep,
/* Enable the endpoint */
+#warning "Missing logic"
+
+ return OK;
+}
+
+/*******************************************************************************
+ * Name: stm32_epconfigure
+ *
+ * Description:
+ * Configure endpoint, making it usable
+ *
+ * Input Parameters:
+ * ep - the struct usbdev_ep_s instance obtained from allocep()
+ * desc - A struct usb_epdesc_s instance describing the endpoint
+ * last - true if this this last endpoint to be configured. Some hardware
+ * needs to take special action when all of the endpoints have been
+ * configured.
+ *
+ *******************************************************************************/
+
+static int stm32_epconfigure(FAR struct usbdev_ep_s *ep,
+ FAR const struct usb_epdesc_s *desc,
+ bool last)
+{
+ FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep;
+ uint16_t maxpacket;
+ uint8_t eptype;
+ int ret;
+
+ usbtrace(TRACE_EPCONFIGURE, privep->epphy);
+ DEBUGASSERT(desc->addr == ep->eplog);
+
+ /* Initialize EP capabilities */
+
+ maxpacket = GETUINT16(desc->mxpacketsize);
+ eptype = desc->attr & USB_EP_ATTR_XFERTYPE_MASK;
+#warning "Missing Logic"
+
+ /* Setup Endpoint Control Register */
+
if (privep->isin)
{
-#warning "Missing logic"
+ ret = stm32_epinconfigure(privep, eptype, maxpacket);
}
else
{
-#warning "Missing logic"
+ ret = stm32_epoutconfigure(privep, eptype, maxpackt);
}
-
- return OK;
+
+ return ret;
+}
+
+/*******************************************************************************
+ * Name: stm32_ep0configure
+ *
+ * Description:
+ * Reset Usb engine
+ *
+ *******************************************************************************/
+
+static void stm32_ep0configure(FAR struct stm32_usbdev_s *priv)
+{
+ /* Enable EP0 IN and OUT */
+
+ (void)stm32_epinconfigure(&priv->epin[EP0], USB_EP_ATTR_XFER_CONTROL,
+ CONFIG_USBDEV_EP0_MAXSIZE);
+ (void)stm32_epoutconfigure(&priv->epout[EP0], USB_EP_ATTR_XFER_CONTROL,
+ CONFIG_USBDEV_EP0_MAXSIZE);
}
/*******************************************************************************