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

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. Java调用.NET 的Web Service服务故障排除

    参考路径:http://blog.sina.com.cn/s/blog_4c925dca01014y3r.html

  2. Vasya and a Tree CodeForces - 1076E(线段树+dfs)

    I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个 ...

  3. JarvisOJ Basic Base64?

    GUYDIMZVGQ2DMN3CGRQTONJXGM3TINLGG42DGMZXGM3TINLGGY4DGNBXGYZTGNLGGY3DGNBWMU3WI=== 题目非常具有迷惑性,我一开始以为就是一 ...

  4. fastjson 操作

    1.String 转 bean String addition = ...; CoffeeFormula formula = JSON.parseObject(addition, new TypeRe ...

  5. python之旅七【第七篇】面向对象之类成员

    面向对象的类成员 相关知识点 一  字段 字段包括:普通字段和静态字段,他们在定义和使用中有所区别,而最本质的区别是内存中保存的位置不同, 普通字段属于对象 静态字段属于类 class Provinc ...

  6. [WC2018]即时战略——动态点分治(替罪羊式点分树)

    题目链接: [WC2018]即时战略 题目大意:给一棵结构未知的树,初始时除1号点其他点都是黑色,1号点是白色,每次你可以询问一条起点为白色终点任意的路径,交互库会自动返回给你这条路径上与起点相邻的节 ...

  7. Power Network POJ - 1459 网络流 DInic 模板

    #include<cstring> #include<cstdio> #define FOR(i,f_start,f_end) for(int i=f_startl;i< ...

  8. [AHOI2008]紧急集合 / 聚会

    题目描述 欢乐岛上有个非常好玩的游戏,叫做“紧急集合”.在岛上分散有N个等待点,有N-1条道路连接着它们,每一条道路都连接某两个等待点,且通过这些道路可以走遍所有的等待点,通过道路从一个点到另一个点要 ...

  9. 白兔的刁难 IDFT

    题目描述 给你\(n,k\),求 \[ \forall 0\leq t< k,s_t=\sum_{i=-t}^{n-t}[k|i]\binom{n}{i+t} \] 对\(998244353\) ...

  10. rsync服务部署

    构建rsync远程同步----------同步源----------------发起端-------------192.168.1.1 192.168.1.101.配置IP地址并保证互通2.确定备份源 ...