usart_handler: DMA based memory copy
This commit is contained in:
parent
e8ab90c2b3
commit
ecd6c1d5d6
13 changed files with 367 additions and 408 deletions
39
lib/memcpy_dma.c
Normal file
39
lib/memcpy_dma.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* memcpy_dma.c
|
||||
*
|
||||
* Created on: Oct 1, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
#include "memcpy_dma.h"
|
||||
#include "dma_helper.h"
|
||||
|
||||
volatile uint8_t g_memcpyDmaBusy = 0;
|
||||
|
||||
static DMAINFO g_memcpyDmaInfo;
|
||||
|
||||
void InitMemcpyDma(DMA_TypeDef *dma, uint32_t stream)
|
||||
{
|
||||
InitDmaInfo(&g_memcpyDmaInfo, dma, stream);
|
||||
LL_DMA_EnableIT_TC(dma, stream);
|
||||
}
|
||||
|
||||
void * MemcpyDma(void *dst, void const *src, size_t length)
|
||||
{
|
||||
LL_DMA_SetM2MSrcAddress(g_memcpyDmaInfo.dma, g_memcpyDmaInfo.stream, (uint32_t)src);
|
||||
LL_DMA_SetM2MDstAddress(g_memcpyDmaInfo.dma, g_memcpyDmaInfo.stream, (uint32_t)dst);
|
||||
LL_DMA_SetDataLength(g_memcpyDmaInfo.dma, g_memcpyDmaInfo.stream, (length+3)/4 );
|
||||
g_memcpyDmaBusy = 1;
|
||||
//DIAG_CRC_CALC_START();
|
||||
LL_DMA_EnableStream(g_memcpyDmaInfo.dma, g_memcpyDmaInfo.stream);
|
||||
while(g_memcpyDmaBusy);
|
||||
return dst;
|
||||
}
|
||||
|
||||
void HandleMemcpyDmaIrq()
|
||||
{
|
||||
if(*g_memcpyDmaInfo.isReg & g_memcpyDmaInfo.tcMask) { // DMA transfer complete
|
||||
*g_memcpyDmaInfo.ifcReg = g_memcpyDmaInfo.tcMask;
|
||||
LL_DMA_DisableStream(g_memcpyDmaInfo.dma, g_memcpyDmaInfo.stream);
|
||||
g_memcpyDmaBusy = 0;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue