Linux下简易蜂鸣器驱动代码及测试实例
驱动代码:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/err.h> #include <linux/miscdevice.h> #include <mach/gpio.h>
#include <mach/regs-gpio.h>
#include <plat/gpio-cfg.h> #define DEVICE_NAME "beep3" #define BEEP_MAGIC 'k'
#define BEEP_START_CMD _IO (BEEP_MAGIC, 1)
#define BEEP_STOP_CMD _IO (BEEP_MAGIC, 2) static void beep3_stop(void) {
printk("in the beep3_stop!!\n");
s3c_gpio_cfgpin(S5PV210_GPD0(), S3C_GPIO_OUTPUT);
gpio_set_value(S5PV210_GPD0(), ); } static void beep3_start(void) {
printk("in the beep3_start!!\n");
s3c_gpio_cfgpin(S5PV210_GPD0(), S3C_GPIO_OUTPUT);
gpio_set_value(S5PV210_GPD0(), ); } static long beep3_ioctl(struct file *filep, unsigned int cmd,
unsigned long arg)
{
printk("in the beep3_ioctl!!\n");
switch ( cmd ) {
case BEEP_START_CMD: {
printk("in the start_cmd!!\n");
beep3_start(); break;
}
case BEEP_STOP_CMD: {
printk("in the stop_cmd!!\n");
beep3_stop(); break;
}
default: {
break;
}
} return ;
} static struct file_operations beep3_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = beep3_ioctl,
}; static struct miscdevice beep3_misc_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &beep3_fops,
}; static int __init beep3_dev_init(void) {
int ret; ret = gpio_request(S5PV210_GPD0(), DEVICE_NAME);
if (ret) {
printk("request GPIO %d failed\n",S5PV210_GPD0());
return ret;
}
s3c_gpio_cfgpin(S5PV210_GPD0(), S3C_GPIO_OUTPUT);
gpio_set_value(S5PV210_GPD0(), ); ret = misc_register(&beep3_misc_dev); printk(DEVICE_NAME "\tinitialized\n"); return ret;
} static void __exit beep3_dev_exit(void) {
beep3_stop(); misc_deregister(&beep3_misc_dev);
} module_init(beep3_dev_init);
module_exit(beep3_dev_exit); MODULE_LICENSE("GPL");
MODULE_AUTHOR("mhb@SEU");
MODULE_DESCRIPTION("S5PV210 beep Driver");
测试实例:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#define BEEP_MAGIC 'k'
#define BEEP_START_CMD _IO (BEEP_MAGIC, 1)
#define BEEP_STOP_CMD _IO (BEEP_MAGIC, 2) int main(int argc ,char* argv[])
{
int m_fd=;//
m_fd = open("/dev/beep3", O_RDONLY); ioctl(m_fd, BEEP_STOP_CMD);
while()
{
printf("enter any key to start !!\n");
getchar();
ioctl(m_fd, BEEP_START_CMD);
printf("start success!!\n");
printf("enter any key to stop !!\n");
getchar();
ioctl(m_fd, BEEP_STOP_CMD);
}
close(m_fd);
return ;
}
Linux下简易蜂鸣器驱动代码及测试实例的更多相关文章
- Linux下18b20温度传感器驱动代码及测试实例
驱动代码: #include <linux/module.h> #include <linux/fs.h> #include <linux/kernel.h> #i ...
- Linux下实现流水灯等功能的LED驱动代码及测试实例
驱动代码: #include <linux/errno.h> #include <linux/kernel.h> #include <linux/module.h> ...
- linux下编译运行驱动
linux下编译运行驱动 嵌入式linux下设备驱动的运行和linux x86 pc下运行设备驱动是类似的,由于手头没有嵌入式linux设备,先在vmware上的linux上学习驱动开发. 按照如下方 ...
- Linux下的硬件驱动——USB设备(转载)
usb_bulk_msg函数 当对usb设备进行一次读或者写时,usb_bulk_msg 函数是非常有用的; 然而, 当你需要连续地对设备进行读/写时,建议你建立一个自己的urbs,同时将urbs 提 ...
- Linux下 USB设备驱动分析(原创)
之前做过STM32的usb HID复合设备,闲来看看linux下USB设备驱动是怎么一回事, 参考资料基于韦东山JZ2440开发板,以下,有错误欢迎指出. 1.准备知识 1.1USB相关概念: USB ...
- 如何编写linux下nand flash驱动-4
2. 软件方面 如果想要在Linux下编写Nand Flash驱动,那么就先要搞清楚Linux下,关于此部分的整个框架.弄明白,系统是如何管理你的nand flash的,以及,系统都帮你做 ...
- linux下的声卡驱动架构
1.linux下的声卡驱动架构主要分为OSS架构和ALSA架构. 2.OSS架构 OSS全称是Open Sound System,叫做开放式音频系统,这种早期的音频系统这种基于文件系统的访问方式,这意 ...
- 【转】Linux下Android ADB驱动安装详解
原文网址:http://blog.csdn.net/zhenwenxian/article/details/5901350 Linux下Android ADB驱动安装详解 概述 最近由于内置的合作商比 ...
- 怎样在Windows和Linux下写相同的代码
目前,Linux在国内受到了越来越多的业内人士和用户的青睐.相信在不久的将来,在国内为Linux开发 的应用软件将会有很大的增加(这不,金山正在招兵买马移植WPS呢).由于未来将会是Windows和L ...
随机推荐
- MySQL导入txt文件
"Flufy","Harold","cat","f","1993-2-4" "claws& ...
- c#_DropdownList Panel Textbox 控件交互使用,有autopostback和没有的区别
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx. ...
- C#_delegate - 有返回值手工调用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- iOS 图片加载框架- SDWebImage 解读
在iOS的图片加载框架中,SDWebImage可谓是占据大半壁江山.它支持从网络中下载且缓存图片,并设置图片到对应的UIImageView控件或者UIButton控件.在项目中使用SDWebImage ...
- 使用socket实现FTP程序
#-*- coding:utf-8 -*- import socketserver from module import * class server: def __init__(self,reque ...
- TableView不显示没内容的Cell怎么办?
类似这种,我不想让下面那些空的显示. 很简单: self.tableView.tableFooterView = [[UIView alloc] init]; 加完这句之后就变成了这样:
- jqzoom基于jQuery的图片放大镜
1.引入jQuery和jqzoom插件 <script src="/js/common/jquery-1.6.2.js" type="text/javascript ...
- LC-检索
line void LC(tree T,float cost) { //为找一个答案结点检索T if(T是答案结点) {输出T:return:} E=T: //E-结点 将活结点表初始化为空: ) { ...
- h2database源码浅析:MVTable与MVIndex
Database包含一个Store:MVTableEngine.Store getMvStore() MVTableEngine.Store可以获取各tables:java.util.HashMap& ...
- linux时间无法同步的解决方案
问题描述: 在家里的ubuntu和windows上始终无法同步时间,也参考了很多资料还是不行.无意中的一次把笔记本拿到公司,发现可以同步时间,但是就觉得奇怪了.对比之后才发现是移动的网络没法连接ntp ...