beep驅(qū)動從linux2.6.35.7內(nèi)核移植到linux3.0.8,修改的部分為:
'='后面的為修改后的
.ioctl = .unlocked_ioctl
static int beep_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
= static int beep_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
beep_ioctl函數(shù)中struct inode *inode去掉,原因是beep測試程序中ioctl函數(shù)中參數(shù)個數(shù)與beep驅(qū)動相對應(yīng)。如果沒有去掉,測試程序能進入beep驅(qū)動中beep_ioctl函數(shù),但BEEP_START_CMD不能與驅(qū)動中beep_ioctl匹配。
1. beep測試程序為:
#include 2. beep驅(qū)動程序: /*
#include
#include
#include
#include
#define BEEP_MAGIC 'k'
#define BEEP_START_CMD _IO (BEEP_MAGIC, 1)
#define BEEP_STOP_CMD _IO (BEEP_MAGIC, 2)
int main()
{
int i = 0;
int dev_fd;
dev_fd = open('/dev/beep',O_RDWR );
if ( dev_fd == -1 ) {
printf('Cann't open file /dev/beepn');
exit(1);
}
printf('Start beepn');
ioctl (dev_fd, BEEP_START_CMD,0);
getchar();
ioctl (dev_fd, BEEP_STOP_CMD,0);
printf('Stop beep and Close devicen');
close(dev_fd);
return 0;
}
* linux/drivers/char/mini210_beep.c
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include
#include
#include
#include
#include
//#include
//#include
#include
//#include
//#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define BUZZER_PMW_GPIO S5PV210_GPD0(0)
static int beep_major = 0;
#define BEEP_MAGIC 'k'
#define BEEP_START_CMD _IO (BEEP_MAGIC, 1)
#define BEEP_STOP_CMD _IO (BEEP_MAGIC, 2)
/*
* Open the device; in fact, there's nothing to do here.
*/
int beep_open (struct inode *inode, struct file *filp)
{
return 0;
}
ssize_t beep_read(struct file *file, char __user *buff, size_t count, loff_t *offp)
{
return 0;
}
ssize_t beep_write(struct file *file, const char __user *buff, size_t count, loff_t *offp)
{
return 0;
}
void beep_stop( void )
{
s3c_gpio_cfgpin(BUZZER_PMW_GPIO, S3C_GPIO_OUTPUT);
gpio_set_value(BUZZER_PMW_GPIO, 0);
}
void beep_start( void )
{
s3c_gpio_cfgpin(BUZZER_PMW_GPIO, S3C_GPIO_OUTPUT);
gpio_set_value(BUZZER_PMW_GPIO, 1);
}
//static int beep_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
//unsigned long arg)
static int beep_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
//add your src HERE!!!
printk('beep_ioctl');
switch ( cmd ) {
case BEEP_START_CMD: {
beep_start();
printk('start');
break;
}
case BEEP_STOP_CMD: {
printk('stop');
beep_stop(); break;
}
default: {
break;
}
}
return 0;
}
static int beep_release(struct inode *node, struct file *file)
{
return 0;
}
static void beep_setup_cdev(struct cdev *dev,int minor,
struct file_operations *fops)
{
int err, devno = MKDEV(beep_major, minor);
cdev_init(dev, fops);
dev->owner = THIS_MODULE;
dev->ops = fops;
err = cdev_add (dev, devno, 1);
/* Fail gracefully if need be */
if (err)
printk (KERN_NOTICE 'Error %d adding beep%d', err, minor);
}
static struct file_operations beep_remap_ops = {
.owner = THIS_MODULE,
.open = beep_open,
.release = beep_release,
.read = beep_read,
.write = beep_write,
.unlocked_ioctl = beep_ioctl,
//.ioctl = beep_ioctl,
};
static struct cdev BeepDevs;
static int __init beep_init(void) {
int result;
dev_t dev = MKDEV(beep_major,0);
char dev_name[]='beep';
if (beep_major)
result = register_chrdev_region(dev,1,dev_name);
else{
result = alloc_chrdev_region(&dev,0,1,dev_name);
beep_major = MAJOR(dev);
}
if (result < 0) {
printk(KERN_WARNING 'beep: unable to get major %dn', beep_major);
return result;
}
if (beep_major == 0)
beep_major = result;
beep_setup_cdev(&BeepDevs, 0, &beep_remap_ops);
printk('beep device installed, with major %dn', beep_major);
printk('The device name is: %sn', dev_name);
return 0;
}
static void __exit beep_cleanup(void)
{
cdev_del(&BeepDevs);
unregister_chrdev_region(MKDEV(beep_major,0),1);
printk('beep device uninstalledn');
}
module_init(beep_init);
module_exit(beep_cleanup);
MODULE_LICENSE('GPL');
MODULE_AUTHOR('mingli Inc.');
MODULE_DESCRIPTION('S5PV210 beep Driver');
上一篇:tiny210(s5pv210)移植u-boot(基于 2014.4 版本號)——移植u-boot.bin(打印串口控制臺)
下一篇:s5pv210 cpu運行debian
推薦閱讀最新更新時間:2025-07-04 08:02



