LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-03-2008, 09:31 PM   #1
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Rep: Reputation: 41
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
 
Old 06-08-2008, 03:51 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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.
 
Old 06-09-2008, 04:22 AM   #3
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Original Poster
Rep: Reputation: 41
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?
 
Old 06-09-2008, 02:30 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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.
 
Old 06-10-2008, 04:44 AM   #5
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Original Poster
Rep: Reputation: 41
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FreeBSD 6.2, no /usr/src/tools and /usr/src/usr.bin, failed to build world. Mr_Shameless *BSD 4 05-16-2008 08:43 AM
rpmbuild doesn't produce the source code in /usr/src/redhat/BUILD Niceman2005 Linux - Software 2 11-29-2004 05:58 PM
deleting /usr/src/linux-2.6.5-1.358/drivers haddad Linux - General 2 08-16-2004 10:47 AM
where are located the ethernet-card driver sources code in OpenBSD /usr/src/...? maqelgav *BSD 5 06-09-2004 03:02 AM
Creating /usr/src/linux-<xx> from kernel.<xx>.src.rpm jmourik Linux - Newbie 2 02-19-2003 03:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration