fix baudrate error (#8873)

* fix baudrate error

* fix baudrate error

* fix baudrate error

* fix baudrate error

* fix baudrate error

* fix baudrate error

* fix baudrate error

* fix baudrate error

* fix baudrate error
This commit is contained in:
xiao-mang 2024-04-29 18:00:34 +08:00 committed by GitHub
parent e548a99da4
commit b586889216
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 1 deletions

View File

@ -1175,7 +1175,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
config = serial->config; config = serial->config;
baudrate = _get_baudrate(cfgetospeed(tio)); baudrate = _get_baudrate(tio->__c_ispeed);
config.baud_rate = baudrate; config.baud_rate = baudrate;
switch (tio->c_cflag & CSIZE) switch (tio->c_cflag & CSIZE)

View File

@ -175,6 +175,19 @@ rt_inline void _restore_serial(struct rt_serial_device *serial, lwp_tty_t tp,
rt_device_control(&serial->parent, RT_DEVICE_CTRL_NOTIFY_SET, &softc->backup_notify); rt_device_control(&serial->parent, RT_DEVICE_CTRL_NOTIFY_SET, &softc->backup_notify);
} }
static void _serial_tty_set_speed(struct lwp_tty *tp)
{
struct serial_tty_context *softc = (struct serial_tty_context *)(tp->t_devswsoftc);
struct rt_serial_device *serial;
RT_ASSERT(softc);
serial = softc->parent;
rt_device_control(&(serial->parent), TCGETS, &tp->t_termios_init_in);
tp->t_termios_init_in.__c_ispeed = tp->t_termios_init_in.__c_ospeed = cfgetospeed(&tp->t_termios_init_in);
}
static int _serial_isbusy(struct rt_serial_device *serial) static int _serial_isbusy(struct rt_serial_device *serial)
{ {
rt_thread_t user_thread = rt_console_current_user(); rt_thread_t user_thread = rt_console_current_user();
@ -317,6 +330,7 @@ rt_err_t rt_hw_serial_register_tty(struct rt_serial_device *serial)
tty = lwp_tty_create(&serial_ttydevsw, softc); tty = lwp_tty_create(&serial_ttydevsw, softc);
if (tty) if (tty)
{ {
_serial_tty_set_speed(tty);
rc = lwp_tty_register(tty, dev_name); rc = lwp_tty_register(tty, dev_name);
rt_work_init(&softc->work, _tty_rx_worker, tty); rt_work_init(&softc->work, _tty_rx_worker, tty);

View File

@ -349,6 +349,7 @@ int lwp_tty_ioctl_adapter(lwp_tty_t tp, int cmd, int oflags, void *args, rt_thre
error = IOCTL(TIOCGETA, (rt_caddr_t)&tios, fflags, td); error = IOCTL(TIOCGETA, (rt_caddr_t)&tios, fflags, td);
if (error) if (error)
break; break;
cfsetospeed(&tios, tios.__c_ispeed);
error = _copy_to_user(args, &tios, sizeof(tios)); error = _copy_to_user(args, &tios, sizeof(tios));
break; break;
@ -356,6 +357,7 @@ int lwp_tty_ioctl_adapter(lwp_tty_t tp, int cmd, int oflags, void *args, rt_thre
error = _copy_from_user(&tios, args, sizeof(tios)); error = _copy_from_user(&tios, args, sizeof(tios));
if (error) if (error)
break; break;
tios.__c_ispeed = tios.__c_ospeed = cfgetospeed(&tios);
error = (IOCTL(TIOCSETA, (rt_caddr_t)&tios, fflags, td)); error = (IOCTL(TIOCSETA, (rt_caddr_t)&tios, fflags, td));
break; break;