LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-22-2011, 03:05 AM   #1
Alessandro_2
LQ Newbie
 
Registered: Feb 2011
Posts: 2

Rep: Reputation: 0
Kernel programming and RTAI: problems with a custom module installation.


Hi guys,
I am facing a weird problem. I am new to kernel programming and to rtai. I am trying to write a simple module that periodically set to 1 and 0 the parallel port's output.
In particular I created two .c. files (main.c and mathlib.c with the header mathlib.h) the file main.c includes the header mathlib.h, with the makefile below.
Within the main file I call a function (say funcx) in the mathlib library that essentially use the snprintf function to store in a string to print an integer value. The code compiles fine but I experience a reboot when I insmod the module. By moving the funcx form the mathlib to the top of the main function, all works fine.
I really can't understand what it is wrong.

Thanks for your help.

Alessandro





EXTRA_CFLAGS += -O -Wall -DMODULE -D__KERNEL__ -I/usr/realtime/include -I/usr/include -mhard-float # -D__KERNEL__ -DMODULE -I/usr/realtime/include -I/usr/include -D_IN_RTAI_ -mhard-float -O3 -pipe -Wall
PWD = $(shell pwd)
obj-m += main_mod.o
main_mod-objs += mathlib.o main.o
module=$(obj-m:.o=.ko)

ifneq ($(shell lsmod | grep $(module:.ko=)),)
$(shell sudo rmmod $(module))
endif

.PHONY: all clean

all: $(clean)

make -C /lib/modules/$(shell uname -r)/build SUBDIRS=$(PWD) modules

clean:
-rm -f *.o *.ko .*.cmd .*.flags *.mod.c *~ *vers
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
 
Old 02-23-2011, 12:01 PM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Did you include linux/module.h?
 
Old 02-24-2011, 02:58 AM   #3
Alessandro_2
LQ Newbie
 
Registered: Feb 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Yes, I did. These are the included headers:

Code:
#include <linux/module.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/ctype.h>
#include <linux/kernel.h>
#include <stdarg.h>
#include <asm/page.h>		/* for PAGE_SIZE */
#include <asm/div64.h>
The function in question in mathlib.c is a simple function:

Code:
void float2string(char string*, float num){

sprintf(tring, "%d.%lld\n",(int)num,(long long int)((float) (num-(long long int) num))*1000);
}
The same happens commenting the sprintf function and using (just for the case) "strcpy(string, "SomeString")". Everything is ok if I do:
Quote:
string[0]='1'; string[1]='2'; .... string[n]='\0';
or, like I said, if I use the functions defined in vsnprintf.c (namely, sprintf) directly in the main.c file.

Sorry to bother for such a stupid problem, but I spent two days trying to figure out what's wrong. I want to be sure that it is neither a configuration issue nor a programming one.
Thanks, for the interest.

Alessandro
 
Old 02-24-2011, 10:55 AM   #4
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Could it be that you are missing the trailing '\0'?
 
  


Reply

Tags
[c]



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
[SOLVED] nvidia kernel module with custom kernel feech Linux - Kernel 2 01-26-2010 01:25 PM
RTAI programming sayooj Programming 0 01-17-2007 10:55 AM
RTAI programming sayoojc Programming 9 11-02-2006 12:36 PM
Kernel module programming Error : module not found coolguy_iiit Programming 1 07-30-2006 07:23 AM
RTAI Installation problems saintt Linux - Software 0 10-31-2001 05:19 AM

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

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

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