X-Git-Url: http://rtime.felk.cvut.cz/gitweb/linux-lin.git/blobdiff_plain/0d8ee841eb433c767280e01f281d5bf9bea177f9..9e7a6be1e8e430e8b420a2b7c712d716c4d90765:/sllin/sllin.c diff --git a/sllin/sllin.c b/sllin/sllin.c index 64eb10b..6b50223 100644 --- a/sllin/sllin.c +++ b/sllin/sllin.c @@ -147,9 +147,15 @@ static int sltty_change_speed(struct tty_struct *tty, unsigned speed) int cflag; mutex_lock(&tty->termios_mutex); + old_termios = *(tty->termios); cflag = tty->termios->c_cflag; + cflag &= ~(CBAUD | CIBAUD); + cflag |= BOTHER; + tty->termios->c_cflag = cflag; + tty_encode_baud_rate(tty, speed, speed); + if (tty->ops->set_termios) tty->ops->set_termios(tty, &old_termios); //priv->io.speed = speed; @@ -233,49 +239,49 @@ static void sll_bump(struct sllin *sl) /* Convert particular CAN frame into LIN frame and send it to TTY queue. */ static void sll_encaps(struct sllin *sl, struct can_frame *cf) { - int actual, idx, i; - char lframe[16] = {0x00, 0x55}; /* Fake break, Sync byte */ - struct tty_struct *tty = sl->tty; - - pr_debug("sllin: %s() invoked\n", __FUNCTION__); - - /* We do care only about SFF frames */ - if (cf->can_id & CAN_EFF_FLAG) - return; - - /* Send only header */ - if (cf->can_id & CAN_RTR_FLAG) { - pr_debug("sllin: %s() RTR CAN frame\n", __FUNCTION__); - lframe[2] = (u8)cf->can_id; /* Get one byte LIN ID */ - - sltty_change_speed(tty, sl->lin_baud / 2); - tty->ops->write(tty, &lframe[0], 1); - sltty_change_speed(tty, sl->lin_baud); - tty->ops->write(tty, &lframe[1], 1); - tty->ops->write(tty, &lframe[2], 1); - } else { - pr_debug("sllin: %s() non-RTR CAN frame\n", __FUNCTION__); - /* idx = strlen(sl->xbuff); - - for (i = 0; i < cf->can_dlc; i++) - sprintf(&sl->xbuff[idx + 2*i], "%02X", cf->data[i]); - - * Order of next two lines is *very* important. - * When we are sending a little amount of data, - * the transfer may be completed inside the ops->write() - * routine, because it's running with interrupts enabled. - * In this case we *never* got WRITE_WAKEUP event, - * if we did not request it before write operation. - * 14 Oct 1994 Dmitry Gorodchanin. - - set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); - actual = sl->tty->ops->write(sl->tty, sl->xbuff, strlen(sl->xbuff)); - sl->xleft = strlen(sl->xbuff) - actual; - sl->xhead = sl->xbuff + actual; - sl->dev->stats.tx_bytes += cf->can_dlc; - */ - } - +// int actual, idx, i; +// char lframe[16] = {0x00, 0x55}; /* Fake break, Sync byte */ +// struct tty_struct *tty = sl->tty; +// +// pr_debug("sllin: %s() invoked\n", __FUNCTION__); +// +// /* We do care only about SFF frames */ +// if (cf->can_id & CAN_EFF_FLAG) +// return; +// +// /* Send only header */ +// if (cf->can_id & CAN_RTR_FLAG) { +// pr_debug("sllin: %s() RTR CAN frame\n", __FUNCTION__); +// lframe[2] = (u8)cf->can_id; /* Get one byte LIN ID */ +// +// sltty_change_speed(tty, sl->lin_baud * 2 / 3); +// tty->ops->write(tty, &lframe[0], 1); +// sltty_change_speed(tty, sl->lin_baud); +// tty->ops->write(tty, &lframe[1], 1); +// tty->ops->write(tty, &lframe[2], 1); +// } else { +// pr_debug("sllin: %s() non-RTR CAN frame\n", __FUNCTION__); +// /* idx = strlen(sl->xbuff); +// +// for (i = 0; i < cf->can_dlc; i++) +// sprintf(&sl->xbuff[idx + 2*i], "%02X", cf->data[i]); +// +// * Order of next two lines is *very* important. +// * When we are sending a little amount of data, +// * the transfer may be completed inside the ops->write() +// * routine, because it's running with interrupts enabled. +// * In this case we *never* got WRITE_WAKEUP event, +// * if we did not request it before write operation. +// * 14 Oct 1994 Dmitry Gorodchanin. +// +// set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); +// actual = sl->tty->ops->write(sl->tty, sl->xbuff, strlen(sl->xbuff)); +// sl->xleft = strlen(sl->xbuff) - actual; +// sl->xhead = sl->xbuff + actual; +// sl->dev->stats.tx_bytes += cf->can_dlc; +// */ +// } +// } /* @@ -289,8 +295,8 @@ static void sllin_write_wakeup(struct tty_struct *tty) struct sllin *sl = (struct sllin *) tty->disc_data; /* First make sure we're connected. */ - if (!sl || sl->magic != SLLIN_MAGIC || !netif_running(sl->dev)) - return; + //if (!sl || sl->magic != SLLIN_MAGIC || !netif_running(sl->dev)) + // return; if (sl->lin_state != SLSTATE_BREAK_SENT) remains = sl->tx_lim - sl->tx_cnt; @@ -432,14 +438,16 @@ static void sllin_receive_buf(struct tty_struct *tty, printk(KERN_INFO "sllin_receive_buf invoked\n"); - if (!sl || sl->magic != SLLIN_MAGIC || !netif_running(sl->dev)) - return; + //if (!sl || sl->magic != SLLIN_MAGIC || !netif_running(sl->dev)) + // return; /* Read the characters out of the buffer */ while (count--) { if (fp && *fp++) { if (!test_and_set_bit(SLF_ERROR, &sl->flags)) sl->dev->stats.rx_errors++; + printk(KERN_INFO "sllin_receive_buf char 0x%02x ignored due marker 0x%02x, flags 0x%lx\n", + *cp, *(fp-1), sl->flags); cp++; continue; } @@ -478,10 +486,22 @@ int sllin_setup_msg(struct sllin *sl, int mode, int id, sl->tx_lim = SLLIN_BUFF_DATA; if ((data != NULL) && len) { + int i; + unsigned csum = 0; + sl->tx_lim += len; memcpy(sl->tx_buff + SLLIN_BUFF_DATA, data, len); + /* compute data parity there */ + for (i = SLLIN_BUFF_DATA; i < sl->tx_lim; i++) { + csum += sl->tx_buff[i]; + if (csum > 255) + csum -= 255; + } + + sl->tx_buff[sl->tx_lim++] = csum; } - sl->rx_lim += len; + if (len != 0) + sl->rx_lim += len + 1; return 0; }