当前位置:文档之家› 蜂鸣器驱动程序设计

蜂鸣器驱动程序设计

{
unsigned int value=0;
value=ioread32(pload+1);//read data register
value&=~0x1<<0;
iowrite32(value,pload+1);
}
long beep_unlocked_ioctl(struct file *fp,unsigned int cmd,unsigned long param)
printk("%s\n",__FUNCTION__);
pload=ioremap(0XE02000A0,16);//convert register physical address to virtual address
value=ioread32(pload);
value&=~0x1<<3;
value&=~0x1<<2;
{
unsigned int value=0;
printk("%s\n",__FUNCTION__);
pload=ioremap(0XE02000A0,16);//convert register physical address to virtual address
value=ioread32(pload);
要使蜂鸣器发声,就是要让GPD0作为输出端,同时该端口要设为高电平。也就是说GPD0设置为01为输出,让GPDDAT的最后一位设置为1则该端口就置成了高电平。
2模块代码分析:
2.1打开设备模块
int beep_open(struct inode *nodep,struct file *fp)
{
unsigned int value=0;
Linux是一个领先的操作系统,世界上运算最快的10台超级计算机运行的都是Linux操作系统。严格来说,Linux这个词本身只表示Linux内核,但实际上人们已经习惯了用Linux来形容整个基于Linux内核,并且使用GNU工程各种工具和数据库的操作系统。Linux得名于天才程序员林纳斯·托瓦兹。
tiny210开发板中模块介绍:
①PWM蜂鸣器模块
PWM(脉冲宽度调制)简单的讲是一种变频技术之一,是靠改变脉冲宽度来控制输出电压,通过改变周期来控制其输出频率。来看看我们实际生活中的例子,我们的电风扇为什么扭一下按扭,风扇的转速就会发生变化;调一下收音机的声音按钮,声音的大小就会发生变化。这些都是PWM的应用,都是通过PWM输出的频率信号进行控制的。
value&=~0x1<<3;
value&=~0x1<<2;
value&=~0x1<<1;
value|=0x1<<0;
iowrite32(value,pload);
return 0;
}
int beep_release(struct inode *nodep,struct file *fp)
{
printk("%s\n",__FUNCTION__);
}
printk("beep_major = %d\n",beep_major);
}
static void initial_cdev(void)
{
cdev_init(&beep_cdev,&beep_ops);
beep_cdev.owner=THIS_MODULE;
beep_cdev.ops=&beep_ops;
蜂鸣器驱动
课程设计
专业:xxxxxxxxxxxxxx
班级:xxxxxxxxx
学号:xxxxxxxxx
姓名:xxxx
设计题目:蜂鸣器驱动程序设计
2016年12月
五.tiny210开发板调试..............................................................................................................9
{
printk("%s\n",__FUNCTION__);
alloc_beep_dev_num();//get device number
initial_cdev();//initial and register cdev variable
return 0;
}
static void __exit beep_exit(void)
return 0;
}
void beep_start(void)
{
unsigned int value=0;
value=ioread32(pload+1);//read data register
value|=0x1<<0;
iowrite32(value,pload+1);
}
void beep_stop(void)
二.
1.
2.
①按键模块:通过按键来操作蜂鸣器的启动与停止。
②蜂鸣器模块:通过加载蜂鸣器驱动模块到内核,驱动蜂鸣器。
①按键模块:
A.正确驱动主设备号和次设备号
B.实现字符设备驱动程序
C.实现file-operation结构
D.实现初始化函数,注册字符设备
E.实现卸载函数,释放字符设备
F.创建文件节点
②按键模块:
static int *pload=NULL;
#define BEEPNUM 3
static int str_len(char *str)
{
int count=0;
while(*str!='\0')
{
count++;
str++;
}
return count;
}
ssize_t beep_read (struct file *fp, char __user *buff, size_t count, loff_t *fps)
beep_cdev.dev=beep_devno;
beep_cdev.count=BEEPNUM;
cdev_add(&beep_cdev,beep_devno,BEEPNUM);//register a cdev variable to linux kernel
}
static int __init beep_init(void)
{
char string[20]="HELLO,EVERYONE\n";
int retur=0;
printk("%s\n",__FUNCTION__);
retur=copy_to_user(buff,string,str_len(string)+1);
return retur;
}
ssize_t beep_write (struct file *fp, const char __user *buff, size_t count, loff_t *fps)
value&=~0x1<<1;
value|=0x1<<0;
iowrite32(value,pload);
return 0;
}
此函数实现了怎么去打开设备,在设备文件上的第一个操作,并不要求驱动程序一定要实现这个方法。如果该项为NULL,设备的打开操作永远成功。
{
.open=beep_open,
.release=beep_release,
.read=beep_read,
.write=beep_write,
.unlocked_ioctl=beep_unlocked_ioctl
};
static void alloc_beep_dev_num(void)
{
if(beep_major>0)
{
printk("%s\n",__FUNCTION__);
switch(cmd)
{
case 0://beep stop
beep_stop();
break;
case 1://beep start
beep_start();
break;
}
return 0;
}
static struct file_operations beep_ops=
3.
要实现PC与tiny210开发板的通信,要求在PC机上的VMware Workstation软件的Red Hat Enterprise Linux环境下编写程序,包含蜂鸣器驱动程序和测试文件。利用交叉编译器arm-linux-gcc-4.5.1-v6-vfp1生成目标文件,最后讲目标文件下载到开发板,并且驱动蜂鸣器根据按键的不同完成启动或者停止的操作。
G.正确驱动住设备号和次设备号
H.实现字符设备驱动程序
I.实现file-operation结构
J.实现初始化函数,注册字符设备
K.实现卸载函数,释放字符设备
L.创建文件节点
模块设计:
(1)beep.c
#include<linux/init.h>
#include<linux/module.h>
#include<linux/fs.h>
#include<linux/cdev.h>
#include<linux/types.h>
#include<asm/io.h>
#include<asm/uaccess.h>
相关主题