mini2440 LED驱动程序开发

发布者:幸福自在最新更新时间:2024-06-18 来源: elecfans关键字:mini2440  LED  驱动程序 手机看文章 扫描二维码
随时随地手机看文章

一、源代码
 
/***********************mini2440_leds.c***********************
 
*
 
*
 
*******************************************************************/
 
#include <linux/miscdevice.h>
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include
 #include   //2.6.32.2内核版本要求
 
#define DEVICE_NAME 'leds'
 //定义GPIO管脚
 static unsigned long led_table [] = {
  S3C2410_GPB(5),  //不能是S3C2410_GPB5;  因为没有这样定义,可以通过#define S3C2410_GPB5 S3C2410_GPB(5)
  S3C2410_GPB(6),
  S3C2410_GPB(7),
  S3C2410_GPB(8),
 };
 //设置管脚模式
 static unsigned int led_cfg_table [] = {
  S3C2410_GPIO_OUTPUT, //随内核版本中定义类型的变化,
  S3C2410_GPIO_OUTPUT,
  S3C2410_GPIO_OUTPUT,
  S3C2410_GPIO_OUTPUT,
 };
 //ioctl函数实现
 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 > 4) {
    return -EINVAL;
  }
  s3c2410_gpio_setpin(led_table[arg], !cmd);
  return 0;
  default:
  return -EINVAL;
  }
 }
 //dev_fops操作指令集
 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,
 };
 //第二步:gpio模式选择,设定管脚
 //  注册混杂设备
 static int __init dev_init(void)
 {
  int ret;
 
 int i;
 
  for (i = 0; i < 4; i++) {
  s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]);
  s3c2410_gpio_setpin(led_table[i], 0);
  }
 
 ret = misc_register(&misc);
 
 printk (DEVICE_NAME'tinitializedn');
 
 return ret;
 }
 
static void __exit dev_exit(void)
 {
  misc_deregister(&misc);
 }
 //第一步:module_init(dev_init);
 //    module_exit(dev_exit);
 module_init(dev_init);
 module_exit(dev_exit);
 MODULE_LICENSE('GPL');
 MODULE_AUTHOR('FriendlyARM Inc.');
 
/**************************Makefile文件************************
 
*
 
*
 
*****************************************************************/
 
ifneq ($(KERNELRELEASE),)
 
obj-m := mini2440_leds.o
 
else
  KDIR:=/home/kernel/linux-2.6.32.2
 all:
  make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=arm-linux-
 clean:
  rm -f *.ko *.o *.mod.o *.mod.c *.symvers  modul*
 

endif


二、测试LED驱动的APP程序
 /*******************************app_leds.c***************************************
 
*
 
*
 
**********************************************************************************/
 
ifneq ($(KERNELRELEASE),)
 
obj-m := mini2440_leds.o
 
else
  KDIR:=/home/kernel/linux-2.6.32.2
 all:
  make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=arm-linux-
 clean:
  rm -f *.ko *.o *.mod.o *.mod.c *.symvers  modul*
 
endif
 
三、遇到的问题
 1、
 [root@localhost LED]# make
make -C /home/kernel/linux-2.6.32.2 M=/home/nfsshare/root_qtopia/Drive/LED modules ARCH=arm CROSS_COMPILE=arm-linux-
 make[1]: Entering directory `/home/kernel/linux-2.6.32.2'
  CC [M]  /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.o
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:29: error: 'S3C2410_GPB5' undeclared here (not in a function)
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:30: error: 'S3C2410_GPB6' undeclared here (not in a function)
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:31: error: 'S3C2410_GPB7' undeclared here (not in a function)
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:32: error: 'S3C2410_GPB8' undeclared here (not in a function)
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:36: error: 'S3C2410_GPB5_OUTP' undeclared here (not in a function)
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:36: error: initializer element is not constant
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:36: error: (near initialization for 'led_cfg_table[0]')
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:37: error: 'S3C2410_GPB6_OUTP' undeclared here (not in a function)
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:37: error: initializer element is not constant
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:37: error: (near initialization for 'led_cfg_table[1]')
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:38: error: 'S3C2410_GPB7_OUTP' undeclared here (not in a function)
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:38: error: initializer element is not constant
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:38: error: (near initialization for 'led_cfg_table[2]')
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:39: error: 'S3C2410_GPB8_OUTP' undeclared here (not in a function)
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:39: error: initializer element is not constant
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:39: error: (near initialization for 'led_cfg_table[3]')
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c: In function 'sbc2440_leds_ioctl':
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:54: error: implicit declaration of function 's3c2410_gpio_setpin'
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c: In function 'dev_init':
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:80: error: implicit declaration of function 's3c2410_gpio_cfgpin'
 make[2]: *** [/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.o] 错误 1
 make[1]: *** [_module_/home/nfsshare/root_qtopia/Drive/LED] 错误 2
 make[1]: Leaving directory `/home/kernel/linux-2.6.32.2'
 make: *** [all] 错误 2
 错误原因:内核版本不对,没有S3C2410_GPB5的类型定义 需要修改为S3C2410_GPB(5)
 
