Dawn Framework 1.0
Universal data acquisition framework for embedded systems
gpo.cxx
1// dawn/src/io/gpo.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/io/gpo.hxx"
7
8using namespace dawn;
9
10int CIOGpo::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 GPO config 0x%08" PRIx32 "\n", item->cfgid.v);
22 return -EINVAL;
23 }
24
25 offset += cfgCmnOffset(item);
26 }
27
28 return OK;
29}
30
31CIOGpo::~CIOGpo()
32{
33 deinit();
34}
35
37{
38 int ret;
39
40 // Configure object
41
42 ret = configureDesc(getDesc());
43 if (ret != OK)
44 {
45 DAWNERR("GPO configure failed (error %d)\n", ret);
46 return ret;
47 }
48
49 // Get path to GPO
50
51 if (getCmnDevno() == -1)
52 {
53 DAWNERR("GPO device number not configured\n");
54 return -EINVAL;
55 }
56
57 snprintf(path, sizeof(path), GPO_PATH_FMT, getCmnDevno());
58
59 // Open file
60
61 fd = gpo_open(path);
62 if (fd < 0)
63 {
64 DAWNERR("gpo_open failed %d\n", -errno);
65 return -errno;
66 }
67
68 // Intialize gpi
69
70 gpo_init(fd);
71
72 return OK;
73}
74
76{
78 {
79 DAWNERR("GPO requires DTYPE_UINT32\n");
80 return -EINVAL;
81 }
82
83 return OK;
84}
85
87{
88 // Close file
89
90 gpo_close(fd);
91 return OK;
92}
93
94int CIOGpo::getDataImpl(IODataCmn &data, size_t len)
95{
96 bool *tmp = static_cast<bool *>(data.getDataPtr());
97 bool invalue;
98 int ret;
99
100 // No batch supported
101
102 if (len != 1)
103 {
104 return -ENOTSUP;
105 }
106
107 // Read output
108
109 ret = gpo_read(fd, &invalue);
110 if (ret < 0)
111 {
112 DAWNERR("gpi_read failed %d\n", ret);
113 return ret;
114 }
115
116#ifdef CONFIG_DAWN_IO_TIMESTAMP
117 if (isTimestamp())
118 {
119 data.getTs() = ts;
120 }
121#endif
122
123 *tmp = static_cast<bool>(invalue);
124
125 return OK;
126}
127
129{
130 bool *outvalue = static_cast<bool *>(data.getDataPtr());
131 int ret;
132
133 // Write output
134
135 ret = gpo_write(fd, *outvalue);
136 if (ret < 0)
137 {
138 DAWNERR("gpo_write failed %d\n", ret);
139 return ret;
140 }
141
142#ifdef CONFIG_DAWN_IO_TIMESTAMP
143 if (isTimestamp())
144 {
145 ts = getTimestamp();
146 }
147#endif
148
149 return OK;
150}
151
153{
154 return sizeof(uint32_t);
155}
156
157size_t CIOGpo::getDataDim() const
158{
159 return 1;
160}
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
int init()
One-time initialize object after bindings are resolved.
Definition gpo.cxx:75
int configure()
Configure object from descriptor data.
Definition gpo.cxx:36
size_t getDataSize() const
Get data size in bytes.
Definition gpo.cxx:152
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition gpo.cxx:94
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
Definition gpo.cxx:128
size_t getDataDim() const
Get data vector dimension.
Definition gpo.cxx:157
int deinit()
De-initialize object.
Definition gpo.cxx:86
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 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.
Single configuration item within object.
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
Definition objectid.hxx:96
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.