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

📄 mcbsp_sinchannel_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  Mcbsp_sinChannel_example.c
 *
 *   @path  $(CSLPATH)\example\mcbsp\mcbsp_single_channel\src
 *
 *   @desc  Example of MCBSP
 *
 *  ============================================================================
 *   @n Target Platform: EVM
 *  ============================================================================
 *   @n <b> Example Description </b>
 *   @n In this example, the MCBSP0 is configured in digital loopback mode,
 *      with 16 bit data transfer, using sample rate generator
 *      to synchronise the frames. Normal mode(Single channel) of transmission 
 *      is selected.
 *      This example,
 *          1. Intializes and opens mcbsp module 
 *          2. Sets up the hardware to default values and single channel 
 *             16 bit data transfe i.e., CSL_mcbspHwSetup() is called for 
 *             module configuration.
 *          3. Brings MCBSP XMT and RCV out of reset
 *          4. For every element to be trasmitted out of MCBSP, it first waits 
 *             for XRDY signal to be ON and then writes that element
 *          6. Since MCBSP is configured in loopback, this value also comes at 
 *             the receiver, which comes in RCV data register
 *          7. For every such element to be received, it waits for RRDY signal 
 *             to be ON and then copies that element from RCV data register to 
 *             a buffer
 *          8. Does the data comparision to ensure the written data is proper or 
 *             not and 
 *          9. Displays the messages based on step 8
 *
 * =============================================================================
 *      
 *   <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 Mcbsp_sinChannel_example.pjt
 *      5. Build the project and load the .out file of the project.
 *          
 *   @endverbatim
 *
 */
 
/* ============================================================================
 *  Revision History
 *  ===============
 *  25-April-2005 Ramitha Mathew. created
 *
 *  16-Dec-2005   ds  Updated documentation
 *  07-Feb-2006   ds  Added "intEvent" configuration to rcvDataCfg and 
 *                    xmtDataCfg  and Changed to use DEV functional layer
 * 21-Feb-2006    ds  Alocated Memory for readHwsetup structure variable which
 *                    is used in CSL_mcbspGetHwSetup() API call.
 *                    Cleared local data structures 
 *                    Added Code to compare the Hwsetup and read Hwsetup 
 *                    parameters
 * ============================================================================
 */

#include <csl_mcbsp.h>
#include <cslr_dev.h>
#include <soc.h>
#include <stdio.h>

/* Macro that gives 2 CLK delay cycles */
#define WAIT_FOR_2_CLK  do {                                   \
                            volatile int delayCnt = 2;      \
                            while(delayCnt > 0) --delayCnt; \
                           }while (0)             

/* Global constants- Number of words to transfer */
#define NumOfWords   100

/* Function declarations */
void singleChannelTransmission(void);
CSL_Status hwSetupVerify (CSL_McbspHwSetup *, 
                          CSL_McbspHwSetup *
                          );


/* Handle for the MCBSP instance */
CSL_McbspHandle   hMcbsp;

/* Create data buffers for transfer */
Uint16      xmt[NumOfWords];
Uint16      rcv[NumOfWords];

/* Global data definition */
CSL_McbspGlobalSetup mcbspGbl = {
    CSL_MCBSP_IOMODE_TXDIS_RXDIS ,
    CSL_MCBSP_DLBMODE_ON,
    CSL_MCBSP_CLKSTP_DISABLE
};

/*  Receive data setup */
CSL_McbspDataSetup mcbspRxData = {
    CSL_MCBSP_PHASE_SINGLE,
    CSL_MCBSP_WORDLEN_16,
     1,            //frame length
    (CSL_McbspWordLen)0,
     0,
    CSL_MCBSP_FRMSYNC_IGNORE, //frame sinc ignore
    CSL_MCBSP_COMPAND_OFF_MSB_FIRST,
    CSL_MCBSP_DATADELAY_0_BIT,
    CSL_MCBSP_RJUSTDXENA_RJUST_RZF ,
    CSL_MCBSP_INTMODE_ON_READY,    
    CSL_MCBSP_32BIT_REVERS_DISABLE
};

/*  Transmit data setup */
CSL_McbspDataSetup mcbspTxData = {
    CSL_MCBSP_PHASE_SINGLE,
    CSL_MCBSP_WORDLEN_16,
     1,
    (CSL_McbspWordLen)0,
     0,
    CSL_MCBSP_FRMSYNC_IGNORE,
    CSL_MCBSP_COMPAND_OFF_MSB_FIRST,
    CSL_MCBSP_DATADELAY_0_BIT,
    CSL_MCBSP_RJUSTDXENA_DXENA_OFF ,
    CSL_MCBSP_INTMODE_ON_READY,    
    CSL_MCBSP_32BIT_REVERS_DISABLE
};

