From b819ec2c6a6c411bd6b35822f4b8d389be9e0ef0 Mon Sep 17 00:00:00 2001 From: Rostislav Lisovy Date: Mon, 12 Dec 2011 16:21:42 +0100 Subject: [PATCH] sllin: Time to sleep during sending Break is computed depending on baud rate. --- sllin/sllin.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sllin/sllin.c b/sllin/sllin.c index bee3e17..51b501d 100644 --- a/sllin/sllin.c +++ b/sllin/sllin.c @@ -571,10 +571,13 @@ int sllin_send_break(struct sllin *sl) int sllin_send_break(struct sllin *sl) { struct tty_struct *tty = sl->tty; - unsigned long break_baud; unsigned long flags; int retval; + unsigned long break_baud; + unsigned long usleep_range_min; + unsigned long usleep_range_max; + break_baud = ((sl->lin_baud * 2) / 3); sl->rx_cnt = SLLIN_BUFF_BREAK; sl->rx_expect = SLLIN_BUFF_BREAK + 1; sl->lin_state = SLSTATE_BREAK_SENT; @@ -586,10 +589,14 @@ int sllin_send_break(struct sllin *sl) return retval; //udelay(712); - usleep_range(650, 750); + usleep_range_min = (1000000l * SLLIN_SAMPLES_PER_CHAR) / break_baud; + usleep_range_max = usleep_range_min + 50; + usleep_range(usleep_range_min, usleep_range_max); retval = tty->ops->break_ctl(tty, 0); - usleep_range(50, 100); + usleep_range_min = (1000000l * 1 /* 1 bit */) / break_baud; + usleep_range_max = usleep_range_min + 30; + usleep_range(usleep_range_min, usleep_range_max); tty->ops->flush_buffer(tty); @@ -983,14 +990,12 @@ static int sllin_open(struct tty_struct *tty) sl->lin_state = SLSTATE_IDLE; -#define SAMPLES_PER_CHAR 10 -#define CHARS_TO_TIMEOUT 12 hrtimer_init(&sl->rx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); sl->rx_timer.function = sllin_rx_timeout_handler; /* timeval_to_ktime(msg_head->ival1); */ sl->rx_timer_timeout = ns_to_ktime( - (1000000000 / sl->lin_baud) * - SAMPLES_PER_CHAR * CHARS_TO_TIMEOUT); + (1000000000l / sl->lin_baud) * + SLLIN_SAMPLES_PER_CHAR * SLLIN_CHARS_TO_TIMEOUT); set_bit(SLF_INUSE, &sl->flags); -- 2.39.2