打印

一个在2440上使用LED之linux-2.6内核驱动的详细例子

[复制链接]
2164|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
capbily|  楼主 | 2007-4-12 09:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
一个在QQ2440上使用的最简单LED的linux-2.6的例子, 适合刚刚接触arm-linux的初学者。您还可以在 http://www.arm123.net下载更多资料

源代码:
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/devfs_fs_kernel.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <asm/arch/regs-gpio.h>
#include <asm/hardware.h>

#define DEVICE_NAME    "leds" /*定义led设备的名字*/
#define LED_MAJOR 231              /*定义led设备的主设备号*/

static unsigned long led_table [] = {
    S3C2410_GPB5,
    S3C2410_GPB6,
         S3C2410_GPB7,
         S3C2410_GPB8,
};

static unsigned int led_cfg_table [] = {
    S3C2410_GPB5_OUTP,
    S3C2410_GPB6_OUTP,
         S3C2410_GPB7_OUTP,
         S3C2410_GPB8_OUTP,
};

static int sbc2440_leds_ioctl(
    struct inode *inode, 
    struct file *file, 
    unsigned int cmd, 
    unsigned long arg)
{
         /*关于ioctl的处理*/
    switch(cmd) {
    case 0:
    case 1:
        if (arg > 4) {
            return -EINVAL;
        }
        s3c2410_gpio_setpin(led_table[arg], !cmd);
        return 0;
    default:
        return -EINVAL;
    }
}

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

static int __init sbc2440_leds_init(void)
{
    int ret;
    int i;
         /*注册字符设备*/
    ret = register_chrdev(LED_MAJOR, DEVICE_NAME, &sbc2440_leds_fops);
    if (ret < 0) {
      printk(DEVICE_NAME " can't register major number\n");
      return ret;
    }

         /*注册到devfs*/
    devfs_mk_cdev(MKDEV(LED_MAJOR, 0), S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP, DEVICE_NAME);
    
    for (i = 0; i < 4; i++) {
        s3c2410_gpio_cfgpin(led_table, led_cfg_table);
        s3c2410_gpio_setpin(led_table, 1);
    }

    printk(DEVICE_NAME " initialized\n");
    return 0;
}

static void __exit sbc2440_leds_exit(void)
{
    devfs_remove(DEVICE_NAME);
    unregister_chrdev(LED_MAJOR, DEVICE_NAME);
}

module_init(sbc2440_leds_init);
module_exit(sbc2440_leds_exit);

相关帖子

沙发
gusto| | 2007-4-12 16:40 | 只看该作者

你这个板在哪里卖啊。

再加个LCD 多少钱?


JTAG下载呢?既然是学习,你们提供什么软件工具和硬件工具?。。。。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

3

帖子

0

粉丝