EMC2 running on Raspberry Pi?

More
14 years 2 months ago #23081 by mungkie
Is there any documentation for writing hal driver modules for linuxcnc?

I have a very basic driver written for my hardware ( I finished soldering up the dual parallel port board this weekend but have not tested it yet).

The driver sort of works on breadboard switching a few pins, but I have to run linuxcnc as root with sudo to be able to access the kernelspace memory, does linuxcnc have any code to load modules with root access?

Is there a driver writing guide?

I am really just hacking this and still don't have a full understanding of how all parts of linuxcnc work together(maybe a stupid way to work but I sort of prefer to use the task to guide what I need to learn and understand).

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago #23082 by ArcEye

Is there any documentation for writing hal driver modules for linuxcnc?

linuxcnc.org/docs/2.5/html/hal/comp.html is a starting point, then look at the components in the source code and pick one which is closest to what you want to do.

Some of these are in pure C, it might be easiest to understand the ones with a .comp suffix to start with, as they just contain pin creation and the relevant function code, without the other
bits that comp fills in.

does linuxcnc have any code to load modules with root access?

You shouldn't need to if the module is loaded with loadrt, it will have access to what it requires, unless you are completely directly hacking and not using rtapi calls.
You will need to be specific as to what you want to achieve when you have been able to study the existing modules.

I suspect the code most of interest to you will be in the ../src/hal/drivers/ directory. Most of them are in pure C, you can always run comp filename to generate a C file from an existing .comp file to see what is added.

Lot of reading to do!

regards

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago #23085 by mungkie
I suppose I should have elaborated more about my current situation:

I have already written a very basic test hal driver in c, it works with linuxcnc and the test LED is blinking when it should (I have only implemented very basic test functionality though the rest is just implementing more IO pins and possibly some caching).

I based the driver on c code from the linuxcnc tree, but have had to shift the driver about in the source tree to get it to compile, and have not sorted out the autogen and configure stuff so basically just hacked the Makefile and submakefile in src/ and src/hal/.

I have written a set of configs for the raspberry pi and the IO card I made and it load the IO card driver with 'loadrt hal_rpi 1' in my .hal file and connected stepgen and axis to the driver, but linuxcnc will not run as the module load fails due to access permissions. The problem is that the userspace driver requires root access to write to memmapped device, so I have to run linuxcnc with 'sudo linuxcnc'.

The driver works when I run linuxcnc as root and moving axes in the axis gui lights the test LEDS, my problem is that I do not want to have to run linuxcnc as root, and I am considering ways of hacking linuxcnc code so that it can run stepper based systems without a RT kernel using some scheduling tricks and some low level FIQ interupts (I have no idea what I am doing as its not something I have done before). Currently without any other hacking of kernel scheduling or interupts I am getting around 1.5KHz of pulses so should run a stepper system with 200 steps per rev at about 450rpm. I know this is all a horrendous hack and jitter and latency could be terrible but in some situation where you don't need to synchronise external events like spindle speed etc, it will be a workable solution (and this is just an interim stop gap that I have hacked up in a couple of weekends work)

Is there a wrapper for loading modules with root permissions?.

I should also say the system is built from the RT_PREEMPT git repo of linuxcnc-2.6 and is built in simulator mode, I am just trying to test the driver at present as I cannot get a realtime kernel at present and I think there are stability issues with RPI that mean it is not worth trying to kernel hack RT_PREEMPT for quite a while yet. I do hope to get a RT kernel running, but I am toying with the idea of running linuxcnc in non realtime as this could be a fairly simple thing to do (though not very accurate it maybe 'good enough' for some situations).

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago #23086 by andypugh
mungkie wrote:

I have already written a very basic test hal driver in c, it works with linuxcnc and the test LED is blinking when it should


In that case:
sudo comp --install path/to/my/filename.c
ought to compile and install the module with the required permissions.

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago #23094 by cmorley
AFAIK
sudo make setuid
gives the important part sudo permission so everything doesn't need sudo.

If you hacked the make file maybe you hacked this part out? or didn't try the command at all.
maybe you can figure it out by looking at the make file. i try and stay away from it :) ...

Chris M

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago #23111 by mungkie
andypugh wrote:

mungkie wrote:

I have already written a very basic test hal driver in c, it works with linuxcnc and the test LED is blinking when it should


In that case:
sudo comp --install path/to/my/filename.c
ought to compile and install the module with the required permissions.



Interesting tip about using comp, I did not know about that thanks andy, unfortunatly it does not help with the actual problem I have but is still very useful :D

I should also say that I tried it and it has same effect as I originally made by hand (I also tried changing permissions and adding sticky bit to rtlib/hal_rpi.so). I should possible double check this again as I think after I tried with 'sudo comp --install' the error message when running scripts/linuxcnc did change and there maybe a problem with group ID also??

What I am really enquiring about is if linuxcnc loads modules via some SUID system or is this cause I am running linuxcnc in simulator mode.

I know X runs as root with some wrapper so it can access low level video hardware, is this how linuxcnc loads drivers?

Please Log in or Create an account to join the conversation.

Time to create page: 0.448 seconds
Powered by Kunena Forum