判断哪些文件被编译进内核:

1、通过 make menuconfig 查看

2、比如查看gpio类型的文件,输入 ls drivers/gpio/*.o,有生成.o文件表示被编译进内核

在编写驱动程序之前要保证该GPIO口没有被其他程序占用,若被占用则需要取消编译那个驱动程序。

/arch/arm/mach-exynos/include/mach/gpio-exynos4.h

/drivers/gpio/gpio-exynos4.c

#include <linux/init.h>
#include <linux/module.h> /*驱动注册的头文件,包含驱动的结构体和注册和卸载的函数*/
#include <linux/platform_device.h>
/*注册杂项设备头文件*/
#include <linux/miscdevice.h>
/*注册设备节点的文件结构体*/
#include <linux/fs.h> /*Linux中申请GPIO的头文件*/
#include <linux/gpio.h>
/*三星平台的GPIO配置函数头文件*/
/*三星平台EXYNOS系列平台,GPIO配置参数宏定义头文件*/
#include <plat/gpio-cfg.h>
#include <mach/gpio.h>
/*三星平台4412平台,GPIO宏定义头文件*/
#include <mach/gpio-exynos4.h> #define DRIVER_NAME "hello_ctl"
#define DEVICE_NAME "hello_ctl" MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("TOPEET"); static long hello_ioctl( struct file *files, unsigned int cmd, unsigned long arg){
printk("cmd is %d,arg is %d\n",cmd,arg); if(cmd > ){
printk(KERN_EMERG "cmd is 0 or 1\n");
}
if(arg > ){
printk(KERN_EMERG "arg is only 1\n");
} gpio_set_value(EXYNOS4_GPL2(),cmd); return ;
} static int hello_release(struct inode *inode, struct file *file){
printk(KERN_EMERG "hello release\n");
return ;
} static int hello_open(struct inode *inode, struct file *file){
printk(KERN_EMERG "hello open\n");
return ;
} static struct file_operations hello_ops = {
.owner = THIS_MODULE,
.open = hello_open,
.release = hello_release,
.unlocked_ioctl = hello_ioctl,
}; static struct miscdevice hello_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &hello_ops,
}; static int hello_probe(struct platform_device *pdv){
int ret; printk(KERN_EMERG "\tinitialized\n"); ret = gpio_request(EXYNOS4_GPL2(),"LEDS");
if(ret < ){
printk(KERN_EMERG "gpio_request EXYNOS4_GPL2(0) failed!\n");
return ret;
} s3c_gpio_cfgpin(EXYNOS4_GPL2(),S3C_GPIO_OUTPUT); gpio_set_value(EXYNOS4_GPL2(),); misc_register(&hello_dev); return ;
} static int hello_remove(struct platform_device *pdv){ printk(KERN_EMERG "\tremove\n");
misc_deregister(&hello_dev);
return ;
} static void hello_shutdown(struct platform_device *pdv){ ;
} static int hello_suspend(struct platform_device *pdv,pm_message_t pmt){ return ;
} static int hello_resume(struct platform_device *pdv){ return ;
} struct platform_driver hello_driver = {
.probe = hello_probe,
.remove = hello_remove,
.shutdown = hello_shutdown,
.suspend = hello_suspend,
.resume = hello_resume,
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
}
}; static int hello_init(void)
{
int DriverState; printk(KERN_EMERG "HELLO WORLD enter!\n");
DriverState = platform_driver_register(&hello_driver); printk(KERN_EMERG "\tDriverState is %d\n",DriverState);
return ;
} static void hello_exit(void)
{
printk(KERN_EMERG "HELLO WORLD exit!\n"); platform_driver_unregister(&hello_driver);
} module_init(hello_init);
module_exit(hello_exit);

