-
-
Save piranha32/4fd285cc8333eeb4ec39 to your computer and use it in GitHub Desktop.
mmapped GPIO test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* memmapped_oe_test.c | |
* | |
* Created on: Jun 11, 2013 | |
* Author: jacek | |
* Compile the code: | |
* gcc memmapped_oe_test.c -o memmapped_oe_test -std=c99 | |
*/ | |
#include <stdint.h> | |
#include <unistd.h> | |
#include <sys/mman.h> | |
#include <fcntl.h> | |
#include <stdio.h> | |
#define DATA_OUT_REG 0x13C | |
#define DATA_IN_REG 0x138 | |
#define GPIO_OE_REG 0x134 | |
int main() | |
{ | |
const uint32_t gpioAddrs[] = | |
{ 0x44E07000, 0x4804C000, 0x481AC000, 0x481AE000 }; | |
uint32_t *gpios[4]; | |
int gpioFd; | |
gpioFd = open("/dev/mem", O_RDWR | O_SYNC); | |
for (int i = 0; i < 4; i++) | |
{ | |
gpios[i] = (uint32_t *) mmap(NULL, 0xfff, | |
PROT_READ | PROT_WRITE, MAP_SHARED, gpioFd, gpioAddrs[i]); | |
printf("gpio[%i] at address 0x%08x mapped at 0x%08x\n",i,gpioAddrs[i],gpios[i]); | |
} | |
int i; | |
i=0; //Bus error | |
//i=1; //OK | |
//i=2; //Bus error | |
//i=3; //Bus error | |
printf("i=%i\n",i); | |
printf("OUT[%i]=0x%08x\n",i,gpios[i][DATA_OUT_REG/4]); | |
printf("IN[%i]=0x%08x\n",i,gpios[i][DATA_IN_REG/4]); | |
printf("OE[%i]=0x%08x\n",i,gpios[i][GPIO_OE_REG/4]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment