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

📄 edma_csl2x_example.c

📁 Dm6455 driver,magbe useful to you!
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  ===========================================================================
 *   Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005
 *
 *   Use of this software is controlled by the terms and conditions found in
 *   the license agreement under which this software has been supplied.
 *   ==========================================================================
 */

/** ===========================================================================
 *   @file  edma_csl2x_example.c
 *
 *   @path $(CSLPATH)\example\edma\src
 *
 *   @desc  This is an example program for EDMA of CSL 2x
 *
 * =============================================================================
 *   @n Target Platform: EVM
 *  ============================================================================
 *   @n <b> Example Description </b>
 *   @n This example Performs EDMA transfers in different modes. 
 *        1. Sets up the INTC module for use by the EDMA
 *        2. Performs a simple memory to memory transfer using EDMA
 *        3. Performs a simple memory to memory transfer using QDMA
 *        4. Performs a memory to memory transfer that involves linking
 *        5. Performs a memory to memory transfer that involves chaining
 *
 * =============================================================================
 *      
 *   <b> Procedure to run the example </b>
 *   @verbatim
 *      1. Configure the CCS setup to work with the emulator being used
 *      2. Please refer CCS manual for setup configuration and loading 
 *         proper GEL file
 *      3. Launch CCS window
 *      4. Open project Edma_Csl2x_Example.pjt
 *      5. Build the project and load the .out file of the project.
 *          
 *   @endverbatim
 *
 */

/* ============================================================================
 *  Revision History
 *  ================
 *  28-Jul-2005    Chandra    File created.
 *  11-Aug-2005    Chandra    Minor format changes.
 *  16-Dec-2005    DS         Updated documentation 
 * ============================================================================
 */

#include <csl_edma2.h>
#include <stdio.h>
#include <csl_intc.h>
#include <edma_int_dispatcher.h>

/* Macros for buffer sizes */
#define SIMPLE_TRANSFER_SIZE (16)
#define LINK_BUF_SIZE        (16)
#define CHAIN_BUF_SIZE       (16)

/* Macros to manipulate the TCC and TCCM fields */
#define TCC_SHIFT            (16)
#define TCCM_SHIFT           (9)
#define TCC_MASK             (0x0000000F)
#define TCCM_MASK            (0x00000030)

/* LINK and Reload default */
#define NO_RELOAD_AND_LINK   (0xFFFF)

/* OPT word value for different transfers */

/*
   Simple transfer

   Priority  - 2
   Esize     - 3 (1 byte)
   2DS       - 0 (1 dimensional source)
   SUM       - 1 (increment source)
   2DD       - 0 (1 dimensional destination)
   DUM       - 1 (increment destination)
   TCINT     - 1 (transfer complete interrupt ON)
   TCC, TCCM - ?, 0 (transfer completion code is ?)
                    A value for TCC is selected in the function.
   ATCINT    - 0 (alternate transfer completion interrupt OFF)
   ATTC      - 0 (alternate transfer completion code is 0)
   PDTS      - 0 (source peripheral device transfer is OFF)
   PDTD      - 0 (destination peripheral device transfer is OFF)
   LINK      - 0 (linking is OFF)
   FS        - 1 (frame synchronization ON)
*/
#define SIMPLE_TRANSFER_OPTIONS (0x51300001)

/*
   First of the link transfers
   
   Priority  - 2
   Esize     - 3 (1 byte)
   2DS       - 0 (1 dimensional source)
   SUM       - 1 (increment source)
   2DD       - 0 (1 dimensional destination)
   DUM       - 1 (increment destination)
   TCINT     - 0 (transfer complete interrupt ON)
   TCC, TCCM - ?, 0 (transfer completion code is ?)
   ATCINT    - 0 (alternate transfer completion interrupt OFF)
   ATTC      - 0 (alternate transfer completion code is 0)
   PDTS      - 0 (source peripheral device transfer is OFF)
   PDTD      - 0 (destination peripheral device transfer is OFF)
   LINK      - 1 (linking is ON)
   FS        - 1 (frame synchronization ON)
*/
#define LINK_OPTIONS_WITH_LINK (0x45300003)