linux driver ------ GPIO的驱动编写和调用的更多相关文章

  1. linux driver ------ 字符设备驱动 之 “ 创建设备节点流程 ”

    在字符设备驱动开发的入门教程中,最常见的就是用device_create()函数来创建设备节点了,但是在之后阅读内核源码的过程中却很少见device_create()的踪影了,取而代之的是device ...

  2. linux driver error ------ 编译驱动出现 ERROR: Kernel configuration is invalid

       ERROR: Kernel configuration is invalid.         include/generated/autoconf.h or include/config/au ...

  3. 树莓派GPIO口驱动编写

    一.wiringpi写法 #include <wiringPi.h> #include <stdlib.h> int main(int argc,char *argv[]) { ...

  4. 如何编写linux下nand flash驱动-4

    2.       软件方面 如果想要在Linux下编写Nand Flash驱动,那么就先要搞清楚Linux下,关于此部分的整个框架.弄明白,系统是如何管理你的nand flash的,以及,系统都帮你做 ...

  5. nand flash详解及驱动编写

    https://www.crifan.com/files/doc/docbook/linux_nand_driver/release/html/linux_nand_driver.html#nand_ ...

  6. Linux驱动:I2C驱动编写要点

    继续上一篇博文没讲完的内容“针对 RepStart 型i2c设备的驱动模型”,其中涉及的内容有:i2c_client 的注册.i2c_driver 的注册.驱动程序的编写. 一.i2c 设备的注册分析 ...

  7. ARM Linux驱动篇 学习温度传感器ds18b20的驱动编写过程

    ARM Linux驱动篇 学习温度传感器ds18b20的驱动编写过程 原文地址:http://www.cnblogs.com/NickQ/p/9026545.html 一.开发板与ds18b20的入门 ...

  8. Linux GPIO键盘驱动开发记录_OMAPL138

    Linux GPIO键盘驱动开发记录_OMAPL138 Linux基本配置完毕了,这几天开始着手Linux驱动的开发,从一个最简单的键盘驱动开始,逐步的了解开发驱动的过程有哪些.看了一下Linux3. ...

  9. 调试exynos4412—ARM嵌入式Linux—LEDS/GPIO驱动之二

    /** ****************************************************************************** * @author    暴走的小 ...

随机推荐

  1. Lodop打印设计矩形重合预览线条变粗

    LODOP中的打印设计是辅助进行开发的,实际打印效果应以预览为准,很多效果都是在设计界面显示不出来,或设计和预览界面有差异.例如add_print_text文本的字间距.行间距,旋转,还有允许标点溢出 ...

  2. C# 获取文件详细备注信息 (如图片、视频实际创建时间)

    在整理照片/视频时想根据实际拍摄时间重命名文件,但 System.IO.FileInfo 只能获取到文件的创建时间或最后写入时间,不符合要求,遂寻找解决方案 方案 1: System.Drawing ...

  3. Nintex Workflow Get Attachment link

    不多解释,直接上图,操作简单

  4. Nginx 阻塞与非阻塞

    L:32

  5. Nginx proxy_protocol协议

    L:113

  6. 洛谷 P1484 种树

    题目描述 cyrcyr今天在种树,他在一条直线上挖了n个坑.这n个坑都可以种树,但为了保证每一棵树都有充足的养料,cyrcyr不会在相邻的两个坑中种树.而且由于cyrcyr的树种不够,他至多会种k棵树 ...

  7. python数据类型知识整理

    python数据类型种类 int数字.bool布尔值.dict字典.tunple元组.set集合.list列表.字符串 int数字 #常用来进制转换 num = 11 #转化成2进制 bin_num ...

  8. BZOJ1565[NOI2009]植物大战僵尸——最大权闭合子图+拓扑排序

    题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻.该款游戏包含多 ...

  9. Phone List HDU - 1671 字典树

    题意:给出一堆一组一组的数字  判断有没有哪一个是另外一个的前缀 思路:字典树 插入的同时进行判断  不过 当处理一组数字的时候 需要考虑的有两点1.是否包含了其他的序列2.是否被其他序列包含 刚开始 ...

  10. Machine Schedule POJ - 1325(水归类建边)

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17457   Accepted: 7328 ...