LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Code query on /usr/src/linux/drivers/serial/uart00.c (https://www.linuxquestions.org/questions/programming-9/code-query-on-usr-src-linux-drivers-serial-uart00-c-646822/)

archieval 06-03-2008 09:31 PM

Code query on /usr/src/linux/drivers/serial/uart00.c
 
Hi,

Is there anyone here working on serial drivers? Specifically on serial ports. I cant seem to find any forums (linuxforums and kernelnewbies) that is actively answering any kernel code questions so I came back here. I would want to know your opinion on what does this piece of code in /usr/src/linux/drivers/serial/uart00.c means because I am trying to create a similar functionality based on its algorithm but I not sure what does this code does. What does the highlighted code does? It seems to be dividing the fifosize by 2, and uses the result as count of transmit transaction. But why is this so?

Code:

static void uart00_tx_chars(struct uart_port *port)
{
        int count;
        struct uart_info *info = port->info;

        if (port->x_char) {
                while((UART_GET_TSR(port)& UART_TSR_TX_LEVEL_MSK)==15);
                UART_PUT_CHAR(port, port->x_char);
                port->icount.tx++;
                port->x_char = 0;
               
                return;
        }
        if (info->xmit.head == info->xmit.tail
            || info->tty->stopped
            || info->tty->hw_stopped) {
                uart00_stop_tx(port, 0);
                return;
        }

        count = port->fifosize >> 1;
        do {
                while((UART_GET_TSR(port)& UART_TSR_TX_LEVEL_MSK)==15);
                UART_PUT_CHAR(port, info->xmit.buf[info->xmit.tail]);
                info->xmit.tail = (info->xmit.tail + 1) & (UART_XMIT_SIZE - 1);
                port->icount.tx++;
                if (info->xmit.head == info->xmit.tail)
                        break;
        } while (--count > 0);

        if (CIRC_CNT(info->xmit.head,
                    info->xmit.tail,
                    UART_XMIT_SIZE) < WAKEUP_CHARS)
                uart_write_wakeup(port);

        if (info->xmit.head == info->xmit.tail)
                uart00_stop_tx(port, 0);
}

I use a 2.6.10 montavista 4.0 pro embedded system distro.

Regards,
archie

Mara 06-08-2008 03:51 PM

I see no reason for that piece of code other than something in that uart documentation. From what I see the size is 16, so count is set to 4. Internal buffer, maybe? I can't find out which chip the driver is for exactly, unfortunately.

If you're writing for a different chip, than simply continue with full size, but check documentation of your chip carefully here.

archieval 06-09-2008 04:22 AM

So it means I can use the full fifo size count as the count on how many times to send? It has nothing to do with buffers in serial_core.c, right?

Mara 06-09-2008 02:30 PM

You can if you check the documentation of your chip carefully before. There might be written somewhere that you can write at least N octets at once.

Unrelated to buffers in the driver, because the date is written to the registers/hardware buffers.

archieval 06-10-2008 04:44 AM

Quote:

I see no reason for that piece of code other than something in that uart documentation. From what I see the size is 16, so count is set to 4. Internal buffer, maybe? I can't find out which chip the driver is for exactly, unfortunately.
Ah the size is 16, and it becomes 8 after the shift.

What do you mean by N octets at once? N bytes at once?


All times are GMT -5. The time now is 11:26 AM.