/*
   Last transfer of the link transfers

   Priority  - 2
   Esize     - 3 (1 byte)
   2DS       - 0 (1 dimensional source)
   SUM       - 1 (increment source)
   2DD       - 0 (1 dimensional destination)
   DUM       - 1 (increment destination)
   TCINT     - 0 (transfer complete interrupt ON)
   TCC, TCCM - ?, 0 (transfer completion code is ?)
   ATCINT    - 0 (alternate transfer completion interrupt OFF)
   ATTC      - 0 (alternate transfer completion code is 0)
   PDTS      - 0 (source peripheral device transfer is OFF)
   PDTD      - 0 (destination peripheral device transfer is OFF)
   LINK      - 0 (linking is OFF)
   FS        - 1 (frame synchronization ON)
*/
#define LINK_OPTIONS_WITH_OUT_LINK (0x45300001)

/*
   Chained Transfer

   Priority  - 2
   Esize     - 3 (1 byte)
   2DS       - 0 (1 dimensional source)
   SUM       - 1 (increment source)
   2DD       - 0 (1 dimensional destination)
   DUM       - 1 (increment destination)
   TCINT     - 0 (transfer complete interrupt ON)
   TCC, TCCM - ?, 0 (transfer completion code is ?)
   ATCINT    - 0 (alternate transfer completion interrupt OFF)
   ATTC      - 0 (alternate transfer completion code is 0)
   PDTS      - 0 (source peripheral device transfer is OFF)
   PDTD      - 0 (destination peripheral device transfer is OFF)
   LINK      - 0 (linking is OFF)
   FS        - 1 (frame synchronization ON)
*/
#define CHAIN_OPTIONS (0x45300001)

/*
   QDMA transfer

   PRI     - 2
   ESIZE   - 0 : 4 byte transfers
   2DS     - 0 : 1-d source
   SUM     - 1 : Increment source address
   2DD     - 0 : 1-d destination
   DUM     - 1 : Increment destination address
   FS      - 1 : Transfer is frame synchronized
   CNT = No. of elements to be transferred = Buffer size / size of tx element
   See section 1.16.1 of 'spru234.pdf'
*/
#define QDMA_OPTIONS (0x41300001)

/* forward declarations */
void transfer_example (void);
static void isr (int tccNum);
static void isr2 (int tccNum);

void eventEdmaHandler (void *handle);
void configure_intc (void);
void link_example (void);
void chain_example (void);
void qdma_example (void);
void configure_intc (void);


/* Global */

/* Flags used in the ISRs */
volatile Uint32 isr_cnt = 0;
volatile Uint32 parent_isr_cnt = 0;

/* Data structures for INTC configuration */
CSL_IntcContext intcContext;
CSL_IntcEventHandlerRecord EventHandler[1];

/* Allocation of buffers to use in the transfers */
static Uint8 src[SIMPLE_TRANSFER_SIZE];
static Uint8 dst[SIMPLE_TRANSFER_SIZE];

static Uint8 link_src1[LINK_BUF_SIZE];
static Uint8 link_src2[LINK_BUF_SIZE];

static Uint8 link_dst1[LINK_BUF_SIZE];
static Uint8 link_dst2[LINK_BUF_SIZE];

static Uint8 chain_src1[CHAIN_BUF_SIZE];
static Uint8 chain_src2[CHAIN_BUF_SIZE];

static Uint8 chain_dst1[CHAIN_BUF_SIZE];
static Uint8 chain_dst2[CHAIN_BUF_SIZE];

/**
 * ============================================================================
 *   @func   main
 *
 *   @desc
 *     This is the main routine of this file that invokes the individual
 *     example routines
 * ============================================================================
*/
void main (void)
{
    /* First configure the interupts */
    configure_intc ();

    /* Simple transfer example */
    transfer_example ();

    /* Transfer example using the QDMA */
    qdma_example ();

    /* Transfer example using link feature */
    link_example ();

    /* Transfer example using chain feature */
    chain_example ();

    /* Clean up */
    EDMA_resetAll ();
    EDMA_intResetAll ();
}


/* ISR to handle TCC interrupt */
static void isr (
    Int tccNum
)
{
    isr_cnt++;
}

/* Another ISR to handle TCC interrupt */
static void isr2 (
    Int tccNum
)
{
    parent_isr_cnt++;
}

/**
 * ============================================================================
 *   @func   transfer_example
 *
 *   @desc
 *     This performs a simple EDMA memory to memory transfer.
 *
 *   @n <b> Procedure </b>
 *   @verbatim
       1. Enables a channel
       2. Configures it
       3. Allocates and configures an EDMA channel interrupt
       4. Sets up the interrupt and ISR
       4. Initiates the transfer
       5. Waits for completion of ISR
       6. Verifies the transfer
       7. Cleans up

     @endverbatim
 * ============================================================================
 */
