⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dma1.c

📁 使用在TI 系列dsk5402 的很多可用例子
💻 C
字号:
/*
 *  Copyright 2003 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/* "@(#) DSP/BIOS 4.90.270 06-11-03 (barracuda-m10)" */
/******************************************************************************\
*           Copyright (C) 2000 Texas Instruments Incorporated.
*                           All Rights Reserved
*------------------------------------------------------------------------------
* FILENAME...... dma1.c
* DATE CREATED.. 01/11/2000
* LAST MODIFIED. 09/27/2000
\******************************************************************************/
#include <stdio.h>

#include <csl.h>
#include <csl_dma.h>

/*----------------------------------------------------------------------------*/
/* create a data from DMA transfer */

#define N       16

/* Place data in separate section to ensure placement */
/* within the DMA memory space defined for the device.*/
/* The address ranges chosen for this example in the  */
/* linker command file place src and dst within the   */
/* DMA memory map for the TMS320C5402. When modifying */
/* this example to run on a different C54x target,    */
/* please check the datasheet for your specific       */
/* device to make sure that the src and dst addresses */
/* for your transfer are assigned to a valid DMA      */
/* memory space.                                      */  

/* All processing for DMA initialization. etc.. will  */
/* take place within the funtion, "taskFunc". This    */
/* function has been statically configured as a       */
/* DSPBIOS TASK (TSK), in the dma1a.cdb file that is  */
/* included in this project. This task will execute   */
/* automatically on exit from "main".                 */

#pragma DATA_SECTION(src,"dmaMem")
Uint16 src[N];
    
#pragma DATA_SECTION(dst, "dmaMem")
Uint16 dst[N];

/* In this example, we will be effecting a DMA   */
/* transfer from DATA to DATA space in internal  */
/* memory. The DMA will operate in multi-frame   */
/* mode and we will poll for DMA operation       */
/* complete.                                     */


/* These are the settings we need for the DMA    */
/* mode control register, DMMCR, in order to     */
/* perform the transfer                          */


/*  DMMCR0 = 0x0145u                                  */
/*  #0000000101000101b                                */
/*  ;0~~~~~~~~~~~~~~~ (AUTOINIT)  No Autoinit         */
/*  ;~0~~~~~~~~~~~~~~ (DINM)      No Interrupts       */
/*  ;~~0~~~~~~~~~~~~~ (IMOD)      N/A                 */
/*  ;~~~0~~~~~~~~~~~~ (CTMOD)     Multi-frame on      */
/*  ;~~~~0~~~~~~~~~~~               N/A                 */ 
/*  ;~~~~~001~~~~~~~~ (SIND)        Src addr Post-incr  */
/*  ;~~~~~~~~01~~~~~~ (DMS)       Src in data space   */
/*  ;~~~~~~~~~~0~~~~~             N/A                 */
/*  ;~~~~~~~~~~~001~~ (DIND)      Dst addr Post-incr  */
/*  ;~~~~~~~~~~~~~~01 (DMD)       Dst in data space   */

/* These are the settings required for DMA sync and   */
/* frame count register, DMSFC                        */

/*    DMSFC0 = 0x0000u                                */
/*                                                    */
/*    #0000000000000000b                              */
/*    ;0000~~~~~~~~~~~~ (DSYN)    No sync event       */
/*    ;~~~~0~~~~~~~~~~~ (DBLW)    Single-word mode    */
/*    ;~~~~~000~~~~~~~~           N/A                 */
/*    ;~~~~~~~~00000000 (Frame Count) = 0 (one frame) */
   
/* Create a DMA configuration structure for the transfer */
/* using predefined CSL macros and symbolic constants    */

DMA_Config  myconfig = {   
  1,                                  /* Set Priority */
  DMA_DMMCR_RMK(
    DMA_DMMCR_AUTOINIT_OFF,
    DMA_DMMCR_DINM_OFF,
    DMA_DMMCR_IMOD_FULL_ONLY,
    DMA_DMMCR_CTMOD_MULTIFRAME,
    DMA_DMMCR_SIND_POSTINC,
    DMA_DMMCR_DMS_DATA,
    DMA_DMMCR_DIND_POSTINC,
    DMA_DMMCR_DMD_DATA
  ),                                        /* DMMCR */
  DMA_DMSFC_RMK(
    DMA_DMSFC_DSYN_NONE,
    DMA_DMSFC_DBLW_OFF,
    DMA_DMSFC_FRAMECNT_OF(0)
  ),                                        /* DMSFC */
    (DMA_AdrPtr) &src[0],                   /* DMSRC */
    (DMA_AdrPtr) &dst[0],                   /* DMDST */
    (Uint16)(N-1)                           /* DMCTR */
};

/* Function prototypes */
void taskFunc(void);

/*----------------------------------------------------------------------------*/
void main() {
  Uint16 i;

  /* Initialize CSL library, this step is required */
  CSL_init();

  /* Set Src values and Clear destination */
  for (i=0; i<= N-1; i++) {
    src[i] = 0xBEEF;                   
    dst[i] = 0;
  }

  /* Call function to setup DMA and effect transfer */
  taskFunc();
}

/*----------------------------------------------------------------------------*/
void taskFunc(void) {

   DMA_Handle myhDma;
   Uint16 err = 0;
   Uint16 i;

   printf("<DMA1>");

     
  /* Open DMA channel 0, to use for this transfer */
  myhDma = DMA_open(DMA_CHA0, 0);    

  /* Call DMA_config function to write our configuration */
  /* values to DMA channel control registers             */         
  DMA_config(myhDma, &myconfig);          

  /* Call DMA_start to begin the data transfer */
  DMA_start(myhDma);      

  /* Poll DMA status too see if its done       */                    
  while(DMA_getStatus(myhDma));               

  /* Check the values to make sure DMA transfer is */
  /* correct.                                      */  
  for (i = 0; i <= N-1; i++) {
    if (dst[i] != 0xBEEFu) {
      ++err;
    }
  }

  /* We are done, so close DMA channel */
  DMA_close(myhDma); 
  
  printf("\nInternal memory DMA transfer in multi frame mode with polling..\n");
  printf("%s\n",err?"TEST FAILED":"TEST PASSED");
  printf("<DONE>\n");
}



  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -