Skip navigation.
Home
The QNX Community Portal

View topic - Creating new device node

Creating new device node

For discussion of realtime and/or embedded programming.

Creating new device node

Postby umamahesh » Tue Mar 24, 2015 12:50 pm

Hi
Following code snippet used to create a node and assign major/minor number, but unable to see the device node in /dev.
when I run the RM in background as suggested in the earlier post, I get pid number and "Done" , but when I execute the pidin command to check whether RM is running it is actually not executing, all these issues started facing after modifying RM for updating major and minor please provide suggestions as I neglected it earlier and now running back to correct it. Please check code snippet below

iofunc_attr_init (&dev->attr, S_IFCHR | 0666, 0, 0);
iofunc_func_init (_RESMGR_CONNECT_NFUNCS, &dev->connect_funcs,
_RESMGR_IO_NFUNCS, &dev->io_funcs);


if((dev->attr.rdev = rsrcdbmgr_devno_attach("i2c1", -1, 0))!=-1){

dev->connect_funcs.open = i2c_io_open;
dev->io_funcs.close_ocb = i2c_io_close;
dev->io_funcs.read = i2c_io_read;
dev->io_funcs.write = i2c_io_write;
dev->io_funcs.devctl = i2c_io_devctl;
if ((dev->resmgr_id=resmgr_attach (dev->i2c_dispatch, &resmgr_attr, "/dev/i2c1", _FTYPE_ANY,
0, &dev->connect_funcs, &dev->io_funcs, &dev->attr)) == -1) {
printf("Unable to resmgr_attach");
return EXIT_FAILURE;
}
else {
resmgr_devino( dev->resmgr_id, &dev->io_mount.dev, &dev->attr.inode );
printf("Done\n");
return(EOK);
}
rsrcdbmgr_devno_detach( dev->attr.rdev, 0 );
// allocate a context
dev->i2c_ctp = dispatch_context_alloc (dev->i2c_dispatch);

// wait here forever, handling messages
while (1) {
if ((dev->i2c_ctp = dispatch_block (dev->i2c_ctp)) == NULL) {
printf ("Unable to dispatch_block");
exit (EXIT_FAILURE);
}
dispatch_handler (dev->i2c_ctp);
}
}
else{
printf("Unable to acquire devno\n");

}
umamahesh
Active Member
 
Posts: 39
Joined: Thu Feb 19, 2015 6:12 am

Re: Creating new device node

Postby Tim » Tue Mar 24, 2015 2:03 pm

See this:

Code: Select all
if ((dev->resmgr_id=resmgr_attach (dev->i2c_dispatch, &resmgr_attr, "/dev/i2c1", _FTYPE_ANY,
0, &dev->connect_funcs, &dev->io_funcs, &dev->attr)) == -1) {
    printf("Unable to resmgr_attach");
    return EXIT_FAILURE;
}
else {
resmgr_devino( dev->resmgr_id, &dev->io_mount.dev, &dev->attr.inode );
    printf("Done\n");
    return(EOK);
}


BOTH paths of your 'if' statement are returning. Since you are in your 'main' that means you are exiting the program.

Tim
Tim
Senior Member
 
Posts: 1390
Joined: Wed Mar 10, 2004 12:28 am

Re: Creating new device node

Postby umamahesh » Tue Mar 24, 2015 2:49 pm

Tim,Thanks for correcting me. Removed return(EOK) after resmgr_devino, still problem persists. Please look into following log

# ./proc/boot/i2c-sensor &
[1] 16401
Done
# ls -l /dev/i2c1
I2C Master driver opened
ls: No such process (/dev/i2c1)
[1] + Memory fault ./proc/boot/i2c-sensor


From Client program 'open("/dev/i2c1", O_RDWR)' also fails.

