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
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.
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’
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, 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.
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.
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,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?
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.