Skip to content

Instantly share code, notes, and snippets.

@donghee
Forked from anonymous/main.c
Last active October 12, 2017 00:21
Show Gist options
  • Save donghee/ea679308b527a12d4b2bc12c5b8b238e to your computer and use it in GitHub Desktop.
Save donghee/ea679308b527a12d4b2bc12c5b8b238e to your computer and use it in GitHub Desktop.
Odroid XU4 GPA0.2(#173) toggle/ does not working. todo: fix error
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdint.h>
// Toggle GPA0.2
// Pinmap http://odroid.com/dokuwiki/doku.php?id=en:xu4_shift_shield
#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) {
//// GPA0.2 High
*(gpio + 1) |= (0x1 << 2);
//printf("GPA0DAT register : 0x%08x\n", *(unsigned int *)(gpio + 1));
// GPA0.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