Dawn Framework 1.0
Universal data acquisition framework for embedded systems
dac.cxx
1// dawn/src/io/dac.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/io/dac.hxx"
7
8using namespace dawn;
9
10int CIODac::configureDesc(const CDescObject &desc)
11{
12 const SObjectCfg::SObjectCfgItem *item = nullptr;
13 size_t offset = 0;
14
15 for (size_t i = 0; i < desc.getSize(); i++)
16 {
17 item = desc.objectCfgItemAtOffset(offset);
18
20 {
21 DAWNERR("Unsupported DAC config 0x%08" PRIx32 "\n", item->cfgid.v);
22 return -EINVAL;
23 }
24
25 offset += cfgCmnOffset(item);
26 }
27
28 return OK;
29}
30
31CIODac::~CIODac()
32{
33 deinit();
34}
35
37{
38 int ret;
39
41 {
42 DAWNERR("DAC requires DTYPE_INT32\n");
43 return -EINVAL;
44 }
45
46 // Configure object
47
48 ret = configureDesc(getDesc());
49 if (ret != OK)
50 {
51 DAWNERR("DAC configure failed (error %d)\n", ret);
52 return ret;
53 }
54
55 // Get path to DAC
56
57 if (getCmnDevno() == -1)
58 {
59 DAWNERR("DAC device number not configured\n");
60 return -EINVAL;
61 }
62
63 snprintf(path, sizeof(path), DAC_PATH_FMT, getCmnDevno());
64
65 // Open file
66
67 fd = dac_open(path);
68 if (fd < 0)
69 {
70 DAWNERR("failed to open file %d\n", -errno);
71 return -errno;
72 }
73
74 // Intialize gpi
75
76 dac_init(fd);
77
78 return OK;
79}
80
82{
83 dac_close(fd);
84 return OK;
85}
86
88{
89 int32_t *tmp = static_cast<int32_t *>(data.getDataPtr());
91 int ret;
92
93 // Data dimmention must match DAC supported channels
94
95 if (data.getItems() > 1)
96 {
97 return -ENOMEM;
98 }
99
100 // get data to write
101
102 info.data = *tmp;
103
104 // Write output
105
106 ret = dac_write(fd, &info);
107 if (ret < 0)
108 {
109 DAWNERR("dac_write failed %d\n", ret);
110 return ret;
111 }
112
113#ifdef CONFIG_DAWN_IO_TIMESTAMP
114 if (isTimestamp())
115 {
116 ts = getTimestamp();
117 }
118#endif
119
120 return OK;
121}
122
124{
125 return sizeof(uint32_t) * channels;
126}
127
128size_t CIODac::getDataDim() const
129{
130 return channels;
131}
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemAtOffset(size_t offset) const
Get configuration item at specified offset.
uint64_t getTimestamp()
Get current timestamp.
Definition common.cxx:194
bool isTimestamp() const
Check if I/O supports timestamp.
Definition common.cxx:189
int getCmnDevno() const
Get device number for this I/O.
Definition common.hxx:798
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
Definition common.cxx:144
@ IO_CLASS_ANY
Any I/O class.
Definition common.hxx:86
size_t getDataSize() const
Get data size in bytes.
Definition dac.cxx:123
int configure()
Configure object from descriptor data.
Definition dac.cxx:36
int deinit()
De-initialize object.
Definition dac.cxx:81
size_t getDataDim() const
Get data vector dimension.
Definition dac.cxx:128
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
Definition dac.cxx:87
CDescObject & getDesc()
Get descriptor object for this object.
Definition object.cxx:190
uint8_t getDtype() const
Get data type field.
Definition object.cxx:175
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).
Single configuration item within object.
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
@ DTYPE_INT32
Signed 32-bit integer (-2147483648 to 2147483647).
Definition objectid.hxx:92
DAC write data.
Definition dac.hxx:22
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
Definition objectcfg.hxx:82
uint32_t cls
Object class (bits 21-29, max 511).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.