LinuxQuestions.org
Review your favorite Linux distribution.
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 08-16-2010, 01:39 AM   #1
DonnoWhatToDo
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Rep: Reputation: 0
writing to serial port from kernel


Hey all,
I want to write data to serial port ( ttyS ) from inside the kernel.
Have any idea how to do it ?

thanks in advance.
 
Old 08-16-2010, 04:30 AM   #2
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by DonnoWhatToDo View Post
from inside the kernel.
You mean you want to write a device driver or interrupt handler for writing to the serial port ?
 
Old 08-16-2010, 04:39 AM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Have a look here too:
http://www.linuxquestions.org/questi...-linux-785316/


and
http://tldp.org/HOWTO/Serial-HOWTO.html
http://www.easysw.com/~mike/serial/serial.html

Last edited by Aquarius_Girl; 08-16-2010 at 04:44 AM.
 
Old 08-17-2010, 03:43 AM   #4
DonnoWhatToDo
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
thanks

anishakaul thank you for the reply,
I'll try the explain what I'm trying to do ,
I'm trying to write a function that filters ip packets (L2) and decides either to drop them or to write them to a serial port (ttySx). All inside the kernel space.
I found a way to write to serial port :
void x()
{
char buf[20]={"SOMETHING ...\0"};
loff_t pos = 0;
mm_segment_t old_fs;
struct file *my_filp;
my_filp = filp_open("/dev/ttyS2",O_RDWR|O_LARGEFILE,0);
if (my_filp == NULL)
printk("filp_open error!!.\n");
old_fs=get_fs();
set_fs(get_ds());
vfs_write(my_filp, buf, sizeof(buf), &pos);
set_fs(old_fs);
filp_close(my_filp,NULL);
}

and a place to filter the packages in net/core/dev.c - netif_receive_skb

but when trying to open/write into the serial from the function netif_receive_skb the linux crashes ( probably cause the function above is called in interrupt context ),

Have any suggestions on how to resolve this ?

thanks in advance.
 
Old 08-17-2010, 03:49 AM   #5
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by DonnoWhatToDo
I'm trying to write a function that filters ip packets (L2) and decides either to drop them or to write them to a serial port (ttySx). All inside the kernel space.
Where is this code running ?

Is this code inside some driver written by you ?
 
Old 08-17-2010, 03:54 AM   #6
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
and one more thing:

Quote:
Originally Posted by DonnoWhatToDo
but when trying to open/write into the serial from the function netif_receive_skb the linux crashes ( probably cause the function above is called in interrupt context ),
The following link
http://docs.blackfin.uclinux.org/ker...ing/re222.html
says:
Quote:
This function may only be called from softirq context and interrupts should be enabled.

Last edited by Aquarius_Girl; 08-17-2010 at 04:00 AM. Reason: highlightening
 
  


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
Problem in writing to serial port. srinathduraisamy Linux - General 2 03-25-2010 12:29 AM
Reading and Writing to a Serial Port without SU Steef223 Programming 2 06-16-2008 09:16 AM
writing to serial port, /dev/ttyS0 togunter Programming 2 06-08-2008 09:27 AM
writing to serial port sea waves Programming 6 05-08-2007 11:59 AM
Writing files to serial port...in C colin59 Programming 1 11-03-2005 11:06 AM

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

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