<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > 嵌入式Linux設備驅動(dòng)開(kāi)發(fā)之:GPIO驅動(dòng)程序實(shí)例

嵌入式Linux設備驅動(dòng)開(kāi)發(fā)之:GPIO驅動(dòng)程序實(shí)例

作者: 時(shí)間:2013-09-13 來(lái)源:網(wǎng)絡(luò ) 收藏

本文引用地址:http://dyxdggzs.com/article/257110.htm

staticintgpio_ioctl(structinode*inode,structfile*file,

unsignedintcmd,unsignedlongarg)

{/*ioctl函數接口:主要接口的實(shí)現。對5個(gè)GPIO設備進(jìn)行控制(發(fā)亮或發(fā)聲)*/

unsignedintswt=(unsignedint)arg;

switch(cmd)

{

caseLED_D09_SWT:

{

switch_gpio(S3C2410_GPF7,swt);

}

break;

caseLED_D10_SWT:

{

switch_gpio(S3C2410_GPF6,swt);

}

break;

caseLED_D11_SWT:

{

switch_gpio(S3C2410_GPF5,swt);

}

break;

caseLED_D12_SWT:

{

switch_gpio(S3C2410_GPF4,swt);

}

break;

caseBEEP_SWT:

{

switch_gpio(S3C2410_GPB0,swt);

break;

}

default:

{

printk(Unsupportedcommandn);

break;

}

}

return0;

}

staticintgpio_release(structinode*node,structfile*file)

{/*release操作函數,熄滅所有燈和關(guān)閉蜂鳴器*/

switch_gpio(S3C2410_GPB0,BEEP_SWT_OFF);

switch_gpio(S3C2410_GPF4,LED_SWT_OFF);

switch_gpio(S3C2410_GPF5,LED_SWT_OFF);

switch_gpio(S3C2410_GPF6,LED_SWT_OFF);

switch_gpio(S3C2410_GPF7,LED_SWT_OFF);

return0;

}

staticvoidgpio_setup_cdev(structcdev*dev,intminor,

structfile_operations*fops)

{/*字符設備的創(chuàng )建和注冊*/

interr,devno=MKDEV(major,minor);

cdev_init(dev,fops);

dev->owner=THIS_MODULE;

dev->ops=fops;

err=cdev_add(dev,devno,1);

if(err)

{

printk(KERN_NOTICEError%daddinggpio%d,err,minor);

}

}

staticstructfile_operationsgpio_fops=

{/*gpio設備的file_operations結構定義*/

.owner=THIS_MODULE,

.open=gpio_open,/*進(jìn)行初始化配置*/

.release=gpio_release,/*關(guān)閉設備*/

.read=gpio_read,

.write=gpio_write,

.ioctl=gpio_ioctl,/*實(shí)現主要控制功能*/

};

staticstructcdevgpio_devs;

staticintgpio_init(void)

{

intresult;

dev_tdev=MKDEV(major,0);

if(major)

{/*設備號的動(dòng)態(tài)分配*/

result=register_chrdev_region(dev,1,GPIO_DEVICE_NAME);

}

else

{/*設備號的動(dòng)態(tài)分配*/

result=alloc_chrdev_region(dev,0,1,GPIO_DEVICE_NAME);

major=MAJOR(dev);

}

if(result0)

{

printk(KERN_WARNINGGpio:unabletogetmajor%dn,major);

returnresult;

}

gpio_setup_cdev(gpio_devs,0,gpio_fops);

printk(Themajorofthegpiodeviceis%dn,major);

return0;

}

linux操作系統文章專(zhuān)題:linux操作系統詳解(linux不再難懂)

linux相關(guān)文章:linux教程


蜂鳴器相關(guān)文章:蜂鳴器原理


評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>