#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <errno.h>
#include <unistd.h>
#define aa errno
#define OFF_GPIOH (0x0837)
#define PWR_TFT_BIT (2)
char buf[100];
void *trymmap (void *start, size_t length, int prot, int flags, int fd, off_t offset)
{
char *p;
int aa;
sprintf (buf,"mmap(%X, %X, %X, %X, %X, %X) ... ", (unsigned int)start, length, prot, flags, fd, (unsigned int)offset);
printf (buf);
p = mmap (start, length, prot, flags, fd, offset);
if (p == (char *)0xFFFFFFFF)
sprintf (buf,"failed. errno = %d\n", aa);
else
sprintf (buf,"OK! (%X)\n", (unsigned int)p);
return (void *)p;
}
int main(int argc, char **argv)
{
int i;
int memfd;
unsigned short tfton, tftoff;
unsigned short *mmCpuRegisters;
/* Small initial delay, to let everything settle */
for (i=0;i<100000;i++);
memfd = open("/dev/mem", O_RDWR);
if (memfd == -1)
{
printf ("/dev/mem open failed\n");
return 0;
}
sprintf (buf,"/dev/mem opened successfully - fd = %d\n", memfd);
printf (buf);
mmCpuRegisters = (unsigned short *)trymmap(0, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, 0xc0000000);
if (mmCpuRegisters == (unsigned short *)0xFFFFFFFF)
{
printf ("Failed to map CPU registers\n");
return 1;
}
tfton = mmCpuRegisters[OFF_GPIOH] | (1<<PWR_TFT_BIT);
tftoff = tfton & (~(1<<PWR_TFT_BIT));
// mmCpuRegisters[OFF_GPIOH] = tfton;
mmCpuRegisters[OFF_GPIOH] = tftoff;
return 0;
}