- 论坛徽章:
- 0
|
#include stdio.h>
#include stdlib.h>
#include fcntl.h>
#include unistd.h>
#include string.h>
#include sys/time.h>/*settimeofday,gettimeofday,tm time_t结构体*/
#include linux/kd.h>
#include memory.h>
#include sys/ioctl.h>
#include sys/mman.h>
void Sleep(int iSec,int iUSec)
{
struct timeval tv;
tv.tv_sec = iSec;
tv.tv_usec = iUSec;
select(0,NULL,NULL,NULL,&tv);
}
int main()
{
int fd_mem, i;
unsigned int map_base;
if ((fd_mem = open("/dev/mem", O_RDWR | O_SYNC)) == -1) {
perror("/dev/mem");
return 1;
}
map_base = (unsigned int)
mmap(0, 256 * 12, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, 0xfffff000);
*(volatile unsigned int *)(map_base + 512*2) = 0x18;
*(volatile unsigned int *)(map_base + 512*2 + 0x10) = 0x18;
*(volatile unsigned int *)(map_base + 512*2 + 0x30) = 0x18;
*(volatile unsigned int *)(map_base + 512*3) = 0x129;
*(volatile unsigned int *)(map_base + 512*3 + 0x10) = 0x129;
*(volatile unsigned int *)(map_base + 512*3 + 0x30) = 0x129;
for(i=0;i5;i++) {
*(volatile unsigned int *)(map_base + 512*2 + 0x30) = 0x18;
*(volatile unsigned int *)(map_base + 512*3 + 0x30) = 0x129;
printf("PB8 eable=%x out status=%x %x\n",
*(volatile unsigned int *)(map_base + 512*3 + 0x08),
*(volatile unsigned int *)(map_base + 512*3 + 0x18),
*(volatile unsigned int *)(map_base + 512*3 + 0x38));
Sleep(0,500000);
*(volatile unsigned int *)(map_base + 512*2 + 0x34) = 0x18;
*(volatile unsigned int *)(map_base + 512*3 + 0x34) = 0x129;
printf("PB8 eable=%x out status=%x %x\n",
*(volatile unsigned int *)(map_base + 512*3 + 0x08),
*(volatile unsigned int *)(map_base + 512*3 + 0x18),
*(volatile unsigned int *)(map_base + 512*3 + 0x38));
Sleep(0,500000);
}
close(fd_mem);
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/43090/showart_2069482.html |
|