// tz this is the one that actuall runs all the time... void rtlsdr_perform64(t_rtlsdr *x, t_object *dsp64, double **ins, long numins, double **outs, long numouts, long sampleframes, long flags, void *userparam) { int i; char mesg[100]; int veclen = sampleframes; static int display_counter = 0; static int display_max = 150; // how often to display debug info int diff; t_double *out1 = outs[0]; t_double *out2 = outs[1]; // outlets will send IQ data i = 0; while (sampleframes--) { if(circ_index_read > CIRCMAX) { circ_index_read = 0; } // if radio is off, just output zero's if(x->x_radio_is_running == 0) { *out1 = 0; *out2 = 0; } // raw mode sends baseband IQ data - everything else is demodulated audio // note that raw mode reads buffer twice as fast because its interleaved IQ else { *out1 = linear_map((double) circ_buf_left[circ_index_read++], -32768, 32767, -1, 1); if(circ_index_read > CIRCMAX) { circ_index_read = 0; } *out2 = linear_map((double) circ_buf_left[circ_index_read++], -32768, 32767, -1, 1); } out1++; out2++; } // debugging stuff for circular buffer and latency // display_counter--; // uncomment this line to display debug info if(display_counter <= 0) { display_counter = display_max; if( circ_index_write > circ_index_read) { diff = circ_index_write - circ_index_read; } else { diff = (circ_index_write + CIRCMAX) - circ_index_read; } sprintf(mesg, "wndx %d:, rndx: %d, diff: %d veclen: %d", circ_index_write, circ_index_read, diff, veclen ); post(mesg, 0); } }
int main (int argc, char* argv[]) { unsigned int ret; tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA; printf("\nINFO: Starting single channel PWM on P9_27.\r\n"); /* Initialize the PRU */ prussdrv_init (); /* Open PRU Interrupt */ ret = prussdrv_open(PRU_EVTOUT_0); if (ret) { printf("prussdrv_open open failed\n"); return (ret); } /* Get the interrupt initialized */ prussdrv_pruintc_init(&pruss_intc_initdata); /* Initialize example */ printf("\tINFO: Initializing PWM with default values.\r\n"); //LOCAL_exampleInit(PRU_NUM); //////////////////// LOAD VALUES INTO MEMORY ///////////////// void *DDR_regaddr1, *DDR_regaddr2, *DDR_regaddr3; /* open the device */ mem_fd = open("/dev/mem", O_RDWR); if (mem_fd < 0) { printf("Failed to open /dev/mem (%s)\n", strerror(errno)); return 1; } /* map the DDR memory */ ddrMem = mmap(0, 0x0FFFFFFF, PROT_WRITE | PROT_READ, MAP_SHARED, mem_fd, DDR_BASEADDR); if (ddrMem == NULL) { printf("Failed to map the device (%s)\n", strerror(errno)); close(mem_fd); return 1; } /* Store Addends in DDR memory location */ DDR_regaddr1 = ddrMem + OFFSET_DDR; DDR_regaddr2 = ddrMem + OFFSET_DDR + 0x00000004; DDR_regaddr3 = ddrMem + OFFSET_DDR + 0x00000008; *(unsigned int*) DDR_regaddr1 = PERIOD_CYCLES; *(unsigned int*) DDR_regaddr2 = DUTY_CYCLES; *(unsigned int*) DDR_regaddr3 = STOP_FLAG; /* Execute example on PRU */ printf("\tINFO: Starting PWM output on P9_27.\r\n"); prussdrv_exec_program (PRU_NUM, "./prucode.bin"); signal(SIGINT, intHandler); int fd = open(PORT, O_RDWR); if (fd < 0) error("can't open %s - %m", PORT); if (ioctl(fd, I2C_SLAVE, ADDR) < 0) error("can't ioctl %s:0x%02x - %m", PORT, ADDR); if (write(fd, "\x40", 2) < 0) error("can't setup %s:0x%02x - %m", PORT, ADDR); // again, keep supposedly safe values for start (although this might arm some motors) int last_input = 1060; int input = 1060; int converted = 212000; int loopkey = 1; struct nunchuck_packet packet; int js_x, js_y; while (loopkey) { *(unsigned int*) DDR_regaddr2 = converted; printf("Value entered: %i\n Value sent: %i\n", input, converted); ret = read(fd, &packet, sizeof(struct nunchuck_packet)); if (ret <0) error("read error: %s : 0x%02x - %m ", PORT, ADDR); if (!ret) continue; js_x = (packet.joystick_val[0] ^ 0x17) + 0x17 ; js_y = (packet.joystick_val[1] ^ 0x17) + 0x17 ; input = linear_map(js_x, 0, 255, 0, 3000); printf("input : %d\n", input); last_input = input; //scanf(" %i", &loopkey); if(input > 100 && input < 10000) { // sane value converted = input * 1000 / 5; //input in microseconds converted to nanoseconds and then divided by 5 to get cycles } else { // restore sanity input = last_input; } write(fd, "", 1); } *(unsigned int*) DDR_regaddr3 = 1; // set close register, wait for PRU to halt /* Wait until PRU0 has finished execution */ printf("\tINFO: Waiting for HALT command.\r\n"); prussdrv_pru_wait_event (PRU_EVTOUT_0); printf("\tINFO: PRU completed transfer.\r\n"); prussdrv_pru_clear_event (PRU0_ARM_INTERRUPT); /* // Check if example passed if ( LOCAL_examplePassed(PRU_NUM) ) { printf("Example executed succesfully.\r\n"); } else { printf("Example failed.\r\n"); } */ /* Disable PRU and close memory mapping*/ prussdrv_pru_disable(PRU_NUM); prussdrv_exit (); munmap(ddrMem, 0x0FFFFFFF); close(mem_fd); return(0); }
t_int *rtlsdr_perform(t_int *w) { t_rtlsdr *x = (t_rtlsdr *) w[1]; /* Copy the signal inlet pointer */ float *in = (t_float *) (w[2]); /* Copy the signal outlet pointer */ float *out1 = (t_float *) (w[3]); /* Copy the signal outlet pointer for second outlet */ float *out2 = (t_float *) (w[4]); /* Copy the signal vector size */ int n = w[5]; ///////////////// int i; char mesg[100]; int veclen = n; static int display_counter = 0; static int display_max = 150; // how often to display debug info int diff; // outlets will send IQ data i = 0; while (n--) { if(circ_index_read > CIRCMAX) { circ_index_read = 0; } // if radio is off, just output zero's if(x->x_radio_is_running == 0) { *out1 = 0; *out2 = 0; } // raw mode sends baseband IQ data - everything else is demodulated audio // note that raw mode reads buffer twice as fast because its interleaved IQ else { *out1 = linear_map((float) circ_buf_left[circ_index_read++], -32768, 32767, -1, 1); if(circ_index_read > CIRCMAX) { circ_index_read = 0; } *out2 = linear_map((float) circ_buf_left[circ_index_read++], -32768, 32767, -1, 1); } out1++; out2++; } // debugging stuff for circular buffer and latency // display_counter--; // uncomment this line to display debug info if(display_counter <= 0) { display_counter = display_max; if( circ_index_write > circ_index_read) { diff = circ_index_write - circ_index_read; } else { diff = (circ_index_write + CIRCMAX) - circ_index_read; } sprintf(mesg, "wndx %d:, rndx: %d, diff: %d veclen: %d", circ_index_write, circ_index_read, diff, veclen ); post(mesg, 0); } ///////////////// /* Return the next address on the signal chain */ return w + 6; }