内核版本定义如下:
 
/* arch/arm/mach-s3c2410/include/mach/gpio-nrs.h
  *
  * Copyright (c) 2008 Simtec Electronics
  * http://armlinux.simtec.co.uk/
  * Ben Dooks <ben@simtec.co.uk>
  *
  * S3C2410 - GPIO bank numbering
  *
  * 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.
 */
 
#ifndef __MACH_GPIONRS_H
 #define __MACH_GPIONRS_H
 
#define S3C2410_GPIONO(bank,offset) ((bank) + (offset))
 
#define S3C2410_GPIO_BANKA  (32*0)
 #define S3C2410_GPIO_BANKB  (32*1)
 #define S3C2410_GPIO_BANKC  (32*2)
 #define S3C2410_GPIO_BANKD  (32*3)
 #define S3C2410_GPIO_BANKE  (32*4)
 #define S3C2410_GPIO_BANKF  (32*5)
 #define S3C2410_GPIO_BANKG  (32*6)
 #define S3C2410_GPIO_BANKH  (32*7)
 
/* GPIO bank sizes */A
 #define S3C2410_GPIO_A_NR (32)
 #define S3C2410_GPIO_B_NR (32)
 #define S3C2410_GPIO_C_NR (32)
 #define S3C2410_GPIO_D_NR (32)
 #define S3C2410_GPIO_E_NR (32)
 #define S3C2410_GPIO_F_NR (32)
 #define S3C2410_GPIO_G_NR (32)
 #define S3C2410_GPIO_H_NR (32)
 
#if CONFIG_S3C_GPIO_SPACE != 0
 #error CONFIG_S3C_GPIO_SPACE cannot be zero at the moment
 #endif
 
#define S3C2410_GPIO_NEXT(__gpio)
  ((__gpio##_START) + (__gpio##_NR) + CONFIG_S3C_GPIO_SPACE + 0)
 
#ifndef __ASSEMBLY__
 
enum s3c_gpio_number {
  S3C2410_GPIO_A_START = 0,
  S3C2410_GPIO_B_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_A),
  S3C2410_GPIO_C_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_B),
  S3C2410_GPIO_D_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_C),
  S3C2410_GPIO_E_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_D),
  S3C2410_GPIO_F_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_E),
  S3C2410_GPIO_G_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_F),
  S3C2410_GPIO_H_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_G),
 };
 
#endif /* __ASSEMBLY__ */
 
/* S3C2410 GPIO number definitions. */
 
#define S3C2410_GPA(_nr) (S3C2410_GPIO_A_START + (_nr))
 #define S3C2410_GPB(_nr) (S3C2410_GPIO_B_START + (_nr))
 #define S3C2410_GPC(_nr) (S3C2410_GPIO_C_START + (_nr))
 #define S3C2410_GPD(_nr) (S3C2410_GPIO_D_START + (_nr))
 #define S3C2410_GPE(_nr) (S3C2410_GPIO_E_START + (_nr))
 #define S3C2410_GPF(_nr) (S3C2410_GPIO_F_START + (_nr))
 #define S3C2410_GPG(_nr) (S3C2410_GPIO_G_START + (_nr))
 #define S3C2410_GPH(_nr) (S3C2410_GPIO_H_START + (_nr))
 
