Gpio programming, Reading temperatures, Reading voltages – ADLINK CM3-GF User Manual
Page 84: 5 gpio programming, 6 reading temperatures, 7 reading voltages

TME-104P-CMx-GF-1V7
Rev 1.7
76 (81)
4.5 GPIO programming
The following sample code for Linux demonstrates how to control the 9 FCH_GPIO pins available on connector
X2. The sample uses FCH_GPIO52. The other GPIOs work the same way.
// Primitive sample for programming the FCH_GPIO pins with Linux:
#include
#include
#include
#include
#include
#include
#define FCH_GPIO 52
//connector X2 pin 2
int main() {
int f = open("/dev/mem", O_RDWR); //must be root
if (f==-1) return 1;
// FCH GPIOs are at 0xFED80100..1FF, but mmap must be 4K
// aligned so we start out lower and add the 0x100 later.
volatile unsigned char *fch_gpio_base = mmap(NULL, 0x200,
PROT_READ|PROT_WRITE, MAP_SHARED, f, 0xFED80000);
close(f); //stays mmaped
if (!fch_gpio_base) return 1;
fch_gpio_base += 0x100; //now we're at 0xFED80100
// Each 8 bit register controls 1 GPIO pin:
// bit 7: read current pin state (r/o)
// bit 6: set output state (only if output)
// bit 5: direction, 0=output, 1=input
// bit 4: pull down resistor, 0=disable, 1=enable
// bit 3: pull up resistor, 0=enable(!), 1=disable
// bits 2-0: ... just set to 0
*(fch_gpio_base+FCH_GPIO) = 0x48; //output, set to 1
*(fch_gpio_base+FCH_GPIO) = 0x08; //output, set to 0
*(fch_gpio_base+FCH_GPIO) = 0x20; //input (with PU)
printf("FCH_GPIO%u = %u\n", FCH_GPIO,
*(fch_gpio_base+FCH_GPIO)>>7);
// With long pointers we could set 8 GPIOs at once.
munmap((void*)fch_gpio_base-0x100, 0x200);
return 0;
}
4.6 Reading Temperatures
Reserved for future revisions of manual
4.7 Reading Voltages
Reserved for future revisions of manual