- 论坛徽章:
- 0
|
用户空间驱动的mmap映射失败, 本想在mini2440中使用用户空间驱动, 直接操作led灯, 但是mmap失败了,代码如下- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/mman.h>
- volatile unsigned int *map_base=NULL;
- volatile unsigned int *GpbCon =NULL;
- volatile unsigned int *GpbDat =NULL;
- int main()
- {
- int fd,count=0;
- fd = open("/dev/mem",0,O_RDWR|O_SYNC);
- if(fd == -1 ){
- perror("open failed ");
- return -1;
- }
- map_base = (volatile unsigned int *)mmap(NULL,0x9,PROT_READ|PORT_WRITE,MAP_SHARED,fd,0x56000010);
- // 0x56000010 这个是2440的 GPBCON的物理地址
- if(map_base==NULL || map_base ==MAP_FAILED){
- perror("sorry , can't map\n");
- if(map_base ==MAP_FAILED)
- printf("sorry ,MAP_FAILED\n");
- close(fd);
- return -1;
- }else printf("map secessfully \n");
- GpbCon = (volatile unsigned int *)(map_base);
- GpbDat = (volatile unsigned int *)(map_base + 0x4); // GPB
- *GpbCon &= ~(0xff<<10)|0x2<<5*2|0x2<<6*2|0x2<<7*2|0x2<<8*2;
- *GpbDat = 0x0;
- while(1){
- *GpbDat = ~*GpbDat;
- sleep(1000);
- if(count++>5){
- break;
- }
- }
- munmap((void*)map_base,0x9);
- close(fd);
-
- return 0;
- }
复制代码 放到mini2440中报错:
sorry , can't map
Invalid argument
sorry ,MAP_FAILED
什么原因呢? |
|