I am trying to learn expansion header configuration of a processor on this instruction http://41j.com/blog/2011/09/beagleboard-gpio-input-driverless/
I have a part that I could not understand
volatile ulong *pinconf;
pinconf = (ulong*) mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x48000000);
pinconf[0x2168/4] = 0x001C001C;
Can anyone explain how does the pinconf array works? what value does it store?
Edit: What I really could not understand what does pinconf[0x2168/4] mean. is it an hexadecimal array and what value does it refer to?
I’m the original blog/code author, here’s what I meant:
To answer your main point, pinconf[0x2168/4] refers to the address 0x48002168. The pinconf array starts at the address 0x48000000. It’s been defined as a ulong [1], which on ARM processors is 4 bytes. I know I want to access the address pinconf+0x2168. To convert the address 0x2168 into an index in pinconf I need to divide by 4.
Walking through the code from the start:
pinconf is defined as a ulong (32bit int) pointer. It’s defined as volatile, this means that something outside of our code may change its value. It tells the compiler that every time we use that value we need to read it from memory, this stops the compiler doing clever optimisations that may screw things up.
This sets pinconf to point to the address 0x48000000. Normally you could do something like:
To make pinconf point to an address, but this won’t work. 0x48000000 is a protected address, it’s only accessible by the kernel. The mmap magic gives you a way to access the address from userspace.
We’ve covered this already, but this is writing a value to the address: 0x48000000+0x2168. The value 0x48002168 comes from the OMAP3 datasheets, and is used to do memory mapped IO with the GPIO system. We divide by 4 to convert the address 0x2168 to an index in pinconf.
[1] I should probably have used a uint32_t to be honest.