⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 复件 gpio_test.c

📁 利用开发板上的/dev/mem设备,进行内存映射,驱动cpu的GPIO口,点亮和熄灭led灯.附makefile文件
💻 C
字号:
//ppc编译方法:/eldk/usr/ppc-linux/bin/gcc -o gpio_test.exe gpio_test.c//ppc编译方法:${CROSS_COMPILE}gcc -o gpio_test.exe gpio_test.c/***************************************************************************FileName:	gpio_test.c				copyright:	富通科技WriteDate:	2007-02-06				AUTHOR:		陆冲之Version:	0.1						Last Modify:2007-02-06Content:	这里放置了CLI_Menu的函数***************************************************************************///#include <common.h>
//#include <exports.h>//#include <common.h>			/*include目录下*/
//#include <command.h>		/*include目录下*/
//#include <asm/processor.h>	/*include/asm-ppc目录下??*/
//#include <spi.h>			/*include目录下*/////#include "gpio.h"//#include <asm/types.h>//#include <asm/io.h>#define __KERNEL__//#define CONFIG_4xx//#include <ppc4xx.h>//#include <common.h>
//#include <command.h>
//#include <asm/io.h>


#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>

/*********************************************************************************Func Name	:int main(int argc, char* argv[])Content		:测试GPIOIn  Param	:argc	:输入参数个数量Out Param	:argv	:输入参数值数组return		:0		:正常返回			 其它	:参看程序Write Date	:2007-02-06							AUTHOR	:陆冲之Last Modify	:2007-02-06return to   :NONE********************************************************************************/#define GPIO_REGISTER unsigned intint main(int argc, char* argv[]){		int fd;	char dev_name[] = "/dev/mem";	char *start;	printf("test 7\n");	//printf("%u\n",offset);	fd = open(dev_name,O_RDWR);	if(fd<0)	{		printf("open %s is error\n",dev_name);		return -1 ;	}	start = mmap( NULL, 4, PROT_READ|PROT_WRITE, MAP_SHARED,fd, 0xEF600700/getpagesize());	if(start==NULL || start==MAP_FAILED)	{		printf("gpio base mmap is error\n");		munmap(start,4); /*解除映射*/		close(fd);		return -1;	}	//*gpio_base  = (*gpio_base & ~0x00000002);	printf("%u\n",start);	munmap(start,4); /*解除映射*/	close(fd);	//unsigned int *p = (unsigned int*)ioremap(0xEF600700, 4);	//unsigned int data = readl(0xEF600700);	//writew((data&= ~0x00000002) ,0xEF600700);	//unsigned int add=ioremap(0xEF600700,4); 
	//printk("<1>ioremap 0x%x\n",add); 	/*unsigned int *p;
	unsigned int data;	p = (int *)0xEF600700;	data = *p;	printf("%u",data);	printf("hello,world!\n");	*p &= ~0x00000002;*/	//out32(GPIO0_OR, in32(GPIO0_OR) & ~0x00000002);	//*(volatile ulong *)GPIO0_OR &= ~0x00000002;	return 0;}

⌨️ 快捷键说明

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