Created
July 19, 2017 12:16
-
-
Save pho/2043791b862c7540263718b85c6e4625 to your computer and use it in GitHub Desktop.
CHIP Pro PIO Interrupt Debounce Register Clock select
This file contains hidden or 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
/* | |
CHIP Pro PIO Interrupt Debounce Register Clock select | |
https://github.com/NextThingCo/CHIP-Hardware/blob/master/CHIP%5Bv1_0%5D/CHIPv1_0-BOM-Datasheets/Allwinner%20R8%20User%20Manual%20V1.1.pdf | |
Page 342 | |
0: 32kHz | |
1: 24MHz | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/mman.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#define BASE 0x01C20800 | |
#define CLOCKOFFSET 0x218 | |
#define SIZE 0x20 | |
int main(void){ | |
int fd = open("/dev/mem", O_RDWR|O_SYNC); | |
if (fd < 0){ | |
fprintf(stderr, "Unable to open port\n\r"); | |
exit(fd); | |
} | |
// Truncate offset to a multiple of the page size, or mmap will fail. | |
size_t pagesize = sysconf(_SC_PAGE_SIZE); | |
off_t page_base = (BASE / pagesize) * pagesize; | |
off_t page_offset = BASE - page_base; | |
printf("Pagesize: %d\n", sysconf(_SC_PAGE_SIZE)); | |
printf("Pagebase: %d\n", page_base); | |
printf("Pageoffset: %d\n", page_offset); | |
printf("clock addr: %d\n", page_base + page_offset + CLOCKOFFSET); | |
volatile void * pio = mmap(NULL, page_offset + CLOCKOFFSET + SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, page_base); | |
if (pio == MAP_FAILED){ | |
printf("rip\n"); | |
return -1; | |
} | |
volatile unsigned int * clock = pio + page_offset + CLOCKOFFSET; | |
printf("Current clock is: %d\n",*clock); | |
*clock = 1; | |
printf("And now is: %d\n",*clock); | |
munmap((void*)pio, page_offset + CLOCKOFFSET + SIZE); | |
close(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment