新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 嵌入式Linux設備驅動開發之:GPIO驅動程序實例

        嵌入式Linux設備驅動開發之:GPIO驅動程序實例

        作者: 時間:2013-09-13 來源:網絡 收藏

        本文引用地址:http://www.104case.com/article/257110.htm

        staticintgpio_ioctl(structinode*inode,structfile*file,

        unsignedintcmd,unsignedlongarg)

        {/*ioctl函數接口:主要接口的實現。對5個GPIO設備進行控制(發亮或發聲)*/

        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操作函數,熄滅所有燈和關閉蜂鳴器*/

        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)

        {/*字符設備的創建和注冊*/

        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,/*進行初始化配置*/

        .release=gpio_release,/*關閉設備*/

        .read=gpio_read,

        .write=gpio_write,

        .ioctl=gpio_ioctl,/*實現主要控制功能*/

        };

        staticstructcdevgpio_devs;

        staticintgpio_init(void)

        {

        intresult;

        dev_tdev=MKDEV(major,0);

        if(major)

        {/*設備號的動態分配*/

        result=register_chrdev_region(dev,1,GPIO_DEVICE_NAME);

        }

        else

        {/*設備號的動態分配*/

        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操作系統文章專題:linux操作系統詳解(linux不再難懂)

        linux相關文章:linux教程


        蜂鳴器相關文章:蜂鳴器原理


        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 呼伦贝尔市| 韩城市| 红原县| 沐川县| 当涂县| 无棣县| 出国| 雅江县| 喀喇| 阳江市| 拉萨市| 金溪县| 台东市| 吉林省| 彭州市| 丹巴县| 仁寿县| 龙川县| 巩义市| 常宁市| 滁州市| 湖州市| 多伦县| 谢通门县| 会理县| 文成县| 嘉定区| 汾阳市| 西乡县| 望江县| 南郑县| 平度市| 东乡族自治县| 张掖市| 黄山市| 通江县| 蓝田县| 库尔勒市| 襄城县| 瑞金市| 江北区|