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

📄 test.c

📁 dsp 5509a MMC 卡 ID号读取 12Mhzx16=192M
💻 C
字号:
/*
 *  Copyright 2004 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 */

/*
 *  ======== test.c ========
 *
 *  This is a test program that uses EVM5509A Board Support Library to
 *  perform a confidence test on a EVM5509A.  While it is running, it
 *  will display the current test index in binary on the LEDs.  If it
 *  fails a test, the test index will blink indefinitely to alert you to
 *  the failure.  If all tests pass, all of the LEDs will blink 3 times
 *  then stay on.
 *
 *  The following tests are performed:
 *
 *  Index    Description
 *    1      Internal memory
 *    2      SDRAM
 *    3      Flash ID
 *    4      Flash contents
 *    5      Timer
 *    6      SROM
 *    7      Keypad
 *    8      Codec
 *    9      MMC (requires MMC card to be plugged in)
 *
 *  Please see the EVM5509A BSL Examples for more detailed information.
 */

/*
 *  DSP/BIOS is configured using the DSP/BIOS configuration tool.  Settings
 *  for this example are stored in a configuration file called test.cdb.  At
 *  compile time, Code Composer will auto-generate DSP/BIOS related files
 *  based on these settings.  A header file called testcfg.h contains the
 *  results of the autogeneration and must be included for proper operation.
 *  The name of the file is taken from test.cdb and adding cfg.h.
 */
#include "testcfg.h"

/*
 *  The test uses the Chip Support Library for basic definitions as well as
 *  McBSP manipulation.  Programs that use the CSL must include the
 *  appropriate header files.
 */
#include <csl.h>
#include <csl_mcbsp.h>
#include <csl_dma.h>
#include <csl_timer.h>
#include <csl_gpio.h>
#include <csl_mmc.h>

/*
 *  The Board Support Library is divided into several modules, each
 *  of which has its own include file.  The file evm5509.h must be included
 *  in every program that uses the BSL.  This example also includes
 *  BSL header files for each module it uses.
 */
#include ".\include\evm5509.h"

/* Number of elements for DMA and McBSP loopback tests */
#define N                16



/* Define source and destination arrays for DMA and loopback tests */
Uint16 src[N], dst[N], buffer[256];


/* Variables used by the TEST_sleep() funciton */
Uint16 eventId1;
volatile Uint16 sleepCount = 0;

//TIMER_Handle hTimer1;
/*
 *  Interrupt Service Routines
 */

void sleepIsr()
{
    sleepCount++;
}

/*
 *  Accessory functions
 */

void TEST_sleep(Int16 sleeptime)
{
    sleepCount = 0;


    /* Map the logical event to a physical interrupt */
    IRQ_map(eventId1);

    /* Clear any pending Timer interrupts */
    IRQ_clear(eventId1);

    /* Enable timer interrupt */
    IRQ_enable(eventId1);

    /* Make sure global interrupts are enabled */
    IRQ_globalEnable();


    while(sleepCount < sleeptime);

    /* Disable timer interrupt */
    IRQ_disable(eventId1);
}



