主题 : GPIO的GPB0和GPB1驱动,仿照友善提供的led驱动写的,不知为何没有高电平输出,求助!!! 复制链接 | 浏览器收藏 | 打印
新手啊!!
级别: 新手上路
UID: 21963
精华: 0
发帖: 5
金钱: 25 两
威望: 5 点
综合积分: 10 分
注册时间: 2010-05-24
最后登录: 2012-11-18
楼主  发表于: 2010-06-06 09:46

 GPIO的GPB0和GPB1驱动,仿照友善提供的led驱动写的,不知为何没有高电平输出,求助!!!

驱动测试程序=====================================================================
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>

int main(int argc, char **argv)
{
    int on;
    int led_no;
    int fd;

    fd = open("/dev/myleds", 0);
    if (fd < 0) {
        perror("open device leds");
        exit(1);
    }
    while(1)
    {
        //sleep(1);
        ioctl(fd, 1, 0);
        //sleep(1);
        ioctl(fd, 1, 1);
        printf("hello world\n");
    }
    close(fd);
    return 0;
}
驱动程序========================================================================================
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/ioctl.h>
#include <linux/cdev.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <linux/gpio.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h>


#define DEVICE_NAME "myleds"

static unsigned long led_table [] = {
    S3C2410_GPB(0),
    S3C2410_GPB(1),
};

static unsigned int led_cfg_table [] = {
    S3C2410_GPIO_OUTPUT,
    S3C2410_GPIO_OUTPUT,
};

static int sbc2440_leds_ioctl(
    struct inode *inode,
    struct file *file,
    unsigned int cmd,
    unsigned long arg)
{
    switch(cmd) {
    case 0:
    case 1:
        if (arg > 2) {
            return -EINVAL;
        }
        s3c2410_gpio_setpin(led_table[arg], !cmd);
        return 0;
    default:
        return -EINVAL;
    }
}

static struct file_operations dev_fops = {
    .owner    =    THIS_MODULE,
    .ioctl    =    sbc2440_leds_ioctl,
};

static struct miscdevice misc = {
    .minor = MISC_DYNAMIC_MINOR,
    .name = DEVICE_NAME,
    .fops = &dev_fops,
};

static int __init dev_init(void)
{
    int ret;

    int i;
    
    for (i = 0; i < 2; i++) {
        s3c2410_gpio_cfgpin(led_table, led_cfg_table);
        s3c2410_gpio_setpin(led_table, 0);
    }

    ret = misc_register(&misc);

    printk (DEVICE_NAME"\tinitialized\n");

    return ret;
}

static void __exit dev_exit(void)
{
    misc_deregister(&misc);
}

module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("FriendlyARM Inc.");
================================================
不知道为什么测试程序没能有高电平输出,但有helloworld输出,请各位大侠看看,是不是我的驱动程序有问题,还是GPB0和GPB1不能这么用,小弟初学,还望今后能跟大家好好学习,谢谢了!!!
级别: 圣骑士
UID: 9221
精华: 0
发帖: 376
金钱: 2110 两
威望: 539 点
综合积分: 752 分
注册时间: 2009-09-22
最后登录: 2016-07-04
1楼  发表于: 2010-06-06 11:45
while(1)
    {
        //sleep(1);
        ioctl(fd, 1, 0);
        //sleep(1);
        ioctl(fd, 1, 1);
        printf("hello world\n");
    }
ioctl参数传递的有问题!你的是让0,1端口输出为0(即低电平)
一起学习,一起进步
新手啊!!
级别: 新手上路
UID: 21963
精华: 0
发帖: 5
金钱: 25 两
威望: 5 点
综合积分: 10 分
注册时间: 2010-05-24
最后登录: 2012-11-18
2楼  发表于: 2010-06-06 12:30

 回 1楼(guoyin88) 的帖子

谢谢楼上,我疏忽了led需要的是低电平发光,而这里需要高电平,刚好相反,有点儿弱了,非常感谢!!!
级别: 新手上路
UID: 27268
精华: 0
发帖: 11
金钱: 55 两
威望: 11 点
综合积分: 22 分
注册时间: 2010-08-23
最后登录: 2011-04-20
3楼  发表于: 2011-04-20 13:18
好贴,顶下
级别: 新手上路
UID: 3912
精华: 0
发帖: 25
金钱: 125 两
威望: 25 点
综合积分: 50 分
注册时间: 2009-02-15
最后登录: 2014-04-15
4楼  发表于: 2011-08-03 11:12
mark 下,正需要看gpio
级别: 新手上路
UID: 54501
精华: 0
发帖: 1
金钱: 5 两
威望: 1 点
综合积分: 2 分
注册时间: 2011-08-31
最后登录: 2017-09-13
5楼  发表于: 2011-08-31 19:05
GPIO 能不能多路并行操作?