在线时间445 小时
UID2011467
注册时间2013-5-17
NXP金币0
该用户从未签到
金牌会员
 
- 积分
- 5781
- 最后登录
- 1970-1-1
|
发表于 2015-4-3 15:54:13
|
显示全部楼层
安建议是正确的,最好使用SMOD的功能,我贴上使用SMOD的测试函数,你可以参考一下。- /*******************************************************************************
- * This function will perform the basic transfer using a DMA SMOD feature and
- * using software start and will check for errors in transmission, if any.
- * Points to note:
- * - SMOD size should be equal to the buffer_size defined
- * - data size defined for src and dest xfr should be same
- * as the MEM_FILL_* enum called.
- *
- * Result: This is validated by checking if the data at same source address is
- * taken to be copied to destination address
- * i.e Source address is wrapped after SMOD boundary.
- *
- * For eg:
- * SMOD =32 bytes
- * nbytes=64 bytes
- *
- * 0 32 64
- * SADDR: |-------------------|-------------------|
- * <-------data x-----><-------data y------>
- *
- * 0 32 64
- * DADDR: |-------------------|-------------------|
- * <-------data x-----><-------data x------>
- *
- ******************************************************************************/
- void dma_smod(void)
- {
- int dma_ch, loop_count;
- uint32 dest_addr;
- uint32 buffer_size;
- uint32 Nbytes = 64; //=16*4
- //uint32 Nbytes = 128; //=64*2
- //uint32 Nbytes = 256; //=64*4
- //uint32 Nbytes = 1024; //512*2
- //uint32 Nbytes = 4096; //2K*2
- //uint32 Nbytes = 8192; //4K*2 L2K has 16K Sram, 0x1FFFF000 - 0x20003000, so SMOD < 9
-
- printf("\n DMA transfer test using SMOD feature.");
-
- /* Initialize test variables */
- tcd.saddr = SRAM_SADDRESS;
- tcd.daddr = SRAM_DADDRESS;
- tcd.nbytes = Nbytes;
- tcd.ctrl = DMA_DCR_SSIZE_LONGWORD //long word transfer
- | DMA_DCR_SINC_MASK
- | DMA_DCR_DSIZE_LONGWORD //long word transfer
- | DMA_DCR_DINC_MASK
- | DMA_DCR_SMOD(0x1); //circular buffer size of 16 bytes
- //| DMA_DCR_SMOD(0x3); //circular buffer size of 64 bytes
- //| DMA_DCR_SMOD(0x6); //circular buffer size of 512 bytes
- //| DMA_DCR_SMOD(0x8); //circular buffer size of 2K bytes
- //| DMA_DCR_SMOD(0x9); //circular buffer size of 4K bytes
- /* Note: This is simple DMA transfer, so Auto Align and interrupt
- * are not used.
- * Also, if AA is enabled, DINC and SINC will increase no matter
- * what value they have */
-
- /* Note: For this test the no of bytes to be xfred must be evenly divisible
- * by the buffer_size; else the for loop used to check the end results,
- * will not work correctly */
- /* Size of the circular source buffer, Must be a power of 2 and should be
- * equal to SMOD size. */
- buffer_size = 16; //0x10
- //buffer_size = 64; //0x40
- //buffer_size = 512; //0x200
- //buffer_size = 2048; //0x800
- //buffer_size = 4096; //0x1000 P0FC has 16K Sram, 0x1FFFE000 - 0x20002000, so SMOD < 9
- /* Use all 4 DMA channels to check the basic transmission of data */
- for(dma_ch = 0; dma_ch < 4; dma_ch++)
- {
- /* Initialize data at source location */
- for(int j = 0; j < buffer_size; j++)
- *((uint8 *)(tcd.saddr + j)) = j + dma_ch;
-
- tcd.channelno = dma_ch;
- /* Clear status */
- DMA_DSR_BCR(dma_ch) |= DMA_DSR_BCR_DONE_MASK;
-
- /* Configure DMA registers */
- dma_config(CONFIG_BASIC_XFR,&tcd);
-
- /* Start DMA transmission */
- dma_config(DMA_SOFT_START, &tcd);
-
- /* Wait till transfer is done */
- dma_config(XFR_OVER_WAIT, &tcd);
-
- /* Check data coherence */
- dest_addr = tcd.daddr;
- for(loop_count = 0; loop_count < (Nbytes/buffer_size); loop_count++)
- {
- tcd.daddr = dest_addr + (loop_count * buffer_size) ;
- tcd.nbytes = buffer_size;
- dma_config(CMP_MEM, &tcd);
- }
- tcd.daddr = dest_addr;
- tcd.nbytes = Nbytes;
- printf("\nDMA channel %01x test complete.\n", dma_ch);
- printf("\n Press a character to proceed to next DMA CHANNEL...");
- in_char();
- }
-
- if(dma_error)
- {
- printf("\nTESTCASE FAIL\r\n");
- }
- else
- {
- printf("\nTESTCASE PASS\r\n");
- }
- }
复制代码
|
|