LED驱动程序的测试

前面大概聊了一下本人对led驱动的学习情况以及一些总结,现在我们用一个小的测试程序来玩一下

先给出基本的Makefile:

1 obj-m := led.o
  2 KERNEL_DIR := ~/kernel/linux-3.0.54/
  3 PWD := $(shell pwd)
  4 all:  
  5     make -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules  
  6 clean:  
  7     rm *.o *.ko *.mod.c  
  8 
  9 .PHONY:clean

再给出测试程序test.c:

t.c                                                                                                                             
  1 /*********************************************************************************
  2  *      Copyright:  (C) 2017 minda
  3  *                  All rights reserved.
  4  *
  5  *       Filename:  test.c
  6  *    Description:  This file 
  7  *                 
  8  *        Version:  1.0.0(03/29/2017)
  9  *         Author:  tangyanjun <519656780@qq.com>
 10  *      ChangeLog:  1, Release initial version on "03/29/2017 02:55:07 PM"
 11  *                 
 12  ********************************************************************************/
 13 #include<stdio.h>
 14 #include<stdlib.h>
 15 #include<unistd.h>
 16 #include<fcntl.h>
 17 #include<errno.h>
 18 #include<string.h>
 19 #include<asm/ioctl.h>
 20 #ifndef __KERNEL__
 21 #include <sys/ioctl.h>
 22 #endif
 23 
 24 #define PLATDRV_MAGIC      0X60
 25 #define LED_ON              _IO (PLATDRV_MAGIC, 0x19)
 26 #define LED_OFF            _IO (PLATDRV_MAGIC, 0x18)
 27 #define LEN_LED             4
 28 #define LED_BUF            128
 29 
 30 int main(int argc,char **argv)
 31 {
 32     int fd[LEN_LED];
 33     char dev_name[LED_BUF];
 34     int i;
 35 
 36         for(i=0;i<LEN_LED;i++)
 37         {
 38             snprintf(dev_name,sizeof(dev_name),"/dev/led%d",i);
 39             fd[i]=open(dev_name,O_RDWR,0755);
 40                 if(fd[i]<0)
 41                   {
 42                     printf("open failure:%s",strerror(errno));
 43                   }
 44         }
 45 
 46                 while(1)
 47                {
 48                   for(i=0;i<LEN_LED;i++)
 49                   {
 50                   //   ioctl(fd[i],LED_OFF);
 51                    //  sleep(0.5);
 52                      ioctl(fd[i],LED_ON);
 53                      sleep(1);
 54                      ioctl(fd[i],LED_OFF);
 55                      sleep(0.5);
 56                   }
 57 
 58 
 59               }
 60 
 61         for(i=0;i<LEN_LED;i++)
 62        {
 63              close(fd[i]);
 64              return 0;
 65        }                                                                                                                           }          


测试小程序就是根据驱动代码的一些函数调用来写,这里要注意判断出错问题,可以用来检查程序。


那么怎么测试呢?

1.先将上述Makefile和上篇的led.c驱动放在同一目录下,make编译生成“.ko”文件。

2.因为我们要把测试程序放到开发板上去测试,所以我们应该使用交叉编译器arm-linux-gcc来编译上述test.c文件,生成可执行文件。

3.将上述生成的.ko文件和可执行文件烧到开发板中:

这里的地址为我们的服务器地址。

4.在开发板中用insmod安装我们的led模块:

此时lsmod看看我们安装的驱动模块:

驱动安装好以后我们就该创建设备节点了,因为要找次设备号嘛,主设备号都是统一的,我们的板子有4个led,亮哪个灭哪个由次设备号决定,我们先查一下我们的主设备号:

我们的led为251,所有用mknod建立设备节点:

mknod /dev/led0 c 251 0
mknod /dev/led1 c 251 1
mknod /dev/led2 c 251 2
mknod /dev/led3 c 251 3

最后给我们的test可执行文件可执行权限,然后执行:


我这里创建了四个节点,点亮了四个led,所以根据测试代码,我的led灯是流水灯,这里的延时可以根据需要自己设置。


当然我们如果要卸载驱动,既可以rmmod led,记得查看:

有了这个我们才可以卸载。

HD2010操作说明(HD2010 operating instructions) ⅰ.软件安装(Installed software) 双击光盘HD2010 V2.0目录下的安装文件图标 ,将控制系统安装到个人电脑.如下图2-1 (Open Profile HD2010 V2.0 in the compact disk,Dblclick Installed the HD2010 V2.0 in your personal computer.As shown in Figure 2-1) 图(Figure)2-1 点击确定后进入下一步如图2-2 (Click确定intro- next step.As shown in Figure 2-2 ) 图(Figure)2-2 点击下一步后进入下一步(英文环境)在中文环境直接点击下一步完成安装)如图2-3 2-4 2-5 2-6 2-7 (Click next intro- next step.As shown in Figure 2-3 2-4 2-5 2-6 2-7) 图(Figure)2-3 注意:发送的文件保存在安装目录下的ProjFile文件夹里,点击下一步完成安装 (Announcements:The file what you send saved in the ProjFile in path of Install.And click next to install and finish) 图(Figure)2-4 图(Figure)2-5 图(Figure)2-6 安装最后一步如图2-7 (The final step of install. As shown in Figure 2-7) 图(Figure)2-7 点击完成打开软件主界面如图2-8 (Click finish open main interface of the software. As shown in Figure 2-8) ⅱ.软件设置(Setting software) ⅱ.ⅰ主界面如图2-8(Main interface.As shown in Figure 2-8) 图(Figure)2-8 ⅱ.ⅱ软件属性(Software properties) 1.文件菜单(File menu) a.新建--新建一个新的显示屏(New—Create a new screen) b.打开--打开一个显示屏(Open—Open a exist screen) c.保存--保存建立的文件(Save—Save file) d.另存为--保存副本(Save as—save a copy) e.导出.hds--导出.hds文件,用于u盘读取文件 (Export.hds—Export.hds file,for usb reading) f.退出--退出软件(Exit—Exit the software) 2.设置菜单(Settings menu) a.屏参设置--设置显示屏属性 (Screen settings—Display Screen configuration attributes) b.通信设置--通信端口/方式设置 (Communication settings—Set Communication prot and fashion) c.系统设置--配置系统默认项 (System settings—Set the acquice properties of software) 3.操作菜单(Operate menu) a.发送项目--发送节目(Send project—send the programmes) b.导出到U盘--把节目导入到U盘 (Export to U disk—send the programme to your U disk) c.时间设置--时间校对 (Time setting—get the right time im your computer) d.亮度设置--选择亮度模式 (Luminance setting—Choice the module of Luminance) e.固件更新--固件升级(Update Firmware—Update your controller Firmware) 4.语言菜单(Language menu) a.简体中文(Simplified Chinese) b.繁体中文(Chinese Traditional) c.英语(English) ⅱ.ⅲ节目编辑(Edit
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值