linux设备驱动之LED驱动测试

编程入门 行业动态 更新时间:2024-10-09 14:20:44

linux设备驱动之LED驱动<a href=https://www.elefans.com/category/jswz/34/1771117.html style=测试"/>

linux设备驱动之LED驱动测试

上篇对LED驱动代码进行分析,现在来写个LED测试测序测试该驱动。
1.驱动文件   [weiming@Huangweiming driver]$mkdir s3c_led [weiming@Huangweiming driver]$ cd s3c_led/ [weiming@Huangweiming s3c_led]$ vim s3c_led.c
/**********************************************************************************      Copyright:  (C) 2012 Guo Wenxue<guowenxue@gmail>  *                  All rights reserved.**       Filename:  s3c_led.c*    Description:  This file *                 *        Version:  1.0.0(07/26/2012~)*         Author:  Guo Wenxue <guowenxue@gmail>*      ChangeLog:  1, Release initial version on "07/26/2012 10:03:40 PM"*                 ********************************************************************************/#include <linux/module.h>   /* Every Linux kernel module must include this head */
#include <linux/init.h>     /* Every Linux kernel module must include this head */
#include <linux/kernel.h>   /* printk() */
#include <linux/fs.h>       /* struct fops */
#include <linux/errno.h>    /* error codes */
#include <linux/cdev.h>     /* cdev_alloc()  */
#include <asm/io.h>         /* ioremap()  */
#include <linux/ioport.h>   /* request_mem_region() */#include <asm/ioctl.h>      /* Linux kernel space head file for macro _IO() to generate ioctl command  */
#ifndef __KERNEL__
#include <sys/ioctl.h>      /* User space head file for macro _IO() to generate ioctl command */
#endif
//#include <linux/printk.h> /* Define log level KERN_DEBUG, no need include here */#define DRV_AUTHOR                "Guo Wenxue <guowenxue@gmail>"
#define DRV_DESC                  "S3C24XX LED driver"#define DEV_NAME                  "led"			//定义设备名称
#define LED_NUM                   4				//定义设备数量/* Set the LED dev major number */
//#define LED_MAJOR                 79
#ifndef LED_MAJOR
#define LED_MAJOR                 0	/*如果没有定义主设备好,则默认为0,一般这个定义的设备号是固定不可用的,但是这为自动分配主设备号的逻辑提供了方便。*/
#endif#define DRV_MAJOR_VER             1
#define DRV_MINOR_VER             0
#define DRV_REVER_VER             0#define DISABLE                   0	
#define ENABLE                    1#define GPIO_INPUT                0x00	//宏定义00为输入模式
#define GPIO_OUTPUT               0x01	//宏定义01为输出模式#define PLATDRV_MAGIC             0x60	//定义了一个魔数
#define LED_OFF                   _IO (PLATDRV_MAGIC, 0x18)
#define LED_ON                    _IO (PLATDRV_MAGIC, 0x19) 				/*魔数有着特殊的功能。我们定义了led_on和led_off,但是这个宏定义可能和系统的别的重复,因此我们采用魔术机制,定义一个系统未用的魔数,然后让魔术生成我们定义的led_on和led_off,这样就不会和系统相同了*/#define S3C_GPB_BASE              0x56000010	//GPB引脚基地址
#define GPBCON_OFFSET             0				//GPBCON偏移地址
#define GPBDAT_OFFSET             4				//GPBDAT偏移地址
#define GPBUP_OFFSET              8
#define S3C_GPB_LEN               0x10        /* 0x56000010~0x56000020  */int led[LED_NUM] = {5,6,8,10};  /* Four LEDs use GPB5,GPB6,GPB8,GPB10 */static void __iomem *s3c_gpb_membase;	
/* 定义s3c_gpb_membase为void __iomem*类型指针 ,在后面用来保存映射后的虚拟空间基地址。*/#define s3c_gpio_write(val, reg) __raw_writel((val), (reg)+s3c_gpb_membase)		//设置当前寄存器的值	 
#define s3c_gpio_read(reg)       __raw_readl((reg)+s3c_gpb_membase)				//读取当前虚拟地址寄存器的值  int dev_count = ARRAY_SIZE(led);	//设备个

更多推荐

linux设备驱动之LED驱动测试

本文发布于:2024-02-13 14:15:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759098.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:测试   设备   linux   LED

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!