Accessing user space from C code

What is the appropriate manner in which to access and change pins exposed through the sysfs in compiled code?
ie: change PWM parameters in C

Example Configuration:
Following example shows steps to configure the PWM for 100 HZ with 50% duty cycle.

target$ echo 1 >  /sys/class/pwm/ehrpwm.2:0/request
target$ echo 100 > /sys/class/pwm/ehrpwm.2:0/period_freq
target$ echo 50 > /sys/class/pwm/ehrpwm.2:0/duty_percent
target$ echo 1 > /sys/class/pwm/ehrpwm.2:0/run

Based on further investigations I’ve found some information regarding this.

Kernel maintainers seem to object to the idea of direct reads and writes…which I seem to agree with. Doesn’t seem like a reliable production technique.
http://www.mjmwired.net/kernel/Documentation/sysfs-rules.txt

This library based on the udev utilities seems like the most robust and reasonable way to go about things.
http://www.freedesktop.org/software/systemd/libudev/

I’m used to embedded micro controllers without OS overhead. How is this done under Linux?

Steve wrote:

What is the appropriate manner in which to access and change pins exposed through the sysfs in compiled code?
ie: change PWM parameters in C

open(), write(), close()

+1

system()

This code will print out the proper pin configuration, but I can’t change it.

MemMapAddressContMod = (volatile uint32_t *) mmap(NULL, CONT_MOD_REG_LENGTH,
PROT_WRITE, MAP_SHARED, MemoryFileDescriptor, CONT_MOD_REG_START);
if (MemMapAddressContMod == (volatile uint32_t *) MAP_FAILED) {
perror(“mmap failed for Control Module Registers”);
close(MemoryFileDescriptor);
return 1;
}
//Set Port 9 Pin 14 to ehrpwm1A_mux1
MemMapAddressContMod[CONF_GPMC_A2_OFFSET / sizeof(uint32_t)] = 0x6;
fprintf (stderr,“mmap of mux %d\n”,MemMapAddressContMod[CONF_GPMC_A2_OFFSET / sizeof(uint32_t)]);

If I…

echo “any number” > /sys/kernel/debug/omap_mux/gpmc_a2

the code will fprintf the new value

this code is borrowed from here
https://groups.google.com/forum/?fromgroups#!searchin/beagleboard/mux$20pwm$20/beagleboard/p7LmXqIpTNk/13sey5a9dtIJ