設(shè)計資源 培訓(xùn) 開發(fā)板 精華推薦
- 適用于汽車應(yīng)用的 LT3973HMSE-3.3 3.3V 降壓轉(zhuǎn)換器的典型應(yīng)用
- R_08_V30基于IPS2電機換向傳感器的設(shè)計
- 使用 Microchip Technology 的 PIC16C782 的參考設(shè)計
- 使用 LT1054CSW 基本型電壓逆變器 / 穩(wěn)壓器的典型應(yīng)用
- 使用 LTC3637EDHC 4V 至 76V 輸入至 1.8V 超級電容器充電器的典型應(yīng)用
- 儀表用 ADC 驅(qū)動器
- EN6310QA 1A PowerSoC 電壓模式同步 PWM 降壓與集成電感器的典型應(yīng)用
- STEVAL-ISV012V1,使用 L6924D 高達 5 W 太陽能電池充電器的演示板,用于單節(jié)鋰離子和鋰聚合物電池
- 適用于汽車應(yīng)用的 A5974D 正降壓-升壓穩(wěn)壓器的典型應(yīng)用電路
- 使用 NXP Semiconductors 的 TDA2582Q 的參考設(shè)計
- 高性能電動滑板車 BLDC 電機驅(qū)動器:技術(shù)解析與應(yīng)用展望
- 5G工業(yè)網(wǎng)關(guān)的“邊緣計算+AI推理”一體化設(shè)計,PLC協(xié)議解析與缺陷檢測的實時聯(lián)動
- AR眼鏡的“工業(yè)指令投射”系統(tǒng),SLAM的空間定位、PLC數(shù)據(jù)實時疊加顯示
- 多光譜氣體傳感器的抗交叉干擾設(shè)計
- 多模態(tài)融合感知的“語義-幾何”聯(lián)合建模
- 工業(yè)觸摸屏的“壓感-手勢”多模態(tài)交互設(shè)計
- 工業(yè)機器人高精度力控的“雙模融合”傳感器設(shè)計
- 工業(yè)機器人集群的“數(shù)字孿生-物理實體”閉環(huán)優(yōu)化
- 工業(yè)以太網(wǎng)交換機的“時間敏感網(wǎng)絡(luò)(TSN)”改造
- 工業(yè)現(xiàn)場信號測試:耦合方式選擇實戰(zhàn)案例
- 人工智能行業(yè)發(fā)展趨勢分析 四大突破點應(yīng)用落地
- 疫苗造假不能忍 安防強監(jiān)管做起來
- 智能安防領(lǐng)域 中小企業(yè)或可借多模態(tài)識別突圍
- 瑞薩電子:大力發(fā)展主動醫(yī)療監(jiān)測,高效的利用有限的醫(yī)療資源
- Marvell成立符合CISPR 25標(biāo)準(zhǔn)的汽車EMC實驗室
- 機器人進入安防市場,底氣何在?
- 當(dāng)機器人有了人造神經(jīng),就能真實感覺到你?
- 云計算安全誰來負責(zé)?怎么負責(zé)?
- 機器人有何底氣進入安防市場?
- AI不穩(wěn)定,就業(yè)有風(fēng)險,所以要招本科生?