Jump to content
OMRON Forums

Manually Create a Kernel-Mode Thread


shansen

Recommended Posts

I have been using the Threading library created by KEJR and Delta Tau, and it has been working very well so far. Thanks for your effort guys!

 

Now, I'm trying to figure out if I can create a kernel-mode thread from a user-mode program...does anyone know if this is possible? And if so, what is the syntax for associating an IRQ with a kernel-mode thread?

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I have been using the Threading library created by KEJR and Delta Tau, and it has been working very well so far. Thanks for your effort guys!

 

Now, I'm trying to figure out if I can create a kernel-mode thread from a user-mode program...does anyone know if this is possible? And if so, what is the syntax for associating an IRQ with a kernel-mode thread?

 

Sweet, glad you could use the library.

 

I am not going to speak for DT, but I know on other linux based RTOS I've worked on (RTAI and RTLinux) that you had to compile code with some special makefules and/or flags and then insert them into the kernel with the insmod program. I don't know if the IDE will support this other than the built in hooks now for the user algorithms and things like that.

 

I have to ask though, do you really want to do this? You need to have pretty low jitter requirements to need to do this. Maybe this is where your IRQ comes in? I'm now curious what you are trying to do.

 

 

Link to comment
Share on other sites

KEJR,

 

Yes, my jitter requirements are the reason I need a kernel mode thread. I am writing a current/voltage regulator for a 3 phase PWM converter, and I would prefer to create my own thread so I can easily hook into some of the shared memory extensions my company has written for the PPMAC.

 

I can also use DT's motor phase interrupt (i.e. user phase code), but that will not be as clean in terms of interfacing to our custom shared memory code.

 

To clarify what I am asking, I was hoping that I could write user phase code and use the IDE to compile it (it already does this, i.e. adding the compiler switches to compile for kernel-mode), but then be able to start that kernel-mode thread from a background "capp" instead of using the right click->user servo setup.

 

So, as a summary:

 

1) Write DT user phase code

2) Use IDE to compile user phase code

3) Use user-mode code to create a kernel mode thread that would run the compiled user phase code

Link to comment
Share on other sites

 

You could try creating a thread from the useralgo the first time it runs and have the thread wait in a sleep but it might crash since it would be trying to create a thread from the context of an interrupt.

 

You could also try creating the thread from a Cfromscript function see the link below it has a nice write up on using Cfromscript

http://forums.deltatau.com/showthread.php?tid=669&highlight=Cfromscript

 

You may have to resort to creating your own driver from scratch in that case you will have to compile from a command line prompt and learn how to make a linux driver from scratch.

 

KEJR,

 

Yes, my jitter requirements are the reason I need a kernel mode thread. I am writing a current/voltage regulator for a 3 phase PWM converter, and I would prefer to create my own thread so I can easily hook into some of the shared memory extensions my company has written for the PPMAC.

 

I can also use DT's motor phase interrupt (i.e. user phase code), but that will not be as clean in terms of interfacing to our custom shared memory code.

 

To clarify what I am asking, I was hoping that I could write user phase code and use the IDE to compile it (it already does this, i.e. adding the compiler switches to compile for kernel-mode), but then be able to start that kernel-mode thread from a background "capp" instead of using the right click->user servo setup.

 

So, as a summary:

 

1) Write DT user phase code

2) Use IDE to compile user phase code

3) Use user-mode code to create a kernel mode thread that would run the compiled user phase code

 

 

Link to comment
Share on other sites

It sounds like you have some custom C code that reads/writes shared memory in a certain way and you wan to use this in a user phase algorithm?

 

If all you want to do is access shared memory could you write a user algorithm that gets switched on and off via some PVar or other shared memory drivers using a simple IF statement. This gives you control from a user mode C application.

 

if (GetMySharedMem(MyVar))
   DoMyUserAlgorithm();

 

I have not tried this but then you could do a #include on your C source and header file to get your custom C code "into" the user algo file. I haven't tried it for the user algorithm, but it should work, there is no magic to the C preprocessor it'll include C code as well as header files. I *think* this accomplished most of what you want but I don't know the gory details of your shared memory code.

 

KEJR

Link to comment
Share on other sites

Henry,

 

If I create and compile my own device driver, what is the proper way to link a function within the driver to the phase interrupt?

 

I am a little confused. I thought you wanted something running as a separate thread? Do you want to do both?

 

If you want a function called by the phase interrupt use the built in useralgo. If you must start a thread in addition to having a routine started called by the ISR you can modify useralgomain.c and in the init_module you can launch your thread. If you want to start the thread from a user app create an ioctl as part of the kernel module in useralogmain.c

 

If you look at the folder where useralgo is created you will see useralgomain.c is created by the IDE. However , there is an issue that the IDE overwrites useralgomain.c and the makefile every time you build and download so you would have to manually type make -f [project.mak] from a command line then copy the useralgo.ko to the PowerPMAC.

 

If you wanted to do your own seperate kernel module and wanted a particular function callable by the phase routine. You would need to EXPORT_SYMBOL the function you wanted callable and Force the address of your function into UserAlgo.PhaseAddr[] with a c application. Once your kernel module is loaded ie. with a insmod yourdrv.ko you could do a cat /proc/kallsyms | grep your_function and you will see what the address of your function is.

 

If your ambitions see the references book Linux Device Drivers by Corbet,Rubini and Kroah-Hartman for writing Linux Drivers

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...