DM8168 GPIO驱动与測试程序
本次測试针对GPIO1进行,挑选了GP1[31],引脚的复用默认的就是GPIO
还是老规矩,贴上driver.c,Makefile,test.c:
dm8168_gpio.c:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/uaccess.h> /* copy_to_user,copy_from_user */
#include <linux/miscdevice.h>
#include <linux/device.h>
#include <asm/io.h> static struct class *gpio_class; volatile unsigned long *DIR;
volatile unsigned long *DAT; int gpio_open (struct inode *inode,struct file *filp) {
*DIR = 0x0; //output
return 0;
} ssize_t gpio_read (struct file *filp, char __user *buf, size_t count,loff_t *f_pos)
{
return 0;
} ssize_t gpio_write (struct file *filp, const char __user *buf, size_t count,loff_t *f_pos)
{
char val_buf[2];
int ret;
ret = copy_from_user(val_buf,buf,count); switch(val_buf[0])
{
case 0x31 :
*DAT = 0xf0000000; //gp1[31]
break;
case 0x30 :
*DAT = 0x0; //gp1[31]
break;
default :
break;
}
return count;
} struct file_operations gpio_fops =
{
.owner = THIS_MODULE,
.open = gpio_open,
.read = gpio_read,
.write = gpio_write,
} ; int major;
int gpio_init (void)
{ major = register_chrdev(0,"DM8168_gpio",&gpio_fops);
gpio_class = class_create(THIS_MODULE, "DM8168_gpio");
device_create(gpio_class,NULL,MKDEV(major,0),NULL,"gpio"); DIR = (volatile unsigned long *)ioremap(0x4804C134,4);
DAT = (volatile unsigned long *)ioremap(0x4804C13C,4); printk ("gpio is ready\n");
return 0;
} void gpio_exit (void)
{
unregister_chrdev(major,"DM8168_gpio");
device_destroy(gpio_class,MKDEV(major,0));
class_destroy(gpio_class); iounmap(DIR);
iounmap(DAT); printk ("module exit\n");
return ;
} MODULE_LICENSE("GPL");
module_init(gpio_init);
module_exit(gpio_exit);
Makefile:
obj-m:= dm8168_gpio.o CROSSCOMPILE := /opt/codesourcery/arm-2009q1/bin/arm-none-linux-gnueabi- CC := $(CROSSCOMPILE)gcc KDIR:=/home/***/ti-ezsdk_dm816x-evm_5_03_01_15/board-support/linux-2.6.37-psp04.00.01.13.patch2 PWD :=$(shell pwd) default:
$(MAKE) -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-
clean:
rm -rf *.ko *.o .*cmd *.mod.c .tmp_versions
gpio_test:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h> int main(int argc, char *argv[])
{
int fd;
int val=0; fd=open("/dev/gpio",O_RDWR); if(fd<0)
{
printf("open device failed !\n");
exit(1);
}
else
{
printf("open success ! \n");
} write(fd,argv[1],1); close(fd);
return 0;
}
測试 :
模块编译后载入:insmod dm8168_gpio.ko
交叉编译測试程序:arm-none-linux-gnueabi-gcc -o gpio_test gpio_test.c
执行:./gpio_test 1
GP1[31]为3.3V
执行:./gpio_test 0
GP1[31]为0V
DM8168 GPIO驱动与測试程序的更多相关文章
- DM8168 PWM驱动与測试程序
昨天把DM8168的Timer设置给摸了一遍,为写PWM的底层驱动做好了准备,如今就要进入主题了. dm8168_pwm.c: #include <linux/module.h> #inc ...
- mini2440驱动奇谭——ADC驱动与測试(动态挂载驱动)
博客:http://blog.csdn.net/muyang_ren 实现功能:开发板动态载入adc驱动模块并能通过測试程序 系统:Ubuntu 14.04 驱动交叉编译内核:linux-2. ...
- DLL程序的创建步骤和測试程序
首先,创建DLL程序 然后,加入一个导出类 比如: //Test.h #pragma once class AFX_EXT_CLASS Test { public: Test(void); ~Te ...
- H264解码的一个測试程序
网上看到的一个H264视频格式的解码測试程序,能够用来參考其逻辑流程. 代码例如以下: Test_Display_H264(){ in_fd = open(H264_INPUT_FILE, ...
- spark0.9.1集群模式执行graphx測试程序(LiveJournalPageRank,新增Connected Components)
spark最新版公布了.之前的版本号就已经集成了graphx,这个版本号还改了一些bug. 我做了简单測试,只是网上关于集群模式执行spark资料太少了,仅仅有关于EC2(见參考资料1)的.可是还非常 ...
- 自己主动化測试程序之中的一个自己定义键盘的模拟測试程序(C语言)
一.測试程序编写说明 我们做的终端设备上运行的是QT应用程序.使用自己定义的键盘接口.经过測试人员长时间的人机交互測试,来确认系统的功能是否满足需求. 如今须要编写一个自己主动化的測试程序,能够依照预 ...
- S3C6410+FPGA+2*RTL8211 驱动 iperf測试
驱动也写的差点儿相同了,所以有必要測试下性能怎样?本次採用了iperf进行測试.而且对照了下s3c6410+ks8851的測试结果 1.iperf怎样交叉编译? https://iperf.fr/ 官 ...
- 一个Nodejs的简单计算測试程序
測试目的: 1 測试二维数组的使用 2 输出函数的使用 代码: var util = require('util'); a = 3; b = 4; c = a + b; a = []; for(i = ...
- Android JNI用于驱动測试
硬件平台:S3C6410 操作系统:Ubuntu.windows 板子系统:Android 开发工具:jdk.ndk,eclipse 本次測试从linux内核模块编译開始.以S3C6410的pwm驱动 ...
随机推荐
- RecordSet .CacheSize, Properties,CurserType,PageSize
使用 CacheSize 属性可以控制一次要从提供者那里将多少个记录检索到本地内存中.例如,如果 CacheSize 为 10,首次打开 Recordset 对象后,提供者将把前 10 个记录检索到本 ...
- jq实现瀑布流效果
<!doctype html><html><head><meta http-equiv="Content-Type" content=&q ...
- StartSSL免费SSL证书成功申请-HTTPS让访问网站更安全
StartSSL免费SSL证书成功申请-HTTPS让访问网站更安全 一.StartSSL个人证书登录申请 1.StartSSL官网: 1.官方首页:http://www.startssl.com/ 2 ...
- BZOJ 1854 游戏
Description lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有\(2\)个属性,这些属性的值用\([1,10000]\)之间的数表示.当他使用某种装备时,他只能使用该 ...
- KeilC51使用详解 (二)
深入理解并应用C51对标准ANSIC的扩展是学习C51的关键之一.因为大多数扩展功能都是直接针对8051系列CPU硬件的.大致有以下8类: 8051存储类型及存储区域 存储模式 存储器类型声明 变量类 ...
- solr异常--Expected mime type application/octet-stream but got text/html.
Exception in thread "main" org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrExce ...
- mysql中的timestamp类型时间比较:unix_timestamp函数
在mysql中,某字段的类型设置为了timestamp,那么我们现在希望取出指定时间段的记录,该如何做呢? 在php中有time()和strtotime()来进行日期和时间戳的格式化,而在mysql中 ...
- 【游戏框架】Phaser
PhaserDesktop and Mobile HTML5 game framework Phaser Examples
- unity3d Human skin real time rendering with blood and water drop effect真实模拟人皮实时渲染之血液和水珠掉落效果
在之前的一篇(链接在此)文章中写了下关于真实模拟皮肤渲染,在此基础之上又想加上血液效果,在洗澡的时候(= =:)又想在skin上加上水珠的效果,所以研究了下,做出来效果感觉还不错,放下效果图: 水珠 ...
- 【转】关于 Endnote 与 Word 卡死问题 标记语法错误
转自:http://hi.baidu.com/lvneng/item/8147dcbb1436bfd085dd7962 当使用 Word 写论文或稿件时,Endnote 绝对是一个不错的帮手,不过偶尔 ...