led驱动测试程序

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

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


生成a.out可执行文件
接下来在开发板上测试:
一:将s3c_led.ko,a.out传到开发板上
tftp -gr s3c_led.ko 192.168.1.2
tftp -gr a.out 192.168.1.2


二:开发板中用insmod安装我们的s3c_led模块
insmod s3c_led.ko
此时lsmod看看我们安装的驱动模块:

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

用mknod建立设备节点

给a.out执行权限
chmod 777 a.out
./a.out
做到这里就可以观察开发板上led的测试情况了!(我们如果要卸载驱动,既可以rmmod
注:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值