MFsio (sio.c 1.413: cleaned up and fixed setting of speeds in comparam()).

This is just a cleanup here (modulo rev.1.108 of kern/tty.c), since the
input speed can be different from to output speed and extra code to
handle both speeds naturally handled all cases.
This commit is contained in:
bde 2003-09-27 12:40:23 +00:00
parent 53154ee13f
commit dbd9fee48d
3 changed files with 36 additions and 69 deletions

View File

@ -1878,25 +1878,22 @@ comparam(tp, t)
int s;
int unit;
/* do historical conversions */
if (t->c_ispeed == 0)
t->c_ispeed = t->c_ospeed;
unit = DEV_TO_UNIT(tp->t_dev);
com = com_addr(unit);
/* check requested parameters */
cy_clock = CY_CLOCK(com->gfrcr_image);
idivisor = comspeed(t->c_ispeed, cy_clock, &iprescaler);
if (idivisor < 0)
if (idivisor <= 0)
return (EINVAL);
odivisor = comspeed(t->c_ospeed, cy_clock, &oprescaler);
if (odivisor < 0)
odivisor = comspeed(t->c_ospeed != 0 ? t->c_ospeed : tp->t_ospeed,
cy_clock, &oprescaler);
if (odivisor <= 0)
return (EINVAL);
/* parameters are OK, convert them to the com struct and the device */
s = spltty();
if (odivisor == 0)
if (t->c_ospeed == 0)
(void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */
else
(void)commctl(com, TIOCM_DTR, DMBIS);
@ -1905,14 +1902,10 @@ comparam(tp, t)
/* XXX we don't actually change the speed atomically. */
if (idivisor != 0) {
cd_setreg(com, CD1400_RBPR, idivisor);
cd_setreg(com, CD1400_RCOR, iprescaler);
}
if (odivisor != 0) {
cd_setreg(com, CD1400_TBPR, odivisor);
cd_setreg(com, CD1400_TCOR, oprescaler);
}
cd_setreg(com, CD1400_RBPR, idivisor);
cd_setreg(com, CD1400_RCOR, iprescaler);
cd_setreg(com, CD1400_TBPR, odivisor);
cd_setreg(com, CD1400_TCOR, oprescaler);
/*
* channel control
@ -1990,18 +1983,14 @@ comparam(tp, t)
/*
* Set receive time-out period, normally to max(one char time, 5 ms).
*/
if (t->c_ispeed == 0)
itimeout = cd_getreg(com, CD1400_RTPR);
else {
itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
#ifdef SOFT_HOTCHAR
#define MIN_RTP 1
#else
#define MIN_RTP 5
#endif
if (itimeout < MIN_RTP)
itimeout = MIN_RTP;
}
if (itimeout < MIN_RTP)
itimeout = MIN_RTP;
if (!(t->c_lflag & ICANON) && t->c_cc[VMIN] != 0 && t->c_cc[VTIME] != 0
&& t->c_cc[VTIME] * 10 > itimeout)
itimeout = t->c_cc[VTIME] * 10;

View File

@ -1878,25 +1878,22 @@ comparam(tp, t)
int s;
int unit;
/* do historical conversions */
if (t->c_ispeed == 0)
t->c_ispeed = t->c_ospeed;
unit = DEV_TO_UNIT(tp->t_dev);
com = com_addr(unit);
/* check requested parameters */
cy_clock = CY_CLOCK(com->gfrcr_image);
idivisor = comspeed(t->c_ispeed, cy_clock, &iprescaler);
if (idivisor < 0)
if (idivisor <= 0)
return (EINVAL);
odivisor = comspeed(t->c_ospeed, cy_clock, &oprescaler);
if (odivisor < 0)
odivisor = comspeed(t->c_ospeed != 0 ? t->c_ospeed : tp->t_ospeed,
cy_clock, &oprescaler);
if (odivisor <= 0)
return (EINVAL);
/* parameters are OK, convert them to the com struct and the device */
s = spltty();
if (odivisor == 0)
if (t->c_ospeed == 0)
(void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */
else
(void)commctl(com, TIOCM_DTR, DMBIS);
@ -1905,14 +1902,10 @@ comparam(tp, t)
/* XXX we don't actually change the speed atomically. */
if (idivisor != 0) {
cd_setreg(com, CD1400_RBPR, idivisor);
cd_setreg(com, CD1400_RCOR, iprescaler);
}
if (odivisor != 0) {
cd_setreg(com, CD1400_TBPR, odivisor);
cd_setreg(com, CD1400_TCOR, oprescaler);
}
cd_setreg(com, CD1400_RBPR, idivisor);
cd_setreg(com, CD1400_RCOR, iprescaler);
cd_setreg(com, CD1400_TBPR, odivisor);
cd_setreg(com, CD1400_TCOR, oprescaler);
/*
* channel control
@ -1990,18 +1983,14 @@ comparam(tp, t)
/*
* Set receive time-out period, normally to max(one char time, 5 ms).
*/
if (t->c_ispeed == 0)
itimeout = cd_getreg(com, CD1400_RTPR);
else {
itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
#ifdef SOFT_HOTCHAR
#define MIN_RTP 1
#else
#define MIN_RTP 5
#endif
if (itimeout < MIN_RTP)
itimeout = MIN_RTP;
}
if (itimeout < MIN_RTP)
itimeout = MIN_RTP;
if (!(t->c_lflag & ICANON) && t->c_cc[VMIN] != 0 && t->c_cc[VTIME] != 0
&& t->c_cc[VTIME] * 10 > itimeout)
itimeout = t->c_cc[VTIME] * 10;

View File

@ -1878,25 +1878,22 @@ comparam(tp, t)
int s;
int unit;
/* do historical conversions */
if (t->c_ispeed == 0)
t->c_ispeed = t->c_ospeed;
unit = DEV_TO_UNIT(tp->t_dev);
com = com_addr(unit);
/* check requested parameters */
cy_clock = CY_CLOCK(com->gfrcr_image);
idivisor = comspeed(t->c_ispeed, cy_clock, &iprescaler);
if (idivisor < 0)
if (idivisor <= 0)
return (EINVAL);
odivisor = comspeed(t->c_ospeed, cy_clock, &oprescaler);
if (odivisor < 0)
odivisor = comspeed(t->c_ospeed != 0 ? t->c_ospeed : tp->t_ospeed,
cy_clock, &oprescaler);
if (odivisor <= 0)
return (EINVAL);
/* parameters are OK, convert them to the com struct and the device */
s = spltty();
if (odivisor == 0)
if (t->c_ospeed == 0)
(void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */
else
(void)commctl(com, TIOCM_DTR, DMBIS);
@ -1905,14 +1902,10 @@ comparam(tp, t)
/* XXX we don't actually change the speed atomically. */
if (idivisor != 0) {
cd_setreg(com, CD1400_RBPR, idivisor);
cd_setreg(com, CD1400_RCOR, iprescaler);
}
if (odivisor != 0) {
cd_setreg(com, CD1400_TBPR, odivisor);
cd_setreg(com, CD1400_TCOR, oprescaler);
}
cd_setreg(com, CD1400_RBPR, idivisor);
cd_setreg(com, CD1400_RCOR, iprescaler);
cd_setreg(com, CD1400_TBPR, odivisor);
cd_setreg(com, CD1400_TCOR, oprescaler);
/*
* channel control
@ -1990,18 +1983,14 @@ comparam(tp, t)
/*
* Set receive time-out period, normally to max(one char time, 5 ms).
*/
if (t->c_ispeed == 0)
itimeout = cd_getreg(com, CD1400_RTPR);
else {
itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
#ifdef SOFT_HOTCHAR
#define MIN_RTP 1
#else
#define MIN_RTP 5
#endif
if (itimeout < MIN_RTP)
itimeout = MIN_RTP;
}
if (itimeout < MIN_RTP)
itimeout = MIN_RTP;
if (!(t->c_lflag & ICANON) && t->c_cc[VMIN] != 0 && t->c_cc[VTIME] != 0
&& t->c_cc[VTIME] * 10 > itimeout)
itimeout = t->c_cc[VTIME] * 10;