michallenc commented on code in PR #6614: URL: https://github.com/apache/incubator-nuttx/pull/6614#discussion_r922208583
########## arch/arm/src/samv7/sam_xdmac.c: ########## @@ -1921,6 +1936,130 @@ int sam_dmarxsetup(DMA_HANDLE handle, uint32_t paddr, uint32_t maddr, return ret; } +/**************************************************************************** + * Name: sam_dmarxsetup_circular + * + * Description: + * Configure DMA for receipt of two circular buffers for peripheral to + * memory transfer. Function sam_dmastart_circular() needs to be called + * to start the transfer. Only peripheral to memory transfer is currently + * supported. + * + * Input Parameters: + * handle - DMA handler + * descr - array with DMA descriptors + * maddr - array of memory addresses (i.e. destination addresses) + * paddr - peripheral address (i.e. source address) + * nbytes - number of bytes to transfer + * ndescrs - number of descriptors (i.e. the lenght of descr array) + * + ****************************************************************************/ + +int sam_dmarxsetup_circular(DMA_HANDLE handle, + struct chnext_view1_s *descr[], + uint32_t maddr[], + uint32_t paddr, + size_t nbytes, + uint8_t ndescrs) +{ + struct sam_xdmach_s *xdmach = (struct sam_xdmach_s *)handle; + uint32_t cubc; + uint8_t nextdescr; + int i; + + /* Set circular as true */ + + xdmach->circular = true; + + xdmach->cc = sam_rxcc(xdmach); + + /* Calculate the number of transfers for CUBC */ + + cubc = sam_cubc(xdmach, nbytes); + cubc |= (CHNEXT_UBC_NDE | CHNEXT_UBC_NVIEW_1 | CHNEXT_UBC_NDEN | + CHNEXT_UBC_NSEN); + + nextdescr = 0; + + for (i = ndescrs - 1; i >= 0; i--) + { + descr[i]->cnda = (uint32_t)descr[nextdescr]; /* Next Descriptor Address */ + descr[i]->cubc = cubc; /* Channel Microblock Control Register */ + descr[i]->csa = paddr; /* Source address */ + descr[i]->cda = maddr[i]; /* Destination address */ + + /* Clean data cache */ + + up_clean_dcache((uintptr_t)descr[i], + (uintptr_t)descr[i] + + sizeof(struct chnext_view1_s)); + up_clean_dcache((uintptr_t)maddr[i], (uintptr_t)(maddr + nbytes)); Review Comment: Good spot, that could create some mess when cleaning the cache. Others should be done too. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org