/******************************************************************************* ** ** Function userial_vendor_set_baud ** ** Description Set new baud rate ** ** Returns None ** *******************************************************************************/ void userial_vendor_set_baud(uint8_t userial_baud) { uint32_t tcio_baud; userial_to_tcio_baud(userial_baud, &tcio_baud); cfsetospeed(&vnd_userial.termios, tcio_baud); cfsetispeed(&vnd_userial.termios, tcio_baud); tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios); }
/******************************************************************************* ** ** Function userial_vendor_set_baud ** ** Description Set new baud rate ** ** Returns None ** *******************************************************************************/ void userial_vendor_set_baud(uint8_t userial_baud) { uint32_t tcio_baud; VNDUSERIALDBG("## userial_vendor_set_baud: %d", userial_baud); userial_to_tcio_baud(userial_baud, &tcio_baud); cfsetospeed(&vnd_userial.termios, tcio_baud); cfsetispeed(&vnd_userial.termios, tcio_baud); tcsetattr(vnd_userial.fd, TCSADRAIN, &vnd_userial.termios); /* don't change speed until last write done */ // tcflush(vnd_userial.fd, TCIOFLUSH); }
/******************************************************************************* ** ** Function userial_vendor_set_baud ** ** Description Set new baud rate ** ** Returns None ** *******************************************************************************/ void userial_vendor_set_baud(uint8_t userial_baud) { uint32_t tcio_baud; ALOGI("userial_vendor_set_baud++"); userial_to_tcio_baud(userial_baud, &tcio_baud); if(cfsetospeed(&vnd_userial.termios, tcio_baud)<0) ALOGE("cfsetospeed fail"); if(cfsetispeed(&vnd_userial.termios, tcio_baud)<0) ALOGE("cfsetispeed fail"); if(tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios)<0) ALOGE("tcsetattr fail "); tcflush(vnd_userial.fd, TCIOFLUSH); ALOGI("userial_vendor_set_baud--"); }
/******************************************************************************* ** ** Function userial_vendor_open ** ** Description Open the serial port with the given configuration ** ** Returns device fd ** *******************************************************************************/ int userial_vendor_open(tUSERIAL_CFG *p_cfg) { uint32_t baud; uint8_t data_bits; uint16_t parity; uint8_t stop_bits; uint8_t buf[]={1,2,3,4,5,6,7,8,9,10}; vnd_userial.fd = -1; if (!userial_to_tcio_baud(p_cfg->baud, &baud)) { return -1; } if(p_cfg->fmt & USERIAL_DATABITS_8) data_bits = CS8; else if(p_cfg->fmt & USERIAL_DATABITS_7) data_bits = CS7; else if(p_cfg->fmt & USERIAL_DATABITS_6) data_bits = CS6; else if(p_cfg->fmt & USERIAL_DATABITS_5) data_bits = CS5; else { ALOGE("userial vendor open: unsupported data bits"); return -1; } if(p_cfg->fmt & USERIAL_PARITY_NONE) parity = 0; else if(p_cfg->fmt & USERIAL_PARITY_EVEN) parity = PARENB; else if(p_cfg->fmt & USERIAL_PARITY_ODD) parity = (PARENB | PARODD); else { ALOGE("userial vendor open: unsupported parity bit mode"); return -1; } if(p_cfg->fmt & USERIAL_STOPBITS_1) stop_bits = 0; else if(p_cfg->fmt & USERIAL_STOPBITS_2) stop_bits = CSTOPB; else { ALOGE("userial vendor open: unsupported stop bits"); return -1; } ALOGI("userial vendor open: opening %s %d %d", vnd_userial.port_name,baud,p_cfg->baud); if ((vnd_userial.fd = open(vnd_userial.port_name, O_RDWR)) == -1) { ALOGE("userial vendor open: unable to open %s", vnd_userial.port_name); return -1; } tcflush(vnd_userial.fd, TCIOFLUSH); tcgetattr(vnd_userial.fd, &vnd_userial.termios); cfmakeraw(&vnd_userial.termios); vnd_userial.termios.c_cflag |= (/*CRTSCTS | */stop_bits); //vnd_userial.termios.c_cflag &= ~(CRTSCTS); ALOGI("remove CRTSCTS"); tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios); tcflush(vnd_userial.fd, TCIOFLUSH); tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios); tcflush(vnd_userial.fd, TCIOFLUSH); tcflush(vnd_userial.fd, TCIOFLUSH); /* set input/output baudrate */ cfsetospeed(&vnd_userial.termios, baud); cfsetispeed(&vnd_userial.termios, baud); tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios); #if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE) userial_ioctl_init_bt_wake(vnd_userial.fd); #endif ALOGI("device fd = %d open", vnd_userial.fd); //write(vnd_userial.fd,buf,10); //ALOGI("Send over"); return vnd_userial.fd; }
/******************************************************************************* ** ** Function userial_vendor_open ** ** Description Open the serial port with the given configuration ** ** Returns device fd ** *******************************************************************************/ int userial_vendor_open(tUSERIAL_CFG *p_cfg) { uint32_t baud; uint8_t data_bits; uint16_t parity; uint8_t stop_bits; vnd_userial.fd = -1; if (!userial_to_tcio_baud(p_cfg->baud, &baud)) { return -1; } if(p_cfg->fmt & USERIAL_DATABITS_8) data_bits = CS8; else if(p_cfg->fmt & USERIAL_DATABITS_7) data_bits = CS7; else if(p_cfg->fmt & USERIAL_DATABITS_6) data_bits = CS6; else if(p_cfg->fmt & USERIAL_DATABITS_5) data_bits = CS5; else { ALOGE("userial vendor open: unsupported data bits"); return -1; } if(p_cfg->fmt & USERIAL_PARITY_NONE) parity = 0; else if(p_cfg->fmt & USERIAL_PARITY_EVEN) parity = PARENB; else if(p_cfg->fmt & USERIAL_PARITY_ODD) parity = (PARENB | PARODD); else { ALOGE("userial vendor open: unsupported parity bit mode"); return -1; } if(p_cfg->fmt & USERIAL_STOPBITS_1) stop_bits = 0; else if(p_cfg->fmt & USERIAL_STOPBITS_2) stop_bits = CSTOPB; else { ALOGE("userial vendor open: unsupported stop bits"); return -1; } ALOGI("userial vendor open: opening %s-%d-%d-%d", vnd_userial.port_name, parity,stop_bits,p_cfg->baud); if ((vnd_userial.fd = open(vnd_userial.port_name, O_RDWR)) == -1) { ALOGE("userial vendor open: unable to open %s", vnd_userial.port_name); return -1; } tcflush(vnd_userial.fd, TCIOFLUSH); tcgetattr(vnd_userial.fd, &vnd_userial.termios); cfmakeraw(&vnd_userial.termios); if(p_cfg->hw_fctrl == USERIAL_HW_FLOW_CTRL_ON) { ALOGI("userial vendor open: with HW flowctrl ON"); vnd_userial.termios.c_cflag |= (CRTSCTS | stop_bits| parity); } else { ALOGI("userial vendor open: with HW flowctrl OFF"); vnd_userial.termios.c_cflag &= ~CRTSCTS; vnd_userial.termios.c_cflag |= (stop_bits| parity); } tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios); tcflush(vnd_userial.fd, TCIOFLUSH); tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios); tcflush(vnd_userial.fd, TCIOFLUSH); tcflush(vnd_userial.fd, TCIOFLUSH); /* set input/output baudrate */ cfsetospeed(&vnd_userial.termios, baud); cfsetispeed(&vnd_userial.termios, baud); tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios); #if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE) userial_ioctl_init_bt_wake(vnd_userial.fd); #endif ALOGI("device fd = %d open", vnd_userial.fd); return vnd_userial.fd; }