Example #1
0
/*
 * In this function, you should block I/O, call the line discipline,
 * and unblock I/O. We do not want to receive interrupts while
 * modifying the input buffer.
 */
int
tty_read(bytedev_t *dev, int offset, void *buf, int count)
{
        /*DRIVERS {{{*/
        void *data;
        tty_device_t *tty;
        tty_ldisc_t *ldisc;
        tty_driver_t *driver;
        int nbytes;

        KASSERT(NULL != dev);
        tty = bd_to_tty(dev);

        ldisc = tty->tty_ldisc;
        KASSERT(NULL != ldisc);
        KASSERT(NULL != ldisc->ld_ops);
        KASSERT(NULL != ldisc->ld_ops->read);

        driver = tty->tty_driver;
        KASSERT(NULL != driver);
        KASSERT(NULL != driver->ttd_ops);
        KASSERT(NULL != driver->ttd_ops->block_io);
        KASSERT(NULL != driver->ttd_ops->unblock_io);

        data = driver->ttd_ops->block_io(driver);
        nbytes = ldisc->ld_ops->read(ldisc, buf, count);
        driver->ttd_ops->unblock_io(driver, data);
        return nbytes;
        /*DRIVERS }}}*/

        return 0;
}
Example #2
0
/*
 * In this function, you should block I/O, call the line discipline,
 * and unblock I/O. We do not want to receive interrupts while
 * modifying the input buffer.
 */
int
tty_read(bytedev_t *dev, int offset, void *buf, int count)
{
    tty_device_t *tty = bd_to_tty(dev);
    //unit8_t intr = intr_getipl();
    void * data = tty->tty_driver->ttd_ops->block_io(tty->tty_driver);
    int length_read = tty->tty_ldisc->ld_ops->read(tty->tty_ldisc, buf, count);
    tty->tty_driver->ttd_ops->unblock_io(tty->tty_driver, data);

        NOT_YET_IMPLEMENTED("DRIVERS: tty_read");

        return length_read;
}
Example #3
0
/*
 * In this function, you should block I/O, process each
 * character with the line discipline and output the result to
 * the driver, and then unblock I/O.
 *
 * Important: You should return the number of bytes processed,
 * _NOT_ the number of bytes written out to the driver.
 */
int
tty_write(bytedev_t *dev, int offset, const void *buf, int count)
{
        /*DRIVERS {{{*/
        void *data;
        tty_device_t *tty;
        tty_ldisc_t *ldisc;
        tty_driver_t *driver;
        int i, nbytes;
        const char *cbuf = (const char *)buf;

        KASSERT(NULL != dev);
        tty = bd_to_tty(dev);

        ldisc = tty->tty_ldisc;
        KASSERT(NULL != ldisc);
        KASSERT(NULL != ldisc->ld_ops);
        KASSERT(NULL != ldisc->ld_ops->process_char);

        driver = tty->tty_driver;
        KASSERT(NULL != driver);
        KASSERT(NULL != driver->ttd_ops);
        KASSERT(NULL != driver->ttd_ops->provide_char);

        data = driver->ttd_ops->block_io(driver);

        nbytes = 0;
        for (i = 0; i < count; ++i) {
                const char *out = ldisc->ld_ops->process_char(ldisc, cbuf[i]);
                ++nbytes;
                tty_echo(driver, out);
        }

        driver->ttd_ops->unblock_io(driver, data);

        return nbytes;
        /*DRIVERS }}}*/

        return 0;
}
Example #4
0
 //echo in the kshell will call this
 // call tty_echo
int
tty_write(bytedev_t *dev, int offset, const void *buf, int count)
{

    char * buffer = (char *) buf;
    tty_device_t *tty = bd_to_tty(dev);
    //unit8_t intr = intr_getipl();
    void * data = tty->tty_driver->ttd_ops->block_io(tty->tty_driver);
    int i = 0;
    while(i < count && buffer[i] != '\0'){
        char * tem = tty->tty_ldisc->ld_ops->process_char(tty->tty_ldisc, buffer[i]);
        tty_echo(tty->tty_driver, tem);
        //kfree(tem);
        i++;
    }
    //buf = buffer;
    tty->tty_driver->ttd_ops->unblock_io(tty->tty_driver, data);

        NOT_YET_IMPLEMENTED("DRIVERS: tty_write");

        return 0;
}