Dawn Framework 1.0
Universal data acquisition framework for embedded systems
boardctl.cxx
1// dawn/src/io/boardctl.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/io/boardctl.hxx"
7
8#include <sys/boardctl.h>
9
10using namespace dawn;
11
12#ifdef CONFIG_BOARDCTL_RESET
13#endif
14#ifdef CONFIG_BOARDCTL_RESET_CAUSE
15#endif
16#ifdef CONFIG_BOARDCTL_POWEROFF
17#endif
18
20{
21 return dim;
22}
23
24size_t CIOBoardctl::getDataDim(uint16_t cls) const
25{
26 switch (cls)
27 {
28#ifdef CONFIG_BOARDCTL_RESET_CAUSE
30 {
31 return 2;
32 }
33#endif
34
35#ifdef CONFIG_BOARDCTL_RESET
37 {
38 return 1;
39 }
40#endif
41
42#ifdef CONFIG_BOARDCTL_POWEROFF
44 {
45 return 1;
46 }
47#endif
48
49 default:
50 {
51 DAWNERR("Invalid boardctl class %d\n", cls);
52 return 0;
53 }
54 }
55}
56
57int CIOBoardctl::getDataImpl(IODataCmn &data, size_t len)
58{
59 int ret = OK;
60
61 // Read not supported
62
63 if (!isRead())
64 {
65 return -ENOTSUP;
66 }
67
68 // No batch supported
69
70 if (len != 1)
71 {
72 return -ENOTSUP;
73 }
74
75 // Handle request
76
77 switch (getCls())
78 {
79#ifdef CONFIG_BOARDCTL_RESET_CAUSE
81 {
82 uint32_t *tmp = static_cast<uint32_t *>(data.getDataPtr());
83 struct boardioc_reset_cause_s cause;
84
85 std::memset(&cause, 0, sizeof(struct boardioc_reset_cause_s));
86
87 ret = boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&cause);
88 if (ret < 0)
89 {
90 DAWNERR("BOARDIOC_RESET_CAUSE failed %d\n", ret);
91 return ret;
92 }
93
94 // Copy data
95
96 tmp[0] = cause.cause;
97 tmp[1] = cause.flag;
98
99 break;
100 }
101#endif
102
103 default:
104 {
105 return -EINVAL;
106 }
107 }
108
109 return ret;
110}
111
113{
114 UNUSED(data);
115
116 // Write not supported
117
118 if (!isWrite())
119 {
120 return -ENOTSUP;
121 }
122
123 // Handle request
124
125 switch (getCls())
126 {
127#ifdef CONFIG_BOARDCTL_RESET
129 {
130 int32_t *outvalue = static_cast<int32_t *>(data.getDataPtr());
131 return boardctl(BOARDIOC_RESET, (int)*outvalue);
132 }
133#endif
134
135#ifdef CONFIG_BOARDCTL_POWEROFF
137 {
138 int32_t *outvalue = static_cast<int32_t *>(data.getDataPtr());
139 return boardctl(BOARDIOC_POWEROFF, (int)*outvalue);
140 }
141#endif
142
143 default:
144 {
145 return -EINVAL;
146 }
147 }
148}
149
151{
152 switch (getCls())
153 {
154#ifdef CONFIG_BOARDCTL_RESET
156 {
157 return sizeof(int32_t) * dim;
158 }
159#endif
160
161#ifdef CONFIG_BOARDCTL_RESET_CAUSE
163 {
164 return sizeof(uint32_t) * dim;
165 }
166#endif
167
168#ifdef CONFIG_BOARDCTL_POWEROFF
170 {
171 return sizeof(int32_t) * dim;
172 }
173#endif
174
175 default:
176 {
177 return 0;
178 }
179 }
180}
181
183{
184 switch (getCls())
185 {
186#ifdef CONFIG_BOARDCTL_RESET
188 {
189 return false;
190 }
191#endif
192
193#ifdef CONFIG_BOARDCTL_RESET_CAUSE
195 {
196 return true;
197 }
198#endif
199
200#ifdef CONFIG_BOARDCTL_POWEROFF
202 {
203 return false;
204 }
205#endif
206
207 default:
208 {
209 DAWNERR("Unknown boardctl class %d for isRead\n", getCls());
210 return false;
211 }
212 }
213};
214
216{
217 switch (getCls())
218 {
219#ifdef CONFIG_BOARDCTL_RESET
221 {
222 return true;
223 }
224#endif
225
226#ifdef CONFIG_BOARDCTL_RESET_CAUSE
228 {
229 return false;
230 }
231#endif
232
233#ifdef CONFIG_BOARDCTL_POWEROFF
235 {
236 return true;
237 }
238#endif
239
240 default:
241 {
242 DAWNERR("Unknown boardctl class %d for isWrite\n", getCls());
243 return false;
244 }
245 }
246};
size_t getDataSize() const
Get data size in bytes.
Definition boardctl.cxx:150
bool isRead() const
Check if IO supports read operations.
Definition boardctl.cxx:182
bool isWrite() const
Check if IO supports write operations.
Definition boardctl.cxx:215
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition boardctl.cxx:57
size_t getDataDim() const
Get data vector dimension.
Definition boardctl.cxx:19
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
Definition boardctl.cxx:112
@ IO_CLASS_SYSTEM_RESETCAUSE
Reset cause.
Definition common.hxx:153
@ IO_CLASS_SYSTEM_POWEROFF
Power off control.
Definition common.hxx:154
@ IO_CLASS_SYSTEM_RESET
System reset control.
Definition common.hxx:152
uint16_t getCls() const
Get object class field.
Definition object.cxx:170
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).