/*********************************************************************************
* Copyright: (C) 2015 lingyun
* All rights reserved.
*
* Filename: test_plat_led.c
* Description: This file
*
*
* Version: 1.0.0(2015年04月11日)
* Author: lzj <530604689@qq.com>
* ChangeLog: 1, Release initial version on "2015年04月11日 19时18分05秒"
*
********************************************************************************/
#include <stdio.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <stdlib.h>
#define PLATDRV_MAGIC 0x60
#define LED_OFF _IO (PLATDRV_MAGIC, 0x18)
#define LED_ON _IO (PLATDRV_MAGIC, 0x19)
#define LED_BLINK _IO (PLATDRV_MAGIC, 0x1A)
int main(int argc,char **argv)
{
int i;
int led_num;
int cmd_num;
int fd;
char dev_name[10]={0};
if(argc<3)
{
printf("too few parameters,please input:./%s 0|1|2|3 0(ON)|1(OFF)|2(BLINK)\n",argv[0]);
return -1;
}
snprintf(dev_name,sizeof(dev_name),"/dev/led");
fd=open(dev_name,O_RDWR);
led_num=atoi(argv[1]);
cmd_num=atoi(argv[2]);
switch(cmd_num)
{
case 0:
ioctl(fd,LED_ON,led_num);
break;
case 1:
ioctl(fd,LED_OFF,led_num);
break;
case 2:
ioctl(fd,LED_BLINK,led_num);
break;
default:
printf("failure\n");
break;
}
close(fd);
return 0;
}
编译成功后下载到开发板执行
./a.out 0 0就可以让第一盏灯亮 ./a.out 0 1即灭 ./a.out 0 2即闪依次类推./a.out 1 0是控制第二盏灯..........