From 56959ae057f6711bdd709758b798e64489e8af60 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 19 Feb 2012 18:04:25 +0000 Subject: Fix error in STM32 DMA driver stream index calculation git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4405 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/arm/src/stm32/stm32f40xxx_dma.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'nuttx/arch/arm/src/stm32/stm32f40xxx_dma.c') diff --git a/nuttx/arch/arm/src/stm32/stm32f40xxx_dma.c b/nuttx/arch/arm/src/stm32/stm32f40xxx_dma.c index 8dedde3ac..d92903104 100644 --- a/nuttx/arch/arm/src/stm32/stm32f40xxx_dma.c +++ b/nuttx/arch/arm/src/stm32/stm32f40xxx_dma.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/stm32/stm32f40xxx_dma.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -427,6 +427,11 @@ void weak_function up_dmainitialize(void) * Hmm.. I suppose this interface could be extended to make a non-blocking * version. Feel free to do that if that is what you need. * + * Input parameter: + * chan - Identifies the stream/channel resource. For the STM32 F4, this + * is a bit-encoded value as provided by the the DMAMAP_* definitions + * in chip/stm32f40xxx_dma.h + * * Returned Value: * Provided that 'stndx' is valid, this function ALWAYS returns a non-NULL, * void* DMA channel handle. (If 'stndx' is invalid, the function will @@ -439,12 +444,20 @@ void weak_function up_dmainitialize(void) * ****************************************************************************/ -DMA_HANDLE stm32_dmachannel(int stndx) +DMA_HANDLE stm32_dmachannel(unsigned int chan) { - struct stm32_dma_s *dmast = &g_dma[stndx]; + struct stm32_dma_s *dmast; + int stndx; + + /* Get the stream index from the bit-encoded channel value */ + stndx = STM32_DMA_STREAM(chan); DEBUGASSERT(stndx < DMA_NSTREAMS); + /* Then get the stream structure associated with the stream index */ + + dmast = &g_dma[stndx]; + /* Get exclusive access to the DMA channel -- OR wait until the channel * is available if it is currently being used by another driver */ -- cgit v1.2.3