summaryrefslogtreecommitdiff
path: root/nuttx/arch/arm/src/lpc17xx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-12-19 17:49:53 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-12-19 17:49:53 +0000
commita8017c26317f8f47e6684bed887ff8bc3993c5d0 (patch)
tree4d0c223ae80863744f083f18c8906a1e43e20cf2 /nuttx/arch/arm/src/lpc17xx
parentd7e9d1011eafa7f0d8fc272566e3c8c9afaec83c (diff)
downloadpx4-nuttx-a8017c26317f8f47e6684bed887ff8bc3993c5d0.tar.gz
px4-nuttx-a8017c26317f8f47e6684bed887ff8bc3993c5d0.tar.bz2
px4-nuttx-a8017c26317f8f47e6684bed887ff8bc3993c5d0.zip
More descriptor stuff
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3197 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/arm/src/lpc17xx')
-rwxr-xr-xnuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h10
-rwxr-xr-xnuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c94
2 files changed, 85 insertions, 19 deletions
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h b/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h
index 453c55d7a..431a8d8d3 100755
--- a/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h
+++ b/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h
@@ -127,7 +127,7 @@
/* Derived size of user endpoint descriptor (ED) memory. */
-#define LPC17_FREEED_SIZE (CONFIG_USBHOST_NEDS * LPC17_ED_SIZE)
+#define LPC17_EDFREE_SIZE (CONFIG_USBHOST_NEDS * LPC17_ED_SIZE)
/* Configurable number of descriptor buffer (TDBUFFER) */
@@ -170,7 +170,7 @@
*
* Sizes of things
* CONFIG_USBHOST_NEDS 2
- * LPC17_FREEED_SIZE 48
+ * LPC17_EDFREE_SIZE 48
* LPC17_TDBUFFER_SIZE 128
* LPC17_TDBUFFER_SIZE 512
*
@@ -185,7 +185,7 @@
* LPC17_TDHEAD_ADDR 0x2000bd00
* LPC17_TDTAIL_ADDR 0x2000bd10
* LPC17_EDCTRL_ADDR 0x2000bd20
- * LPC17_FREEED_BASE 0x2000bd30
+ * LPC17_EDFREE_BASE 0x2000bd30
* LPC17_TDBUFFER_BASE 0x2000bd50
* LPC17_IOBUFFER_BASE 0x2000bdd0
* LPC17_IOBUFFERS (0x2000c000 + 0x2000bdd0) / 512 = 560/512 = 1
@@ -197,8 +197,8 @@
#define LPC17_TDHEAD_ADDR (LPC17_OHCIRAM_BASE + LPC17_HCCA_SIZE)
#define LPC17_TDTAIL_ADDR (LPC17_TDHEAD_ADDR + LPC17_TD_SIZE)
#define LPC17_EDCTRL_ADDR (LPC17_TDTAIL_ADDR + LPC17_TD_SIZE)
-#define LPC17_FREEED_BASE (LPC17_EDCTRL_ADDR + LPC17_ED_SIZE)
-#define LPC17_TDBUFFER_BASE (LPC17_FREEED_BASE + LPC17_FREEED_SIZE)
+#define LPC17_EDFREE_BASE (LPC17_EDCTRL_ADDR + LPC17_ED_SIZE)
+#define LPC17_TDBUFFER_BASE (LPC17_EDFREE_BASE + LPC17_EDFREE_SIZE)
#define LPC17_IOBUFFER_BASE (LPC17_TDBUFFER_BASE + LPC17_TDBUFFER_SIZE)
/* Finally, use the remainder of the allocated OHCI for IO buffers */
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c b/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c
index 1f6552a4a..c415794b4 100755
--- a/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c
+++ b/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c
@@ -101,10 +101,16 @@
#define TDHEAD ((volatile struct lpc17_hctd_s *)LPC17_TDHEAD_ADDR)
#define TDTAIL ((volatile struct lpc17_hctd_s *)LPC17_TDTAIL_ADDR)
#define EDCTRL ((volatile struct lpc17_hced_s *)LPC17_EDCTRL_ADDR)
-#define FREEEDS ((volatile struct lpc17_hced_s *)LPC17_FREEED_BASE)
+#define EDFREE ((struct lpc17_hced_s *)LPC17_EDFREE_BASE)
#define TDBuffer ((volatile uint8_t *)(LPC17_TDBUFFER_BASE)
+/* Descriptors *****************************************************************/
+
+/* TD delay interrupt value */
+
+#define TD_DELAY(n) (uint32_t)((n) << GTD_STATUS_DI_SHIFT)
+
/* Debug ***********************************************************************/
/* Trace error codes */
@@ -166,10 +172,10 @@ struct lpc17_hced_s
/* The following is used manage a list of free EDs */
-struct lpc17_edmem_s
+struct lpc17_edlist_s
{
- struct lpc17_edmem_s *flink; /* Link to next ED in the list */
- uint32_t pad[3]; /* To make the same size as struct lpc17_hced_s */
+ struct lpc17_edlist_s *flink; /* Link to next ED in the list */
+ uint32_t pad[3]; /* To make the same size as struct lpc17_hced_s */
};
/*******************************************************************************
@@ -188,6 +194,14 @@ static void lpc17_putreg(uint32_t val, uint32_t addr);
# define lpc17_putreg(val,addr) putreg32(val,addr)
#endif
+/* Descriptor helper functions *************************************************/
+
+static struct lpc17_hced_s *lpc17_edalloc(struct lpc17_usbhost_s *priv);
+static void lpc17_edfree(struct lpc17_usbhost_s *priv, struct lpc17_hced_s *ed);
+static void lpc17_enqueuetd(volatile struct lpc17_hced_s *ed, uint32_t dirpid,
+ uint32_t toggle, volatile uint8_t *buffer,
+ size_t buflen);
+
/* Interrupt handling **********************************************************/
static int lpc17_usbinterrupt(int irq, FAR void *context);
@@ -236,7 +250,7 @@ static struct lpc17_usbhost_s g_usbhost =
/* This is a free list of EDs */
-static struct lpc17_edmem_s *g_freeeds;
+static struct lpc17_edlist_s *g_edfree;
/*******************************************************************************
* Public Data
@@ -369,6 +383,64 @@ static void lpc17_putreg(uint32_t val, uint32_t addr)
#endif
/*******************************************************************************
+ * Name: lpc17_edalloc
+ *
+ * Description:
+ * Allocate an ED from the free list
+ *
+ *******************************************************************************/
+
+static struct lpc17_hced_s *lpc17_edalloc(struct lpc17_usbhost_s *priv)
+{
+ struct lpc17_hced_s *ret = (struct lpc17_hced_s *)g_edfree;
+ if (ret)
+ {
+ g_edfree = ((struct lpc17_edlist_s*)ret)->flink;
+ }
+ return ret;
+}
+
+/*******************************************************************************
+ * Name: lpc17_edfree
+ *
+ * Description:
+ * Return an ED to the free list
+ *
+ *******************************************************************************/
+
+static void lpc17_edfree(struct lpc17_usbhost_s *priv, struct lpc17_hced_s *ed)
+{
+ struct lpc17_edlist_s *edfree = (struct lpc17_edlist_s *)ed;
+ edfree->flink = g_edfree;
+ g_edfree = edfree;
+}
+
+/*******************************************************************************
+ * Name: lpc17_enqueuetd
+ *
+ * Description:
+ * Enqueue a transfer descriptor
+ *
+ *******************************************************************************/
+
+static void lpc17_enqueuetd(volatile struct lpc17_hced_s *ed, uint32_t dirpid,
+ uint32_t toggle, volatile uint8_t *buffer, size_t buflen)
+{
+ TDHEAD->ctrl = (GTD_STATUS_R | dirpid | TD_DELAY(0) | toggle | GTD_STATUS_CC_MASK);
+ TDTAIL->ctrl = 0;
+ TDHEAD->currptr = (uint32_t)buffer;
+ TDTAIL->currptr = 0;
+ TDHEAD->next = (uint32_t)TDTAIL;
+ TDTAIL->next = 0;
+ TDHEAD->bufend = (uint32_t)(buffer + (buflen - 1));
+ TDTAIL->bufend = 0;
+
+ ed->headtd = (uint32_t)TDHEAD | ((ed->headtd) & 0x00000002);
+ ed->tailtd = (uint32_t)TDTAIL;
+ ed->next = 0;
+}
+
+/*******************************************************************************
* Name: lpc17_usbinterrupt
*
* Description:
@@ -691,19 +763,13 @@ void up_usbhostinitialize(void)
lpc17_tdinit(TDTAIL);
lpc17_edinit(EDCTRL);
+ /* Initialize user-configurable EDs */
+
for (i = 0; i < CONFIG_USBHOST_NEDS; i++)
{
- struct lpc17_edmem_s *freeed;
-
- /* Initialize the ED */
-
- lpc17_edinit(&FREEEDS[i]);
-
/* Put the ED in a free list */
- freeed = (struct lpc17_edmem_s *)&FREEEDS[i];
- freeed->flink = g_freeeds;
- g_freeeds = freeed;
+ lpc17_edfree(priv, &EDFREE[i]);
}
/* Wait 50MS then perform hardware reset */