Int16 TEST_mcbsp(Int16 devid, Int16 delayed)
{
    Int16 i;
    Uint16 receivedata;
    MCBSP_Handle hMcbsp;
    MCBSP_Config mcbspCfg_loopback = {
        0xa000,        /*  Serial Port Control Register 1   */
        0x0100,        /*  Serial Port Control Register 2   */
        0x0140,        /*  Receive Control Register 1   */
        0x0000,        /*  Receive Control Register 2   */
        0x0140,        /*  Transmit Control Register 1   */
        0x0000,        /*  Transmit Control Register 2   */
        0x0000,        /*  Sample Rate Generator Register 1   */
        0x2000,        /*  Sample Rate Generator Register 2   */
        0x0000,        /*  Multichannel Control Register 1   */
        0x0000,        /*  Multichannel Control Register 2   */
        0x0a03,        /*  Pin Control Register   */
        0x0000,        /*  Receive Channel Enable Register Partition A   */
        0x0000,        /*  Receive Channel Enable Register Partition B   */
        0x0000,        /*  Receive Channel Enable Register Partition C   */
        0x0000,        /*  Receive Channel Enable Register Partition D   */
        0x0000,        /*  Receive Channel Enable Register Partition E   */
        0x0000,        /*  Receive Channel Enable Register Partition F   */
        0x0000,        /*  Receive Channel Enable Register Partition G   */
        0x0000,        /*  Receive Channel Enable Register Partition H   */
        0x0000,        /*  Transmit Channel Enable Register Partition A   */
        0x0000,        /*  Transmit Channel Enable Register Partition B   */
        0x0000,        /*  Transmit Channel Enable Register Partition C   */
        0x0000,        /*  Transmit Channel Enable Register Partition D   */
        0x0000,        /*  Transmit Channel Enable Register Partition E   */
        0x0000,        /*  Transmit Channel Enable Register Partition F   */
        0x0000,        /*  Transmit Channel Enable Register Partition G   */
        0x0000         /*  Transmit Channel Enable Register Partition H   */
    };

    /* Initialize source data, zero dest */
    for (i = 0; i < N; i++) {
        src[i] = (i << 8) | i + 1;
        dst[i] = 0;
    }

    /* Open the McBSP */
    hMcbsp = MCBSP_open(devid, MCBSP_OPEN_RESET);

    /* Configure the McBSP for loopback mode */
    MCBSP_config(hMcbsp, &mcbspCfg_loopback);

    /* Start the McBSP */
    MCBSP_start(hMcbsp,
        MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC |
        MCBSP_RCV_START | MCBSP_XMIT_START, 0x200);

    /* Data transfer loop */
    for (i = 0; i < (N + delayed); i++) {
        /* Wait for XRDY signal before writing data to DXR */
        while (!MCBSP_xrdy(hMcbsp));

        /* Write 16 bit data value to DXR */
        MCBSP_write16(hMcbsp,src[i]);
    //    EVM5509_waitusec(1);

        /* Wait for RRDY signal to read data from DRR */
        while (!MCBSP_rrdy(hMcbsp));

        /* Read 16 bit value from DRR */
        receivedata = MCBSP_read16(hMcbsp);
        if (i >= delayed)
            dst[i - delayed] = receivedata;
    }

    /* Close the McBSP */
    MCBSP_close(hMcbsp);

    /* Check data to make sure transfer was successful */
    for (i = 0; i < N; i++)
        if (dst[i] != src[i])
            return 1;

    /* Test passed */
    return 0;
}

Int16 TEST_mcbsp0()
{
    /* Do an internal loopback test on McBSP0 */
    return TEST_mcbsp(0, 1);
}

Int16 TEST_dma()
{
    Int16 i;
    DMA_Handle hDma0;
    DMA_Config dmaCfg0 = {
        0x0205, /* Source Destination Register (CSDP) */
        0x5060, /* Control Register (CCR) */
        0x0008, /* Interrupt Control Register (CICR) */
        0,      /* Lower Source Address (CSSA_L) - Symbolic(Byte Address) */
        NULL,   /* Upper Source Address (CSSA_U) - Symbolic(Byte Address) */
        0,      /* Lower Destination Address (CDSA_L) - Symbolic(Byte Address) */
        NULL,   /* Upper Destination Address (CDSA_U) - Symbolic(Byte Address) */
        0x0010, /* Element Number (CEN) */
        0x0001, /* Frame Number (CFN) */
        0x0000, /* Frame Index (CFI) */
        0x0000  /* Element Index (CEI) */
    };

    /* Set src and dst addresses (in bytes instead of 16-bit words) */
    dmaCfg0.dmacssal = (DMA_AdrPtr)(((Uint32)(&src) << 1) & 0xFFFF);
    dmaCfg0.dmacssau = (Uint16)((Uint32)(&src) >> 15);
    dmaCfg0.dmacdsal = (DMA_AdrPtr)(((Uint32)(&dst) << 1) & 0xFFFF);
    dmaCfg0.dmacdsau = (Uint16)((Uint32)(&dst) >> 15);

    /* Set src values and clear destination */
    for (i = 0; i < N; i++) {
        src[i] = i;
        dst[i] = 0;
    }

    /* Open DMA channel */
    hDma0 = DMA_open(DMA_CHA0, DMA_OPEN_RESET);

    /* Configure the DMA */
    DMA_config(hDma0, &dmaCfg0);

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

    /* Read the status register to clear it */
    i = DMA_RGET(DMACSR0);

    /* Poll DMA status too see if its done */
    while (!DMA_FGETH(hDma0, DMACSR, FRAME))
    {
        ;
    }

    /* We are done, so close DMA channel */
    DMA_close(hDma0);

    /* Check data */
    for (i = 0; i < N; i++)
        if (dst[i] != src[i])
            return 1;

    /* Test passed */
    return 0;
}