/* compatibility until drivers can be modified */
 
//宏定义了GPA和GPE
 
#define S3C2410_GPA0 S3C2410_GPA(0)
 #define S3C2410_GPA1 S3C2410_GPA(1)
 #define S3C2410_GPA3 S3C2410_GPA(3)
 #define S3C2410_GPA7 S3C2410_GPA(7)
 
#define S3C2410_GPE0 S3C2410_GPE(0)
 #define S3C2410_GPE1 S3C2410_GPE(1)
 #define S3C2410_GPE2 S3C2410_GPE(2)
 #define S3C2410_GPE3 S3C2410_GPE(3)
 #define S3C2410_GPE4 S3C2410_GPE(4)
 #define S3C2410_GPE5 S3C2410_GPE(5)
 #define S3C2410_GPE6 S3C2410_GPE(6)
 #define S3C2410_GPE7 S3C2410_GPE(7)
 #define S3C2410_GPE8 S3C2410_GPE(8)
 #define S3C2410_GPE9 S3C2410_GPE(9)
 #define S3C2410_GPE10 S3C2410_GPE(10)
 
#define S3C2410_GPH10 S3C2410_GPH(10)
 
#endif /* __MACH_GPIONRS_H */
 
2、问题二
 
[root@localhost LED]# make
 make -C /home/kernel/linux-2.6.32.2 M=/home/nfsshare/root_qtopia/Drive/LED modules ARCH=arm CROSS_COMPILE=arm-linux-
 make[1]: Entering directory `/home/kernel/linux-2.6.32.2'
  CC [M]  /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.o
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c: In function 'sbc2440_leds_ioctl':
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:54: error: implicit declaration of function 's3c2410_gpio_setpin'
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c: In function 'dev_init':
 /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:80: error: implicit declaration of function 's3c2410_gpio_cfgpin'
 make[2]: *** [/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.o] 错误 1
 make[1]: *** [_module_/home/nfsshare/root_qtopia/Drive/LED] 错误 2
 make[1]: Leaving directory `/home/kernel/linux-2.6.32.2'
 
原因:没有声明s3c2410_gpio_setpin和s3c2410_gpio_cfpin
 
j解决方法:调价头文件#include
 
3、问题三
 
在securecat中加载mini2440.ko文件,出现File existed
 
原因:使用的内核已经编译了led驱动模块,因此报错
 
解决:重新编译内核模块,在make menuconfig中不选择led选项
 

[1] [2]
关键字:mini2440  LED  驱动程序 引用地址:mini2440 LED驱动程序开发

上一篇:mini2440烧写裸机程序
下一篇:mini2440学习之2440时钟配置解

推荐阅读最新更新时间:2026-03-21 11:30