# ./proc/boot/i2c-sensor &
[1] 24593
Done
# ls /dev/
bpf io-usb ptyp4 snd tap3 ttyp6
bpf0 mem ptyp5 socket text ttyp7
console null ptyp6 stderr tty tun0
dbgmem pipe ptyp7 stdin ttyp0 tun1
fs0 profiler sem stdout ttyp1 tun2
fs0p0 ptyp0 ser1 tap ttyp2 tun3
hd0 ptyp1 ser3 tap0 ttyp3 tymem
hd0t12 ptyp2 shmem tap1 ttyp4 zero
i2c1 ptyp3 slog tap2 ttyp5
# ./proc/boot/se
sensor-app setkey
# ./proc/boot/sensor-app
I2C Sensor MMA8451Q Application Program
I2C Master driver opened (RM open operation)
ERROR: open(-1) failed
[1] + Memory fault ./proc/boot/i2c-sensor
umamahesh
Active Member
 
Posts: 39
Joined: Thu Feb 19, 2015 6:12 am

Re: Creating new device node

Postby Tim » Tue Mar 24, 2015 5:03 pm

The 'memory fault' indicates your i2c-sensor program is crashing.

Why, I don't know. You'll have to debug the code and find out where it's happening and then figure out why. You can do that with the debugger OR by adding printf's to the code to see where it happens.

Tim
Tim
Senior Member
 
Posts: 1390
Joined: Wed Mar 10, 2004 12:28 am

Re: Creating new device node

Postby umamahesh » Fri Mar 27, 2015 9:18 am

Thanks for the reply, but why client program 'open' should fail. I am just taking sample RM and executing it. Is the device node creation procedure is correct. Following code snippet,
if((dev->attr.rdev = rsrcdbmgr_devno_attach("i2c1", -1, 0))!=-1), should I pass i2c1 or _MAJOR_DEV?. In both the cases it tells /dev/i2c1 'No such process ' or 'Unable to initialize the device /dev/i2c1' when I run 'pdebug /dev/i2c1'
umamahesh
Active Member
 
Posts: 39
Joined: Thu Feb 19, 2015 6:12 am

Re: Creating new device node

Postby Tim » Fri Mar 27, 2015 1:59 pm

"i2c1" is correct.

If you just do a 'ls /dev' do you see your i2c1 entry and your RM doesn't crash? If that's true then the problem is in the code that handles the 'open' request which I don't see (it would help if you post more of your RM code. Don't need the I2C code).

Not sure what you expect 'pdebug /dev/i2c1' to do. That's not how you debug your RM with the debugger. You have to attach to the RM process, not the /dev entry it creates.

Tim
Tim
Senior Member
 
Posts: 1390
Joined: Wed Mar 10, 2004 12:28 am

Re: Creating new device node

Postby umamahesh » Fri Mar 27, 2015 2:19 pm

Tim, Please see the attachment, basic code which I am trying to control the open and close functions of RM from client program.
As you suggested earlier RM is executed as background process, I am able to see i2c1 when I do ls /dev/ and RM doesn't crash, it get crashed when I do ls /dev/i2c1.
Attachments
i2c-sensor_rm.zip
RM code
(2.41 KiB) Downloaded 388 times
sensor-app.zip
Client app
(1.32 KiB) Downloaded 399 times
umamahesh
Active Member
 
Posts: 39
Joined: Thu Feb 19, 2015 6:12 am

Re: Creating new device node

Postby Tim » Fri Mar 27, 2015 7:34 pm

Two things.

1) You are assigning your custom functions *after* doing the resmgr_attach() call. The doc's always show these being done *before* this call. Move your i2c_io_open and close call assignments before the attach.
2) To help facilitate debugging better I suggest adding another printf in your while(1) loop. Add it after your if statement and before you do the dispatch_handler() call so you are reaching this point.

I would also suggest creating i2c_io_read() and write() functions even if they just have a printf in them. Then assign those as too where you are doing your io_open assignment.

Tim
Tim
Senior Member
 
Posts: 1390
Joined: Wed Mar 10, 2004 12:28 am

Re: Creating new device node

Postby umamahesh » Sun Mar 29, 2015 7:57 am

