1 /*
2 * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3 */
4
5 #include <sys/ioctl.h>
6 #include <stdlib.h>
7 #include <fcntl.h>
8
9 #if AOS_COMP_CLI
10 #include "aos/cli.h"
11 #endif
12 #include "aos/vfs.h"
13
14 #include <drivers/u_ld.h>
15 #include <vfsdev/adc_dev.h>
16 #include <drivers/char/u_device.h>
17
vfs_adc_handler(void * arg)18 void vfs_adc_handler (void *arg) {
19 ddkc_warn("enter %s arg:%p, fd = %d\r\n", __func__, arg, *((int *)arg));
20
21 return;
22 }
23
vfs_adc_test(int index)24 int vfs_adc_test(int index)
25 {
26 int ret = 0;
27 int fd = 0;
28 int sampling_cycle = 100;
29 char name[16] = {0};
30 io_adc_arg_t adc_arg;
31
32 snprintf(name, sizeof(name), "/dev/adc%d", index);
33 ddkc_info("opening name:%s\r\n", name);
34 fd = open(name, 0);
35 ddkc_warn("open %s %s, fd:%d\r\n", name, fd >= 0 ? "success" : "fail", fd);
36
37 if (fd >= 0) {
38 // correct parameters
39 ret = ioctl(fd, IOC_ADC_START, sampling_cycle);
40 ddkc_warn("start adc %s, ret:%d\r\n", ret ? "fail" : "succeed", ret);
41
42 sleep(1);
43 adc_arg.value = 0;
44 adc_arg.timeout = 500000; // in unit of us
45
46 ret = ioctl(fd, IOC_ADC_GET_VALUE, (unsigned long)&adc_arg);
47 ddkc_warn("get value result:%d, value:0x%x\r\n", ret, adc_arg.value);
48 sleep(1);
49
50 ret = ioctl(fd, IOC_ADC_STOP, 0);
51
52 close(fd);
53 }
54 return 0;
55 }
56
vfs_adc_cli_cmd(int argc,char ** argv)57 static void vfs_adc_cli_cmd(int argc, char **argv)
58 {
59 int ret = 0;
60 int index = argc > 1 ? atoi(argv[1]) : 1;
61
62 ddkc_info("argc:%d, index:%d\r\n", argc, index);
63 ret = vfs_adc_test(index);
64
65 ddkc_info("vfs adc test %s, ret:%d\r\n", ret ? "failed" : "success", ret);
66
67 return;
68 }
69
70 #if AOS_COMP_CLI
71 /* reg args: fun, cmd, description*/
72 ALIOS_CLI_CMD_REGISTER(vfs_adc_cli_cmd, adc_example, adc vfs example)
73 #endif
74