ledtest.c

来自「Linux Device Driver 3 的例子程序」· C语言 代码 · 共 39 行

C
39
字号

#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h>
#include <fcntl.h>
#include <string.h>

#include <unistd.h>
#include <sys/stat.h>
#include <sys/ioctl.h>


#include <sys/mman.h>

#define LED_SIZE 0x200
//#define LED_PORT (*(volatile unsigned*)0x80000000)
#define LED_PORT	0x80000000

unsigned int *led_ptr;
int fd;

int main(int argc, char *argv[])
{
	fd=open("/dev/mem",O_RDWR);
//	led_ptr= mmap(NULL, LED_SIZE, PROT_WRITE, MAP_SHARED, fd, LED_PORT);

	led_ptr= mmap(NULL, LED_SIZE, PROT_WRITE, MAP_SHARED, fd, LED_PORT);
	printf("buffer address 0x%x \n",led_ptr+0x100);                                
     //printf("buffer data <%s> \n",p); 
//	close(fd);

//	*((volatile unsigned *)(led_ptr+0x100)) = 0xff;
	write(0xaa,led_ptr+0x100,1);
    	printf("buffer data <%x> \n",*(led_ptr+0x100)); 
	close(fd);
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?