int cnxt_console_setup(struct console *cp, char *arg) { if (!cp) return(-1); cnxt_init_console(); uart_speed(); return(0); }
int cmd_uart(struct command *cmd) { int err; char *dev = NULL; struct uart_t *u = NULL; closelog(); openlog(__argv[0], LOG_PERROR|LOG_PID, LOG_USER); if (__argc - optind < 1 || (cmd->cmd == CMD_OPEN_UART && __argc - optind < 2)) { print_usage(cmd); exit(1); } if (cmd->cmd != CMD_INIT_UART) dev = __argv[optind++]; if (cmd->cmd != CMD_CLOSE_UART) { u = get_by_type(__argv[optind++]); if (!u) { BTERROR("Device unknown.\n"); return 1; } if (!__argv[optind]) goto next; u->speed = atoi(__argv[optind++]); if (!__argv[optind]) goto next; /* get 0xXXXX flags */ if (sscanf(__argv[optind], "0x%x", &u->flags) > 0) goto next; else { /* get symbolic */ u->flags = 0; if (!str2mask(uart_flags, argv2str(__argv + optind), &u->flags)) { BTERROR("flags error\n"); return -1; } } next: if (cmd->cmd == CMD_OPEN_UART) { /* atatch device */ err = hci_open_uart(dev, u->type, u->proto, uart_speed(u->speed), u->flags); } else { /* init device */ err = init_uart(btdev, u); if (err < 0) BTERROR("Can't init device\n"); } } else { err = hci_close_uart(dev); } if (err) BTERROR("%s", hci_error(err)); return err; }
/* Initialize UART device */ int init_uart(char *dev, struct uart_t *u) { struct termios ti; int fd, err; int to = 20, speed; /* now device ready for initialization */ signal(SIGALRM, &sig_alarm); alarm(to); BTINFO("Initializing UART"); if (uart_rate) speed = uart_speed(uart_rate > 0 ? uart_rate : u->init_speed); else speed = 0; err = hci_setup_uart(dev, u->proto, speed, u->flags); if (err) return err; /* Vendor specific initialization */ if (u->init) { fd = _hci_open(dev); if (fd < 0) { BTERROR("unable to open: %s\n", dev); return fd; } err = u->init(fd, u, &ti); close(fd); } /* Set actual baudrate */ if (!err) { err = hci_setup_uart(dev, u->proto, uart_speed(u->speed), u->flags); if (err) BTERROR("Can't setup uart"); } alarm(0); return err; }
static int init_uart2pc(int port, int speed) { struct termios ti; int fd; int baudenum; char dev[20] = {0}; sprintf(dev, "/dev/ttyMT%d", port); fd = open(dev, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd < 0) { ERR("Can't open serial port\n"); return -1; } tcflush(fd, TCIOFLUSH); if (tcgetattr(fd, &ti) < 0) { ERR("Can't get UART port setting\n"); close(fd); return -1; } cfmakeraw(&ti); ti.c_cflag |= CLOCAL; ti.c_lflag = 0; ti.c_cflag &= ~CRTSCTS; ti.c_iflag &= ~(IXON | IXOFF | IXANY); /* Set baudrate */ baudenum = uart_speed(speed); if ((baudenum == B57600) && (speed != 57600)) { ERR("Serial port baudrate not supported!\n"); close(fd); return -1; } cfsetospeed(&ti, baudenum); cfsetispeed(&ti, baudenum); if (tcsetattr(fd, TCSANOW, &ti) < 0) { ERR("Can't set UART port setting\n"); close(fd); return -1; } tcflush(fd, TCIOFLUSH); return fd; }
/* * Output a single character, using UART polled mode. * This is ised for console output. */ void cnxt_console_write(struct console *cp, const char *p, unsigned len) { if (!console_initialized) { cnxt_init_console(); uart_speed(); } while (len-- > 0) { if (*p == '\n') { cnxt_put_char('\r'); } cnxt_put_char(*p++); } }
/* * This routine is called to set the UART divisor registers to match * the specified baud rate for a serial port. */ static void change_speed(struct cnxt_serial *info) { unsigned cflag; int i; if (!info->tty || !info->tty->termios) return; cflag = info->tty->termios->c_cflag; /* set the baudrate */ i = cflag & CBAUD; info->baud = baud_table[i]; uart_speed(); start_rx(); tx_start(info->uart, info->use_ints); return; }
/* Initialize serial port to PC */ static int init_serial(int port, int speed) { struct termios ti; int fd; int baudenum; char dev[20] = {0}; char usb_prop[PROPERTY_VALUE_MAX]; if (port < 4){ //serial port UART sprintf(dev, "/dev/ttyMT%d", port); } else{ //serial port USB sprintf(dev, "/dev/ttyGS2"); } fd = open(dev, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd < 0) { ERR("Can't open serial port %s\n", dev); return -1; } tcflush(fd, TCIOFLUSH); if (tcgetattr(fd, &ti) < 0) { ERR("Can't get serial port setting\n"); close(fd); return -1; } cfmakeraw(&ti); if (port < 4){ //serial port UART ti.c_cflag |= CLOCAL; ti.c_lflag = 0; ti.c_cflag &= ~CRTSCTS; ti.c_iflag &= ~(IXON | IXOFF | IXANY); /* Set baudrate */ baudenum = uart_speed(speed); if ((baudenum == B57600) && (speed != 57600)) { ERR("Serial port baudrate not supported!\n"); close(fd); return -1; } cfsetospeed(&ti, baudenum); cfsetispeed(&ti, baudenum); } else{ //serial port USB /* Set USB property to acm_third: add 1 acm port to /dev/ttyGS2 */ property_get("sys.usb.config", usb_prop, NULL); if(0 != strcmp(usb_prop, "acm_third")){ if(property_set("sys.usb.config", "acm_third") < 0){ ERR("Can't set USB property to open a VCOM\n"); close(fd); return -1; } else{ DBG("Set USB property to open a VCOM\n"); } } } if (tcsetattr(fd, TCSANOW, &ti) < 0) { ERR("Can't set serial port setting\n"); close(fd); return -1; } tcflush(fd, TCIOFLUSH); return fd; }