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

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. 【README.md】Markdown语言常用语法

    转自:http://blog.csdn.net/zhaokaiqiang1992 这里只介绍最常用和最常见的功能,若想查看全部的语法,请移步http://wowubuntu.com/markdown/ ...

  2. codeforces231C

    To Add or Not to Add CodeForces - 231C A piece of paper contains an array of n integers a1, a2, ..., ...

  3. sklearn训练感知器用iris数据集

    简化版代码 from sklearn import datasets import numpy as np #获取data和类标 iris = datasets.load_iris() X = iri ...

  4. 错误代码 0x800700b7 配置错误定义了重复的“system.web.extensions/scripting/scriptResourceHandler”节

    如果是运行VS时就报错,改个端口号就可以解决问题,改完以下两个地方重新运行

  5. Codeforces Round #468 Div. 1

    D:首先考虑如果给定白棋位置,如何判断胜负.黑棋获胜需要四个方向都有能贴上白棋的棋子.由于每一轮都必须移动,显然先对平面黑白染色一下,只有与白棋所在格异色的黑棋才需要考虑.考虑让一个黑棋去贴上白棋某个 ...

  6. CodeForces615A-Bulbs-模拟

    水题 #include <cstdio> #include <algorithm> using namespace std; ]; int main() { scanf(&qu ...

  7. 洛谷3704 [SDOI2017] 数字表格 【莫比乌斯反演】

    题目分析: 比较有意思,但是套路的数学题. 题目要求$ \prod_{i=1}^{n} \prod_{j=1}^{m}Fib(gcd(i,j)) $. 注意到$ gcd(i,j) $有大量重复,采用莫 ...

  8. MT【312】特征根法求数列通项

    (2016清华自招领军计划37题改编) 设数列$\{a_n\}$满足$a_1=5,a_2=13,a_{n+2}=\dfrac{a^2_{n+1}+6^n}{a_n}$则下面不正确的是(      )A ...

  9. MT【245】小概率事件

    (2011年AAA测试)将一枚均匀的硬币连续抛掷$n$次,以$P_n$ 表示未出现连续3次正面的概率.求$\{P_n\}$.并讨论$\{P_n\}$单调性和极限. 分类讨论:第$n$次反面则未出现连续 ...

  10. 【题解】 bzoj2982: combination (Lucas定理)

    题面戳我 Solution 板子题 Code //It is coded by ning_mew on 7.25 #include<bits/stdc++.h> #define LL lo ...