+int open_serial_device(t_lpc *lpc) {
+
+ struct termios term;
+
+ //memset(&term,0,sizeof(struct termios));
+
+ /* open serial device */
+
+ lpc->sfd=open(lpc->sdev,O_RDWR);
+ if(lpc->sfd<0) {
+ perror("tts open");
+ return lpc->sfd;
+ }
+
+ /* configure the serial device */
+
+ tcgetattr(lpc->sfd,&term);
+
+ // input/output baudrate
+
+ cfsetispeed(&term,B9600);
+ cfsetospeed(&term,B9600);
+
+ // control options -> 8n1
+
+ term.c_cflag&=~PARENB; // no parity
+ term.c_cflag&=~CSTOPB; // only 1 stop bit
+ term.c_cflag&=~CSIZE; // no bit mask for data bits
+ term.c_cflag|=CS8; // 8 data bits
+
+ // line options -> raw input
+
+ term.c_lflag&=~(ICANON|ECHO|ECHOE|ISIG);
+
+ // input options -> disable flow control
+
+ term.c_iflag&=~(IXON|IXOFF|IXANY);
+
+ // more control options -> timeout
+
+ term.c_cc[VMIN]=0;
+ term.c_cc[VTIME]=10; // 1 second timeout
+
+ tcsetattr(lpc->sfd,TCSANOW,&term);
+
+ return lpc->sfd;
+}
+
+int open_firmware(t_lpc *lpc) {
+
+ /* open firmware file */
+
+ lpc->fwfd=open(lpc->fwfile,O_RDONLY);
+
+ if(lpc->fwfd<0)
+ perror("fw open");
+
+ return lpc->fwfd;
+}
+
+int txrx(t_lpc *lpc,char *buf,int len,u8 type) {