Dawn Framework 1.0
Universal data acquisition framework for embedded systems
adc_fetch.cxx
1// dawn/src/io/adc_fetch.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/io/adc_fetch.hxx"
7
8using namespace dawn;
9
10int CIOAdcFetch::getDataImpl(IODataCmn &data, size_t len)
11{
12 auto *dst = static_cast<uint8_t *>(data.getDataPtr());
13 size_t expected = getDataSize();
14 size_t total = 0;
15 int ret;
16
17 if (len != 1)
18 {
19 return -ENOTSUP;
20 }
21
22 if (data.getItems() < getChans())
23 {
24 return -ENOMEM;
25 }
26
27 ret = adc_start(getFdInternal());
28 if (ret < 0)
29 {
30 return ret;
31 }
32
33 // Drain the whole conversion - a short read leaves samples in the FIFO
34 // and rotates the channel order of the next fetch
35
36 while (total < expected)
37 {
38 ret = adc_read(getFdInternal(),
39 reinterpret_cast<dawn::porting::adc_read_s *>(dst + total),
40 expected - total);
41 if (ret < 0)
42 {
43 return ret;
44 }
45
46 if (ret == 0)
47 {
48 return -EIO;
49 }
50
51 total += static_cast<size_t>(ret);
52 }
53
54#ifdef CONFIG_DAWN_IO_TIMESTAMP
55 if (isTimestamp())
56 {
57 data.getTs() = getTimestamp();
58 }
59#endif
60
61 return OK;
62}
63
65{
66 return OK;
67}
68
70{
71 return OK;
72}
73
74int CIOAdcFetch::trigger(uint8_t cmd)
75{
76 UNUSED(cmd);
77 return adc_start(getFdInternal());
78}
size_t getDataSize() const
Get data size in bytes.
Definition adc_base.cxx:112
int trigger(uint8_t cmd)
Execute a trigger command.
Definition adc_fetch.cxx:74
int doStop()
Stop implementation hook.
Definition adc_fetch.cxx:69
int doStart()
Start implementation hook.
Definition adc_fetch.cxx:64
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition adc_fetch.cxx:10
uint64_t getTimestamp()
Get current timestamp.
Definition common.cxx:194
bool isTimestamp() const
Check if I/O supports timestamp.
Definition common.cxx:189
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Base interface for I/O data buffers (static and dynamic).
Definition idata.hxx:21
virtual size_t getItems()=0
Get number of items per batch.
virtual void * getDataPtr(size_t batch=0)=0
Get pointer to data only (skips timestamp if present).
virtual uint64_t & getTs(size_t batch=0)=0
Get timestamp reference for batch.
ADC read data.
Definition adc.hxx:23