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) ... */ }
static void c2speedtest(int mode, char inputfile[]) { struct CODEC2 *codec2; short *inbuf, *outbuf, *pinbuf, *dummy_buf; unsigned char *bits; int nsam, nbit, nframes; FILE *fin; int f, nread; codec2 = codec2_create(mode); nsam = codec2_samples_per_frame(codec2); nframes = SPEED_TEST_SAMPLES/nsam; outbuf = (short*)malloc(nsam*sizeof(short)); inbuf = (short*)malloc(SPEED_TEST_SAMPLES*sizeof(short)); nbit = codec2_bits_per_frame(codec2); bits = (unsigned char*)malloc(nbit*sizeof(char)); dummy_buf = (short*)malloc(2*nsam*sizeof(short)); fin = fopen(inputfile, "rb"); if (fin == NULL) { printf("Error opening input file: %s\nTerminating....\n",inputfile); exit(1); } printf("reading samples ....\n"); nread = fread(inbuf, sizeof(short), SPEED_TEST_SAMPLES, fin); if (nread != SPEED_TEST_SAMPLES) { printf("error reading %s, %d samples reqd, %d read\n", inputfile, SPEED_TEST_SAMPLES, nread); } fclose(fin); pinbuf = inbuf; for(f=0; f<nframes; f++) { //printf("read ADC\n"); while(adc1_read(dummy_buf, nsam*2) == -1); /* runs at Fs = 16kHz */ //printf("Codec 2 enc\n"); GPIOD->ODR = (1 << 13); codec2_encode(codec2, bits, pinbuf); pinbuf += nsam; GPIOD->ODR &= ~(1 << 13); //printf("Codec 2 dec\n"); codec2_decode(codec2, outbuf, bits); //printf("write to DAC\n"); while(dac1_write(dummy_buf, nsam*2) == -1); /* runs at Fs = 16kHz */ //printf("."); } free(inbuf); free(outbuf); free(bits); codec2_destroy(codec2); }
int main(void) { short buf[N]; float sd1, sd2; adc_open(2*N); printf("Starting!\n"); while(1) { while(adc1_read(buf, N) == -1); sd1 = calc_sd(buf, N); while(adc2_read(buf, N) == -1); sd2 = calc_sd(buf, N); printf("adc1: %5.1f adc2: %5.1f\n", (double)sd1, (double)sd2); } }
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) { 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) ... */ }