/* c_cflag bit meaning */ #define CBAUD 0000377 #define B0 0000000 /* hang up */ #define B50 0000001 #define B75 0000002 #define B110 0000003 #define B134 0000004 #define B150 0000005 #define B200 0000006 #define B300 0000007 #define B600 0000010 #define B1200 0000011 #define B1800 0000012 #define B2400 0000013 #define B4800 0000014 #define B9600 0000015 #define B19200 0000016 #define B38400 0000017 #define EXTA B19200 #define EXTB B38400 #define CBAUDEX 0000000 #define B57600 00020 #define B115200 00021 #define B230400 00022 #define B460800 00023 #define B500000 00024 #define B576000 00025 #define B921600 00026 #define B1000000 00027 #define B1152000 00030 #define B1500000 00031 #define B2000000 00032 #define B2500000 00033 #define B3000000 00034 #define B3500000 00035 #define B4000000 00036
+ #if ABCS0_BGDM_EN + if(baud > 6250000){ + //SEMR_BGDM:Baud rate generator double-speed mode Select: + //SEMR_ABCS0:Asynchronous Base Clock Select: + serial_port_out(port, SEMR, + serial_port_in(port, SEMR) | (SEMR_ABCS0 | SEMR_BGDM)); + freq *= 2; + prediv /= 2; + }else if(baud > 3125000){ + //SEMR_BGDM:Baud rate generator double-speed mode Select: + serial_port_out(port, SEMR, + serial_port_in(port, SEMR) | SEMR_BGDM); + freq *= 2; + } + #endif
diff --git a/drivers/tty/tty_baudrate.c b/drivers/tty/tty_baudrate.c index bdfaee2c1331..75d287893d11 100644 --- a/drivers/tty/tty_baudrate.c +++ b/drivers/tty/tty_baudrate.c @@ -24,7 +24,7 @@ static const speed_t baud_table[] = { 1000000, 1152000, 1500000, 2000000 #else 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, - 2500000, 3000000, 3500000, 4000000 + 2500000, 3000000, 3500000, 4000000, 3125000, 6250000, 12500000 #endif }; @@ -36,7 +36,7 @@ static const tcflag_t baud_bits[] = { B1000000, B1152000, B1500000, B2000000 #else B500000, B576000, B921600, B1000000, B1152000, B1500000, B2000000, - B2500000, B3000000, B3500000, B4000000 + B2500000, B3000000, B3500000, B4000000, B3125000, B6250000, B12500000 #endif }; @@ -73,6 +73,14 @@ speed_t tty_termios_baud_rate(struct ktermios *termios) else cbaud += 15; } + if (cbaud & CBAUDEX2) { + cbaud &= ~CBAUDEX2; + + if (cbaud < 1 || cbaud + 30 > n_baud_table) + termios->c_cflag &= ~CBAUDEX2; + else + cbaud += 30; + } return cbaud >= n_baud_table ? 0 : baud_table[cbaud]; } EXPORT_SYMBOL(tty_termios_baud_rate); diff --git a/include/uapi/asm-generic/termbits.h b/include/uapi/asm-generic/termbits.h index 7db62a33ee52..1353300b6934 100644 --- a/include/uapi/asm-generic/termbits.h +++ b/include/uapi/asm-generic/termbits.h @@ -110,7 +110,7 @@ struct ktermios { #define FF1 0100000 /* c_cflag bit meaning */ -#define CBAUD 0010017 +#define CBAUD 0030017 #define B0 0000000 /* hang up */ #define B50 0000001 #define B75 0000002 @@ -158,7 +158,9 @@ struct ktermios { #define B3500000 0010016 #define B4000000 0010017 +#define CBAUDEX2 0020000 +#define B3125000 0020001 +#define B6250000 0020002 +#define B12500000 0020003 #define CIBAUD 002003600000 /* input baud rate */ #define CMSPAR 010000000000 /* mark or space (stick) parity */ #define CRTSCTS 020000000000 /* flow control */
#define B3125000 0020001 #define B6250000 0020002 #define B12500000 0020003 ** ** 串口配置 ** 参数 cfg 指向一个 uart_cfg_t 结构体对象 **/ static int uart_cfg(const uart_cfg_t *cfg) { struct termios new_cfg = {0}; //将 new_cfg 对象清零 speed_t speed; /* 设置为原始模式 */ cfmakeraw(&new_cfg); /* 使能接收 */ new_cfg.c_cflag |= CREAD| CLOCAL; /* 设置波特率 */ speed = B3125000; // B3125000 B6250000 B12500000 new_cfg.c_cflag |= speed; /* 串口的其他属性配置参考标准的POSIX */ /* 写入配置、使配置生效 */ if (0 > tcsetattr(fd, TCSANOW, &new_cfg)) { fprintf(stderr, "tcsetattr error: %s\n", strerror(errno)); return -1; }
全部0条评论
快来发表一下你的评论吧 !