Zepan / lichee-pi-zero

Lichee Zero: An SD-Size (breadboard-compatible) Cortex-A7 Board

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Direct acess memmory

beetlea opened this issue · comments

Hi. I'm trying to go straight to the registers, but nothing works. What am I doing wrong ??

#include <sys/mman.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>

int main(){
printf("new program");
char dev_name[] = "/dev/mem";
int gpio_base;
int fd = open(dev_name, O_RDWR|O_SYNC);
if(fd<0){
printf("open %s is error\n",dev_name);
return -1 ;
}
int sz = getpagesize();
printf("\ngetsize = %u\n", sz);
printf("str = %x ",(0x1c208d8/sz) * sz);
volatile unsigned int str = (0x1c208d8/sz) * sz;
/

unsigned char buf[100];
lseek(fd, 0, SEEK_SET);
lseek(fd, 0x1c208d8, SEEK_SET);
read(fd, buf,1000000);
*/
for(int i = 0; i < 200; i+=1)
{
/*if ((int)(buf[i] <<3| buf[i+ 1] <<2| buf[i+2] << 1| buf[i +4]) == 0x7$
{
printf("ok");
}
*/
printf("\n %x \n", gpio_base[i]);
}

////*gpio_base_out &=0xfffffff8;
////*gpio_base_out = 1;
int mum = munmap(gpio_base, 0x32);
if (mum== 0)
{
printf("\nOK\n");
}
else
{
printf("\nNO OK \n");
}

if(gpio_base == NULL){
printf("gpio base mmap is error\n");
close(fd);
return -1;
}

return 0;

}