驱动代码:

#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下简易蜂鸣器驱动代码及测试实例的更多相关文章

  1. Linux下18b20温度传感器驱动代码及测试实例

    驱动代码: #include <linux/module.h> #include <linux/fs.h> #include <linux/kernel.h> #i ...

  2. Linux下实现流水灯等功能的LED驱动代码及测试实例

    驱动代码: #include <linux/errno.h> #include <linux/kernel.h> #include <linux/module.h> ...

  3. linux下编译运行驱动

    linux下编译运行驱动 嵌入式linux下设备驱动的运行和linux x86 pc下运行设备驱动是类似的,由于手头没有嵌入式linux设备,先在vmware上的linux上学习驱动开发. 按照如下方 ...

  4. Linux下的硬件驱动——USB设备(转载)

    usb_bulk_msg函数 当对usb设备进行一次读或者写时,usb_bulk_msg 函数是非常有用的; 然而, 当你需要连续地对设备进行读/写时,建议你建立一个自己的urbs,同时将urbs 提 ...

  5. Linux下 USB设备驱动分析(原创)

    之前做过STM32的usb HID复合设备,闲来看看linux下USB设备驱动是怎么一回事, 参考资料基于韦东山JZ2440开发板,以下,有错误欢迎指出. 1.准备知识 1.1USB相关概念: USB ...

  6. 如何编写linux下nand flash驱动-4

    2.       软件方面 如果想要在Linux下编写Nand Flash驱动,那么就先要搞清楚Linux下,关于此部分的整个框架.弄明白,系统是如何管理你的nand flash的,以及,系统都帮你做 ...

  7. linux下的声卡驱动架构

    1.linux下的声卡驱动架构主要分为OSS架构和ALSA架构. 2.OSS架构 OSS全称是Open Sound System,叫做开放式音频系统,这种早期的音频系统这种基于文件系统的访问方式,这意 ...

  8. 【转】Linux下Android ADB驱动安装详解

    原文网址:http://blog.csdn.net/zhenwenxian/article/details/5901350 Linux下Android ADB驱动安装详解 概述 最近由于内置的合作商比 ...

  9. 怎样在Windows和Linux下写相同的代码

    目前,Linux在国内受到了越来越多的业内人士和用户的青睐.相信在不久的将来,在国内为Linux开发 的应用软件将会有很大的增加(这不,金山正在招兵买马移植WPS呢).由于未来将会是Windows和L ...

随机推荐

  1. 金蝶KIS 13.0专业版破解方法破解安装流程 金蝶KIS 13.0专业版安装流程

    金蝶KIS 13.0安装 1.先安装操作系统Windows server 2008 R2. 2.再安装SQL2008 R2. 3.再安装金蝶KIS 13.0专业版. 在安装时记住须要将系列号设置成为1 ...

  2. C++中如何修改const变量

      一.结论 声明:不同于C语言的const变量修改问题(可以通过指针间接修改const变量的值),这里只讨论C++ 里的const. C++ const 修饰符,表示常量,即如果以后保证不会修改则声 ...

  3. Qt数据库(sqlite) — 总结

    #include <QtSql>QT += sql QSqlDatabase类实现了数据库连接的操作QSqlQuery类用来执行SQL语句QSqlRecord类 封装数据库所有记录 第一: ...

  4. dynamic_cast用法

    dynamic_cast < type-id > ( expression ) 该运算符把expression转换成type-id类型的对象.Type-id必须是类的指针.类的引用或者vo ...

  5. javascript——touch事件

    前言 诸如智能手机和平板电脑一类的移动设备通常会有一(capacitive touch-sensitivescreen),以捕捉用户的手指所做的交互.随着移动网络的发展,其能够支持越来越复杂的应用,w ...

  6. Mantis 安装与配置

    1. 适用范围 a. 本文介绍基于 Windows 下的缺陷管理平台 Mantis. 2. 软件准备 a. 下载 EasyPHP:http://www.easyphp.org/easyphp-devs ...

  7. Upgrade Guide

    Upgrade Guide This guide will point out the key points to be aware of when upgrading to version 3. A ...

  8. Asp.Net 之 调用远程Web_Service

    一.添加web service引用 1.右键 Web 项目 → “添加服务引用”: 2.右键已有的 App_WebReferences 文件夹 → “添加服务引用”: 二.引用远程web servic ...

  9. Android_Notification

    xml文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...

  10. Cstring到string

    要利用mfc,然后接受一个图片. imread只能读const string& filename 的东西. imread 原型: CV_EXPORTS_W Mat imread( ); 它的参 ...