From 21a0a16908dbdf4f3b37f63887c84c388d16545c Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 13 Sep 2012 14:14:18 +0000 Subject: [PATCH] USB device drivers: Add hooks to to use common, external DMA buffer allocation implementation.. git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5142 42af7a65-404d-4744-a932-0658087f49c3 --- arch/arm/src/dm320/dm320_usbdev.c | 20 ++++++++++---- arch/arm/src/lpc17xx/lpc17_usbdev.c | 40 +++++++++++++++++++++++---- arch/arm/src/lpc214x/lpc214x_usbdev.c | 38 +++++++++++++++++++++---- arch/arm/src/lpc31xx/lpc31_usbdev.c | 20 ++++++++++---- arch/arm/src/lpc43xx/lpc43_usb0dev.c | 20 ++++++++++---- arch/arm/src/stm32/stm32_otgfsdev.c | 20 ++++++++++---- arch/avr/src/at90usb/at90usb_usbdev.c | 21 ++++++++++---- 7 files changed, 143 insertions(+), 36 deletions(-) diff --git a/arch/arm/src/dm320/dm320_usbdev.c b/arch/arm/src/dm320/dm320_usbdev.c index abc89e31d9..c924db1976 100644 --- a/arch/arm/src/dm320/dm320_usbdev.c +++ b/arch/arm/src/dm320/dm320_usbdev.c @@ -324,7 +324,7 @@ static int dm320_epconfigure(FAR struct usbdev_ep_s *ep, static int dm320_epdisable(FAR struct usbdev_ep_s *ep); static FAR struct usbdev_req_s *dm320_epallocreq(FAR struct usbdev_ep_s *ep); static void dm320_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req); -#ifdef CONFIG_DM320_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static FAR void *dm320_epallocbuffer(FAR struct usbdev_ep_s *ep, uint16_t nbytes); static void dm320_epfreebuffer(FAR struct usbdev_ep_s *ep, void *buf); #endif @@ -353,7 +353,7 @@ static const struct usbdev_epops_s g_epops = .disable = dm320_epdisable, .allocreq = dm320_epallocreq, .freereq = dm320_epfreereq, -#ifdef CONFIG_DM320_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA .allocbuffer = dm320_epallocbuffer, .freebuffer = dm320_epfreebuffer, #endif @@ -1979,11 +1979,16 @@ static void dm320_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s * *******************************************************************************/ -#ifdef CONFIG_DM320_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void *dm320_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) { usbtrace(TRACE_EPALLOCBUFFER, privep->epphy); - return malloc(bytes) + +#ifdef CONFIG_USBDEV_DMAMEMORY + return usbdev_dma_alloc(bytes); +#else + return malloc(bytes); +#endif } #endif @@ -1995,11 +2000,16 @@ static void *dm320_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) * *******************************************************************************/ -#ifdef CONFIG_DM320_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void dm320_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf) { usbtrace(TRACE_EPFREEBUFFER, privep->epphy); + +#ifdef CONFIG_USBDEV_DMAMEMORY + usbdev_dma_free(buf); +#else free(buf); +#endif } #endif diff --git a/arch/arm/src/lpc17xx/lpc17_usbdev.c b/arch/arm/src/lpc17xx/lpc17_usbdev.c index ccaa3528a4..a5cb443e4b 100644 --- a/arch/arm/src/lpc17xx/lpc17_usbdev.c +++ b/arch/arm/src/lpc17xx/lpc17_usbdev.c @@ -434,7 +434,7 @@ static int lpc17_epdisable(FAR struct usbdev_ep_s *ep); static FAR struct usbdev_req_s *lpc17_epallocreq(FAR struct usbdev_ep_s *ep); static void lpc17_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *); -#ifdef CONFIG_LPC17_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static FAR void *lpc17_epallocbuffer(FAR struct usbdev_ep_s *ep, uint16_t nbytes); static void lpc17_epfreebuffer(FAR struct usbdev_ep_s *ep, void *buf); @@ -471,7 +471,7 @@ static const struct usbdev_epops_s g_epops = .disable = lpc17_epdisable, .allocreq = lpc17_epallocreq, .freereq = lpc17_epfreereq, -#ifdef CONFIG_LPC17_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA .allocbuffer = lpc17_epallocbuffer, .freebuffer = lpc17_epfreebuffer, #endif @@ -2684,9 +2684,11 @@ static void lpc17_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s * *******************************************************************************/ -#ifdef CONFIG_LPC17_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static FAR void *lpc17_epallocbuffer(FAR struct usbdev_ep_s *ep, uint16_t nbytes) { +#if defined(CONFIG_LPC17_USBDEV_DMA) + FAR struct lpc17_ep_s *privep = (FAR struct lpc17_ep_s *)ep; int descndx; @@ -2699,7 +2701,19 @@ static FAR void *lpc17_epallocbuffer(FAR struct usbdev_ep_s *ep, uint16_t nbytes /* Set UDCA to the allocated DMA descriptor for this endpoint */ g_udca[privep->epphy] = &g_usbddesc[descndx]; - return &g_usbddesc[descndx] + return &g_usbddesc[descndx] + +#elif defined(CONFIG_USBDEV_DMAMEMORY) + + usbtrace(TRACE_EPALLOCBUFFER, privep->epphy); + return usbdev_dma_alloc(bytes); + +#else + + usbtrace(TRACE_EPALLOCBUFFER, privep->epphy); + return malloc(bytes); + +#endif } #endif @@ -2711,9 +2725,11 @@ static FAR void *lpc17_epallocbuffer(FAR struct usbdev_ep_s *ep, uint16_t nbytes * *******************************************************************************/ -#ifdef CONFIG_LPC17_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void lpc17_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf) { +#if defined(CONFIG_LPC17_USBDEV_DMA) + FAR struct lpc17_ep_s *privep = (FAR struct lpc17_ep_s *)ep; usbtrace(TRACE_EPFREEBUFFER, privep->epphy); @@ -2724,7 +2740,19 @@ static void lpc17_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf) /* Mark the DMA descriptor as free for re-allocation */ -#error "LOGIC INCOMPLETE" +# error "LOGIC INCOMPLETE" + +#elif defined(CONFIG_USBDEV_DMAMEMORY) + + usbtrace(TRACE_EPFREEBUFFER, privep->epphy); + usbdev_dma_free(buf); + +#else + + usbtrace(TRACE_EPFREEBUFFER, privep->epphy); + free(buf); + +#endif } #endif diff --git a/arch/arm/src/lpc214x/lpc214x_usbdev.c b/arch/arm/src/lpc214x/lpc214x_usbdev.c index 1d4cd54743..78a5fe1c37 100644 --- a/arch/arm/src/lpc214x/lpc214x_usbdev.c +++ b/arch/arm/src/lpc214x/lpc214x_usbdev.c @@ -445,7 +445,7 @@ static int lpc214x_epdisable(FAR struct usbdev_ep_s *ep); static FAR struct usbdev_req_s *lpc214x_epallocreq(FAR struct usbdev_ep_s *ep); static void lpc214x_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *); -#ifdef CONFIG_LPC214X_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static FAR void *lpc214x_epallocbuffer(FAR struct usbdev_ep_s *ep, uint16_t nbytes); static void lpc214x_epfreebuffer(FAR struct usbdev_ep_s *ep, void *buf); @@ -482,7 +482,7 @@ static const struct usbdev_epops_s g_epops = .disable = lpc214x_epdisable, .allocreq = lpc214x_epallocreq, .freereq = lpc214x_epfreereq, -#ifdef CONFIG_LPC214X_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA .allocbuffer = lpc214x_epallocbuffer, .freebuffer = lpc214x_epfreebuffer, #endif @@ -2652,6 +2652,8 @@ static void lpc214x_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_ #ifdef CONFIG_LPC214X_USBDEV_DMA static FAR void *lpc214x_epallocbuffer(FAR struct usbdev_ep_s *ep, uint16_t nbytes) { +#ifdef CONFIG_USBDEV_DMA + FAR struct lpc214x_ep_s *privep = (FAR struct lpc214x_ep_s *)ep; int descndx; @@ -2664,7 +2666,19 @@ static FAR void *lpc214x_epallocbuffer(FAR struct usbdev_ep_s *ep, uint16_t nbyt /* Set UDCA to the allocated DMA descriptor for this endpoint */ USB_UDCA[privep->epphy] = &USB_DDESC[descndx]; - return &USB_DDESC[descndx] + return &USB_DDESC[descndx] + +#elif defined(CONFIG_USBDEV_DMAMEMORY) + + usbtrace(TRACE_EPALLOCBUFFER, privep->epphy); + return usbdev_dma_alloc(bytes); + +#else + + usbtrace(TRACE_EPALLOCBUFFER, privep->epphy); + return malloc(bytes); + +#endif } #endif @@ -2676,9 +2690,11 @@ static FAR void *lpc214x_epallocbuffer(FAR struct usbdev_ep_s *ep, uint16_t nbyt * *******************************************************************************/ -#ifdef CONFIG_LPC214X_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA + static void lpc214x_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf) { +#ifdef CONFIG_LPC214X_USBDEV_DMA FAR struct lpc214x_ep_s *privep = (FAR struct lpc214x_ep_s *)ep; usbtrace(TRACE_EPFREEBUFFER, privep->epphy); @@ -2689,7 +2705,19 @@ static void lpc214x_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf) /* Mark the DMA descriptor as free for re-allocation */ -#error "LOGIC INCOMPLETE" +# error "LOGIC INCOMPLETE" + +#elif defined(CONFIG_USBDEV_DMAMEMORY) + + usbtrace(TRACE_EPFREEBUFFER, privep->epphy); + usbdev_dma_free(buf); + +#else + + usbtrace(TRACE_EPFREEBUFFER, privep->epphy); + free(buf); + +#endif } #endif diff --git a/arch/arm/src/lpc31xx/lpc31_usbdev.c b/arch/arm/src/lpc31xx/lpc31_usbdev.c index 0e8fcf17c5..255f28da14 100755 --- a/arch/arm/src/lpc31xx/lpc31_usbdev.c +++ b/arch/arm/src/lpc31xx/lpc31_usbdev.c @@ -401,7 +401,7 @@ static int lpc31_epdisable(FAR struct usbdev_ep_s *ep); static FAR struct usbdev_req_s *lpc31_epallocreq(FAR struct usbdev_ep_s *ep); static void lpc31_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *); -#ifdef CONFIG_LPC31_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void *lpc31_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes); static void lpc31_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf); #endif @@ -438,7 +438,7 @@ static const struct usbdev_epops_s g_epops = .disable = lpc31_epdisable, .allocreq = lpc31_epallocreq, .freereq = lpc31_epfreereq, -#ifdef CONFIG_LPC31_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA .allocbuffer = lpc31_epallocbuffer, .freebuffer = lpc31_epfreebuffer, #endif @@ -1955,11 +1955,16 @@ static void lpc31_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s * *******************************************************************************/ -#ifdef CONFIG_LPC31_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void *lpc31_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) { usbtrace(TRACE_EPALLOCBUFFER, privep->epphy); - return malloc(bytes) + +#ifdef CONFIG_USBDEV_DMAMEMORY + return usbdev_dma_alloc(bytes); +#else + return malloc(bytes); +#endif } #endif @@ -1971,11 +1976,16 @@ static void *lpc31_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) * *******************************************************************************/ -#ifdef CONFIG_LPC31_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void lpc31_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf) { usbtrace(TRACE_EPFREEBUFFER, privep->epphy); + +#ifdef CONFIG_USBDEV_DMAMEMORY + usbdev_dma_free(buf); +#else free(buf); +#endif } #endif diff --git a/arch/arm/src/lpc43xx/lpc43_usb0dev.c b/arch/arm/src/lpc43xx/lpc43_usb0dev.c index 2ce19a3250..b4ca554204 100644 --- a/arch/arm/src/lpc43xx/lpc43_usb0dev.c +++ b/arch/arm/src/lpc43xx/lpc43_usb0dev.c @@ -404,7 +404,7 @@ static int lpc43_epdisable(FAR struct usbdev_ep_s *ep); static FAR struct usbdev_req_s *lpc43_epallocreq(FAR struct usbdev_ep_s *ep); static void lpc43_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *); -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void *lpc43_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes); static void lpc43_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf); #endif @@ -441,7 +441,7 @@ static const struct usbdev_epops_s g_epops = .disable = lpc43_epdisable, .allocreq = lpc43_epallocreq, .freereq = lpc43_epfreereq, -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA .allocbuffer = lpc43_epallocbuffer, .freebuffer = lpc43_epfreebuffer, #endif @@ -1958,11 +1958,16 @@ static void lpc43_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s * *******************************************************************************/ -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void *lpc43_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) { usbtrace(TRACE_EPALLOCBUFFER, privep->epphy); - return malloc(bytes) + +#ifdef CONFIG_USBDEV_DMAMEMORY + return usbdev_dma_alloc(bytes); +#else + return malloc(bytes); +#endif } #endif @@ -1974,11 +1979,16 @@ static void *lpc43_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) * *******************************************************************************/ -#ifdef CONFIG_LPC433x_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void lpc43_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf) { usbtrace(TRACE_EPFREEBUFFER, privep->epphy); + +#ifdef CONFIG_USBDEV_DMAMEMORY + usbdev_dma_free(buf); +#else free(buf); +#endif } #endif diff --git a/arch/arm/src/stm32/stm32_otgfsdev.c b/arch/arm/src/stm32/stm32_otgfsdev.c index 81c919cdfd..461d500ad1 100644 --- a/arch/arm/src/stm32/stm32_otgfsdev.c +++ b/arch/arm/src/stm32/stm32_otgfsdev.c @@ -607,7 +607,7 @@ static void stm32_ep_freereq(FAR struct usbdev_ep_s *ep, /* Endpoint buffer management */ -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void *stm32_ep_allocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes); static void stm32_ep_freebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf); #endif @@ -669,7 +669,7 @@ static const struct usbdev_epops_s g_epops = .disable = stm32_ep_disable, .allocreq = stm32_ep_allocreq, .freereq = stm32_ep_freereq, -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA .allocbuffer = stm32_ep_allocbuffer, .freebuffer = stm32_ep_freebuffer, #endif @@ -4070,11 +4070,16 @@ static void stm32_ep_freereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s * *******************************************************************************/ -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void *stm32_ep_allocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) { usbtrace(TRACE_EPALLOCBUFFER, privep->epphy); - return malloc(bytes) + +#ifdef CONFIG_USBDEV_DMAMEMORY + return usbdev_dma_alloc(bytes); +#else + return malloc(bytes); +#endif } #endif @@ -4086,11 +4091,16 @@ static void *stm32_ep_allocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) * *******************************************************************************/ -#ifdef CONFIG_STM32_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void stm32_ep_freebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf) { usbtrace(TRACE_EPFREEBUFFER, privep->epphy); + +#ifdef CONFIG_USBDEV_DMAMEMORY + usbdev_dma_free(buf); +#else free(buf); +#endif } #endif diff --git a/arch/avr/src/at90usb/at90usb_usbdev.c b/arch/avr/src/at90usb/at90usb_usbdev.c index dcda5d6d09..89949e662b 100644 --- a/arch/avr/src/at90usb/at90usb_usbdev.c +++ b/arch/avr/src/at90usb/at90usb_usbdev.c @@ -313,7 +313,7 @@ static int avr_epdisable(FAR struct usbdev_ep_s *ep); static FAR struct usbdev_req_s *avr_epallocreq(FAR struct usbdev_ep_s *ep); static void avr_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *); -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void *avr_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes); static void avr_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf); #endif @@ -346,7 +346,7 @@ static const struct usbdev_epops_s g_epops = .disable = avr_epdisable, .allocreq = avr_epallocreq, .freereq = avr_epfreereq, -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA .allocbuffer = avr_epallocbuffer, .freebuffer = avr_epfreebuffer, #endif @@ -2314,11 +2314,17 @@ static void avr_epfreereq(FAR struct usbdev_ep_s *ep, * *******************************************************************************/ -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void *avr_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) { usbtrace(TRACE_EPALLOCBUFFER, privep->ep.eplog); - return malloc(bytes)} + +#ifdef CONFIG_USBDEV_DMAMEMORY + return usbdev_dma_alloc(bytes); +#else + return malloc(bytes); +#endif +} #endif /******************************************************************************* @@ -2329,11 +2335,16 @@ static void *avr_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) * *******************************************************************************/ -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void avr_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf) { usbtrace(TRACE_EPFREEBUFFER, privep->ep.eplog); + +#ifdef CONFIG_USBDEV_DMAMEMORY + usbdev_dma_free(buf); +#else free(buf); +#endif } #endif