int main(int argc, const char *argv[]){ printf("\n\n"); // Listen to SIGINT signals (program termination) signal(SIGINT, signal_handler); // Tell linux not to use the user leds in the board. take_over_leds(); // Load device tree overlay to enable PRU hardware. load_device_tree_overlay(); // Load and run binary into pru0 init_pru_program(); open_sound_file(); start_thread(); /* while(!finish){ */ sleep(5); /* } */ prussdrv_pru_disable(PRU_NUM); prussdrv_exit (); stop_thread(); close_sound_file(); return 0; }
int main(int argc, const char *argv[]){ printf("\n\n"); // Listen to SIGINT signals (program termination) signal(SIGINT, signal_handler); // Load device tree overlay to enable PRU hardware. load_device_tree_overlay(); // Load and run binary into pru0 init_pru_program(); open_sound_file(); /* sleep(1); */ start_thread(); while(!finish){} //sleep(500); prussdrv_pru_disable(PRU_NUM); prussdrv_exit (); stop_thread(); close_sound_file(); // Calculate sample rate /* int i; */ /* unsigned long sum = 0; */ /* for(i=0; i<times_count; i++){ */ /* sum += times[i]; */ /* } */ /* float avg = (float)sum / (float)times_count; */ /* printf("Freq: %f \n", 128.0*1000000.0/avg); */ return 0; }
int main(int argc, char **argv) { int opt; uint8_t bufferIndexPins; uint8_t sampleRateOption; pthread_t producer_thread, consumer_thread; /*pointer to shared RAM*/ void *p; struct sigaction signalaction; memset(&signalaction, 0, sizeof(signalaction)); signalaction.sa_sigaction = &sighandler; signalaction.sa_flags = SA_SIGINFO; if (sigaction(SIGTERM, &signalaction, NULL) < 0 || sigaction(SIGHUP, &signalaction, NULL) < 0 || sigaction(SIGINT, &signalaction, NULL) < 0) { fprintf(stderr, "%s\n", strerror(errno)); return (-1); } if (argc == 1) { help(argv[0]); return (-1); } sampleRateOption=0; if (buffer_init(&dataCapturedValues, BUFFER_LENGTH) == -1) { return (-3); } init_channels(); while ((opt = getopt(argc, argv, "p:s:f:")) != -1) { switch (opt) { case 'p': { bufferIndexPins = atoi(optarg); cfgPins[bufferIndexPins] = 1; break; } case 's': { sampleRateOption = atoi(optarg); break; } case 'f': { fd=open(optarg,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); if(fd==-1) { fprintf(stderr,"%s\n",strerror(errno)); fd=STDOUT_FILENO; } break; } default: { help(argv[0]); buffer_destroy(&dataCapturedValues); return (-5); } } } calculate_sample_period(sampleRateOption); init_pru_program(); dbg("PRU program initialized...\n"); prussdrv_map_prumem(PRUSS0_SHARED_DATARAM, &p); shared_ram=(unsigned int *)p; dbg("PRU shared memory was mapped...\n"); shared_ram[0]=sample_delay; shared_ram[1]=sample_delay>>8; shared_ram[2]=sample_delay>>16; shared_ram[3]=sample_delay>>24; create_header(fd,sample_delay,cfgPins); /*Initialize mutex and condition variables*/ pthread_mutex_init(&shared_var_mutex, NULL); pthread_cond_init(&cond_consumer, NULL); pthread_cond_init(&cond_producer, NULL); dbg("Mutex and conditions were initialized..."); /*create threads*/ pthread_create(&consumer_thread, NULL, consumer, NULL); pthread_create(&producer_thread, NULL, producer, NULL); pthread_join(consumer_thread, NULL); pthread_join(producer_thread, NULL); /*Cleanup threads*/ pthread_mutex_destroy(&shared_var_mutex); pthread_cond_destroy(&cond_consumer); pthread_cond_destroy(&cond_producer); close(fd); prussdrv_pru_disable(PRU_NUM); prussdrv_exit(); close(fd); buffer_destroy(&dataCapturedValues); return 0; }