Tim,As suggested added a printf before dispatch_handler() it never printed, added printf after 'if ' condition it never reached

if ((dev->i2c_ctp = dispatch_block (dev->i2c_ctp)) == NULL) {
printf ("Unable to dispatch_block\n");
exit (EXIT_FAILURE);
}

Added printf before if, it printed once

while (1) {
printf("inside while\n");
if ((dev->i2c_ctp = dispatch_block (dev->i2c_ctp)) == NULL) {
printf ("Unable to dispatch_block\n");
exit (EXIT_FAILURE);
}
printf("b4 dispatch handler\n");
dispatch_handler (dev->i2c_ctp);
}

As suggested I have moved open/close/read/write calls before resmgr_attach(), still it fails and gives memory fault. Spent a lot of time, I am just extracting the RM code as in example code and printer RM shared to me, hope I have shared the code which I am working right now. Requesting to suggest/ correct me where things are going wrong, so that I can proceed further. Is there any dependency in Momentics 6.5 IDE?
umamahesh
Active Member
 
Posts: 39
Joined: Thu Feb 19, 2015 6:12 am

Re: Creating new device node

Postby umamahesh » Sun Mar 29, 2015 8:45 am

Compiled example RM code generated using Momentics IDE6.5, it doesn't give any fault or "No such process"

# ./proc/boot/NeutrinoResourceManager &
[1] 16401
null: starting...
# ./proc/boot/i2c-sensor &
[2] 20500
inside while
# cat /dev/Null
# cat /dev/i2c1
/dev/i2c1: No such process
[2] + Memory fault ./proc/boot/i2c-sensor
umamahesh
Active Member
 
Posts: 39
Joined: Thu Feb 19, 2015 6:12 am

Re: Creating new device node

Postby Tim » Mon Mar 30, 2015 1:45 pm

Since the QNX example one doesn't crash, why don't you just use that one instead of yours that is crashing in the dispatch_block() call?

Just add your functions into that RM and replace the NULL name with your i2c1 name. There is nothing special about the NULL name.

The only other things that I noticed is:
1) When you malloc for your mx6x_i2c_dev_t structure you don't memset it to 0
2) your iofunc_attr_init() function you specify S_IFCHR vs S_IFNAM

Tim

P.S. Here's another sample RM code you can look at that might help.
http://himmele.googlecode.com/svn/trunk ... eManager.c
Tim
Senior Member
 
Posts: 1390
Joined: Wed Mar 10, 2004 12:28 am

Re: Creating new device node

Postby umamahesh » Tue Apr 21, 2015 1:03 pm

From the link shared, I wrote a client app to read from the RM, but it fails. Following is the code snippet

memset( &data, 0, sizeof(data));
/*Dummy read/write routine*/

if(read(fd,&data,sizeof(data))!=sizeof(data)){
printf("read failed\n");
return -1;
}

Any suggestions on this.
umamahesh
Active Member
 
Posts: 39
Joined: Thu Feb 19, 2015 6:12 am

Re: Creating new device node

Postby Veda Ross » Wed Sep 09, 2015 6:02 am

I am writing a module for the Linux kernel and also I want to create some device nodes in the init function

int init_module(void)
{
Major = register_chrdev(0, DEVICE_NAME, &fops);
// Now I want to create device nodes with the returned major number
}

I also want the kernel to assign a minor number for my first node, and then I will assign the other nodes' minor numbers by myself.
How can I do this in the code. I don't want to create devices from the shell using mknod.

_______________________________
#Veda
Working for resume writing service
Veda Ross
New Member
 
Posts: 1
Joined: Sat Sep 05, 2015 6:13 am

Re: Creating new device node

Postby maschoen » Sat Sep 12, 2015 2:58 am

Uhhh, this is probably not the best place to ask questions about writing a Linux driver.

By "place" I mean this website. It's dedicated to QNX, not Linux. The two are almost entirely different at the level of writing a driver.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm


Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 2 guests

cron