📄 mx21_dma.c
字号:
/**********************************************************************
*
* (C) COPYRIGHT 2004 FREESCALE, INC.
* ALL RIGHTS RESERVED
*
*
* Group/Division: WMSG/MMDO
*
* Description:
*
* Related Specifications:
*
* Errata:
*
* File Name: MX21_DMA.c
* Revision Number: 0.1
* Author(s): E Kroitor
* Date created: 30 September 2004
* Revision History:
* Date Rev Description
* ---- --- -----------
* 30Sept04 0.1 First draft
*
**********************************************************************/
#include "MX21_DMA.h"
uint32_t gFailCount, ccnr0, i, pattern;
p_uint32_t memSrc, ps, memDst;
void
dmaDemo(void)
{
// define memory source, where dat is copied from
memSrc = (p_uint32_t)(SOURCE_ADDRESS);
// define memory destination, where the memory is being copied to
memDst = (p_uint32_t)(DESTINATION_ADDRESS);
/*************************************************
*** DMA Transfer
*************************************************/
dmaSetUp(memSrc, memDst, NUMBER_OF_BYTES, DMA_BURST_LENGTH); // call DMA setup function
fillMem(Enable); // call the pattern generation and memory fill function
enableDmaTransfer(Enable); // call the DMA transfer function
} /* end of main */
void
dmaSetUp(p_uint32_t src, p_uint32_t dest, int num_bytes, int burst_length)
{
printf("\n DMA transfer program from memory to memory.\n");
PRINTF(" Number of bytes to transfer: %d\n", NUMBER_OF_BYTES);
// reset the DMA
DMAC_DCR.bits.DRST = Enable;
// PCCR0 DMA Clocks Enable
PLLCLK_PCCR0.bits.HCLK_DMA_EN = Enable;
PLLCLK_PCCR0.bits.DMA_EN = Enable;
// set up DMA control registers
PRINTF("Setting up DMA registers \n");
// enable the DMA
DMAC_DCR.bits.DEN = Enable;
// DMA source address
DMAC_SAR0.all = (uint32_t)src;
// DMA destination address
DMAC_DAR0.all = (uint32_t)dest;
// set up the channel count register with
DMAC_CNTR0.all = num_bytes;
// number of bytes to transfer
DMAC_BLR0.all = burst_length;
// set up the Channel Control Register
// DMOD and SMOD are linear, MDIR is incrementing, DSIZ is word
// SSIZ is word, REN = initiate DMA transfer when CEN = 1
DMAC_CCR0.all = 0x00000000;
} /* End of dmaSetUp function */
void
fillMem(uint32_t EN)
{
// fill memory source
for( ps = memSrc, i = 0, pattern = 0; i < SDRAM_TEST_LENGTH ; i+= 4, ps += 1 )
{
*ps = pattern;
pattern += 0x11112222;
}
gFailCount = 0;
// verify values were programmed
for( ps = memSrc, i = 0, pattern = 0; i < SDRAM_TEST_LENGTH; i+= 4, ps += 1 )
{
if (*ps != pattern)
{
gFailCount++;
}
pattern += 0x11112222;
}
if (gFailCount != 0)
{
// the data in source memory does NOT match the data that was programmed there
PRINTF(" **FAIL: Memory was NOT programmed correctly\n");
}
else
{
// the data in source memory matches the data that was programmed there
PRINTF(" Memory was programmed correctly.\n");
}
} /* End of fillMem function */
void
enableDmaTransfer(uint32_t EN)
{
gFailCount = 0;
// enable interrupts by disabling masking
DMAC_DIMR.bits.CH15_CH0 = 0xFFFF; // ~!@ Check on this then delete
// enable DMA channel
DMAC_CCR0.bits.CEN = EN;
// wait until transfer complete
while (DMAC_DISR.bits.CH15_CH0 = 0);
printf(" DMA transfer complete \n");
// calculate number of bytes transferred by reading CCNR0 register
// then print result on console
ccnr0 = DMAC_CCNR0.all;
printf(" Bytes transferred = %d\n", ccnr0);
gFailCount = 0;
// verify that data was transferred correctly
for (ps = memDst, i = 0, pattern = 0; i < SDRAM_TEST_LENGTH; i+= 4, ps += 1 )
{
if (*ps != pattern)
{
gFailCount++;
PRINTF(" Address = %x\n", ps); // address of memory location that failed
}
pattern += 0x11112222;
}
if (gFailCount != 0)
{
// dma transfer issue since data in destination memory does not match data in source memory
printf(" **FAIL: Memory didn't transfer correctly, DMA transfer failed\n");
printf (" gFailCount = %d\n", gFailCount);
}
else
{
// dma transfer took place and programmed correctly in destination address
printf(" Memory was transfered correctly via DMA.\n");
}
} /* End of enableDmaTransfer function */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -