#include #include #include #include #include #include #include #include #include #include #include #include #include #include "thrdef.h" #include "globdef.h" #include "uidef.h" #include "lconf.h" #include "xdef.h" #include "ldef.h" #include "hwaredef.h" struct termios old_options; char serport_name[]="/dev/ttyd?"; extern int saved_euid; void lir_mutex_init(void) { pthread_mutex_init(&parport_lock,NULL); } void lir_mutex_destroy(void) { pthread_mutex_destroy(&parport_lock); } void lir_mutex_lock(void) { pthread_mutex_lock(&parport_lock); } void lir_mutex_unlock(void) { pthread_mutex_unlock(&parport_lock); } void lirerr(int errcod) { if(kill_all_flag) return; DEB"\nlirerr(%d)",errcod); if(dmp != 0)fflush(dmp); lir_errcod=errcod; sem_post(&sem_kill_all); lir_sleep(100000); } void lir_open_serport(int serport_number, int baudrate,int stopbit_flag) { int rte; struct termios options; if(serport != -1)return; if(serport_number < 1 || serport_number > 4) { lirerr(1279); return; } sprintf(&serport_name[9],"%d",serport_number-1); serport=open(serport_name,O_RDWR | O_NOCTTY | O_NDELAY); if (serport == -1) { lirerr(1244); return; } fcntl(serport,F_SETFL,0); if(tcgetattr(serport,&options) != 0) { lirerr(1277); goto close_x; } switch ( baudrate ) { case 110: rte=B110; break; case 300: rte=B300; break; case 600: rte=B600; break; case 1200: rte=B1200; break; case 2400: rte=B2400; break; case 4800: rte=B4800; break; case 9600: rte=B9600; break; case 19200: rte=B19200; break; case 38400: rte=B38400; break; case 57600: rte=B57600; break; default: lirerr(1280); goto close_x; } old_options=options; cfsetispeed(&options,rte); cfsetospeed(&options,rte); options.c_cflag|= (CLOCAL | CREAD); // No parity options.c_cflag&= ~PARENB; if(stopbit_flag) { options.c_cflag|= CSTOPB; } else { options.c_cflag&= ~CSTOPB; } options.c_cflag&= ~CSIZE; options.c_cflag|= CS8; options.c_oflag &= ~OPOST; if(tcsetattr(serport, TCSAFLUSH,&options) != 0) { close_x: lirerr(1278); close(serport); serport=-1; } } void lir_close_serport(void) { if(serport == -1)return; if(tcsetattr(serport, TCSAFLUSH,&old_options) != 0)lirerr(1278); close(serport); serport=-1; } int lir_write_serport(void *s, int bytes) { int n; n=write(serport,s,bytes); if (n<0) { return -1; } else { return 0; } } int lir_parport_permission(void) { int i=0; // Get permission to write to the parallel port if(ui.parport < 0x400-4) { seteuid(saved_euid); i=i386_set_ioperm(ui.parport,4,1); seteuid(getuid()); } if(i != 0) { return FALSE; } else { parport_ack_sign=0; switch (ui.parport_pin) { case 15: parport_ack=8; break; case 13: parport_ack=16; break; case 10: parport_ack=64; break; case 11: parport_ack=128; parport_ack_sign=128; break; } parport_status=ui.parport+1; parport_control=ui.parport+2; return TRUE; } } void lir_sched_yield(void) { sched_yield(); } void win_global_uiparms(int n) { // Do something with n to keep the compiler happy: lir_inkey=n; // Dummy routine. Not used under Linux. } void linrad_thread_create(int no) { thread_status_flag[no]=THRFLAG_INIT; thread_command_flag[no]=THRFLAG_ACTIVE; pthread_create(&thread_identifier[no],NULL,(void*)thread_routine[no], NULL); threads_running=TRUE; } void thread_kill_all(void) { int i; // Wait until the semaphore is released. // Then stop all processing threads so main can write any // error code/message and exit. sem_wait(&sem_kill_all); kill_all(); i=0; pthread_exit(&i); } double current_time(void) { struct timeval t; gettimeofday(&t,NULL); recent_time=0.000001*t.tv_usec+t.tv_sec; return recent_time; } int ms_since_midnight(void) { int i; double dt1; dt1=current_time(); i=dt1/(24*3600); dt1-=24*3600*i; i=1000*dt1; return i%(24*3600000); } double lir_get_cpu_time(void) { struct rusage rudat; double tm; getrusage(RUSAGE_SELF,&rudat); tm=0.000001*(rudat.ru_utime.tv_usec + rudat.ru_stime.tv_usec)+ rudat.ru_utime.tv_sec + rudat.ru_stime.tv_sec; return tm; } void lir_sync(void) { // This routine is called to force a write to the hard disk sync(); } void lir_sem_post(int no) { sem_post(&lirsem[no]); } void lir_sem_wait(int no) { sem_wait(&lirsem[no]); } void lir_sem_free(int no) { if(lirsem_flag[no] == 0)lirerr(1203); lirsem_flag[no]=0; } void lir_sem_init(int no) { if(lirsem_flag[no] != 0)lirerr(1204); lirsem_flag[no]=1; sem_init(&lirsem[no],0,0); } int lir_get_epoch_seconds(void) { struct timeval tim; gettimeofday(&tim,NULL); return tim.tv_sec; } void lir_join(int no) { if(thread_command_flag[no]==THRFLAG_NOT_ACTIVE)return; pthread_join(thread_identifier[no],0); thread_status_flag[no]=THRFLAG_NOT_ACTIVE; } void lir_sleep(int us) { usleep(us); } void lir_outb(char byte, int port) { int i; if(ui.parport < 0x400-4) { seteuid(saved_euid); i=i386_set_ioperm(ui.parport,4,1); seteuid(getuid()); } if(i!=0)lirerr(764921); i=1000; outb(byte,port); while(i>0)i--; } char lir_inb(int port) { int i; if(ui.parport < 0x400-4) { seteuid(saved_euid); i=i386_set_ioperm(ui.parport,4,1); seteuid(getuid()); } if(i!=0)lirerr(764921); return inb(port); } float lir_random(void) { return (float)(random())/RAND_MAX; } void lir_srandom(void) { unsigned int seed; seed=current_time(); srandom(seed); } // ********************************************************************* // Thread entries for Linux // ********************************************************************* void thread_main_menu(void) { int i; main_menu(); i=0; pthread_exit(&i); } void thread_tune(void) { int i; tune(); i=0; pthread_exit(&i); } void thread_sdr14_input(void) { int i; sdr14_input(); i=0; pthread_exit(&i); } void thread_cal_filtercorr(void) { int i; cal_filtercorr(); i=0; pthread_exit(&i); } void thread_cal_interval(void) { int i; do_cal_interval(); i=0; pthread_exit(&i); } void thread_user_command(void) { int i; user_command(); i=0; pthread_exit(&i); } void thread_narrowband_dsp(void) { int i; narrowband_dsp(); i=0; pthread_exit(&i); } void thread_wideband_dsp(void) { int i; wideband_dsp(); i=0; pthread_exit(&i); } void thread_tx_input(void) { int i; tx_input(); i=0; pthread_exit(&i); } void thread_tx_output(void) { int i; tx_output(); i=0; pthread_exit(&i); } void thread_screen(void) { int i; screen_routine(); i=0; pthread_exit(&i); } void thread_rx_file_input(void) { int i; rx_file_input(); i=0; pthread_exit(&i); } void thread_cal_iqbalance(void) { int i; cal_iqbalance(); i=0; pthread_exit(&i); } void thread_rx_adtest(void) { int i; rx_adtest(); i=0; pthread_exit(&i); } void thread_powtim(void) { int i; powtim(); i=0; pthread_exit(&i); } void thread_txtest(void) { int i; txtest(); i=0; pthread_exit(&i); }