Linux kernel documentation here.
Using MMap
void TurnOnLED ()
{
int fd = open("/dev/mem", O_RDWR);
volatile ulong *A;
if (fd < 0)
{
printf("Could not open /dev/mem\n");
return;
}
A = (ulong*) mmap(NULL, 0x10000, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0x49050000);
if (A == MAP_FAILED)
{
printf("Mapping IO failed\n");
close(fd);
return;
}
A[0x603C / 4] |= 0x600000;
munmap(A, 0x10000);
close (fd);
}
the use of "volatile" tells the compiler that each use of the variable A in the program must result in an actual load or store instruction.
Using sysfs
#Export the led pin:
echo 139 > /sys/class/gpio/export
for i in `seq 1 10`;
do
#Turn on the led
echo "high" > /sys/class/gpio/gpio139/direction
sleep 1
#Turn off the led
echo "low" > /sys/class/gpio/gpio139/direction
sleep 1
done
#unexport the led pin
echo 139 > /sys/class/gpio/unexport
calculating the pin io instruction can be found in the following video:
אין תגובות:
הוסף רשומת תגובה