void transfer_example (void)
{
    EDMA_Handle  handle;
    Uint32       chan_no;
    EDMA_Config  conf = { 0 };
    Uint32       index;
    Uint32       tcc;

    /* Setup the source and destination memory areas */
    for (index = 0; index < SIMPLE_TRANSFER_SIZE; index++) {
        src[index] = index;
        dst[index] = 0;
    }

    /* Reset all interrupts of all channels of EDMA */
    EDMA_intResetAll ();
    
    /* Consider the channel 4 of EDMA */
    chan_no = 4;               
    handle = EDMA_open (chan_no, EDMA_OPEN_RESET);

    /* Choose the same TCC as the channel */
    tcc = EDMA_intAlloc (chan_no);      
    if (tcc != chan_no) {
        printf ("Error in allocating TCC\n");
        return;
    }

    /* Setup the config structure */
    conf.opt =
        SIMPLE_TRANSFER_OPTIONS | ((tcc & TCC_MASK) << TCC_SHIFT) | ((tcc &
            TCCM_MASK) << TCCM_SHIFT);
    conf.cnt = SIMPLE_TRANSFER_SIZE;
    conf.idx = 0;               /* 1-d source, 1-d destination, address
                                   increment for both, so
                                   FRMIDX = ELEIDX = don't care */
    conf.rld = NO_RELOAD_AND_LINK;
    conf.dst = (Uint32) & dst[0];
    conf.src = (Uint32) & src[0];

    printf
        ("EDMA: Example ... Config. a memory to memory transfer of %d bytes\n",
        SIMPLE_TRANSFER_SIZE);
    EDMA_config (handle, &conf);

    /* Setup the ISR */
    edmaEventHook (chan_no, isr);

    /* Enable EDMA interrupt for the selected channel */
    EDMA_intEnable (chan_no);

    printf ("EDMA: Example ... Initiating the transfer\n");
    EDMA_setChannel (handle);   /* Set event register, this should result in
                                   interrupt */

    /* Wait for the ISR to run */
    while (1) {
        if (isr_cnt > 0) {
            isr_cnt = 0;
            break;
        }
    }
    printf ("EDMA: Example ... Data transfer is complete\n");

    /* Verify the transferred data */
    for (index = 0; index < SIMPLE_TRANSFER_SIZE; index++) {
        if (src[index] != dst[index]) {
            break;
        }
    }
    if (index == SIMPLE_TRANSFER_SIZE) {
        printf ("EDMA: Example ... Data transferred correctly\n");
    }
    else {
        printf ("EDMA: Example ... Data not transferred correctly\n");
        return;
    }

    /* Clean up */
    EDMA_intReset (tcc);
    EDMA_intFree (tcc);
    EDMA_close (handle);
    printf ("EDMA: Simple Example ... DONE\n");

}

/**
 * ============================================================================
 *   @func   link_example
 *
 *   @desc
 *     This performs a EDMA memory to memory transfer in two stages, by link.
 *
 *   @n <b> Procedure </b>
 *   @verbatim
       1. Setup the data destinations and sources for 2 transfers
       2. Enable a channel
       3. Allocate and configure an interrupt
       4. Configure the PaRAM of the channel
       5. Allocate and configure another PaRAM for link transfer
       6. Link the second PaRAM with the first
       7. Start transfer on the channel
       8. Verify the data transfer
       9. Start the second transfer on the same channel
      10. Verify the data transfer
      11. Clean up

     @endverbatim
 * ============================================================================
 */
void link_example (void)
{
    EDMA_Handle     handle;
    EDMA_Handle     link_handle;
    Uint32          chan_no;
    Uint32          tcc;
    EDMA_Config     conf = { 0 };
    Int             index;

    /* Setup the data area */
    for (index = 0; index < LINK_BUF_SIZE; index++) {
        link_src1[index] = index;
        link_dst1[index] = 0;
        link_src2[index] = LINK_BUF_SIZE - index;
        link_dst2[index] = 0;
    }

    /* Reset all interrupts of all channels of EDMA */
    EDMA_intResetAll ();

    /* Open a channel and allocate a PaRAM for linking */
    chan_no = 3;                /* Use channel 3 of EDMA */
    handle = EDMA_open (chan_no, EDMA_OPEN_RESET);

    /* Allocate and enable interrupt of same number as channel */
    tcc = EDMA_intAlloc (chan_no);
    if (tcc != chan_no) {
        printf ("Error in allocating TCC\n");

⌨️ 快捷键说明

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