void load_main(prog_t *prog) { void *module; char *error_s; ulong64 tv2,tv1; tv1 = gettime_us(); module = dlopen (prog->filename, RTLD_LAZY|RTLD_GLOBAL); if (!module) die(1, "loading invoked application: '%s'\n", dlerror()); dlerror(); prog->entry = (entry_t)dlsym(module, "main"); error_s = dlerror(); tv2 = gettime_us(); info("opening of %s took %llu usec\n", prog->filename, tv2-tv1); if (error_s != NULL) die(1, "loading symbol 'main': '%s'\n", error_s); }
int main(int argc,char **argv) { start_time=time(0); start_usec=gettime_us(); int opt; while ((opt = getopt(argc, argv, "b:s:l:c:")) != -1) { switch (opt) { case 'l': strcpy(serial_port,optarg); break; case 's': serial_speed=atoi(optarg); switch(serial_speed) { case 1000000: case 1500000: case 4000000: case 230400: case 2000000: break; default: usage(); } break; case 'b': bitstream=strdup(optarg); break; case 'c': queue_command(optarg); break; default: /* '?' */ usage(); } } if (argc-optind==1) usage(); // Load bitstream if file provided if (bitstream) { char cmd[1024]; snprintf(cmd,1024,"fpgajtag -a %s",bitstream); fprintf(stderr,"%s\n",cmd); system(cmd); fprintf(stderr,"[T+%lldsec] Bitstream loaded\n",(long long)time(0)-start_time); } #ifndef APPLE // Try to set USB serial port to low latency { char latency_timer[1024]; int offset=strlen(serial_port); while(offset&&serial_port[offset-1]!='/') offset--; snprintf(latency_timer,1024,"/sys/bus/usb-serial/devices/%s/latency_timer", &serial_port[offset]); int old_latency=999; FILE *f=fopen(latency_timer,"r"); if (f) { fscanf(f,"%d",&old_latency); fclose(f); } if (old_latency!=1) { snprintf(latency_timer,1024,"echo 1 | sudo tee /sys/bus/usb-serial/devices/%s/latency_timer", &serial_port[offset]); printf("Attempting to reduce USB latency via '%s'\n",latency_timer); system(latency_timer); } } // And also another way struct serial_struct serial; ioctl(fd, TIOCGSERIAL, &serial); serial.flags |= ASYNC_LOW_LATENCY; ioctl(fd, TIOCSSERIAL, &serial); #endif errno=0; fd=open(serial_port,O_RDWR); if (fd==-1) { fprintf(stderr,"Could not open serial port '%s'\n",serial_port); perror("open"); exit(-1); } fcntl(fd,F_SETFL,fcntl(fd, F_GETFL, NULL)|O_NONBLOCK); // Set higher speed on serial interface to improve throughput set_speed(fd,2000000); slow_write(fd,"\r+9\r",4,5000); set_speed(fd,4000000); stop_cpu(); sdhc_check(); if (queued_command_count) { for(int i=0;i<queued_command_count;i++) execute_command(queued_commands[i]); return 0; } else { char *cmd=NULL; while((cmd=readline("MEGA65 SD-card> "))!=NULL) { execute_command(cmd); } } return 0; }