I am interested what are the differences in the system that makes this simple task so differently achieved in both systems.
They aren't necessarily different, although there may be different methods available for you to choose between. You can choose to use exactly the same method on both boards.
If you stick to using the sysfs
interface, your code should run without modification on both devices, so if that is a priority then that is what you should do. If you are unclear on this, see the kernel docs. If you have specific questions about that, feel free to ask.
The sysfs interface uses file nodes and hence is language agnostic. The use of file nodes does NOT mean there is some significant I/O overhead involved. There may still be some extra cost in the use of read()
and write()
because these are system calls, meaning, they require the execution of kernel space code, but that does not mean that they require waiting on I/O with some peripheral device other than main memory, which pretty much everything including mmap'd methods must do also.
Things like wiringPi instead use mmap()
to access a region of memory exposed via the the kernel's /dev/mem
interface. So the major difference between the two would be that using the sysfs method uses the kernel gpio driver, whereas the mmap method bypasses that. It does not, however, really bypass the kernel -- the kernel implements mmap()
just as it implements the gpio driver. However, manipulating the map can be done completely in userspace code without invoking the kernel (hence no overhead for system calls).
So, the advantage to using the hardware specific mem-mapped method is that you may get lower latency with very fast transitions. However, this may or may not be significant depending on context: you still have to do this from userspace on a multi-tasking system. Again, if you want your code to work on something other than the pi, don't use a pi specific method unless you are sure you have no other choice -- use the kernel sysfs based interface.
I am really interested in this two different methods required to change status of a GPIO just because of the change in kernel.
https://www.youtube.com/watch?v=wui_wU1AeQc&list=PLF4A1A7E09E5E260A&index=11
– Denis Dec 02 '14 at 11:23