Dawn Framework 1.0
Universal data acquisition framework for embedded systems
pulsecount.cxx
1// dawn/src/porting/nuttx/pulsecount.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/porting/pulsecount.hxx"
7
8#include <errno.h>
9#include <fcntl.h>
10#include <nuttx/timers/pulsecount.h>
11#include <sys/ioctl.h>
12#include <unistd.h>
13
14#include "dawn/debug.hxx"
15
16int pulsecount_open(const char *path)
17{
18 int fd;
19
20 fd = open(path, O_WRONLY | O_NONBLOCK);
21 DAWNINFO("pulsecount: open %s %d\n", path, fd);
22 if (fd < 0)
23 {
24 DAWNERR("Failed to open pulsecount file %s (error %d)\n", path, fd);
25 return -EIO;
26 }
27
28 return fd;
29}
30
31void pulsecount_close(int fd)
32{
33 if (fd >= 0)
34 {
35 close(fd);
36 }
37}
38
39void pulsecount_init(int fd)
40{
41 (void)fd;
42}
43
44int pulsecount_start(int fd)
45{
46 return ioctl(fd, PULSECOUNTIOC_START, 0);
47}
48
49int pulsecount_stop(int fd)
50{
51 return ioctl(fd, PULSECOUNTIOC_STOP, 0);
52}
53
54int pulsecount_write(int fd, const dawn::porting::pulsecount_write_s *pulsecount)
55{
56 struct pulsecount_info_s info = {0};
57 int ret;
58
59 info.high_ns = pulsecount->high_ns;
60 info.low_ns = pulsecount->low_ns;
61 info.count = pulsecount->count;
62
63 ret = ioctl(fd, PULSECOUNTIOC_SETCHARACTERISTICS, reinterpret_cast<unsigned long>(&info));
64 if (ret < 0)
65 {
66 DAWNERR("PULSECOUNTIOC_SETCHARACTERISTICS failed %d\n", -errno);
67 return -errno;
68 }
69
70 return ret;
71}
Pulse-count output settings.