/*  Clock setup defaults */
CSL_McbspClkSetup mcbspClock = {
    CSL_MCBSP_FSCLKMODE_INTERNAL,    /* XMT Frame-sync */
    CSL_MCBSP_FSCLKMODE_INTERNAL,    /* RCV Frame-sync */
    CSL_MCBSP_TXRXCLKMODE_INTERNAL,  /* XMT clock */
    CSL_MCBSP_TXRXCLKMODE_INTERNAL,  /* RCV clock */
    CSL_MCBSP_FSPOL_ACTIVE_HIGH,     /* XMT Frame-sync active high */
    CSL_MCBSP_FSPOL_ACTIVE_HIGH,     /* RCV Frame-sync active high */
    CSL_MCBSP_CLKPOL_TX_RISING_EDGE, /* XMT clock rising edge */
    CSL_MCBSP_CLKPOL_RX_FALLING_EDGE,/* RCV clock falling edge */
    1,                               /* Frame-sync pulse width = 1 bit */
    0x40,                            /* Frame-sync pulse period  */
    0x1,                             /*clk divide by 2 */
    CSL_MCBSP_SRGCLK_CLKCPU,
    CSL_MCBSP_CLKPOL_TX_RISING_EDGE ,/* CLKS pin signal rising edge */
    CSL_MCBSP_TXFSMODE_DXRCOPY,
    CSL_MCBSP_CLKGSYNCMODE_OFF   /* GSYNC = 0 means no clock synchronisation */
};

/*  Multichannel setup  */
CSL_McbspMulChSetup mcbspMul = {
    CSL_MCBSP_PARTMODE_2PARTITION, /* RX */
    CSL_MCBSP_PARTMODE_2PARTITION, /* TX */
    (Uint16)0,        /*  rxMulChSel */
    (Uint16)0,        /*  txMulChSel */
    CSL_MCBSP_PABLK_0,/* rxPartABlk */
    CSL_MCBSP_PBBLK_1,/* rxPartBBlk */
    CSL_MCBSP_PABLK_0,/* txPartABlk */
    CSL_MCBSP_PBBLK_1 /* txPartABlk */
};

/*  Mcbsp hwsetup  */
CSL_McbspHwSetup myHwSetup = {
    &mcbspGbl,
    &mcbspRxData,
    &mcbspTxData,
    &mcbspClock,
    &mcbspMul,
    CSL_MCBSP_EMU_FREERUN,
    NULL
};

/*
 * ============================================================================
 *   @func   main
 *
 *   @desc
 *     This is the main routine for the file.
 *
 * ============================================================================
*/
void main (void)
{   
    Bool  mcbsp0En;
    
    /* Unlock the PERCFG0 register */
    CSL_FINST (((CSL_DevRegs*)CSL_DEV_REGS)->PERLOCK, DEV_PERLOCK_LOCKVAL, 
               UNLOCK);
               
    /* Enable the powersaver for the MCBSP 0 */
    CSL_FINST (((CSL_DevRegs*)CSL_DEV_REGS)->PERCFG0, DEV_PERCFG0_MCBSP0CTL, 
               ENABLE);
    
    do {
        mcbsp0En = (Bool) CSL_FEXT(((CSL_DevRegs*)CSL_DEV_REGS)->PERSTAT0, 
                                   DEV_PERSTAT0_MCBSP0STAT);
    } while (mcbsp0En != TRUE);

    printf("Powersaver for MCBSP 0 is enabled\n");

    
    /* Invoke example */
    singleChannelTransmission();    

    return;
}

/*
 * ============================================================================
 * @func  singleChannelTransmission()
 *
 * @desc
 *     This function performs following steps:
 *      -#  Opens one MCBSP port
 *      -#  Resets MCBSP SRGR, XMT, RCV and Frame-sync
 *      -#  Brings MCBSP XMT and RCV out of reset
 *      -#  For every element to be transmitted out of MCBSP, it first waits for
 *          XRDY signal to be ON and then writes that element
 *      -#  Since MCBSP is configured in loopback, this value also comes at the
 *          receiver, which comes in RCV data register
 *      -#  For every such element to be received, it waits for RRDY signal to
 *          be ON and then copies that element from RCV data register to
 *          a buffer
 *      -#  After all the data is transmitted out of MCBSP, it compares
 *          the two buffers and prints the result to stdout
 *      -#  In the end it closes the MCBSP instance that was opened
 *
 * ============================================================================
*/
void singleChannelTransmission(void)
{
   
    CSL_Status           status = CSL_SOK;
    CSL_McbspContext     pContext;
    CSL_McbspObj         mcbspObj;
    Uint16               loopIndex;
    CSL_BitMask16        ctrlMask;
    CSL_BitMask16        response;
    CSL_McbspHwSetup     readHwSetup;
    Uint16               maxTimeout = 1000;
    Uint16               timeout    = 0;
    Uint16               errCount   = 0; 
    CSL_McbspGlobalSetup globalSetup;
    CSL_McbspDataSetup   rxDataSetup;
    CSL_McbspDataSetup   txDataSetup;
    CSL_McbspClkSetup    clkSetup;

    /* Clear local data structures */   
    memset (&readHwSetup, 0, sizeof(CSL_McbspHwSetup)); 
    memset (&mcbspObj, 0, sizeof(CSL_McbspObj)); 

    /* Allocated memory for variable */
    readHwSetup.global = &globalSetup;
    readHwSetup.rxdataset = &rxDataSetup;

⌨️ 快捷键说明

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