# HG changeset patch # User Florian Pose # Date 1264432556 -3600 # Node ID 7198caede74170282bf1a1f96d851df25e15d102 # Parent 9ed0334edaf9f4deece57f3d9bac3a996a6e5e5c Sorted methods. diff -r 9ed0334edaf9 -r 7198caede741 tty/module.c --- a/tty/module.c Fri Jan 22 17:25:36 2010 +0100 +++ b/tty/module.c Mon Jan 25 16:15:56 2010 +0100 @@ -66,6 +66,8 @@ ec_tty_t *ttys[EC_TTY_MAX_DEVICES]; struct semaphore tty_sem; +void ec_tty_wakeup(unsigned long); + /*****************************************************************************/ /** \cond */ @@ -177,105 +179,9 @@ printk(KERN_INFO PFX "Module unloading.\n"); } -/*****************************************************************************/ - -unsigned int ec_tty_tx_size(ec_tty_t *tty) -{ - unsigned int ret; - - if (tty->tx_write_idx >= tty->tx_read_idx) { - ret = tty->tx_write_idx - tty->tx_read_idx; - } else { - ret = EC_TTY_TX_BUFFER_SIZE + tty->tx_write_idx - tty->tx_read_idx; - } - - return ret; -} - -/*****************************************************************************/ - -unsigned int ec_tty_tx_space(ec_tty_t *tty) -{ - return EC_TTY_TX_BUFFER_SIZE - 1 - ec_tty_tx_size(tty); -} - -/*****************************************************************************/ - -unsigned int ec_tty_rx_size(ec_tty_t *tty) -{ - unsigned int ret; - - if (tty->rx_write_idx >= tty->rx_read_idx) { - ret = tty->rx_write_idx - tty->rx_read_idx; - } else { - ret = EC_TTY_RX_BUFFER_SIZE + tty->rx_write_idx - tty->rx_read_idx; - } - - return ret; -} - -/*****************************************************************************/ - -unsigned int ec_tty_rx_space(ec_tty_t *tty) -{ - return EC_TTY_RX_BUFFER_SIZE - 1 - ec_tty_rx_size(tty); -} - -/*****************************************************************************/ - -void ec_tty_wakeup(unsigned long data) -{ - ec_tty_t *tty = (ec_tty_t *) data; - size_t to_recv; - - /* Wake up any process waiting to send data */ - if (tty->wakeup) { - if (tty->tty) { -#if EC_TTY_DEBUG >= 1 - printk(KERN_INFO PFX "Waking up.\n"); -#endif - tty_wakeup(tty->tty); - } - tty->wakeup = 0; - } - - /* Push received data into TTY core. */ - to_recv = ec_tty_rx_size(tty); - if (to_recv && tty->tty) { - unsigned char *cbuf; - int space = tty_prepare_flip_string(tty->tty, &cbuf, to_recv); - - if (space < to_recv) { - printk(KERN_WARNING PFX "Insufficient space to_recv=%d space=%d\n", - to_recv, space); - } - - if (space < 0) { - to_recv = 0; - } else { - to_recv = space; - } - - if (to_recv) { - unsigned int i; - -#if EC_TTY_DEBUG >= 1 - printk(KERN_INFO PFX "Pushing %u bytes to TTY core.\n", to_recv); -#endif - - for (i = 0; i < to_recv; i++) { - cbuf[i] = tty->rx_buffer[tty->rx_read_idx]; - tty->rx_read_idx = (tty->rx_read_idx + 1) % EC_TTY_RX_BUFFER_SIZE; - } - tty_flip_buffer_push(tty->tty); - } - } - - tty->timer.expires += 1; - add_timer(&tty->timer); -} - -/*****************************************************************************/ +/****************************************************************************** + * ec_tty_t methods. + *****************************************************************************/ int ec_tty_init(ec_tty_t *tty, int minor, int (*cflag_cb)(void *, tcflag_t), void *cb_data) @@ -314,6 +220,50 @@ /*****************************************************************************/ +unsigned int ec_tty_tx_size(ec_tty_t *tty) +{ + unsigned int ret; + + if (tty->tx_write_idx >= tty->tx_read_idx) { + ret = tty->tx_write_idx - tty->tx_read_idx; + } else { + ret = EC_TTY_TX_BUFFER_SIZE + tty->tx_write_idx - tty->tx_read_idx; + } + + return ret; +} + +/*****************************************************************************/ + +unsigned int ec_tty_tx_space(ec_tty_t *tty) +{ + return EC_TTY_TX_BUFFER_SIZE - 1 - ec_tty_tx_size(tty); +} + +/*****************************************************************************/ + +unsigned int ec_tty_rx_size(ec_tty_t *tty) +{ + unsigned int ret; + + if (tty->rx_write_idx >= tty->rx_read_idx) { + ret = tty->rx_write_idx - tty->rx_read_idx; + } else { + ret = EC_TTY_RX_BUFFER_SIZE + tty->rx_write_idx - tty->rx_read_idx; + } + + return ret; +} + +/*****************************************************************************/ + +unsigned int ec_tty_rx_space(ec_tty_t *tty) +{ + return EC_TTY_RX_BUFFER_SIZE - 1 - ec_tty_rx_size(tty); +} + +/*****************************************************************************/ + int ec_tty_get_serial_info(ec_tty_t *tty, struct serial_struct *data) { struct serial_struct tmp; @@ -329,6 +279,63 @@ return 0; } +/*****************************************************************************/ + +/** Timer function. + */ +void ec_tty_wakeup(unsigned long data) +{ + ec_tty_t *tty = (ec_tty_t *) data; + size_t to_recv; + + /* Wake up any process waiting to send data */ + if (tty->wakeup) { + if (tty->tty) { +#if EC_TTY_DEBUG >= 1 + printk(KERN_INFO PFX "Waking up.\n"); +#endif + tty_wakeup(tty->tty); + } + tty->wakeup = 0; + } + + /* Push received data into TTY core. */ + to_recv = ec_tty_rx_size(tty); + if (to_recv && tty->tty) { + unsigned char *cbuf; + int space = tty_prepare_flip_string(tty->tty, &cbuf, to_recv); + + if (space < to_recv) { + printk(KERN_WARNING PFX "Insufficient space to_recv=%d space=%d\n", + to_recv, space); + } + + if (space < 0) { + to_recv = 0; + } else { + to_recv = space; + } + + if (to_recv) { + unsigned int i; + +#if EC_TTY_DEBUG >= 1 + printk(KERN_INFO PFX "Pushing %u bytes to TTY core.\n", to_recv); +#endif + + for (i = 0; i < to_recv; i++) { + cbuf[i] = tty->rx_buffer[tty->rx_read_idx]; + tty->rx_read_idx = + (tty->rx_read_idx + 1) % EC_TTY_RX_BUFFER_SIZE; + } + tty_flip_buffer_push(tty->tty); + } + } + + tty->timer.expires += 1; + add_timer(&tty->timer); +} + /****************************************************************************** * Device callbacks *****************************************************************************/ @@ -733,7 +740,8 @@ for (i = 0; i < size; i++) { tty->rx_buffer[tty->rx_write_idx] = buffer[i]; - tty->rx_write_idx = (tty->rx_write_idx + 1) % EC_TTY_RX_BUFFER_SIZE; + tty->rx_write_idx = + (tty->rx_write_idx + 1) % EC_TTY_RX_BUFFER_SIZE; } } }