/*H***************************************************************************** * * $Archive:: $ * $Revision:: $ * $Date:: $ * $Author:: $ * * DESCRIPTION: * This example is for the 5410 EVM. It builds on the timer example by * adding the multi channel buffered serial port and the AD50 codec to * display waveforms. Using the serial port receive interrupt, it will * rotate through 4 waveforms (sin, triangle, saw, and square) at 1 second * intervals toggling through the various amplitudes and sampling frequencies * that are available through the AD50 codec. By doing this, it demonstrates * reads and writes to the codec, how to set up a simple serial port, how to * send data through the serial port, and how to run 2 interrupts in the same * program. * * GLOBALS * * PUBLIC FUNCTIONS: * * PRIVATE FUNCTIONS: * * USAGE/LIMITATIONS: * * NOTES: * * By: Patrick Cresap * *H***************************************************************************/ #define C54Xex3_c /*---- compilation control switches ----------------------------------------*/ /***************************************************************************** * INCLUDE FILES *****************************************************************************/ /*---- system and platform files -------------------------------------------*/ #include #include /*---- program files -------------------------------------------------------*/ #include "evm54102.h" #include "timer54102.h" #include "mcbsp54102.h" #include "codec_controls2.h" #include "data2.h" /***************************************************************************** * EXTERNAL REFERENCE *****************************************************************************/ /*---- data declarations ---------------------------------------------------*/ /*---- function prototypes -------------------------------------------------*/ /***************************************************************************** * PUBLIC DECLARATIONS *****************************************************************************/ /*---- data declarations ---------------------------------------------------*/ /***************************************************************************** * USER DEFINED VARIABLES *****************************************************************************/ /*-- Sets the Frequency of the Target---*/ unsigned short PLL_FREQUENCY = 100; #define DEFAULT_TIMER 9999 /* sets PRD */ /***************************************************************************** * NOT USER DEFINED VARIABLES *****************************************************************************/ volatile unsigned int *bdxr0Ptr = (unsigned int *)0x0023; volatile unsigned int *bdrr0Ptr = (unsigned int *)0x0021; /*-- Interrupt Register Definitions ---------------------------------*/ #define IMR ( (unsigned short *) 0x0000) #define IFR ( (unsigned short *) 0x0001) #define IMR_RINT0 0x0010 unsigned short serial_port_mode; CODEC_CONTROL_OPTIONS codec_control; /*contains the time*/ CLOCK_STRUCT clock; unsigned short count; unsigned short waveform_start_time = 0; unsigned short isr_sec_flag = ISR_IDLE; unsigned short user_request; unsigned short temp = 0; unsigned short fft_true = 0; /***************************************************************************** * PRIVATE DECLARATIONS *****************************************************************************/ /*---- context -------------------------------------------------------------*/ /*---- data declarations ---------------------------------------------------*/ /*---- function prototypes -------------------------------------------------*/ void fft_input(unsigned short data); void fft_output(); void fft_signal(); void filter_signal(DATA * data); /*---- macros --------------------------------------------------------------*/ /***************************************************************************** * PUBLIC FUNCTION DEFINITIONS *****************************************************************************/ /***************************************************************************** * INTERRUPT ROUTINE DEFINITIONS *****************************************************************************/ /*F*************************************************************************** * NAME: interrupt void c_int19( void ) * * DESCRIPTION: * A basic interrupt ticks at ever timer interrupt * * NOTES: 19 is the timer interrupt for the C54X. * *F***************************************************************************/ interrupt void c_int19( void ) { clock.tick++; } /*F*************************************************************************** * NAME: interrupt void c_int20( void ) * * DESCRIPTION: * A serial port receive interrupt service routine. * * NOTES: 20 is the serial port receive interrupt for the C54X. * *F***************************************************************************/ interrupt void c_int20( void ) { if( isr_sec_flag == ISR_IDLE) { isr_sec_flag = user_isr_convert(); } switch( isr_sec_flag ) { case ISR_IDLE: /* PRIMARY */ codec_control.ctl_xfer_busy = 0; if (serial_port_mode == LOOP_BACK) { codec_control.rcv_buffer = *bdrr0Ptr & NO_SEC_MASK; } fft_input(codec_control.rcv_buffer); fft_output(); no_sec_mask(); isr_sec_flag = ISR_IDLE; break; case ISR_SEC_REQ_WRITE: /* PRIMARY REQUEST READ COMMAND */ codec_control.ctl_xfer_busy = 0; codec_secondary_req(); isr_sec_flag = ISR_SEND_WRITE_CMD; break; case ISR_SEND_WRITE_CMD: /* SECONDARY SEND WRITE COMMAND */ *bdxr0Ptr= codec_control.write_cmd; isr_sec_flag = ISR_IDLE; break; default: break; } } void fft_output() { if (rec_array == 0) { codec_control.xmit_buffer = in_buf1->data_array[in_buf1_count++]; in_buf1_count++; } else if (rec_array == 1) { codec_control.xmit_buffer = in_buf2->data_array[in_buf2_count++]; in_buf2_count++; } else if (rec_array == 2) { codec_control.xmit_buffer = in_buf0->data_array[in_buf0_count++]; in_buf0_count++; } } void fft_input(unsigned short data) { if ((rec_array == 0) && (in_buf0_count == ARRAY_BUF_LEN)) { rec_array = 1; in_buf0_count = 0; in_buf1_count = 0; in_buf2_count = 0; fft_true = 1; } else if ((rec_array == 1) && (in_buf1_count == ARRAY_BUF_LEN)) { rec_array = 2; in_buf0_count = 0; in_buf1_count = 0; in_buf2_count = 0; fft_true = 1; } else if ((rec_array == 2) && (in_buf2_count == ARRAY_BUF_LEN)) { rec_array = 0; in_buf0_count = 0; in_buf1_count = 0; in_buf2_count = 0; fft_true = 1; } if (rec_array == 0) { in_buf0->data_array[in_buf0_count++] = data; in_buf0->data_array[in_buf0_count++] = 0; } else if (rec_array == 1) { in_buf1->data_array[in_buf1_count++] = data; in_buf1->data_array[in_buf1_count++] = 0; } else if (rec_array == 2) { in_buf2->data_array[in_buf2_count++] = data; in_buf2->data_array[in_buf2_count++] = 0; } } void fft_signal() { if (fft_true) { fft_true = 0; if (rec_array == 0) { cbrev(in_buf2->data_array,in_buf2->data_array,IN_BUF_LEN); cfft(in_buf2->data_array,IN_BUF_LEN,scale); filter_signal(in_buf2->data_array); cbrev(in_buf2->data_array,in_buf2->data_array,IN_BUF_LEN); cifft(in_buf2->data_array,IN_BUF_LEN,noscale); } else if (rec_array == 1) { cbrev(in_buf0->data_array,in_buf0->data_array,IN_BUF_LEN); cfft(in_buf0->data_array,IN_BUF_LEN,scale); filter_signal(in_buf0->data_array); cbrev(in_buf0->data_array,in_buf0->data_array,IN_BUF_LEN); cifft(in_buf0->data_array,IN_BUF_LEN,noscale); } else if (rec_array == 2) { cbrev(in_buf1->data_array,in_buf1->data_array,IN_BUF_LEN); cfft(in_buf1->data_array,IN_BUF_LEN,scale); filter_signal(in_buf1->data_array); cbrev(in_buf1->data_array,in_buf1->data_array,IN_BUF_LEN); cifft(in_buf1->data_array,IN_BUF_LEN,noscale); } } } void filter_signal(DATA * data) { unsigned int i; for (i=0; idata_array[i]; } } main() { unsigned short i = 0; unsigned short codec_wave = 0x0000; unsigned short codec_wave_out = 0x0000; unsigned short time_per_waveform; /* -- clear time ----------------------------------------------------*/ clock.tick = 0; clock.millisecond = 0; clock.second = 0; clock.minute = 0; clock.hour = 0; /*initialize the control structure*/ codec_control.sw_reset_cmd = 0x0180; codec_control.sw_reset_count = 3; codec_control.ctl_xfer_busy = 0; codec_control.xmit_buffer = 0; codec_control.rcv_buffer = 0; count = 0; for (i=0; idata_array[i] = 1; h->data_array[i+IN_BUF_LEN] = 1; } // for (i=ARRAY_BUF_LEN; i>(ARRAY_BUF_LEN - 20); i--) // { // h->data_array[i] = 1; // } // for (i= 0; i<38; i++) // { // h->data_array[i] = 0; // } // for (i= 158; i<256; i++) // { // h->data_array[i] = 0; // } user_request = USER_RESET; /* serial port mode: * TRANSMIT: Will transmit the 4 software defined waveforms through the * serial port. * LOOP_BACK: Will loop back a signal from an external source(function generator) * * NOTE: LOOP_BACK has only changing amplitudes because the sampling frequency * has no effect on an inputted waveform. */ serial_port_mode = LOOP_BACK; Init_Sin_Table(); InitCPU(PLL_FREQUENCY); C5XX_TimerInit( DEFAULT_TIMER ); SerialPortInit(); *IMR = IMR_RINT0 | IMR_TINT; *IFR = 0xffff; /*clear all pending interrupts*/ *bdxr0Ptr = 0; *bdrr0Ptr = 0; GLOBAL_INT_ENABLE; while ( 1 ) { i++; // codec_wave = zero_min_scale (codec_wave); //codec_wave_out = sin_wave(); fft_signal(); write_codec_ctl( codec_wave_out); // codec_wave = reverse_zero_min_scale (codec_wave_out); // set_time(); } }