int main(void) { struct freedv *f; short buf[FREEDV_NSAMPLES]; int nin, nout; /* init all the drivers for various peripherals */ sm1000_leds_switches_init(); dac_open(4*DAC_BUF_SZ); adc_open(); f = freedv_open(FREEDV_MODE_1600); /* LEDs into a known state */ led_pwr(1); led_ptt(0); led_rt(0); led_err(0); /* TODO: [ ] UT analog interfaces from file IO [ ] UTs for simultaneous tx & rx on analog interfaces [ ] measure CPU load of various parts with a blinky [ ] detect program assert type errors with a blinky [ ] timer tick function to measure 10ms-ish type times [ ] switch debouncing? [ ] light led with bit errors */ while(1) { if(switch_ptt()) { /* Transmit -------------------------------------------------------------------------*/ /* ADC2 is the SM1000 microphone, DAC1 is the modulator signal we send to radio tx */ if (adc2_read(buf, FREEDV_NSAMPLES) == FREEDV_NSAMPLES) { freedv_tx(f, buf, buf); dac1_write(buf, FREEDV_NSAMPLES); led_ptt(1); led_rt(0); led_err(0); } } else { /* Receive --------------------------------------------------------------------------*/ /* ADC1 is the demod in signal from the radio rx, DAC2 is the SM1000 speaker */ nin = freedv_nin(f); f->total_bit_errors = 0; if (adc1_read(buf, nin) == nin) { nout = freedv_rx(f, buf, buf); dac2_write(buf, nout); led_ptt(0); led_rt(f->fdmdv_stats.sync); led_err(f->total_bit_errors); } } } /* while(1) ... */ }
int main(void) { struct freedv *f; short adc16k[FDMDV_OS_TAPS_16K+FREEDV_NSAMPLES_16K]; short dac16k[FREEDV_NSAMPLES_16K]; short adc8k[FREEDV_NSAMPLES]; short dac8k[FDMDV_OS_TAPS_8K+FREEDV_NSAMPLES]; SWITCH_STATE ss; int nin, nout, i; /* init all the drivers for various peripherals */ SysTick_Config(SystemCoreClock/168000); /* 1 kHz SysTick */ sm1000_leds_switches_init(); dac_open(4*DAC_BUF_SZ); adc_open(4*ADC_BUF_SZ); f = freedv_open(FREEDV_MODE_1600); /* put outputs into a known state */ led_pwr(1); led_ptt(0); led_rt(0); led_err(0); not_cptt(1); /* clear filter memories */ for(i=0; i<FDMDV_OS_TAPS_16K; i++) adc16k[i] = 0.0; for(i=0; i<FDMDV_OS_TAPS_8K; i++) dac8k[i] = 0.0; ss.state = SS_IDLE; ss.mode = ANALOG; while(1) { iterate_select_state_machine(&ss); if (switch_ptt()) { /* Transmit -------------------------------------------------------------------------*/ /* ADC2 is the SM1000 microphone, DAC1 is the modulator signal we send to radio tx */ if (adc2_read(&adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES_16K) == 0) { GPIOE->ODR = (1 << 3); fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES); if (ss.mode == ANALOG) { for(i=0; i<FREEDV_NSAMPLES; i++) dac8k[FDMDV_OS_TAPS_8K+i] = adc8k[i]; fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], FREEDV_NSAMPLES); dac1_write(dac16k, FREEDV_NSAMPLES_16K); } if (ss.mode == DV) { freedv_tx(f, &dac8k[FDMDV_OS_TAPS_8K], adc8k); fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], FREEDV_NSAMPLES); dac1_write(dac16k, FREEDV_NSAMPLES_16K); } if (ss.mode == TONE) { while(dac1_write((short*)aSine, SINE_SAMPLES) == 0); } led_ptt(1); led_rt(0); led_err(0); not_cptt(0); GPIOE->ODR &= ~(1 << 3); } } else { /* Receive --------------------------------------------------------------------------*/ not_cptt(1); led_ptt(0); /* ADC1 is the demod in signal from the radio rx, DAC2 is the SM1000 speaker */ if (ss.mode == ANALOG) { /* force analog bypass when select down */ if (adc1_read(&adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES_16K) == 0) { fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES); for(i=0; i<FREEDV_NSAMPLES; i++) dac8k[FDMDV_OS_TAPS_8K+i] = adc8k[i]; fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], FREEDV_NSAMPLES); dac2_write(dac16k, FREEDV_NSAMPLES_16K); led_rt(0); led_err(0); } } else { /* regular DV mode */ nin = freedv_nin(f); nout = nin; f->total_bit_errors = 0; if (adc1_read(&adc16k[FDMDV_OS_TAPS_16K], 2*nin) == 0) { GPIOE->ODR = (1 << 3); fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], nin); nout = freedv_rx(f, &dac8k[FDMDV_OS_TAPS_8K], adc8k); fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], nout); dac2_write(dac16k, 2*nout); led_rt(f->fdmdv_stats.sync); led_err(f->total_bit_errors); GPIOE->ODR &= ~(1 << 3); } } } } /* while(1) ... */ }