Some kernel library function questions


 
Thread Tools Search this Thread
Operating Systems Linux Some kernel library function questions
# 1  
Old 12-05-2008
Some kernel library function questions

Sir,

I am trying to learn how to write a device driver for an input device. As a start I tried to understand the actual device driver code written for linux 2.6.9 kernel. It is always good to follow masters in programming . I understood some parts of the code . But I got stuck with some library functions and macros . Hope you masters can shed some light in to my doubts.

1. What is time_after() function ? It is used in the actual serial mouse driver for kernel 2.6.9. Below given is the line where it is used

if (time_after(jiffies, my_mouse->last + HZ/10))
my_mouse->count = 0;

I tried to get the logic behind the line but I failed to do so . I read that jiffies is a global variable that increase with every time tick starting from system log on. Can anybody help me to understand the logic behind this line.

2. There is a mouse connect function which is called whenever we connect a serial mouse to the serial port. The function takes two arguments, a pointer to struct serio and struct serio_drv. This struct serio pointer is used throughout the connect function but we are not initializing it anywhere. So What I understand is that when we connect the serial mouse the input sub system automatically initializes this structure with the details of the mouse we connected so that the driver program can use these details to select the protocol and type of mouse. I just want a conformation from you that what I understand is right (I hope so) .

3. in serio.h headerfile there are some macros defined. like

#define SERIO_TYPE 0xff000000UL
#define SERIO_PROTO 0xFFUL

In the both definition the label UL is used which I believe(?) stands for unsigned long. What my doubt is that why ff (small letter) and FF(capital letter ) is used . What is the difference between these two .

Sorry if the way I asked my questine is not right. My english is not that great. Can anyone help me to understand these points. Thanking you...
# 2  
Old 12-05-2008
Note: my responses might not be accurate:

Quote:
Originally Posted by iamjayanth
1. What is time_after() function ? It is used in the actual serial mouse driver for kernel 2.6.9. Below given is the line where it is used

if (time_after(jiffies, my_mouse->last + HZ/10))
my_mouse->count = 0;
Jiffies, as you noted, is the global clock tick in Linux. So this says, if it's now later that the last state-change of the mouse (within one-tenth of HZ), reset the mouse's "count", whatever that is. You could user > or < than or whatever here, except for the fact that sometimes, the jiffies parameter will wrap around -- it can do this on 32-bit machines if running longer than, say, a [strike]year[/strike] day. This function supposedly handles that case. See this thread: http://marc.info/?l=linux-kernel&m=101406885521792


Quote:
2. ... So What I understand is that when we connect the serial mouse the input sub system automatically initializes this structure
I don't know. Sorry.

Quote:
3. ... In the both definition the label UL is used which I believe(?) stands for unsigned long.
Correct.
Quote:
What my doubt is that why ff (small letter) and FF(capital letter ) is used . What is the difference between these two .
None. Absolutely none.

All hex digits are the numbers 0 through 9 and A through F. In C, and in most programming languages, it doesn't matter if the letter if upper or lowercase.

Last edited by otheus; 12-05-2008 at 07:34 AM.. Reason: showing my age
# 3  
Old 12-05-2008
Thanks otheus...... You are brilliant....... Please help me little bit more.......
So you are saying ff is same and FF......so
0xFFUL is 0x000000FF
and
0xff000000 is 0xFF000000
Am I correct? thanks again...
# 4  
Old 12-05-2008
Correct.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

I need help movingworking code into library function and calling it obj13-2.pl

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! I need help moving working code into library function called obj13-lib.pl and call the same function in obj13-2.pl I am a Linux newbie and this certificate is my first step... (0 Replies)
Discussion started by: cllinuxhelp
0 Replies

2. Linux

Unload kernel module at boot time (Debian Wheezy 7.2, 3.2.0-4-686-pae kernel)

Hi everyone, I am trying to prevent the ehci_hcd kernel module to load at boot time. Here's what I've tried so far: 1) Add the following line to /etc/modprobe.d/blacklist.conf (as suggested here): 2) Blacklisted the module by adding the following string to 3) Tried to blacklist the module... (0 Replies)
Discussion started by: gacanepa
0 Replies

3. AIX

Calling functions from main program from dlopened library function

Hello All, I am trying to call a function from the calling main program from a dlopened library function, below is the entire code, when I execute it it crashes with sigill. Can you guys help me out I guess I am missing out on the linker flag or something here. besides I am new to AIX and... (1 Reply)
Discussion started by: syedtoah
1 Replies

4. Programming

Where are the library function definitions located?

Hi friends, I hope everyone is doing fine. I have this confusion, hope you can help me out with it. The header files contain only function prototypes. Where are the function definitions located. For example, if I would like to see how printf works, where can I see its definition, stdio.h only... (2 Replies)
Discussion started by: gabam
2 Replies

5. Linux

./configure problem for libsf library due to apparently missing libdb library.

Hello, ./configure script fails to configure libsf. Please check the following last few lines of configure script error. checking for db1/db.h... no checking for db.h... yes checking for dbopen in -ldb1... no configure: error: No libdb? No libsf. But find command shows the following; ... (4 Replies)
Discussion started by: vectrum
4 Replies

6. Homework & Coursework Questions

Print questions from a questions folder in a sequential order

1.) I am to write scripts that will be phasetest folder in the home directory. 2.) The folder should have a set-up,phase and display files I have written a small script which i used to check for the existing users and their password. What I need help with: I have a set of questions in a... (19 Replies)
Discussion started by: moraks007
19 Replies

7. Programming

which function copies data from user to kernel mode

when transitionaning from user to kernel mode which function copies data from user mode buffer to kernel mode? (5 Replies)
Discussion started by: rupeshkp728
5 Replies

8. Solaris

Which file is read by kernel to set its default system kernel parameters values?

Hi gurus Could anybody tell me which file is read by kernel to set its default system kernal parameters values in solaris. Here I am not taking about /etc/system file which is used to load kernal modules or to change any default system kernal parameter value Is it /dev/kmem file or something... (1 Reply)
Discussion started by: girish.batra
1 Replies

9. Linux

load dynamic and shared library in kernel

hi how can i load dynamic or shared library in linux kernel modules . mtaghiloo@yahoo.com (0 Replies)
Discussion started by: mtaghiloo
0 Replies
Login or Register to Ask a Question