/***********************************************************/ /* Program: evmstart.c */ /* This program can be used as the starting point for all */ /* DSP programs for EE 345S initializes the C6701 */ /* EVM board, configures the McBSP0 serial port, and then */ /* configures the stereo codec. It then enters an infinite */ /* loop that reads a sample from the codec A/D and loops it*/ /* back out to the codec D/A. This loop should be replaced*/ /* by the code to achieve the goals of the experiment. */ /***********************************************************/ #include #include /***********************************************************/ /* For using the TI DSP support software. See */ /* TMS320C6201/6701 Evaluation Module Technical Reference,*/ /* SPRU305, Chapter 3. */ /* TMS320C6x Peripheral Support Library Programmer's */ /* Reference, SPRU273B. */ /* These headers are in C:\C6701\evm6x\dsp\include */ /***********************************************************/ #include /* macros for bit fields */ #include /* for components on EVM board */ #include /* serial port drivers */ #include /* for codec configuration */ #include /**********************************************************/ #include /* NOTE: The TI compiler gives warnings if math.h is moved up under stdlib.h */ #define PORT_0 0 #define sampling_rate 16000 void main(void); void config(void); #include "math.h" #define pi 3.141592653589 void main(void) { int sample=0; float f0=2000; float delta=(2*pi*f0)/sampling_rate; float angle=0; int left; int right; float twopi = 2*pi; config(); for(;;) { left=15000.0*sin(angle); right=15000.0*sin(angle); sample=(left << 16 ) | (right & 0xFFFF); angle+=delta; if(angle>=twopi) angle-=twopi; while(!MCBSP_XRDY(0)); MCBSP_WRITE(0, sample); } } /******************************************************************/ /******************************************************************/ /******************************************************************/ /******************************************************************/ void config(void){ Mcbsp_dev bspH; /* handle to serial port */ Mcbsp_config mcbspConfig; /* config obj: mcbsp regs */ /* int act_samp_rate; */ /*******************************************************/ /* The object module for evm_init() is located in: */ /* C:\C6701\evm6x\dsp\lib\drivers\drv6x.lib */ /* It initializes the EVM for use by determining the */ /* C6x map mode, setting the default EMIF to the EVM */ /* configuration, and setting external peripheral base */ /* addresses which are dependent on the map mode. It */ /* also installs default interrupt service routines. */ /*******************************************************/ evm_init(); mcbsp_drv_init(); /* init the MCBSPdrv library */ /* (in drv6x.lib) */ bspH = mcbsp_open(0); /* open mcbsp & return handle */ /* (prototyped in mcbspdrv.h) */ mcbsp_reset(bspH); /* reset the serial port */ /***********************************************************/ /* configure serial port configuration structure */ /***********************************************************/ memset(&mcbspConfig, 0, sizeof(mcbspConfig)); /* Initialize all structure elements to 0 */ mcbspConfig.loopback = DLB_DISABLE; mcbspConfig.tx.update = TRUE; mcbspConfig.tx.interrupt_mode = INTM_RDY; mcbspConfig.tx.clock_polarity = CLKX_POL_RISING; mcbspConfig.tx.frame_sync_polarity = FSYNC_POL_HIGH; mcbspConfig.tx.clock_mode = CLK_MODE_EXT; mcbspConfig.tx.frame_sync_mode = FSYNC_MODE_EXT; mcbspConfig.tx.phase_mode = SINGLE_PHASE; mcbspConfig.tx.frame_length1 = 0; mcbspConfig.tx.frame_length2 = 0; mcbspConfig.tx.word_length1 = WORD_LENGTH_32; mcbspConfig.tx.word_length2 = 0; mcbspConfig.tx.companding = NO_COMPAND_MSB_1ST; mcbspConfig.tx.frame_ignore = NO_FRAME_IGNORE; mcbspConfig.tx.data_delay = DATA_DELAY0; mcbspConfig.rx.update = TRUE; mcbspConfig.rx.interrupt_mode = INTM_RDY; mcbspConfig.rx.justification = RXJUST_RJZF; mcbspConfig.rx.clock_polarity = CLKR_POL_FALLING; mcbspConfig.rx.frame_sync_polarity = FSYNC_POL_HIGH; mcbspConfig.rx.clock_mode = CLK_MODE_EXT; mcbspConfig.rx.frame_sync_mode = FSYNC_MODE_EXT; mcbspConfig.rx.phase_mode = SINGLE_PHASE; mcbspConfig.rx.frame_length1 = 0; mcbspConfig.rx.frame_length2 = 0; mcbspConfig.rx.word_length1 = WORD_LENGTH_32; mcbspConfig.rx.word_length2 = 0; mcbspConfig.rx.companding = NO_COMPAND_MSB_1ST; mcbspConfig.rx.frame_ignore = NO_FRAME_IGNORE; mcbspConfig.rx.data_delay = DATA_DELAY0; /* Now call mcbsp_config() to load the McBSP registers */ /* according to the structure values. */ mcbsp_config( bspH, &mcbspConfig ); /* If you uncomment the next statement, you will have */ /* to map .text to SBSRAM_PROG_MEM because it will not */ /* fit in INT_PROG_MEM. */ /* printf("McBSP0 configuration completed\n"); */ /********************************************************/ /* Configure the CODEC */ /* These routines reside in drv6x.lib */ /********************************************************/ codec_init(); /* A/D 0 dB gain, no 20dB mic gain, sel (L/R)LINE input */ codec_adc_control(LEFT, 0.0, FALSE, LINE_SEL); codec_adc_control(RIGHT, 0.0, FALSE, LINE_SEL); /* mute (L/R)LINE input to mixer */ codec_line_in_control(LEFT, MIN_AUX_LINE_GAIN, TRUE); codec_line_in_control(RIGHT, MIN_AUX_LINE_GAIN, TRUE); /* D/A 0.0 dB atten, do not mute DAC outputs */ codec_dac_control(LEFT, 0.0, FALSE); codec_dac_control(RIGHT, 0.0, FALSE); /* Set codec data format (mono=FALSE, stereo=TRUE) */ codec_audio_data_format(LINEAR_16BIT_SIGNED_LE, TRUE, BOTH); /* Set the sampling rate. The rate is quantized to the */ /* nearest of the following values (in kHz): */ /* 5.5125, 6.6150, 8.0000, 96.000, 11.025, 16.0000, */ /* 189000, 22.0500, 27.4286, 32.0000, 33.0750, 37.8000,*/ /* 44.1000, 48.0000 */ /* act_samp_rate = codec_change_sample_rate(sampling_rate,TRUE); */ codec_change_sample_rate(sampling_rate,TRUE); /* Disable Codec interrupts */ codec_interrupt_disable(); /* printf("The codec sampling rate is %d\n", act_samp_rate); */ /***********************************************************/ /* Turn on the serial port transmitter and receiver */ /***********************************************************/ MCBSP_ENABLE(PORT_0, MCBSP_RX|MCBSP_TX); }