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) { unsigned short unsigned_buf[N]; short buf[N]; int sam; int i, j, fifo_sz; FILE *fadc; fadc = fopen("adc.raw", "wb"); if (fadc == NULL) { printf("Error opening output file: adc.raw\n\nTerminating....\n"); exit(1); } fifo_sz = ADC_TUNER_BUF_SZ; printf("Starting! bufs: %d %d\n", BUFS, fifo_sz); adc_open(fifo_sz); adc_set_tuner_en(0); /* dump raw samples, no tuner */ sm1000_leds_switches_init(); for (i=0; i<BUFS; i++) { while(adc1_read((short*)unsigned_buf, N) == -1); /* convert to signed */ for(j=0; j<N; j++) { sam = (int)unsigned_buf[j] - 32768; buf[j] = sam; } /* most of the time will be spent here */ GPIOE->ODR |= (1 << 3); fwrite(buf, sizeof(short), N, fadc); GPIOE->ODR &= ~(1 << 3); } fclose(fadc); printf("Finished!\n"); }
int main(void) { short buf[SINE_SAMPLES]; int i; dac_open(4*DAC_BUF_SZ); adc_open(ADC_FS_16KHZ, 4*ADC_BUF_SZ); sm1000_leds_switches_init(); while (1) { /* keep DAC FIFOs topped up */ while(adc2_read(buf, SINE_SAMPLES) == -1); if (!switch_select()) { for(i=0; i<SINE_SAMPLES; i++) buf[i] = aSine[i]; } dac2_write(buf, SINE_SAMPLES); } }
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) ... */ }