Skip to content

Instantly share code, notes, and snippets.

Created October 11, 2017 19:01
Show Gist options
  • Save anonymous/4c95f066cd0e744468ab9e1133c7f60d to your computer and use it in GitHub Desktop.
Save anonymous/4c95f066cd0e744468ab9e1133c7f60d to your computer and use it in GitHub Desktop.
Odroid XU4 GPA0.2(#173) toggle
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdint.h>
// Toggle GPA0.2
#define ODROIDXU_GPA_BASE 0x14010000
static volatile uint32_t *gpio;
int main(int argc, char **argv)
{
int fd ;
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC) ) < 0) {
printf("Unable to open /dev/mem\n");
return -1;
}
gpio = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, ODROIDXU_GPA_BASE);
if (gpio < 0){
printf("Mmap failed.\n");
return -1;
}
// Print GPA0BASE
//printf("GPA0BASE: 0x%08x\n", (unsigned int)(gpio));
// Set direction of GPA0.2 configuration register as out.
*(gpio + 0) |= (0x1 << 8);
//printf("GPA0CON register : 0x%08x\n", *(unsigned int *)(gpio));
while(1) {
//// GPX1.2 High
*(gpio + 1) |= (0x1 << 2);
//printf("GPA0DAT register : 0x%08x\n", *(unsigned int *)(gpio + 1));
// GPX1.2 Low
*(gpio + 1) &= ~(0x1 << 2);
//printf("GPA0DAT register : 0x%08x\n", *(unsigned int *)(gpio + 1));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment