Kernel Source?

Hi *,

gradually I am in the process of making my first steps with the beaglebone. I now managed to write a small C program using the /sys/class/gpio infrastructure to blink an led. I found this opening of “files” etc. a bit clumsy, so I made my own wrapper function. When I did this, I basically discovered that all I want is essentially in linux/gpio.h, but that seems to be reservered for kernel development. Never mind, I could learn to write a module (which would then be in kernel space?). However, I think I am missing the whole src or at least header files or whatever I need. How can I obtain these. Is that a particular package from the angstrom distribution, can I git pull it from somewhere?
Any pointers would be very welcome,

Markus

http://ninjablocks.com/setting-up-gpio-on-the-beaglebone/

http://www.gigamegablog.com/2012/01/05/beaglebone-coding-101-blinking-an-led/

For kernel module:

http://www.mjmwired.net/kernel/Documentation/gpio.txt

and for a userspace C program:

https://groups.google.com/group/beagleboard/browse_thread/thread/fc82798494a2b831?hl=en&noredirect=true

for a userspace scripting:

https://groups.google.com/group/beagleboard/browse_thread/thread/6c665c087c07c2b2?hl=en&noredirect=true

Thank you, Peter!
especially what the user C program looks like is what I wrote myself already…

int gpio_export(int pin) {
FILE *f = fopen("/sys/class/gpio/export", “w”);
fprintf(f, “%d”, pin);
fclose(f);
}

int gpio_direction(int pin, char *direction) {
char loc[128];
sprintf(loc, “/sys/class/gpio/gpio%d/direction”, pin);
printf("%s\n", loc);
FILE *f = fopen(loc, “w”);
fprintf(f, “%s”, direction);
fclose(f);
}

int gpio_value(int pin, int value) {
char loc[128];
sprintf(loc, “/sys/class/gpio/gpio%d/value”, pin);
printf("%s\n", loc);
FILE *f = fopen(loc, “w”);
fprintf(f, “%d”, value);
fclose(f);
}

However, the my question is: how do I get access to linux/gpio.h
It is not on my machine, so my guess is that I need to build the kernel from source, so that I can write kernel modules. Is that right? As I am on Mac OS X as a host, I read that it is very poorly supported on using the openembedded build system. Could I use the beaglebone itself after installing the required dependencies to build the kernel? Do I actually have to build one? I believe that I am somehow on the wrong track as I cannot believe that every programm in the user space rewrites these simple methods as outlined above and in your links.

Markus

2012/3/3 Peter Teoh <htmldeveloper@gmail.com>