Ejemplo n.º 1
0
int main(void) {
    short  buf[N];
    FILE  *fplay;

    dac_open(2*N);

    while(1) {
        fplay = fopen("stm_in.raw", "rb");
        if (fplay == NULL) {
            printf("Error opening input file: stm_in.raw\n\nTerminating....\n");
            exit(1);
        }

        printf("Starting!\n");

        while(fread(buf, sizeof(short), N, fplay) == N) {
            while(dac1_write(buf, N) == -1);
            while(dac2_write(buf, N) == -1);
        }

        printf("Finished!\n");
        fclose(fplay);
    }

    /* let FIFO empty */

    while(1);
}
Ejemplo n.º 2
0
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) ... */
}
Ejemplo n.º 3
0
int main(void) {
    int tstart,tup,tend,cyc,i;

    memset((void*)outbuf,0,sizeof(short)*DAC_DUC_BUF_SZ);
    setup_timer();
    fast_dac_open(2*DAC_DUC_BUF_SZ,2*DAC_BUF_SZ);
    tstart=tend=tup=cyc=0;
    //Initalize complex input with signal at zero
    for(i=0;i<DUC_48N;i++){
        comp_in[i].real=1;
        comp_in[i].imag=0;
    }
    while (1) {
	cyc++;
        //if(cyc>GMSK_TEST_LEN)
        //    cyc=0;
	if(cyc%10000==0){
                printf("48c80r takes %d uSecs\n",tup-tstart);
		printf("iir upconvert takes %d uSecs\n",tend-tup);
	}
        tstart = TIM_GetCounter(TIM2);

        upconv_48c_80r(comp_in,tx_imm,1);

	tup = TIM_GetCounter(TIM2);

	iir_upconv_fixp(tx_imm,outbuf);

	tend = TIM_GetCounter(TIM2);

        //Sit and spin until we can get more samples into the dac
	while(dac1_write((short*)outbuf,DAC_DUC_BUF_SZ)<0);
    }

}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
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) ... */
}