-
Notifications
You must be signed in to change notification settings - Fork 5
/
regs_bit_clr.c
61 lines (56 loc) · 1.19 KB
/
regs_bit_clr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<string.h>
#include<unistd.h>
#include<sys/mman.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include "ls1c_regs.h"
uint32_t hextol(char * str) {
uint8_t i=0,l;
uint32_t ret=0;
l=strlen(str);
for(i=0;i<l;i++) str[i]=str[i]|0x20; //'A-Z' to 'a-z'
for(i=2;i<l;i++){
ret=(ret<<4);
if(str[i]>'9') ret|=(str[i]-'a'+10);
else ret|=(str[i]&0xf);
}
return ret;
}
int main(int argc, char *argv[])
{
uint32_t * map_base;
FILE *f;
int n, fd;
uint32_t addr_base;
uint16_t addr_offset;
uint8_t dat;
if(argc!=3) {
printf("regs_bit_clr 0x1fd011c0 0 \r\n");
return (-2);
}
addr_base=hextol(argv[1]);
addr_offset=addr_base&0xfff;
addr_base=addr_base&0xfffff000;
dat=atoi(argv[2]);
if(dat>=32) {
printf("bit < 32 \r\n");
return(-3);
}
fd = open("/dev/mem", O_RDWR|O_SYNC);
if (fd == -1) {
return (-1);
}
/* 把xxxxx000开始0x1000字节,映射到map_base */
map_base = mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, addr_base);
if (map_base == 0) {
printf("NULL pointer!\n");
}
map_base[addr_offset/sizeof(uint32_t)]&=~(1 << dat);
close(fd);
munmap(map_base, 0xff);
return (dat);
}