Int16 TEST_mmc()
{
    MMC_InitObj Init = {
        1,     /* Enable/disable DMA for data read/write */
        0,     /* Set level of edge detection on DAT3 pin */
        0,     /* Determines if MMC goes IDLE during IDLE instr */
        0,     /* Memory clk reflected on CLK Pin */
        15,    /* CPU CLK to MMC function clk divide down (192 MHz / 16 = 12 MHz) */
        0x84,  /* MMC function clk to memory clk divide down (divide 12 MHz func clock by 4) */
        0,     /* No. memory clks to wait before response timeout */
        0,     /* No. memory clks to wait before data timeout */
        512    /* Block Length must be same as CSD */
    };

    MMC_CardIdObj cardid;
    MMC_CardObj card;
    MMC_Handle mmc0;

    Int16 i, status;

    /* This block of code was taken from SPRA808A entitled "Programming the TMS320VC5509
     * Multi Media Controller in Native Mode".  It does not behave exactly as we would
     * expect, but if a card is inserted it does provide a valid signal level board
     * connection test.
     */

    /* Open MMC device */
    mmc0 = MMC_open(MMC_DEV1);

    /* Initialize MMC device */
    MMC_setupNative(mmc0, &Init);

    /* Idle all cards */
    MMC_sendGoIdle(mmc0);

    /* Wait for card reset */
    //EVM5509_waitusec(300);

    /* Send operating conditions to all cards */
    status = MMC_sendOpCond(mmc0, 0x0010000);

    /* Get card IDs */
    status = MMC_sendAllCID(mmc0, &cardid);

    /* Send relative address to card */
    status = MMC_setRca(mmc0, &card, 1);

    /* Select card for reading/writing */
    status = MMC_selectCard(mmc0,&card);

    /* Fill buffer with pattern */
    for (i = 0; i < 256; i++)
        buffer[i] = i;

    /* Write a block */
    status = MMC_write(mmc0, 0, buffer, 512);

    /* Clear buffer */
    for (i = 0; i < 256; i++)
        buffer[i] = 0;

    /* Read pattern back */
    status = MMC_read(mmc0, 0, buffer, 512);

    /* Compare data, would expect buffer[i] = i, but CSL doesn't return that */
    status = 0;
    for (i = 0; i < 255; i++)
        if (buffer[i] != (i + 1))
            status = 1;

    /* Close the MMC device*/
    MMC_close(mmc0);

    return status;
}



Int16 TEST_timer()
{
    /* Wait for 100 timer interrupts */
    TEST_sleep(100);

    return 0;
}

Int16 TEST_null()
{
    return 0;
}

void TEST_execute(Int16 (*funchandle)(), Int16 ledmask, Int16 insertdelay)
{
    Int16 status;

    /* Display test ID */
    //LED_binary(ledmask);

    /* Call test function */
    status = funchandle();

    /* Pause so LEDs can be read */
    if (insertdelay)
        TEST_sleep(100);

    /* Check for test fail */
  //  if (status)
  //      LED_error(ledmask);
}

main()
{
    /* Call BSL init */
//    EVM5509_init();
//    hTimer1 = TIMER_open(TIMER_DEV1, TIMER_OPEN_RESET);
//    TIMER_config(hTimer1, &timerCfg1);
    IRQ_globalEnable();

    /* Set initial LED state */
//    EVM5509_LED_init();

  //TEST_power();

    /* Run the tests sequentially */
    //TEST_execute(TEST_intMem,     1,  1);  /* Internal memory */
   // TEST_execute(TEST_sdram,      2,  0);  /* SDRAM */
   // TEST_execute(TEST_flashID,    3,  0);  /* Flash ID */
   // TEST_execute(TEST_flash,      4,  0);  /* Flash contents */
   // TEST_execute(TEST_timer,      5,  0);  /* Timer test */
   // TEST_execute(TEST_srom,       6, 0);   /* SROM test */
   // TEST_execute(TEST_keypad,     7, 0);   /* Keypad test */
   // TEST_execute(TEST_codec,      8, 0);   /* Codec test */
  TEST_execute(TEST_mmc,        9,  1);  /* MMC test (needs card) */

    /* All tests complete, board passes */
  //  LED_blink(0xf, 3);

    /* Leave all LEDs on */
   // LED_binary(0xf);

    /* Disable interrupts */
    IRQ_globalDisable();
}

⌨️ 快捷键说明

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