guowenxue
2020-08-21 b6b1283d697715c924f84f6378d2df673099dc46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*********************************************************************************
 *      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() ----- */