博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mmap
阅读量:4285 次
发布时间:2019-05-27

本文共 2604 字,大约阅读时间需要 8 分钟。

1 /*  2  * Configure PCIE   3  */  4   5 #include 
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 17 #define PCIE1_MEM_BASE 0xA0000000 18 #define PCIE1_MEM_SIZE 0x100000 /* 1M bytes*/ 19 #define HOST_INTF_GPIO_OUT_OFFSET "0x4048" 20 #define WLAN_ON "0x00000000" 21 #define WLAN_OFF "0x01000000" 22 23 #define RETURN_FAILED (-1) 24 #define IO_REG32_READ(_reg) (*((volatile unsigned int*) (_reg))) 25 #define IO_REG32_WRITE(_reg, _val) ((*((volatile unsigned int*) (_reg))) = (_val)) 26 27 static void *pcie_base_addr; 28 static int mem_fd; 29 30 static inline void 31 usage (const char *pgname) 32 { 33 printf("Usage:\n"); 34 printf(" %s [on | off | twinkle]\n", pgname); 35 exit(1); 36 } 37 38 /* 39 * Map PCIE base address 40 */ 41 int 42 mmap_io (void) 43 { 44 // mmap CPU register's memory spaces 45 mem_fd = open("/dev/mem", O_RDWR | O_SYNC); 46 if (mem_fd < 0) { 47 printf("open /dev/mem error !\n\r"); 48 return RETURN_FAILED; 49 } 50 51 pcie_base_addr = mmap(0, PCIE1_MEM_SIZE, (PROT_READ | PROT_WRITE), 52 MAP_SHARED, mem_fd, PCIE1_MEM_BASE); 53 54 if (pcie_base_addr == NULL) { 55 printf("mmap error ! \n\r"); 56 return RETURN_FAILED; 57 } 58 59 pcie_base_addr = mmap(0, PCIE1_MEM_SIZE, (PROT_READ | PROT_WRITE), 60 MAP_SHARED, mem_fd, PCIE1_MEM_BASE); 61 62 if (pcie_base_addr == NULL) { 63 printf("mmap error ! \n\r"); 64 close(mem_fd); 65 return RETURN_FAILED; 66 } 67 68 return (int) pcie_base_addr; 69 } 70 71 void 72 wlan_twinkel (void) 73 { 74 printf("todo\n"); 75 exit(1); 76 } 77 78 79 int 80 munmap_io (void) 81 { 82 if(mem_fd < 0) 83 return RETURN_FAILED; 84 85 /* unmap */ 86 if(munmap(pcie_base_addr, PCIE1_MEM_SIZE) < 0) { 87 return RETURN_FAILED; 88 } 89 90 if(close(mem_fd) < 0) { 91 return RETURN_FAILED; 92 } 93 } 94 95 96 int 97 main (int argc, char *argv[]) 98 { 99 unsigned int roffset= 0;100 unsigned int val = 0;101 102 103 if (argc != 2) {104 usage(argv[0]);105 }106 107 /* Map IMMR register base */108 if(mmap_io() < 0 ) {109 return RETURN_FAILED;110 }111 112 switch (argv[1][1]) {113 case 'n':114 roffset = strtoul(HOST_INTF_GPIO_OUT_OFFSET, NULL, 16);115 val = strtoul(WLAN_ON, NULL, 16);116 break;117 case 'f':118 roffset = strtoul(HOST_INTF_GPIO_OUT_OFFSET, NULL, 16);119 val = strtoul(WLAN_OFF, NULL, 16);120 break;121 case 'w':122 wlan_twinkel();123 default:124 usage(argv[0]);125 }126 127 /* Set register value */128 IO_REG32_WRITE((pcie_base_addr+roffset), val);129 130 /* unmap */131 munmap_io();132 133 return 0;134 }

转载地址:http://lxsgi.baihongyu.com/

你可能感兴趣的文章
(文件)输出不使用科学技术法
查看>>
LaTeX 算法代码排版 --latex2e范例总结
查看>>
常用泰勒展开
查看>>
vector length_error
查看>>
Shell脚本处理浮点数的运算和比较实例
查看>>
bash shell for循环1到100
查看>>
latex中长公式换行,很好的办法
查看>>
nohup命令
查看>>
make 操作技巧指南--gcc版本设置
查看>>
sort和sortrows对矩阵排序
查看>>
matlab专区--------------matlab里面如何保留小数特定位数
查看>>
Matlab 绘图坐标轴刻度设置小数位数
查看>>
Matlab 条形图绘制 以及 添加误差棒 改变条形图形状
查看>>
cmake基本用法
查看>>
matlab 增加或减少图例 legend 线的长度
查看>>
matlab:把cell中的某个元素删去
查看>>
matlab 集合运算 交集 并集 差集
查看>>
C++ 给vector去重的三种方法
查看>>
map的详细用法
查看>>
C++初始化函数列表
查看>>