/*********************************************************************************
|
* Copyright: (C) 2017 LingYun IoT Studio <www.iot-yun.com>
|
* All rights reserved.
|
*
|
* Filename: test_plat_led.c
|
* Description: This file used to test platdrv_led.c driver
|
*
|
* Version: 1.0.0(03/15/2014)
|
* Author: Guo Wenxue <guowenxue@gmail.com>
|
* ChangeLog: 1, Release initial version on "03/15/2014 02:03:22 PM"
|
*
|
********************************************************************************/
|
#include <stdio.h>
|
#include <string.h>
|
#include <stdarg.h>
|
#include <sys/types.h>
|
#include <sys/stat.h>
|
#include <fcntl.h>
|
#include <sys/ioctl.h>
|
#include <unistd.h>
|
#include <sys/select.h>
|
#include <errno.h>
|
|
#define LED_CNT 4
|
|
#define PLATDRV_MAGIC 0x60
|
#define LED_OFF _IO (PLATDRV_MAGIC, 0x18)
|
#define LED_ON _IO (PLATDRV_MAGIC, 0x19)
|
#define LED_BLINK _IO (PLATDRV_MAGIC, 0x20)
|
|
static inline msleep(unsigned long ms)
|
{
|
struct timeval tv;
|
|
tv.tv_sec = ms/1000;
|
tv.tv_usec = (ms%1000)*1000;
|
|
select(0, NULL, NULL, NULL, &tv);
|
}
|
|
int main (int argc, char **argv)
|
{
|
int i;
|
int fd;
|
|
if( (fd=open("/dev/led", O_RDWR, 0755)) < 0 )
|
{
|
printf("open led device failure: %s\n", strerror(errno));
|
return 0;
|
}
|
|
for(i=0; i<LED_CNT; i++)
|
ioctl(fd, LED_BLINK, i);
|
|
sleep(3);
|
|
while(1)
|
{
|
for(i=0; i<LED_CNT; i++)
|
{
|
ioctl(fd, LED_OFF, i);
|
msleep(800);
|
ioctl(fd, LED_ON, i);
|
msleep(800);
|
}
|
}
|
|
close(fd);
|
|
return 0;
|
} /* ----- End of main() ----- */
|