linux-2.6.32在mini2440开发板上移植 LED 驱动程序移植
LED 驱动程序移植 编者;对于led的驱动程序,很多文章都有详细的介绍,我的博客里面有一篇专门详解这个的。需要看的,可以找下。led灯的驱动其实就代表了I/O口的驱动。在linux系统下,操作一个I/O口,可以说实在是麻烦至极与裸机操作相比较的话。这里简介移植过程,没写分析。 1 LED 驱动原理 这个就给个图就够了,搞驱动要连这个都搞不懂,那就完了。 2、驱动的移植。 在drivers/char 目录下,我们建立一个驱动程序文件mini2440_leds.c,内容如下: span style= font-size: 18px; #include linux/miscdevice.h #include linux/dela
[单片机]
linux-2.6.32在<font color='red'>mini2440</font>开发板上移植 <font color='red'>LED</font> <font color='red'>驱动程序</font>移植
mini2440 ADC可调电阻驱动程序开发源代码(杂项设备驱动框架)
/*********************************************************/ /****s3c2440 ADC可调电阻驱动程序开发源代码(杂项设备驱动框架)****/ /********************************************************/ #include #include #include #define DEVICE_NAME adc_driver /*设备名称*/ static void __iomem *adc_base; /*定义了一个用来保存经过虚拟映射后的内存地址 */ static struct clk *adc_cl
[单片机]
linux-2.6.32在mini2440开发板上移植 按键驱动程序移植
编者:按键驱动程序涉及到linux中断程序的编写。 1、按键原理图。 2、驱动程序的编写移植。 在/linux-2.6.32.2/drivers/char/目录下创建一个新的驱动程序文件mini2440_buttons.c,内容及详细注释如下: span style= font-size: 18px; #include linux/module.h #include linux/kernel.h #include linux/fs.h #include linux/init.h #include linux/delay.h #include linux/poll.h #include linux/irq.h #include
[单片机]
linux-2.6.32在<font color='red'>mini2440</font>开发板上移植 按键<font color='red'>驱动程序</font>移植
mini2440 LED灯裸机硬件控制程序
查找mini2440的原理图,找到LED部分的原理图: 然后查找nLED_1到nLED_4分别连接的S3C2440的引脚: 由图可知: nLED_1---GPB5 nLED_2---GPB6 nLED_3---GPB7 nLED_4---GPB8 在S3C2440的引脚划分中,这四个引脚都属于Port B,因此可以通过配置Port B的控制寄存器对这四个引脚的功能进行配置 如果要让LED灯亮,nLED_1到nLED_4端需要低电平,因此GPB5到GPB8引脚需要: (1)输出:GPBCON 因此,GPBCON寄存器的11,13,15,17位要设置为0,而10,12,14,16位要设置为1,而且我们还知道GPBCON
[单片机]
<font color='red'>mini2440</font> <font color='red'>LED</font>灯裸机硬件控制程序
mini2440驱动分析之LED
看LDD3有一段时间了,里面的例程也大部分实践了一下。现在进入真正的驱动程序学习。从友善之臂mini2440提供的驱动程序开始,把一些基本的驱动程序都分析一遍,以提高自己对驱动程序的认识,提高自己的编程能力。下面开始分析友善之臂mini2440提供的led驱动程序,对应文件mini2440_leds.c,内核版本号为2.6.32.2。 1. 模块注册函数 驱动程序作为内核模块出现,首先要做的就是注册自己,也就是在模块初始化中调用一些初始化以及注册函数,下面分析led驱动的模块初始化函数 static int __init dev_init(void) { int ret; int i; for (
[单片机]
mini2440汇编实例--led
系统启动阶段的代码我还是比较喜欢用汇编,可以对ARM的指令更了解一些,我用汇编改写了韦老师的led例子,代码如下 .equ GPBCON, 0x56000010 .equ GPBDAT, 0x56000014 .equ GPB5_out, (1 (5*2)) .equ GPB6_out, (1 (6*2)) .equ GPB7_out, (1 (7*2)) .equ GPB8_out, (1 (8*2)) .equ GPBVALUE, (GPB5_out | GPB6_out | GPB7_out | GPB8_out) .text .global _start _start: ldr r0,
[单片机]
三.mini2440按键控制LED
首先看原理图知道KEY的引脚: 那么我们知道了按键的引脚,根据上一篇的led的引脚,可以理清楚,按键按下会修改某寄存器的值,CPU检测到按键修改,则输出电平到LED数据寄存器,进而控制LED的亮灭。 那么来修改程序。 /*LED.c*/ #define GPBCON ((volatile unsigned int *)0x56000010)/*led控制引脚*/ #define GPBDAT ((volatile unsigned int *)0x56000014)/*led数据引脚*/ #define GPGCON ((volatile unsigned int *)0x56000060)/*key控制
[单片机]
三.<font color='red'>mini2440</font>按键控制<font color='red'>LED</font>
Mini2440通过GPIO驱动LED
以下是驱动的源码。 #includelinux/config.h//配置头文件 #includelinux/kernel.h//用于调用kmalloc和kfree #includelinux/sched.h//调度,进程睡眠,唤醒,中断申请,中断释放 #includelinux/timer.h/ #includelinux/init.h//用户定义模块初始函数名需引用的头文件 #includelinux/module.h #includeasm/hardware.h #includeasm/arch/S3C2440.h #defineDEVICE_NAMEquot;ledsquot; staticunsignedlongled_t
[单片机]
小广播
最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

厂商技术中心

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2026 EEWORLD.com.cn, Inc. All rights reserved