测试"/>
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驱动测试
发布评论