📄 main.c
字号:
/*=============================================================================*/
/*All software and related documentation is provided "AS IS" and without */
/*warranty or support of any kind and Texas Instruments expressly disclaims */
/*all other warranties,express or implied, including, but not limited to, the */
/*implied warranties of merchantability and fitness for a particular purpose. */
/*Under no circumstances shall Texas Instruments be liable for any incidental, */
/*special or consequential damages that result from the use or inability to */
/*use the software or related documentation, even if Texas Instruments has */
/*been advised of the liability. */
/* */
/*Unless otherwise stated, software written and copyrighted by Texas */
/*Instruments is distributed as "freeware". You may use and modify this */
/*software without any charge or restriction. You may distribute to others, */
/*as long as the original author is acknowledged. */
/*=============================================================================*/
/***************************************************************************/
/*Function: main() */
/*file name: main.c */
/*Description: Main Function for Using the DMA to collect MAX samples */
/* from TLV2548 ADC. Begin by setting up the DSP, CPLD, and McBSP */
/* Then Send Configuration Word, and begin the First Conversion Cycle.*/
/* Once this cycle is complete the DMA will collect MAX number of */
/* samples from the ADC attached to McBSP1. The Samples are */
/* stored in Array DataTable_0[]. Once MAX samples have been */
/* collected, the DMA will be produce a DMACO interrupt to the DSP. */
/*Inputs: None */
/*Outputs: None */
/*Returns: None */
/*Note: */
/* AUTHOR : AAP Application Group, L. Philipose, Dallas */
/* CREATED 2000(C) BY TEXAS INSTRUMENTS INCORPORATED. */
/****************************************************************************/
#include "c5402Reg.h" /*File Contains structures definitions for DSP, McBSP and DMA */
#include "adc_const.h" /*File Contains ADC parameter data for each Data Converter(DC) */
MCBSP McBSP1; /*Intialize McBSP Register Stuctures*/
unsigned int n=0,l=0; /*Global Index useful DataTable array */
unsigned int DataTable_0[NSAMPLES]; /*Data Table */
ioport unsigned int port0; /*write to i/o address 0x0*/
ioport unsigned int port4; /*write to i/o address 0x4*/
/*FUNCTION used to communicate with ADC on McBSP1*/
unsigned int McBSP1WriteRead(unsigned int value)
{
/*Write McBSP1 */
SPSA1_ADDR = SPCR21_SUB;
while(SPCR21_ADDR->bitval.xrdy != 1);
DXR11_ADDR = value;
// /*Read McBSP1 */
// SPSA1_ADDR = SPCR11_SUB;
// while(SPCR11_ADDR->bitval.rrdy != 1);
// return ( DRR11_ADDR );
return ( 0 );
}
void McBSP1Read(void)
{
unsigned int trash;
SPSA1_ADDR = SPCR11_SUB;
while(SPCR11_ADDR->bitval.rrdy != 1);
trash=DRR11_ADDR;
return;
}
void main(void)
{
unsigned int CLKGDV,ChnlSelCmd; /*divide-down ratio for CPU to produce CLKX in SRGR1 */
unsigned int channel0,source0, /*Varaibles used to store DMA register settings*/
destination0, count0,
frame_sync0, control_mode0;
unsigned int channel1,source1,
destination1, count1,
frame_sync1, control_mode1;
port4 = 0x0003; /*Set CNTL2, in CPLD, allow daughtercard as input to McBSP1*/
port0 = 0x0088; /*Set CNTL1, in CPLD, allow INT3# from daughtercard to DSP */
ST1_ADDR->bitval.xf = 1; /*set ADC CS# high */
ST1_ADDR->bitval.intm = 1; /*Disable System Interrupts */
DMAPREC_ADDR->value=0x0; /*Disable DMA channels*/
IMR_ADDR->value = 0; /*Mask out all interrupts */
IFR_ADDR->value = 0xFFFF; /*Clear all pending interrupts by writing ones to register */
PMST_ADDR->value = 0x3620; /*Configure PMST, set IPTR=0x3600. Remap Interrupt Vector Table*/
ST1_ADDR->bitval.intm = 0; /*Enable System Interrupts */
while (n<=NSAMPLES) /*Intialize Data Table 0 with 0xFFFF*/
{
DataTable_0[n++]=0xFFFF;
}
CLKGDV=(DSP_FREQ/(SERCLOCK+1)) ; /*CPU clock (in MHz) divide by desired CLKX Freq (in MHz)*/
/*plus one = SRGR1.CLKGDV*/
/*Intialize McBSP1 registers*/
McBSP1.RegVal.SPCR1_REG = 0x0000; /*Receiver Off*/
McBSP1.RegVal.SPCR2_REG = 0x02C0; /*Free running serial clock, transmitter off*/
/*Frame-Sync Generator and Sample-Rate Generator Reset*/
McBSP1.RegVal.PCR_REG = 0x0A00; /*DX,FSX,CLKX,DR,FSR,CLKR are serial port pins*/
/*CLKX and FSX/R output driven by sample-rate generator, */
McBSP1.RegVal.RCR1_REG = 0x0040; /*Receive 16-bits per frame*/
McBSP1.RegVal.RCR2_REG = 0x0001; /*Reeiver 16-bits per frame, one-bit receive delay */
/*With delay reciever assumes first bit arrives after falling edge of FSR */
McBSP1.RegVal.XCR1_REG = 0x0040; /*Transmit 16-bits per frame*/
McBSP1.RegVal.XCR2_REG = 0x0001; /*Transmit 16-bits per frame and one-bit transmitdelay */
/*With this delay transmiter sends first bit after falling edge of FSX */
McBSP1.RegVal.SRGR1_REG = CLKGDV; /*FSX width is default on Clock. CPU divide-down number determines */
/*CLKX frequency.*/
McBSP1.RegVal.SRGR2_REG = 0x2000; /*Sample-rate generator Clock derived from CPU clock*/
McBSP1.RegVal.MCR1_REG = 0x0; /*Not using this feature*/
McBSP1.RegVal.MCR2_REG = 0x0;
McBSP1.RegVal.RCERA_REG = 0x0;
McBSP1.RegVal.RCERB_REG = 0x0;
McBSP1.RegVal.XCERA_REG = 0x0;
McBSP1.RegVal.XCERB_REG = 0x0;
MCBSP1_init(&McBSP1); /*Intialize McBSP1 registers with user values */
SPSA1_ADDR = SPCR21_SUB; /*Choose Serial Port Control Register 2*/
SPCR21_ADDR->bitval.xrst = 1; /*Enable McBSP1 Transmiter */
SPSA1_ADDR = SPCR11_SUB;
SPCR11_ADDR->bitval.rrst = 1; /*Enable McBSP1 Receiver */
channel0 =0x0; /*Set up DMA Channel 0 store Samples from McBSP1 */
source0 =DRR11_BASE; /*Source addres to read from */
destination0 =(unsigned int)&DataTable_0; /*Destination Address to store Sample to */
count0 =NSAMPLES -1; /*Number of Samples to Store */
frame_sync0 =0x5000; /*Sync of McBSP1 receive event */
control_mode0 =0xC004; /*auto-intialization, interrupt after buffer */
DMA_init( channel0, source0, /*Intialize DMA Channel 0 */
destination0,
count0, frame_sync0,
control_mode0);
/*Set up Transmitter channel 1 */
channel1 =0x1; /*Set up DMA Channel 1 to send Command Word to Transmitter */
source1 =(unsigned int)&ChnlSelCmd; /*Source address to read command Word from */
destination1 =DXR11_BASE; /*Destination Address to Store Command i.e. McBSP1 transmitter */
count1 =NSAMPLES -1; /*Number of Times to transfer Command Word to transmitter */
frame_sync1 =0xE000 ; /*Sync transfer with INT3 event */
control_mode1 =0x8000; /*Auto-intialize registers from transfers */
DMA_init( channel1, source1, /*Intialize DMA Channel 1 */
destination1, count1,
frame_sync1, control_mode1);
ST1_ADDR->bitval.xf = 0; /*Set ADC CS# low */
// McBSP1Read();
McBSP1WriteRead(CFR_WORD); /*Send configuration Word to ADC */
ChnlSelCmd=CHNL_SEL; /*This Channel Select Command will be used */
McBSP1Read(); /*be by the DMA for each conversion cycle. */
McBSP1WriteRead(ChnlSelCmd); /*write channel select command to ADC */
McBSP1Read();
DMAPREC_ADDR->value=0x0183; /*Enable DMA CH0 & CH1. channel 0 has high priority*/
while(IFR_ADDR->bitval.dmac0 != 1); /*wait for DMA buffer to be filled Before quitting */
ST1_ADDR->bitval.xf = 1; /*Desired samples collected. Deselect ADC */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -