Dawn Framework 1.0
Universal data acquisition framework for embedded systems
leds.cxx
1// dawn/src/io/leds.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/porting/leds.hxx"
7
8#include "dawn/io/leds.hxx"
9
10using namespace dawn;
11
12int CIOLeds::configureDesc(const CDescObject &desc)
13{
15 size_t offset = 0;
16
17 for (size_t i = 0; i < desc.getSize(); i++)
18 {
19 item = desc.objectCfgItemAtOffset(offset);
20
21 if (item->cfgid.s.cls != CIOCommon::IO_CLASS_ANY &&
23 {
24 DAWNERR("unsupported leds cfg 0x08%" PRIx32 "\n", item->cfgid.v);
25 return -EINVAL;
26 }
27
29 {
30 offset += cfgCmnOffset(item);
31 continue;
32 }
33
34 switch (item->cfgid.s.id)
35 {
36 case IO_LEDS_CFG_INITVAL:
37 if (item->cfgid.s.size > 0)
38 {
39 initVal = *reinterpret_cast<const uint32_t *>(&item->data[0]);
40 }
41 offset += 1 + item->cfgid.s.size;
42 break;
43
44 default:
45 DAWNERR("unsupported leds cfg id %u\n", item->cfgid.s.id);
46 return -EINVAL;
47 }
48 }
49
50 return OK;
51}
52
53CIOLeds::~CIOLeds()
54{
55}
56
58{
59 int ret;
60
61 // Configure object
62
63 ret = configureDesc(getDesc());
64 if (ret != OK)
65 {
66 return ret;
67 }
68
69 // Get path to LEDS
70
71 if (getCmnDevno() == -1)
72 {
73 DAWNERR("LEDS device number not configured\n");
74 return -EINVAL;
75 }
76
77 snprintf(path, sizeof(path), LEDS_PATH_FMT, getCmnDevno());
78
79 // Open file
80
81 fd = leds_open(path);
82 if (fd < 0)
83 {
84 DAWNERR("leds_open failed %d\n", -errno);
85 return -errno;
86 }
87
88 return OK;
89}
90
92{
93 if (fd < 0)
94 {
95 return -EIO;
96 }
97
98 uint32_t val = initVal;
99 int ret = leds_write(fd, val);
100 if (ret < 0)
101 {
102 DAWNERR("leds init write failed %d\n", ret);
103 return ret;
104 }
105
106 return OK;
107}
108
110{
111 return OK;
112}
113
114int CIOLeds::getDataImpl(IODataCmn &data, size_t len)
115{
116 uint32_t *val;
117 int ret;
118
119 if (len != 1)
120 {
121 return -ENOTSUP;
122 }
123
124 val = static_cast<uint32_t *>(data.getDataPtr());
125 ret = leds_read(fd, val);
126 if (ret < 0)
127 {
128 DAWNERR("leds_read failed %d\n", ret);
129 return ret;
130 }
131
132#ifdef CONFIG_DAWN_IO_TIMESTAMP
133 if (isTimestamp())
134 {
135 data.getTs() = getTimestamp();
136 }
137#endif
138
139 return OK;
140}
141
143{
144 uint32_t *val = static_cast<uint32_t *>(data.getDataPtr());
145 int ret;
146
147 // Write output
148
149 ret = leds_write(fd, *val);
150 if (ret < 0)
151 {
152 DAWNERR("leds_write failed %d\n", ret);
153 return ret;
154 }
155
156#ifdef CONFIG_DAWN_IO_TIMESTAMP
157 if (isTimestamp())
158 {
159 ts = getTimestamp();
160 }
161#endif
162
163 return OK;
164}
165
167{
168 return sizeof(uint32_t);
169}
170
172{
173 return 1;
174}
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
@ IO_CLASS_LEDS
LED output.
Definition common.hxx:167
int init()
One-time initialize object after bindings are resolved.
Definition leds.cxx:91
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
Definition leds.cxx:142
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition leds.cxx:114
int deinit()
De-initialize object.
Definition leds.cxx:109
size_t getDataDim() const
Get data vector dimension.
Definition leds.cxx:171
int configure()
Configure object from descriptor data.
Definition leds.cxx:57
size_t getDataSize() const
Get data size in bytes.
Definition leds.cxx:166
CDescObject & getDesc()
Get descriptor object for this object.
Definition object.cxx:190
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.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
Definition objectcfg.hxx:82
uint32_t cls
Object class (bits 21-29, max 511).
uint32_t id
Configuration identifier (bits 0-4, max 31).
Definition objectcfg.hxx:94
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.