📄 mcbsp_mulchannel_example.c
字号:
/* ===========================================================================
* 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_mulChannel_example.c
*
* @path $(CSLPATH)\example\mcbsp\mcbsp_multi_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 32 bit data transfer, using sample rate generator to synchronise
* the frames.Multi channel mode of transmission is selected.
* This example,
* 1. Intializes and opens mcbsp module
* 2. Sets up the hardware to default values and multi channel
* 32 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_mulChannel_example.pjt
* 5. Build the project and load the .out file of the project.
*
* @endverbatim
*
*/
/* ============================================================================
* Revision History
* ===============
* 25-April-2005 Ramitha Mathew. created
*
* 14-Nov-2005 ds Changed the CLKGDV value during testing
* 16-Dec-2005 ds Updated documentation
* 06-Feb-2006 ds Added "intEvent" configuration to rcvDataCfg and
* xmtDataCfg
* 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 be transmitted*/
#define NumOfWords 25
/* Handle for the MCBSP instance */
CSL_McbspHandle hMcbsp;
/* Create data buffers for transfer */
Uint32 xmt[NumOfWords];
Uint32 rcv[NumOfWords];
/* Function forwards */
void mcbsp_multichannel_example (void);
CSL_Status hwSetupVerify (CSL_McbspHwSetup *,
CSL_McbspHwSetup *
);
/* Global data definition */
CSL_McbspGlobalSetup gblCfg = {
CSL_MCBSP_IOMODE_TXDIS_RXDIS,
CSL_MCBSP_DLBMODE_ON,
CSL_MCBSP_CLKSTP_DISABLE
};
/* Receive data setup */
CSL_McbspDataSetup rcvDataCfg = {
CSL_MCBSP_PHASE_SINGLE,
CSL_MCBSP_WORDLEN_32,
32, /* FRMLEN1 */
CSL_MCBSP_WORDLEN_8, /* Default value for phase2*/
2, /* FRMLEN2 */
CSL_MCBSP_FRMSYNC_DETECT,
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 xmtDataCfg = {
CSL_MCBSP_PHASE_SINGLE,
CSL_MCBSP_WORDLEN_32,
32, /* FRMLEN1 */
CSL_MCBSP_WORDLEN_8, /* Default value */
2, /* FRMLEN2 */
CSL_MCBSP_FRMSYNC_DETECT,
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
};
/* Mcbsp clock setup */
CSL_McbspClkSetup clkCfg = {
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 */
2, /* Frame-sync pulse width=2 CLKG periods */
1024, /* Frame-sync pulse period = 1024 CLKG periods */
1, /* CLKGDIV = 1 means divide by input clock by 2 */
CSL_MCBSP_SRGCLK_CLKCPU, /* SCLKME = 0, CLKSM = 1 */
CSL_MCBSP_CLKPOL_SRG_RISING_EDGE, /* CLKS pin signal Rising Edge */
CSL_MCBSP_TXFSMODE_DXRCOPY, /* If FSGM = 1, XMT Frame-sync driven by
sample rate generater, FSG signal */
CSL_MCBSP_CLKGSYNCMODE_OFF /* GSYNC = 0 means no clock synchronisation */
};
/* Multichannel setup */
CSL_McbspMulChSetup mulChCfg = {
(CSL_McbspPartMode)CSL_MCBSP_PARTMODE_2PARTITION,
(CSL_McbspPartMode)CSL_MCBSP_PARTMODE_2PARTITION,
(Uint16)1, /* Receive multichannel selection enable */
(Uint16)2, /* Transmit multichannel selection enable */
(CSL_McbspPABlk)CSL_MCBSP_PABLK_0,
(CSL_McbspPBBlk)CSL_MCBSP_PBBLK_1,
(CSL_McbspPABlk)CSL_MCBSP_PABLK_0,
(CSL_McbspPBBlk)CSL_MCBSP_PBBLK_1
};
/* Mcbsp hwsetup */
CSL_McbspHwSetup myHwSetup = {
&gblCfg,
&rcvDataCfg,
&xmtDataCfg,
&clkCfg,
&mulChCfg,
CSL_MCBSP_EMU_STOP,
NULL
};
/*
* ============================================================================
* @func main
*
* @desc
* This is the main routine for the file.
*
* ============================================================================
*/
void main (void)
{
Bool mcbsp0En;
/* Unlock the control register */
CSL_FINST (((CSL_DevRegs*)CSL_DEV_REGS)->PERLOCK, DEV_PERLOCK_LOCKVAL,
UNLOCK);
/* Enable the Powersavr for 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("Power saver clock for McBSP0 Enabled\n");
/* Invoke the example */
mcbsp_multichannel_example();
return;
}
/*
* ============================================================================
* @func mcbsp_multichannel_example
*
* @desc
* This function performs follwing steps:
* -# Opens one MCBSP port
* -# Resets MCBSP SRGR, XMT, RCV and Frame-sync
* -# Sets up MCBSP with the initialised hwSetup function
* and waits for 2 CLK cycles
* -# Brings MCBSP SRGR and Frame sync out of reset and waits for 2 CLK
* cycles
* -# Brings MCBSP XMT and RCV out of reset
* -# For every element to be trasmitted 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 mcbsp_multichannel_example (void)
{
CSL_Status status = CSL_SOK;
CSL_McbspContext pContext;
CSL_McbspObj mcbspObj;
Uint16 loopIndex;
CSL_BitMask16 ctrlMask;
CSL_BitMask16 response;
Uint32 err = 0;
CSL_McbspHwSetup readHwSetup;
CSL_McbspChanControl channel;
CSL_McbspGlobalSetup globalSetup;
CSL_McbspDataSetup rxDataSetup;
CSL_McbspDataSetup txDataSetup;
CSL_McbspClkSetup clkSetup;
CSL_McbspMulChSetup mulChSetup;
/* Clear local data structures */
memset(&mcbspObj, 0, sizeof(CSL_McbspObj));
memset(&readHwSetup, 0, sizeof(CSL_McbspHwSetup));
printf("MCBSP Multichannel Example\n");
/* Allocated memory for variable */
readHwSetup.global = &globalSetup;
readHwSetup.rxdataset = &rxDataSetup;
readHwSetup.txdataset = &txDataSetup;
readHwSetup.clkset = &clkSetup;
readHwSetup.mulCh = &mulChSetup;
/* Initilize data buffers. xmt will be 32 bit value
* with element number in lower 16 bits and 2 * element
* in upper 16 bits. i.e. 0x00020001, 0x00040002, etc. */
for(loopIndex = 0; loopIndex <= NumOfWords - 1; loopIndex++) {
xmt[loopIndex] = (((Uint32) (loopIndex + 1) << 17) + (loopIndex + 1));
rcv[loopIndex] = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -