我写的第一个LED驱动的心得
来源:互联网 发布:程序员经典面试题 编辑:程序博客网 时间:2024/05/16 02:03
利用两天的时间,终于写成功了第一个LED驱动,对于一个新手来说,我很兴奋.
下面说一下我的心得
一 首先要在你的宿主机上建立起一个和你的目标机一样的内核环境.
1 先拿到目标机上运行的内核的源代碼
2 读取目标机的内核源代碼的.config文件,这是你的内核设置的文件,用他来建立和目标机一样的内核环境.
3 make zImage
二 写Makefile
__________________________________________________________________________
CC=arm-linux-gcc
LD=arm-linux-ld
KER_INC := /root/s3c2410/DISK4/linux2.4/2.4.18-rmk7/include
LIB_INC := /usr/local/arm/2.95.3/lib/gcc-lib/arm-linux/2.95.3/include/
CFLAGS := -O -s -Wall -D__GNUC__=3 -DMODULE -D__KERNEL__ -march=armv4 -nostdinc -I- -I. -I$(KER_INC) -idirafter $(LIB_INC)
all: led.o
led.o: led_driver.c
@echo
@echo --------------------------------------------------
@echo - Build led
@echo --------------------------------------------------
$(CC) $(CFLAGS) -c led_driver.c
clean:
rm -f *.o
_____________________________________________________________________________
KER_INC:是你的内核的库
LIB_INC:是你的编译器的库
最好使用编译内核的编译器,这样不容易出问题
三 写驱动文件
——————————————————————————————————————
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include<asm-arm/arch/S3C2410.h>
#include<linux/fs.h>
#include<linux/module.h>
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/devfs_fs_kernel.h>
MODULE_LICENSE("GPL");
int led_open(struct inode *,struct file *);
int led_ctl(struct inode *,struct file *,unsigned int command,unsigned long arg);
struct file_operations led_ctl_fops=
{
open:led_open,
ioctl:led_ctl,
};
int led_open(struct inode * a ,struct file * b)
{
//your core
return 0;
}
int led_ctl(struct inode * a,struct file * n,unsigned int command,unsigned long arg)
{
//your core
return 0;
}
int init_led(void)
{
//your core
return 0;
}
void cleanup_led(void)
{
//your core
}
module_init(init_led);
module_exit(cleanup_led);
——————————————————————————————————————
四 感谢
这次主要感谢我的连接里的两位兄弟给了我很大的支持.
他们的BLOG里有好多有用的东西,朋友们有时间可以去看看.
下面说一下我的心得
一 首先要在你的宿主机上建立起一个和你的目标机一样的内核环境.
1 先拿到目标机上运行的内核的源代碼
2 读取目标机的内核源代碼的.config文件,这是你的内核设置的文件,用他来建立和目标机一样的内核环境.
3 make zImage
二 写Makefile
__________________________________________________________________________
CC=arm-linux-gcc
LD=arm-linux-ld
KER_INC := /root/s3c2410/DISK4/linux2.4/2.4.18-rmk7/include
LIB_INC := /usr/local/arm/2.95.3/lib/gcc-lib/arm-linux/2.95.3/include/
CFLAGS := -O -s -Wall -D__GNUC__=3 -DMODULE -D__KERNEL__ -march=armv4 -nostdinc -I- -I. -I$(KER_INC) -idirafter $(LIB_INC)
all: led.o
led.o: led_driver.c
@echo
@echo --------------------------------------------------
@echo - Build led
@echo --------------------------------------------------
$(CC) $(CFLAGS) -c led_driver.c
clean:
rm -f *.o
_____________________________________________________________________________
KER_INC:是你的内核的库
LIB_INC:是你的编译器的库
最好使用编译内核的编译器,这样不容易出问题
三 写驱动文件
——————————————————————————————————————
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include<asm-arm/arch/S3C2410.h>
#include<linux/fs.h>
#include<linux/module.h>
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/devfs_fs_kernel.h>
MODULE_LICENSE("GPL");
int led_open(struct inode *,struct file *);
int led_ctl(struct inode *,struct file *,unsigned int command,unsigned long arg);
struct file_operations led_ctl_fops=
{
open:led_open,
ioctl:led_ctl,
};
int led_open(struct inode * a ,struct file * b)
{
//your core
return 0;
}
int led_ctl(struct inode * a,struct file * n,unsigned int command,unsigned long arg)
{
//your core
return 0;
}
int init_led(void)
{
//your core
return 0;
}
void cleanup_led(void)
{
//your core
}
module_init(init_led);
module_exit(cleanup_led);
——————————————————————————————————————
四 感谢
这次主要感谢我的连接里的两位兄弟给了我很大的支持.
他们的BLOG里有好多有用的东西,朋友们有时间可以去看看.
- 我写的第一个LED驱动的心得
- micro2440写的第一个驱动-LED(2011/10/13)
- 我的第一个嵌入式linux驱动(基于韦东山led驱动)
- 我的第一个嵌入式linux驱动(基于韦东山led驱动)2_完善1
- 我的第一个嵌入式linux驱动(基于韦东山led驱动)3_完善2
- 我的LED驱动
- 我的第一个GNURadio应用程序心得
- 第一个led驱动的加载和实现
- (五)4 写个简单的LED驱动
- flash五子棋心得——致我写的第一个程序
- 我的第一个led实验--基于arm6410
- 我的第一个汇编程序,led流水灯
- 我的第一个GPIO实验,点亮一盏LED
- 我的第一个WINCE驱动
- 我的第一个WINCE驱动
- 【转】我的第一个WINCE驱动
- 第二讲:我的第一个驱动
- 第二讲:我的第一个驱动
- Java解析网络数据流的三种特殊方法
- .net 中访问 excel文件的两种方式
- 计算机端口简介(2)
- 如何在EJB应用程序中使用Spring
- SubVersion初级教程
- 我写的第一个LED驱动的心得
- 原创连载*逃婚小娘子
- 觉得effective c#这一章特别有用,贴在这里...
- 使用Spring更好地处理Struts动作
- 探析软件项目管理九大原则
- 原创连载*逃婚小娘子3
- 什么是Ajax?
- 设计模式 - Composite Pattern(组合模式)
- Shell_NotifyIcon如何强制显示tip