/*H***************************************************************************** * * $Archive:: $ * $Revision:: $ * $Date:: $ * $Author:: $ * * DESCRIPTION: * * GLOBALS * * PUBLIC FUNCTIONS: * * PRIVATE FUNCTIONS: * * USAGE/LIMITATIONS: * * NOTES: * * AUTHOR: Patrick Cresap, 2000 * *H***************************************************************************/ #define C54Xex3_c /*---- compilation control switches ----------------------------------------*/ /***************************************************************************** * INCLUDE FILES *****************************************************************************/ /*---- system and platform files -------------------------------------------*/ #include #include /*---- program files -------------------------------------------------------*/ #include "evm5410.h" #include "timer5410.h" #include "mcbsp5410.h" #include "codec_controls.h" #include "data.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 contents of the control registers of the AD50 codec*/ CODEC_CONTROL_REGISTERS codec_reg; /*contains the time*/ CLOCK_STRUCT clock; unsigned short count; unsigned short waveform_start_time = 0; unsigned short read_register; unsigned short write_command; unsigned short isr_sec_flag = ISR_IDLE; unsigned short user_request; unsigned short temp = 0; unsigned short fft_true = 0; unsigned long loop_count = 0; unsigned short fft_count = 0; /***************************************************************************** * PRIVATE DECLARATIONS *****************************************************************************/ /*---- context -------------------------------------------------------------*/ /*---- data declarations ---------------------------------------------------*/ /*---- function prototypes -------------------------------------------------*/ void fft_input(unsigned short data); void fft_output(); void fft_signal(); DATA * init_impulse_response(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_READ: /* PRIMARY REQUEST READ COMMAND */ codec_control.ctl_xfer_busy = 0; codec_secondary_req(); isr_sec_flag = ISR_SEND_READ_CMD; break; case ISR_SEND_READ_CMD: /* SECONDARY SEND READ COMMAND */ send_read_cmd (read_register); temp = *bdrr0Ptr; *bdxr0Ptr = codec_control.read_cmd; temp = *bdrr0Ptr; isr_sec_flag = ISR_READ_DATA; break; case ISR_READ_DATA : /* PRIMARY READ DATA */ codec_control.read_buffer = *bdrr0Ptr; codec_control.ctl_xfer_busy = 0; no_sec_mask(); write_to_register_structure(); 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_SEC_REQ_READ; break; default: break; } } /*F*************************************************************************** * NAME: void fft_output() * * DESCRIPTION: * Outputs the right buffer based off what buffer is receiving data * * NOTES: * *F***************************************************************************/ void fft_output() { switch( rec_array ) { case 0: codec_control.xmit_buffer = in_buf3->data_array[in_buf3_count++]; in_buf3_count++; break; case 1: codec_control.xmit_buffer = in_buf0->data_array[in_buf0_count++]; in_buf0_count++; break; case 2: codec_control.xmit_buffer = in_buf1->data_array[in_buf1_count++]; in_buf1_count++; break; case 3: codec_control.xmit_buffer = in_buf2->data_array[in_buf2_count++]; in_buf2_count++; break; default: break; } } /*F*************************************************************************** * NAME: void fft_input() * * DESCRIPTION: * This inputs the data into the right buffer, and when it gets to the length * of the impulse response, will change the receive buffer, reset the counts, * and flag that the fft should be implemented. * * NOTES: * *F***************************************************************************/ void fft_input(unsigned short data) { if ((rec_array == 0) && (in_buf0_count == IN_BUF_LEN)) { rec_array = 3; in_buf0_count = 0; in_buf1_count = 0; in_buf2_count = 0; in_buf3_count = 0; fft_true = 1; fft_count++; } else if ((rec_array == 1) && (in_buf1_count == IN_BUF_LEN)) { rec_array = 0; in_buf0_count = 0; in_buf1_count = 0; in_buf2_count = 0; in_buf3_count = 0; fft_true = 1; fft_count++; } else if ((rec_array == 2) && (in_buf2_count == IN_BUF_LEN)) { rec_array = 1; in_buf0_count = 0; in_buf1_count = 0; in_buf2_count = 0; in_buf3_count = 0; fft_true = 1; fft_count++; } else if ((rec_array == 3) && (in_buf3_count == IN_BUF_LEN)) { rec_array = 2; in_buf0_count = 0; in_buf1_count = 0; in_buf2_count = 0; in_buf3_count = 0; fft_true = 1; fft_count++; } if (rec_array == 0) { in_buf0->data_array[IN_BUF_LEN + in_buf0_count++] = data; in_buf0->data_array[IN_BUF_LEN + in_buf0_count++] = 0; in_buf1->data_array[in_buf1_count++] = data; in_buf1->data_array[in_buf1_count++] = 0; } else if (rec_array == 3) { in_buf3->data_array[IN_BUF_LEN + in_buf3_count++] = data; in_buf3->data_array[IN_BUF_LEN + in_buf3_count++] = 0; in_buf0->data_array[in_buf0_count++] = data; in_buf0->data_array[in_buf0_count++] = 0; } else if (rec_array == 2) { in_buf2->data_array[IN_BUF_LEN + in_buf2_count++] = data; in_buf2->data_array[IN_BUF_LEN + in_buf2_count++] = 0; in_buf3->data_array[in_buf3_count++] = data; in_buf3->data_array[in_buf3_count++] = 0; } else if (rec_array == 1) { in_buf1->data_array[IN_BUF_LEN + in_buf1_count++] = data; in_buf1->data_array[IN_BUF_LEN + in_buf1_count++] = 0; in_buf2->data_array[in_buf2_count++] = data; in_buf2->data_array[in_buf2_count++] = 0; } } /*F*************************************************************************** * NAME: void fft_signal() * * DESCRIPTION: * When the fft is flagged, this will take the fft of the correct buffer * based off which buffer is the receive, multiply the fft version by * the impulse response, and then will take the inverse fft. * * NOTES: A temporary buffer is used in the bit reversals and the fft in order * to use less clock cyles. * *F***************************************************************************/ void fft_signal() { unsigned int i; if (fft_true) { fft_true = 0; switch ( rec_array ) { case 0: cbrev(in_buf2->data_array,temp_buf->data_array,IN_BUF_LEN); cfft(temp_buf->data_array,IN_BUF_LEN,scale); for (i=0; idata_array[i] = temp_buf->data_array[i] * h->data_array[i]; } cbrev(temp_buf->data_array,in_buf2->data_array,IN_BUF_LEN); cifft(in_buf2->data_array,IN_BUF_LEN,noscale); break; case 1: cbrev(in_buf3->data_array,temp_buf->data_array,IN_BUF_LEN); cfft(temp_buf->data_array,IN_BUF_LEN,scale); for (i=0; idata_array[i] = temp_buf->data_array[i] * h->data_array[i]; } cbrev(temp_buf->data_array,in_buf3->data_array,IN_BUF_LEN); cifft(in_buf3->data_array,IN_BUF_LEN,noscale); break; case 2: cbrev(in_buf0->data_array,temp_buf->data_array,IN_BUF_LEN); cfft(temp_buf->data_array,IN_BUF_LEN,scale); for (i=0; idata_array[i] = temp_buf->data_array[i] * h->data_array[i]; } cbrev(temp_buf->data_array,in_buf0->data_array,IN_BUF_LEN); cifft(in_buf0->data_array,IN_BUF_LEN,noscale); break; case 3: cbrev(in_buf1->data_array,temp_buf->data_array,IN_BUF_LEN); cfft(temp_buf->data_array,IN_BUF_LEN,scale); for (i=0; idata_array[i] = temp_buf->data_array[i] * h->data_array[i]; } cbrev(temp_buf->data_array,in_buf1->data_array,IN_BUF_LEN); cifft(in_buf1->data_array,IN_BUF_LEN,noscale); break; } } } main() { unsigned short i = 0; unsigned short codec_wave = 0x0000; unsigned short codec_wave_out = 0x0000; unsigned short time_per_waveform; unsigned short init_loop; /* -- 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; init_loop = 10; write_command = 0x0000; count = 0; // h->data_array[0]=1; // h->data_array[1]=1; // for (i=0; idata_array[i]=0; // } for (i=0; idata_array[i]=1; h->data_array[IN_BUF_LEN + i]=1; } // cbrev(h->data_array,h->data_array,IN_BUF_LEN); // cfft(h->data_array,IN_BUF_LEN,scale); user_request = USER_NOTHING; /* 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; InitCPU(PLL_FREQUENCY); C5XX_TimerInit( DEFAULT_TIMER ); SerialPortInit(); *IMR = IMR_RINT0; *IFR = 0xffff; /*clear all pending interrupts*/ *bdxr0Ptr = 0; *bdrr0Ptr = 0; GLOBAL_INT_ENABLE; while( init_loop > 0) { init_loop--; write_codec_ctl( codec_wave_out, write_command); if (user_request == USER_NOTHING) { user_request = USER_WRITE; } } while ( 1 ) { // codec_wave = zero_min_scale (codec_wave); //codec_wave_out = sin_wave(); fft_signal(); loop_count++; // write_codec_ctl( codec_wave_out); // if (user_request == USER_RESET) // { // codec_control.write_cmd = codec_control.sw_reset_cmd; // codec_secondary_req(); // codec_control.sw_reset_count--; // if (codec_control.sw_reset_count == 0) // { // user_request = USER_NOTHING; // } // } // codec_wave = reverse_zero_min_scale (codec_wave_out); // set_time(); } }