LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 01-29-2010, 09:26 AM   #1
bizoo
LQ Newbie
 
Registered: Jul 2009
Posts: 17

Rep: Reputation: 0
RTS toggling in serial port from kernel space


HI

Driven by my needs , i need to toggle only the flow control (RTS, CTS) bits and have nothing to do with the rest of the functionality (e.g. normaltx , rx operation).

I am presuming that there exists a line discipline from user space for toggling RTS as
ioctl (*file, cmd, *unsigned long )
can be used easily to toggle RTS.

However, the use of IOCTL in kernel space for the same purpose brings about no change on RTS (oscilloscope shows no change).

google led me to this
http://www.archivum.info/linux-kerne...dling-RTS.html

and according to that i should make changes directly in the driver.

Can some one give me some more pointers on that? i actually have not seen the serial driver from inside and am hoping if there do exists some other work around so any pointers will be appreciated.
The snippet of my module which tries to toggle the pin in kernel is attached for pointing to possible mistakes

thx

Code:
int x=0;

int actual_module()
{   int k;
    mm_segment_t oldfs;
		f=filp_open("/dev/ttyUSB0",O_RDWR | O_NDELAY,0);
		if ((IS_ERR(f)))
		{printk("device open fail \n");
		 return 1;
		}
		f->f_pos=0; 
		oldfs=get_fs();
		set_fs(KERNEL_DS);	
		tty=(struct tty_struct*)f->private_data;
		x |= TIOCM_RTS;
		//f->f_op->ioctl(f->f_dentry->d_inode, f, TIOCMSET, (unsigned long)&x);
    k=tty->driver->ops->ioctl(tty, f,TIOCMSET, (unsigned long)&x);
		printk("return value is %d \n", k);
		mdelay(1000);
	  x &= ~TIOCM_RTS;
  	set_fs(oldfs);
		return 0;
}
 
Old 01-31-2010, 06:30 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
If you know the nature of the serial hardware, you should be able to use one of the userspace facilities such as io_perm + outb/inb to tickle the right registers in the UART. I am not aware of any ioctl or other calls that permit manipulation of flow control and modem control signals.
Is your application limited to a specific hardware architecture? If so, which?

--- rod.
 
Old 01-31-2010, 11:55 PM   #3
bizoo
LQ Newbie
 
Registered: Jul 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Well
i can easily do it from user space but the time taken between issuing the command and execution is too large (200 us). Thus i am trying to toggle the flow control pins where this delay , though unpredictable, will be on average less.

And i have no special hardware in mind,
the normal x86 processors willl do
thx
 
Old 02-02-2010, 10:15 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I'm only speculating here, but my hunch is that the longish time lag is a result of the overhead of making a system call. In order to eliminate this, you will have to write substantial portions of the application as a kernel driver. Are you sure Linux is the right OS for this?

--- rod.
 
  


Reply



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
Need a Source code for User space serial port driver shree24985 Linux - General 1 01-25-2009 07:04 AM
serial port R/W with DTR and RTS andreski Programming 1 12-06-2007 10:57 AM
serial port interrupts in user space pierre-luc Programming 2 04-24-2007 09:48 PM
Set RTS high on serial port Regulus Linux - Software 1 08-09-2006 04:58 PM
Controlling serial port RTS pin from 'C' program dcarter Slackware 1 09-26-2003 07:01 PM

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

All times are GMT -5. The time now is 04:38 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