From dde5fe0ca30971244dfb948a378bcb809b000b65 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 1 Jan 2011 15:43:53 +0000 Subject: [PATCH] Don't duplicate structures in ohci.h git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3228 42af7a65-404d-4744-a932-0658087f49c3 --- arch/arm/src/lpc17xx/lpc17_usbhost.c | 103 ++++++++++----------------- include/nuttx/usb/ohci.h | 48 ++++++++----- 2 files changed, 65 insertions(+), 86 deletions(-) diff --git a/arch/arm/src/lpc17xx/lpc17_usbhost.c b/arch/arm/src/lpc17xx/lpc17_usbhost.c index 0d6b3c23ea..235d312bcf 100755 --- a/arch/arm/src/lpc17xx/lpc17_usbhost.c +++ b/arch/arm/src/lpc17xx/lpc17_usbhost.c @@ -109,12 +109,12 @@ /* Helper definitions */ -#define HCCA ((volatile struct lpc17_hcca_s *)LPC17_HCCA_BASE) -#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 HCCA ((volatile struct ohci_hcca_s *)LPC17_HCCA_BASE) +#define TDHEAD ((volatile struct ohci_gtd_s *)LPC17_TDHEAD_ADDR) +#define TDTAIL ((volatile struct ohci_gtd_s *)LPC17_TDTAIL_ADDR) +#define EDCTRL ((volatile struct ohci_ed_s *)LPC17_EDCTRL_ADDR) -#define EDFREE ((struct lpc17_hced_s *)LPC17_EDFREE_BASE) +#define EDFREE ((struct ohci_ed_s *)LPC17_EDFREE_BASE) #define TDFREE ((uint8_t *)LPC17_TDFREE_BASE) #define IOFREE ((uint8_t *)LPC17_IOFREE_BASE) @@ -151,43 +151,12 @@ struct lpc17_usbhost_s sem_t wdhsem; /* Semaphore used to wait for Writeback Done Head event */ }; -/* Host Controller Communication Area */ - -struct lpc17_hcca_s -{ - volatile uint32_t inttbl[32]; /* Interrupt table */ - volatile uint32_t frameno; /* Frame number */ - volatile uint32_t donehead; /* Done head */ - volatile uint8_t reserved[116]; /* Reserved for future use */ - volatile uint8_t unused[4]; /* Unused */ -}; - -/* HostController Transfer Descriptor */ - -struct lpc17_hctd_s -{ - volatile uint32_t ctrl; /* Transfer descriptor control */ - volatile uint32_t currptr; /* Physical address of current buffer pointer */ - volatile uint32_t next; /* Physical pointer to next Transfer Descriptor */ - volatile uint32_t bufend; /* Physical address of end of buffer */ -}; - -/* HostController EndPoint Descriptor */ - -struct lpc17_hced_s -{ - volatile uint32_t ctrl; /* Endpoint descriptor control */ - volatile uint32_t tailtd; /* Physical address of tail in Transfer descriptor list */ - volatile uint32_t headtd; /* Physical address of head in Transfer descriptor list */ - volatile uint32_t next; /* Physical address of next Endpoint descriptor */ -}; - /* The following are used to manage lists of free EDs and TD buffers*/ struct lpc17_edlist_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 */ + uint32_t pad[3]; /* To make the same size as struct ohci_ed_s */ }; struct lpc17_buflist_s @@ -224,15 +193,15 @@ static void lpc17_putle16(uint8_t *dest, uint16_t val); /* 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 struct ohci_ed_s *lpc17_edalloc(struct lpc17_usbhost_s *priv); +static void lpc17_edfree(struct lpc17_usbhost_s *priv, struct ohci_ed_s *ed); static uint8_t *lpc17_tdalloc(struct lpc17_usbhost_s *priv); static void lpc17_tdfree(struct lpc17_usbhost_s *priv, uint8_t *buffer); #ifdef CONFIG_UBHOST_AHBIOBUFFERS static uint8_t *lpc17_ioalloc(struct lpc17_usbhost_s *priv); static void lpc17_iofree(struct lpc17_usbhost_s *priv, uint8_t *buffer); #endif -static void lpc17_enqueuetd(volatile struct lpc17_hced_s *ed, uint32_t dirpid, +static void lpc17_enqueuetd(volatile struct ohci_ed_s *ed, uint32_t dirpid, uint32_t toggle, volatile uint8_t *buffer, size_t buflen); static int lpc17_ctrltd(struct lpc17_usbhost_s *priv, uint32_t dirpid, @@ -264,9 +233,9 @@ static void lpc17_disconnect(FAR struct usbhost_driver_s *drvr); /* Initializaion ***************************************************************/ -static void lpc17_tdinit(volatile struct lpc17_hctd_s *td); -static void lpc17_edinit(volatile struct lpc17_hced_s *ed); -static void lpc17_hccainit(volatile struct lpc17_hcca_s *hcca); +static void lpc17_tdinit(volatile struct ohci_gtd_s *td); +static void lpc17_edinit(volatile struct ohci_ed_s *ed); +static void lpc17_hccainit(volatile struct ohci_hcca_s *hcca); /******************************************************************************* * Private Data @@ -490,9 +459,9 @@ static void lpc17_putle16(uint8_t *dest, uint16_t val) * *******************************************************************************/ -static struct lpc17_hced_s *lpc17_edalloc(struct lpc17_usbhost_s *priv) +static struct ohci_ed_s *lpc17_edalloc(struct lpc17_usbhost_s *priv) { - struct lpc17_hced_s *ret = (struct lpc17_hced_s *)g_edfree; + struct ohci_ed_s *ret = (struct ohci_ed_s *)g_edfree; if (ret) { g_edfree = ((struct lpc17_edlist_s*)ret)->flink; @@ -508,7 +477,7 @@ 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_edfree(struct lpc17_usbhost_s *priv, struct ohci_ed_s *ed) { struct lpc17_edlist_s *edfree = (struct lpc17_edlist_s *)ed; edfree->flink = g_edfree; @@ -605,21 +574,21 @@ static void lpc17_iofree(struct lpc17_usbhost_s *priv, uint8_t *buffer) * *******************************************************************************/ -static void lpc17_enqueuetd(volatile struct lpc17_hced_s *ed, uint32_t dirpid, +static void lpc17_enqueuetd(volatile struct ohci_ed_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; + TDHEAD->cbp = (uint32_t)buffer; + TDTAIL->cbp = 0; + TDHEAD->nexttd = (uint32_t)TDTAIL; + TDTAIL->nexttd = 0; + TDHEAD->be = (uint32_t)(buffer + (buflen - 1)); + TDTAIL->be = 0; - ed->headtd = (uint32_t)TDHEAD | ((ed->headtd) & ED_HEADP_C); - ed->tailtd = (uint32_t)TDTAIL; - ed->next = 0; + ed->headp = (uint32_t)TDHEAD | ((ed->headp) & ED_HEADP_C); + ed->tailp = (uint32_t)TDTAIL; + ed->nexted = 0; } /******************************************************************************* @@ -1195,7 +1164,7 @@ static int lpc17_transfer(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer, size_t buflen) { struct lpc17_usbhost_s *priv = (struct lpc17_usbhost_s *)drvr; - struct lpc17_hced_s *ed = NULL; + struct ohci_ed_s *ed = NULL; uint32_t dirpid; uint32_t regval; #ifdef CONFIG_UBHOST_AHBIOBUFFERS @@ -1369,23 +1338,23 @@ static void lpc17_disconnect(FAR struct usbhost_driver_s *drvr) * Initialization *******************************************************************************/ -static void lpc17_tdinit(volatile struct lpc17_hctd_s *td) +static void lpc17_tdinit(volatile struct ohci_gtd_s *td) { td->ctrl = 0; - td->currptr = 0; - td->next = 0; - td->bufend = 0; + td->cbp = 0; + td->nexttd = 0; + td->be = 0; } -static void lpc17_edinit(volatile struct lpc17_hced_s *ed) +static void lpc17_edinit(volatile struct ohci_ed_s *ed) { ed->ctrl = 0; - ed->tailtd = 0; - ed->headtd = 0; - ed->next = 0; + ed->tailp = 0; + ed->headp = 0; + ed->nexted = 0; } -static void lpc17_hccainit(volatile struct lpc17_hcca_s *hcca) +static void lpc17_hccainit(volatile struct ohci_hcca_s *hcca) { int i; @@ -1394,7 +1363,7 @@ static void lpc17_hccainit(volatile struct lpc17_hcca_s *hcca) hcca->inttbl[i] = 0; } - hcca->frameno = 0; + hcca->fmno = 0; hcca->donehead = 0; } diff --git a/include/nuttx/usb/ohci.h b/include/nuttx/usb/ohci.h index 99cf843a9a..bf151b5e64 100755 --- a/include/nuttx/usb/ohci.h +++ b/include/nuttx/usb/ohci.h @@ -258,10 +258,10 @@ /* Transfer Descriptors *****************************************************/ /* Endpoint Descriptor Offsets (4.2.1) */ -#define ED_CONTROL_OFFSET (0x00) /* TD status bits */ -#define ED_TAILP_OFFSET (0x04) /* Current Buffer Pointer (CBP) */ -#define ED_HEADP_OFFSET (0x08) /* Next TD (NextTD) */ -#define ED_NEXTED_OFFSET (0x0c) /* Buffer End (BE) */ +#define ED_CONTROL_OFFSET (0x00) /* ED status/control bits */ +#define ED_TAILP_OFFSET (0x04) /* TD Queue Tail Pointer (TailP) */ +#define ED_HEADP_OFFSET (0x08) /* TD Queue Head Pointer (HeadP) */ +#define ED_NEXTED_OFFSET (0x0c) /* Next Endpoint Descriptor (NextED) */ /* Endpoint Descriptor Bit Definitions (4.2.2) */ @@ -379,25 +379,35 @@ * Public Types ****************************************************************************/ +/* Endpoint Descriptor Offsets (4.2.1) */ + +struct ohci_ed_s +{ + volatile uint32_t ctrl; /* ED status/control bits */ + volatile uint32_t tailp; /* TD Queue Tail Pointer (TailP) */ + volatile uint32_t headp; /* TD Queue Head Pointer (HeadP) */ + volatile uint32_t nexted; /* Next Endpoint Descriptor (NextED) */ +}; + /* General Transfer Descriptor (4.3.1) */ struct ohci_gtd_s { - uint32_t status; /* TD status bits */ - uint32_t cbp; /* Current Buffer Pointer (CBP) */ - uint32_t nexttd; /* Next TD (NextTD) */ - uint32_t be; /* Buffer End (BE) */ + volatile uint32_t ctrl; /* TD status/control bits */ + volatile uint32_t cbp; /* Current Buffer Pointer (CBP) */ + volatile uint32_t nexttd; /* Next TD (NextTD) */ + volatile uint32_t be; /* Buffer End (BE) */ }; /* Isochronous Transfer Descriptor Offsets (4.3.2) */ struct ohci_itd_s { - uint32_t status; /* TD status bits */ - uint32_t bp0; /* Buffer page 0 (BP0 */ - uint32_t nexttd; /* Next TD (NextTD) */ - uint32_t be; /* Buffer End (BE) */ - uint16_t psw[ITD_NPSW]; /* Offset/PSW */ + volatile uint32_t status; /* TD status/control bits */ + volatile uint32_t bp0; /* Buffer page 0 (BP0 */ + volatile uint32_t nexttd; /* Next TD (NextTD) */ + volatile uint32_t be; /* Buffer End (BE) */ + volatile uint16_t psw[ITD_NPSW]; /* Offset/PSW */ }; /* Host Controller Communications Area Format (4.4.1) */ @@ -406,23 +416,23 @@ struct ohci_hcca_s { /* HccaInterrruptTable: 32x32-bit pointers to interrupt EDs */ - uint32_t inttbl[HCCA_INTTBL_WSIZE]; + volatile uint32_t inttbl[HCCA_INTTBL_WSIZE]; /* HccaFrameNumber: Current frame number and * HccaPad1: Zero when frame no. updated */ - uint16_t fmno; - uint16_t pad1; + volatile uint16_t fmno; + volatile uint16_t pad1; /* HccaDoneHead: When the HC reaches the end of a frame and its deferred * interrupt register is 0, it writes the current value of its HcDoneHead to * this location and generates an interrupt. */ - uint32_t donehead; - uint8_t reserved[HCCA_RESERVED_BSIZE]; - uint32_t extra; + volatile uint32_t donehead; + volatile uint8_t reserved[HCCA_RESERVED_BSIZE]; + volatile uint32_t extra; }; /****************************************************************************