Skip to contentSkip to conversation

tiny tty driver sample

DISCUSSION Jon Ringle 5 participants 6 messages Mar 7, 2007

lore
Share & tools
lore

Jon Ringle

author
#0 lore raw

Hello,

I'm trying to write a tty driver and I'm using
http://lwn.net/images/pdf/LDD3/ch18.pdf as a guide. The sample tiny tty driver includes the following code:

            for (i = 0; i < data_size; ++i) {
                        if (tty->flip.count >= TTY_FLIPBUF_SIZE)
                                    tty_flip_buffer_push(tty);
                        tty_insert_flip_char(tty, data[i], TTY_NORMAL);
            }
            tty_flip_buffer_push(tty);

This doesn't compile against Linux 2.6.16 kernel I'm using, because tty->flip.count doesn't exist anymore.
How should this sample be re-coded?

Thanks,

Jon

#1 lore raw
Quoted 9 lines · Jon Ringle

I'm trying to write a tty driver and I'm using
http://lwn.net/images/pdf/LDD3/ch18.pdf as a guide. The sample tiny tty driver includes the following code:

            for (i = 0; i < data_size; ++i) {
                        if (tty->flip.count >= TTY_FLIPBUF_SIZE)
                                    tty_flip_buffer_push(tty);
                        tty_insert_flip_char(tty, data[i], TTY_NORMAL);
            }
            tty_flip_buffer_push(tty);
Quoted 3 lines

This doesn't compile against Linux 2.6.16 kernel I'm using, because tty->flip.count doesn't exist anymore. How should this sample be re-coded?

I guess something like

	tty_buffer_request_room(tty, data_size);
	for (i = 0; i < data_size; ++i)
		work += tty_insert_flip_char(tty, data[i], TTY_NORMAL);
	if (work)
		tty_flip_buffer_push(tty);

will do.

Signature · 1 line
Jiri Kosina
#2 lore raw
Quoted 7 lines

I guess something like

	tty_buffer_request_room(tty, data_size);
	for (i = 0; i < data_size; ++i)
		work += tty_insert_flip_char(tty, data[i], TTY_NORMAL);
	if (work)
		tty_flip_buffer_push(tty);

Unless data_size can be very large and high speed then you can replace the lot with

	if (tty_insert_flip_string(tty, data, data_size))
		tty_flip_buffer_push(tty);
#3 lore raw
Quoted 9 lines · Alan Cox
Quoted 7 lines

I guess something like

	tty_buffer_request_room(tty, data_size);
	for (i = 0; i < data_size; ++i)
		work += tty_insert_flip_char(tty, data[i], TTY_NORMAL);
	if (work)
		tty_flip_buffer_push(tty);
Quoted 6 lines

Unless data_size can be very large and high speed then you can replace the lot with

	if (tty_insert_flip_string(tty, data, data_size))
		tty_flip_buffer_push(tty);

What does "very large and high speed" mean in this context?

-hpa

#4 lore raw
Quoted 8 lines
Quoted 6 lines

Unless data_size can be very large and high speed then you can replace the lot with

	if (tty_insert_flip_string(tty, data, data_size))
		tty_flip_buffer_push(tty);

What does "very large and high speed" mean in this context?

The default behaviour is to generate buffers based upon perceived need and then cycle them, so you tend to get chunks of 512 bytes or so. The logic is abstracted into tty_buffer_find() so can easily be changed.

Some hardware at high speeds with big FIFOs (or virtualised interfaces) produces big chunks of data in blocks with the size known at read time (eg that with large fifos and 100 polls/sec) - for those you can avoid generating a series of allocations or buffers by using the request_room interface to hint the size of the buffer you will actually need.

#5 lore raw
In reply to Jon Ringle

Jon Ringle napsal(a):

Quoted 13 lines

Hello,

I'm trying to write a tty driver and I'm using
http://lwn.net/images/pdf/LDD3/ch18.pdf as a guide. The sample tiny tty driver includes the following code:

            for (i = 0; i < data_size; ++i) {
                        if (tty->flip.count >= TTY_FLIPBUF_SIZE)
                                    tty_flip_buffer_push(tty);
                        tty_insert_flip_char(tty, data[i], TTY_NORMAL);
            }
            tty_flip_buffer_push(tty);
Quoted 3 lines

This doesn't compile against Linux 2.6.16 kernel I'm using, because tty->flip.count doesn't exist anymore.
How should this sample be re-coded?

I think this way:
http://lkml.org/lkml/2007/2/17/65

regards,

Signature · 4 lines
http://www.fi.muni.cz/~xslaby/            Jiri Slaby
faculty of informatics, masaryk university, brno, cz
e-mail: jirislaby gmail com, gpg pubkey fingerprint:
B674 9967 0407 CE62 ACC8  22A0 32CC 55C3 39D4 7A7E