void process_peng_SWI(void) // EIGEN!!!: Muss dieser SWI noch im *.tcf-File deklariert werden? --> Sind angelegt, Priority musste ja noch festgelegt werden { //LOG_printf(&myLog, "process_pEng_SWI"); int i; for(i=0; i<BUFFER_LEN; i++) *(Buffer_out_peng+i) = *(Buffer_in_peng+i); //Algorithmus muss hier eingefügt werden, im Moment "Golden Wire" DSK6713_LED_toggle(3); }
/* * processBuffer() - Process audio data once it has been received. */ void processBuffer(void) { Uint32 pingPong; /* Get contents of mailbox posted by edmaHwi */ pingPong = SWI_getmbox(); /* Copy data from transmit to receive, could process audio here */ if (pingPong == PING) { /* Toggle LED #3 as a visual cue */ DSK6713_LED_toggle(3); /* Copy receive PING buffer to transmit PING buffer */ copyData(gBufferRcvPing, gBufferXmtPing, BUFFSIZE); } else { /* Toggle LED #2 as a visual cue */ DSK6713_LED_toggle(2); /* Copy receive PONG buffer to transmit PONG buffer */ copyData(gBufferRcvPong, gBufferXmtPong, BUFFSIZE); } }
void tsk_led_toggle(void) { /* initializatoin of the task */ /* nothing to do */ /* process */ while(1) { SEM_pendBinary(&SEM_LEDToggle, SYS_FOREVER); if(configComplete) configComplete ++; if(configComplete >= 2) { t_reg = DSK6713_rget(DSK6713_MISC); t_reg &= ~MCBSP1SEL; // Set MCBSP1SEL to 1 (extern) DSK6713_rset(DSK6713_MISC,t_reg); configComplete = 0; //DSK6713_rset(DSK6713_MISC,MCBSP1SEL); //t_reg = DSK6713_rget(DSK6713_MISC); //t_reg &= ~MCBSP1SEL; // Set MCBSP1SEL to 1 (extern) //DSK6713_rset(DSK6713_MISC,t_reg); DSK6713_LED_on(0); DSK6713_LED_on(1); DSK6713_LED_on(2); DSK6713_LED_on(3); } DSK6713_LED_toggle(0); DSK6713_LED_toggle(1); DSK6713_LED_toggle(2); DSK6713_LED_toggle(3); } }
void tsk_led_toggle(void) { /* initialization of the task */ /* nothing to do */ /* process */ while(1) { SEM_pendBinary(&SEM_LEDToggle, SYS_FOREVER); //LOG_printf(&myLog, "tsk_led_toggle"); DSK6713_LED_toggle(0); } }
/* * blinkLED() - Periodic thread (PRD) that toggles LED #0 every 500ms if * DIP switch #0 is depressed. The thread is configured * in the DSP/BIOS configuration tool under Scheduling --> * PRD --> PRD_blinkLed. The period is set there at 500 * ticks, with each tick corresponding to 1ms in real * time. */ void blinkLED(void) { /* Toggle LED #0 if DIP switch #0 is off (depressed) */ if (!DSK6713_DIP_get(0)) DSK6713_LED_toggle(0); }
interrupt void serialPortRcvISR() { union {Uint32 combo; short channel[2];} temp; short ii=0; short jj=0; temp.combo = MCBSP_read(DSK6713_AIC23_DATAHANDLE); // Note that right channel is in temp.channel[0] // Note that left channel is in temp.channel[1] // keep track of largest sample for diagnostics if (temp.channel[0]>max_samp) max_samp = temp.channel[0]; if (state==0) { // SEARCHING STATE // put sample in searching buffer buf[bufindex] = (float) temp.channel[0]; // right channel // compute incoherent correlation zc = 0; zs = 0; for (ii=0;ii<M;ii++) { zc += mfc[ii]*buf[ii]; zs += mfs[ii]*buf[ii]; } zz = zc*zc+zs*zs; if (zz>T1) { // threshold exceeded? max_recbuf = 0; state = 1; // enter "recording" state (takes effect in next interrupt) DSK6713_LED_toggle(0); // toggle LED here for diagnostics // record time of first sample (DRB fixed 4/19/2015: added +1) recbuf_start_clock = sincpulsebuf_counter-M+1; // should not be negative since we started counting when we launched the S->M sinc pulse recbufindex = M; // start recording new samples at position M jj = bufindex; // for (ii=0;ii<M;ii++){ // copy samples from buf to first M elements of recbuf jj++; // the first time through, this puts us at the oldest sample if (jj>=M) jj=0; recbuf[ii] = buf[jj]; buf[jj] = 0; // clear out searching buffer to avoid false trigger } } else { // increment and wrap pointer bufindex++; if (bufindex>=M) bufindex = 0; } } else if (state==1) { // RECORDING STATE // put sample in recording buffer recbuf[recbufindex] = (float) temp.channel[0]; // right channel recbufindex++; if (recbufindex>=(2*N+2*M)) { state = 2; // buffer is full delay_est_done = 0; // clear flag DSK6713_LED_toggle(0); // toggle LED here for diagnostics recbufindex = 0; // shouldn't be necessary } } else if (state==2) { // CALCULATING DELAY ESTIMATES STATE if (delay_est_done==1) { // are the delay estimates done calculating? state = 3; // next state } } else if (state==3) { // WRITE ADJUSTED VIRTUAL CLOCK BUFFER STATE delay_est_done = 0; // clear flag state = 0; // xxx temporary } if (state==-1) { // WARMUP STATE (NO OUTPUT) if (sincpulsebuf_counter>LL/2) { state = 0; } temp.channel[1] = 0; temp.channel[0] = 0; } else { if (vclock_counter==buffer_swap_index) swap_pending = 1; if ((swap_pending==1)&&(state!=2)) // ok to swap buffer { swap_pending = 0; buffer_just_swapped = 1; if (current_clockbuf==0) current_clockbuf = 1; else current_clockbuf = 0; } temp.channel[1] = clockbuf_shifted[current_clockbuf][vclock_counter]; // slave *shifted* clock signal (always played) // temp.channel[1] = clockbuf[vclock_counter]; // slave *unshifted* clock signal (for debug) temp.channel[0] = sincpulsebuf[sincpulsebuf_counter]; // this initiates the sinc pulse exchange with the master } MCBSP_write(DSK6713_AIC23_DATAHANDLE, temp.combo); // output L/R channels // update virtual clock (cycles from 0 to L-1) vclock_counter++; if (vclock_counter>=L) { vclock_counter = 0; // clock tick occurred, wrap } // update sinc pulse counter (cycles from 0 to LL-1) // this is for sinc pulses from the slave to the master // sinc pulses from the slave to the master have their peak at // sincpulsebuf_counter = 0 (this makes clock offset calculations simple) sincpulsebuf_counter++; if (sincpulsebuf_counter>=LL) { sincpulsebuf_counter = 0; // wrap } }
void main() { // initialize the save buffers for(j = 0; j < 2; j++){ for (i=0;i<SAVES;i++) { cde_save[i] = 0; pcf_save[i] = 0; clockoffset_save[i] = 0.0; fde_save[i] = 0.0; imax_save[i] = 0; recbuf_start_clock_save[i] = 0; ppm_estimate_save[i] = 0.0; ytilde_save[i] = 0.0; state_prediction[j][i] = 0.0; state_estimate[j][i] = 0.0; } } // set up the fractionally shifted buffers for(k = 0; k < FER; k++){ fractionalShift = ((double) k )/((double) FER); // number of samples to shift for (i=-N;i<=N;i++){ x = ((double) i - fractionalShift)*BW; if (x==0.0) { y = 32767.0; } else { t = ((double) i - fractionalShift)*CBW; y = 32767.0*cos(2*PI*t)*sin(PI*x)/(PI*x); // double } j = i; if (j<0) { j += L; // wrap } allMyDelayedWaveforms[k][j] = (short) y; } } // set up the cosine and sin matched filters for searching // also initialize searching buffer for (i=0;i<M;i++){ t = i*CBW; // time y = cos(2*PI*t); // cosine matched filter (double) mfc[i] = (float) y; // cast and store y = sin(2*PI*t); // sine matched filter (double) mfs[i] = (float) y; // cast and store buf[i] = 0; // clear searching buffer } // initialize clock buffers for (i=0;i<L;i++) { clockbuf[i] = 0; clockbuf_shifted[0][i] = 0; clockbuf_shifted[1][i] = 0; } // initialize sinc pulse buffer for (i=0;i<LL;i++) sincpulsebuf[i] = 0; // set up clock buffer and sinc pulse buffer // to play modulated sinc centered at zero for (i=-N;i<=N;i++){ x = i*BW; if (i!=0) { t = i*CBW; y = 32767.0*cos(2*PI*t)*sin(PI*x)/(PI*x); // double } else { y = 32767.0; } j = i; if (j<0) { j += L; // wrap } clockbuf[j] = (short) y; j = i; if (j<0) { j += LL; // wrap } sincpulsebuf[j] = (short) y; } // set up inphase and quadrature sinc pulses for coarse and fine delay estimators j = 0; for (i=-N;i<=N;i++){ x = i*BW; if (i!=0) { t = i*CBW; si[j] = (float) (cos(2*PI*t)*sin(PI*x)/(PI*x)); sq[j] = (float) (sin(2*PI*t)*sin(PI*x)/(PI*x)); } else { si[j] = 1.0; sq[j] = 0.0; } j++; } DSK6713_init(); // Initialize the board support library, must be called first DSK6713_LED_init(); // initialize LEDs hCodec = DSK6713_AIC23_openCodec(0, &config); // open codec and get handle // Configure buffered serial ports for 32 bit operation // This allows transfer of both right and left channels in one read/write MCBSP_FSETS(SPCR1, RINTM, FRM); MCBSP_FSETS(SPCR1, XINTM, FRM); MCBSP_FSETS(RCR1, RWDLEN1, 32BIT); MCBSP_FSETS(XCR1, XWDLEN1, 32BIT); // set codec sampling frequency DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_8KHZ); // interrupt setup IRQ_globalDisable(); // Globally disables interrupts IRQ_nmiEnable(); // Enables the NMI interrupt IRQ_map(IRQ_EVT_RINT1,15); // Maps an event to a physical interrupt IRQ_enable(IRQ_EVT_RINT1); // Enables the event IRQ_globalEnable(); // Globally enables interrupts DSK6713_LED_toggle(3); while(1) // main loop { if ((state==2)&&(delay_est_done==0)){ // TIME TO COMPUTE DELAY ESTIMATES DSK6713_LED_toggle(1); // toggle LED here for diagnostics /***************** * * * ESTIMATION * * * ****************/ // compute coarse delay estimate zmax = 0.0; // maximum imax = 0; // index of maximum for (i=0;i<(2*M-1);i++){ // lag index z = 0; for (j=0;j<(2*N+1);j++) { z+= si[j]*recbuf[i+j]; // correlation at lag i } if (abs(z)>zmax) { zmax = abs(z); // store maximum imax = i; // store index of maximum } } cde = recbuf_start_clock + imax + N; // coarse delay estimate (DRB: +N here because si is already shifted by N) // cde is the number of samples elapsed since we launched the S->M sinc pulse // compute fine delay estimate zi = 0.0; // in phase zq = 0.0; // quadrature for (j=0;j<(2*N+1);j++) { zi+= si[j]*recbuf[imax+j]; // correlation at lag imax zq+= sq[j]*recbuf[imax+j]; // correlation at lag imax } pcf = atan2(zq,zi)*(2*INVPI); // assumes wc = pi/2 fde = (float) cde + pcf; // compute actual clock offset // the value computed here is always non-negative and // represents the number of samples the master clock is ahead of the slave clock // (or the number of samples the slave clock is behind the master clock) // S->M sinc pulse was launched at time 0 // M->S sinc pulse was received at time fde (should be positive) // to synchronize, we want slave clock ticks to appear at fde/2 + k*L for k=0,1,.... clockoffset = fde*0.5; // testing/debugging imax_save[save_index] = imax; recbuf_start_clock_save[save_index] = recbuf_start_clock; cde_save[save_index] = cde; pcf_save[save_index] = pcf; fde_save[save_index] = fde; clockoffset_save[save_index] = clockoffset; //If first time running if(!hasSaved && save_index == 0){ state_estimate[0][0] = clockoffset* TS; state_estimate[1][0] = 0; state_prediction[0][1] = clockoffset * TS; state_prediction[1][1] = 0; } else { // save_index > 0 ytilde = clockoffset * TS - state_prediction[0][save_index]; // innovation (difference between current observation and prediction) state_estimate[0][save_index] = state_prediction[0][save_index] + ((double) K1)*ytilde; // filtered clock offset estimate state_estimate[1][save_index] = state_prediction[1][save_index] + ((double)K2)*ytilde; // filtered frequency offset estimate //Determine if a glitch has happened if (save_index+1<SAVES) { // generate predictions for next observation (make sure multiplication by LL doesn't cause datatype problems) state_prediction[0][save_index+1] = state_estimate[0][save_index] + state_estimate[1][save_index] * (double)T0;//* LL; state_prediction[1][save_index+1] = state_estimate[1][save_index]; } else if(save_index + 1 == SAVES){ state_prediction[0][0] = state_estimate[0][save_index] + state_estimate[1][save_index]* (double)T0;//* LL; state_prediction[1][0] = state_prediction[1][save_index]; } } //Calculate the rate offset if(!hasSaved && save_index < 1){ if(save_index == 0) rateoffset_estimate = 0; else rateoffset_estimate = TS * (clockoffset_save[save_index] - clockoffset_save[save_index - 1]); } //Otherwise, use kalman filter else{ rateoffset_estimate = state_prediction[0][save_index] - state_estimate[0][save_index]; } // if(clockoffset_save[save_index] > L && clockoffset_save[save_index - 1] < L) adjustedclockoffset = clockoffset_save[save_index] + 5 * L * rateoffset_estimate; else if(clockoffset_save[save_index] > L && clockoffset_save[save_index - 1] < L) adjustedclockoffset = clockoffset_save[save_index] + 3 * L *rateoffset_estimate; else adjustedclockoffset = clockoffset_save[save_index] + 4 * L * rateoffset_estimate; //////// j = (short) adjustedclockoffset; // casting from float to short just truncates, e.g., 3.99 becomes 3 fractionalShift = adjustedclockoffset - (double) j; // fractionalShift >= 0 and < 1 tells us how much of a sample is left k = (short) (fractionalShift * (double) FER + 0.5); // this now rounds and givse results on 0,...,FER if (k==FER) { // we rounded up to the next whole sample k = 0; j++; } for (i=0;i<L;i++) { ell = j+i; while (ell>=L) { ell = ell-L; } if (current_clockbuf==0) { clockbuf_shifted[1][ell] = allMyDelayedWaveforms[k][i]; // write other buffer } else { clockbuf_shifted[0][ell] = allMyDelayedWaveforms[k][i]; // write other buffer } } // when can we swap buffers? buffer_swap_index = j+L/2; // midpoint of the silent part (I think) while (buffer_swap_index>=L) buffer_swap_index = buffer_swap_index-L; // tell the ISR the calculations are done delay_est_done = 1; // update save index save_index++; if (save_index>=SAVES) // wrap { save_index = 0; hasSaved = 1; } DSK6713_LED_toggle(1); // toggle LED here for diagnostics } else if (buffer_just_swapped==1) { // this code computes the next buffer and attempts to corect for the frequency offset buffer_just_swapped = 0; // copy appropriate fractionally shifted clock buffer to shifted clock buffer adjustedclockoffset = adjustedclockoffset + ((double) L)*one_over_beta; // adjust latency of next pulse while (adjustedclockoffset>((double) L)) adjustedclockoffset = adjustedclockoffset - (double) L; j = (short) adjustedclockoffset; // casting from float to short just truncates, e.g., 3.99 becomes 3 fractionalShift = adjustedclockoffset - (double) j; // fractionalShift >= 0 and < 1 tells us how much of a sample is left k = (short) (fractionalShift * (double) FER); // this also truncates and should give result on 0,...,FER-1 for (i=0;i<L;i++) { ell = j+i; if (ell>=L) { ell = ell-L; } if (current_clockbuf==0) { clockbuf_shifted[1][ell] = allMyDelayedWaveforms[k][i]; // write other buffer } else { clockbuf_shifted[0][ell] = allMyDelayedWaveforms[k][i]; // write other buffer } } } // if ((state==2)&&(delay_est_done==0)) } // while(1) } // void main
interrupt void serialPortRcvISR() { union {Uint32 combo; short channel[2];} temp; temp.combo = MCBSP_read(DSK6713_AIC23_DATAHANDLE); // Note that right channel is in temp.channel[0] // Note that left channel is in temp.channel[1] // keep track of largest sample for diagnostics if (temp.channel[0]>max_samp) max_samp = temp.channel[0]; if (state==STATE_SEARCH) { // SEARCHING STATE //search_for_thresh(&(temp.channel[0]),PASSTHROUGH); // isSearching++; // put sample in searching buffer ///* buf[bufindex] = (float) temp.channel[0]; // right channel if (PASSTHROUGH!=1) { temp.channel[0] = 0; // can comment this out for debugging at home } // compute incoherent correlation zc = 0; zs = 0; for(i=0;i<M;i++) { zc += mfc[i]*buf[i]; zs += mfs[i]*buf[i]; } z = zc*zc+zs*zs; if (z>T1) { // threshold exceeded? max_recbuf = 0; state = 1; // enter "recording" state (takes effect in next interrupt) recbufindex = M; // start recording new samples at position M j = bufindex; // for (i=0;i<M;i++){ // copy samples from buf to first M elements of recbuf j++; // the first time through, this puts us at the oldest sample if (j>=M) j=0; recbuf[i] = (short) buf[j]; buf[j] = 0; // clear out searching buffer to avoid false trigger } } else { // increment and wrap pointer bufindex++; if (bufindex>=M) bufindex = 0; } //*/ } else if (state==STATE_RECORD) { // RECORDING STATE //DEBUG if(!ledTriggered) { DSK6713_LED_toggle(0); ledTriggered = 1; } // put sample in recording buffer recbuf[recbufindex] = temp.channel[0]; // right channel if (PASSTHROUGH!=1) { temp.channel[0] = 0; // can comment this out for debugging at home } if (abs(recbuf[recbufindex])>max_recbuf) { max_recbuf = abs(recbuf[recbufindex]); // keep track of largest sample } recbufindex++; if (recbufindex>=(2*N+2*M)) { state = STATE_WAIT_CLOCK; // buffer is full (stop recording and start counting samples to next clock tick) recbufindex = 0; // shouldn't be necessary wait_count = 0; // reset the wait counter if (max_recbuf<2048) playback_scale = 0; // don't send response (signal was too weak) else if (max_recbuf<4096) playback_scale = 8; // reply and scale by 8 else if (max_recbuf<8192) playback_scale = 4; // reply and scale by 4 else if (max_recbuf<16384) playback_scale = 2; // reply and scale by 2 else playback_scale = 1; // no scaling } } else if (state==STATE_WAIT_CLOCK) { // WAITING STATE (counting up samples until clock tick) if(ledTriggered){ DSK6713_LED_toggle(0); ledTriggered = 0; } if (PASSTHROUGH!=1) { temp.channel[0] = 0; // can comment this out for debugging at home } wait_count++; // only way out of this state is when the virtual clock rolls over } else if (state==STATE_WAIT_PLAYBACK) { // WAITING STATE (counting down samples until reply) if (PASSTHROUGH!=1) { temp.channel[0] = 0; // can comment this out for debugging at home } wait_count--; if (wait_count<0) { state = 4; // done waiting, time to play back rec_buffer in reverse recbufindex = 2*N+2*M; } } else if (state==STATE_RESPOND) { // RESPONSE STATE (play back recording buffer in reverse) recbufindex--; if (recbufindex>=0) { temp.channel[0] = playback_scale*recbuf[recbufindex]; } else { state = STATE_SEARCH; // go back to searching } } temp.channel[1] = clockbuf[vclock_counter]; // master clock signal (always played) MCBSP_write(DSK6713_AIC23_DATAHANDLE, temp.combo); // output L/R channels // update virtual clock (cycles from 0 to L-1) vclock_counter++; if (vclock_counter>=L) { vclock_counter = 0; // clock tick occurred, wrap if (state==STATE_WAIT_CLOCK) { state = STATE_WAIT_PLAYBACK; } } }
interrupt void serialPortRcvISR() { union {Uint32 combo; short channel[2];} temp; temp.combo = MCBSP_read(DSK6713_AIC23_DATAHANDLE); // Note that right channel is in temp.channel[0] // Note that left channel is in temp.channel[1] // keep track of largest sample for diagnostics if (temp.channel[0]>max_samp) max_samp = temp.channel[0]; // filter inbuf[inindex] = (float) temp.channel[0]; // right channel if (CLOCKOUTPUTCHANNEL==0) { // superimposed clocks and sync pulses, need to use HPF to avoid false detections hpfout = 0.0; ii = 0; for (kk=inindex;kk>=0;kk--){ hpfout += inbuf[kk]*B[ii]; ii++; } for (kk=BL-1;kk>inindex;kk--){ hpfout += inbuf[kk]*B[ii]; ii++; } } else { // clocks on left output, no need for HPF hpfout = (float) temp.channel[0]; // right channel } if (state==0) { // SEARCHING STATE // put sample in searching buffer fbuf[bufindex] = hpfout; // right channel buf[bufindex] = (float) temp.channel[0]; // unfiltered right channel if (PASSTHROUGH!=1) { temp.channel[0] = 0; // can comment this out for debugging at home } // compute incoherent correlation on filtered buffer zc = 0; zs = 0; for(i=0;i<M;i++) { zc += mfc[i]*fbuf[i]; zs += mfs[i]*fbuf[i]; } z = zc*zc+zs*zs; if (z>T1) { // threshold exceeded? if (z<minz) minz = z; // diagnostic if (z>maxz) maxz = z; // diagnostic max_recbuf = 0; state = 1; // enter "recording" state (takes effect in next interrupt) DSK6713_LED_toggle(0); // toggle LED for diagnostics recbufindex = M; // start recording new samples at position M j = bufindex; // for (i=0;i<M;i++){ // copy samples from buf to first M elements of recbuf j++; // the first time through, this puts us at the oldest sample if (j>=M) j=0; //recbuf[i] = (short) buf[j]; // Oct 28 bad idea recbuf[i] = (short) fbuf[j]; // DRB: filtered buffer copied now to avoid echoing back clock pulses fbuf[j] = 0; // clear out searching buffer to avoid false trigger buf[j] = 0; // clear out searching buffer to avoid false trigger } } else { // increment and wrap pointer bufindex++; if (bufindex>=M) bufindex = 0; } } else if (state==1) { // RECORDING STATE // put sample in recording buffer //recbuf[recbufindex] = temp.channel[0]; // right channel recbuf[recbufindex] = (short) hpfout; // filtered right channel if (PASSTHROUGH!=1) { temp.channel[0] = 0; // can comment this out for debugging at home } if (abs(recbuf[recbufindex])>max_recbuf) { max_recbuf = abs(recbuf[recbufindex]); // keep track of largest sample for diagnostics } recbufindex++; if (recbufindex>=(2*N+2*M)) { state = 2; // buffer is full (stop recording and start counting samples to next clock tick) DSK6713_LED_toggle(0); // toggle LED for diagnostics recbufindex = 0; // shouldn't be necessary wait_count = 0; // reset the wait counter if (max_recbuf<2000) playback_scale = 0; // don't send response (signal was too weak) else if (max_recbuf<4000) playback_scale = 8; // reply and scale by 8 (DRB now 4 to avoid overflow) else if (max_recbuf<8000) playback_scale = 4; // reply and scale by 4 (DRB now 2 to avoid overflow) else if (max_recbuf<16000) playback_scale = 2; // reply and scale by 2 (DRB now 1 tp avoid overflow) else playback_scale = 1; // no scaling } } else if (state==2) { // WAITING STATE (counting up samples until clock tick) if (PASSTHROUGH!=1) { temp.channel[0] = 0; // can comment this out for debugging at home } wait_count++; // only way out of this state is when the virtual clock rolls over } else if (state==3) { // WAITING STATE (counting down samples until reply) if (PASSTHROUGH!=1) { temp.channel[0] = 0; // can comment this out for debugging at home } wait_count--; if (wait_count<HPFGROUPDELAY) { state = 4; // done waiting, time to play back rec_buffer in reverse recbufindex = 2*N+2*M; } } else if (state==4) { // RESPONSE STATE (play back recording buffer in reverse) recbufindex--; if (recbufindex>=0) { temp.channel[0] = playback_scale*recbuf[recbufindex]; // response always on right channel } else { state = 0; // go back to searching } } // temp.channel[0] right channel has been previously set temp.channel[1] = 0; // clear left channel temp.channel[CLOCKOUTPUTCHANNEL] += clockbuf[vclock_counter]; // master clock signal (always played) // temp.channel[0] = temp.channel[1]; // XXX DIAGNOSTIC FOR OUTPUT OFFSET TEST // temp.channel[0] = clockbuf[vclock_counter]; // XXX DIAGNOSTIC MCBSP_write(DSK6713_AIC23_DATAHANDLE, temp.combo); // output L/R channels // update virtual clock (cycles from 0 to L-1) vclock_counter++; if (vclock_counter>=L) { vclock_counter = 0; // clock tick occurred, wrap if (state==2) { state = 3; } } inindex++; if (inindex>BL-1) inindex = 0; }
void main() { // set up the cosine and sin matched filters for searching // also initialize searching buffer for (i=0;i<M;i++){ t = i*0.25; // time y = cos(2*PI*t); // cosine matched filter (double) mfc[i] = (float) y; // cast and store y = sin(2*PI*t); // sine matched filter (double) mfs[i] = (float) y; // cast and store buf[i] = 0; // clear searching buffer } // initialize clock buffer for (i=0;i<L;i++) clockbuf[i] = 0; // set up clock buffer to play modulated sinc centered at zero for (i=-N;i<=N;i++){ x = i*BW; if (i!=0) { t = i*0.25; y = 32767.0*cos(2*PI*t)*sin(PI*x)/(PI*x); // double } else { y = 32767.0; } j = i; if (j<0) { j += L; // wrap } clockbuf[j] = (short) y; } DSK6713_init(); // Initialize the board support library, must be called first DSK6713_LED_init(); // initialize LEDs hCodec = DSK6713_AIC23_openCodec(0, &config); // open codec and get handle // Configure buffered serial ports for 32 bit operation // This allows transfer of both right and left channels in one read/write MCBSP_FSETS(SPCR1, RINTM, FRM); MCBSP_FSETS(SPCR1, XINTM, FRM); MCBSP_FSETS(RCR1, RWDLEN1, 32BIT); MCBSP_FSETS(XCR1, XWDLEN1, 32BIT); // set codec sampling frequency DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_8KHZ); // interrupt setup IRQ_globalDisable(); // Globally disables interrupts IRQ_nmiEnable(); // Enables the NMI interrupt IRQ_map(IRQ_EVT_RINT1,15); // Maps an event to a physical interrupt IRQ_enable(IRQ_EVT_RINT1); // Enables the event IRQ_globalEnable(); // Globally enables interrupts DSK6713_LED_toggle(3); // toggle LED here for diagnostics (init finished) while(1) // main loop { } }
void PER_Blink_LED(){ DSK6713_LED_toggle(0); DSK6713_LED_toggle(1); }