Dawn Framework 1.0
Universal data acquisition framework for embedded systems
serial.cxx
1// dawn/src/proto/nxscope/serial.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/proto/nxscope/serial.hxx"
7
8#include "dawn/io/common.hxx"
9#include "dawn/io/sdata.hxx"
10
11using namespace dawn;
12
13int CProtoNxscopeSerial::configureDesc(const CDescObject &desc)
14{
16 size_t offset = 0;
17
18 for (size_t i = 0; i < desc.getSize(); i++)
19 {
20 item = desc.objectCfgItemNext(offset);
21
23 {
24 DAWNERR("unsupported nxscope cfg 0x08%" PRIx32 "\n", item->cfgid.v);
25 return -EINVAL;
26 }
27
28 switch (item->cfgid.s.id)
29 {
31 {
32 const size_t wpe = sizeof(SProtoNxscopeIOBind) / 4;
33 size_t j;
34
35 for (j = 0; j < item->cfgid.s.size; j++)
36 {
37 SProtoNxscopeIOBind *tmp =
38 reinterpret_cast<SProtoNxscopeIOBind *>(item->data + j * wpe);
39
40 allocObject(tmp);
41 }
42
43 break;
44 }
45
47 {
48 const size_t wpe = sizeof(SProtoNxscopeIOBind2) / 4;
49 const size_t entry_count = item->cfgid.s.size / wpe;
50 size_t j;
51
52 if (item->cfgid.s.size % wpe != 0)
53 {
54 DAWNERR("unsupported nxscope cfg 0x08%" PRIx32 "\n", item->cfgid.v);
55 return -EINVAL;
56 }
57
58 for (j = 0; j < entry_count; j++)
59 {
60 SProtoNxscopeIOBind2 *tmp =
61 reinterpret_cast<SProtoNxscopeIOBind2 *>(item->data + j * wpe);
62
63 allocObject(&tmp->bind);
64 allocNames(j, &tmp->name);
65 }
66
67 break;
68 }
69
71 {
72 path = reinterpret_cast<const char *>(&item->data);
73 break;
74 }
75
77 {
78 baud = static_cast<uint32_t>(item->data[0]);
79 break;
80 }
81
82 default:
83 {
84 DAWNERR("unsupported nxscope cfg 0x08%" PRIx32 "\n", item->cfgid.v);
85 return -EINVAL;
86 }
87 }
88 }
89
90 return OK;
91}
92
93int CProtoNxscopeSerial::confgureNxscopePriv()
94{
95 int ret;
96
97 // NOTE: nxscope_ser_cfg_s.path is declared FAR char* (non-const)
98 // in the C API, but nxscope_ser_init() only reads it to open the
99 // device — it never modifies the string. Cast is safe.
100 nxsSerCfg.path = const_cast<char *>(path);
101 nxsSerCfg.baud = baud;
102 nxsSerCfg.nonblock = NXSCOPE_RECV_NONBLOCK;
103
104 DAWNINFO("nxscope serial path = %s baud = %ld\n", nxsSerCfg.path, nxsSerCfg.baud);
105
106 ret = nxscope_ser_init(&nxsIntf, &nxsSerCfg);
107 if (ret != OK)
108 {
109 DAWNERR("nxscope_ser_init failed: %d\n", ret);
110 return ret;
111 }
112 serInit = true;
113
114 return ret;
115}
116
117CProtoNxscopeSerial::~CProtoNxscopeSerial()
118{
119}
120
121int CProtoNxscopeSerial::initPriv()
122{
123 int ret;
124
125 // Configure object
126
127 ret = configureDesc(getDesc());
128 if (ret != OK)
129 {
130 return ret;
131 }
132
133 ret = confgureNxscopePriv();
134 if (ret != OK)
135 {
136 return ret;
137 }
138
139 ret = configureNxscope();
140 if (ret != OK)
141 {
142 return ret;
143 }
144
145 return OK;
146}
147
148int CProtoNxscopeSerial::deinitPriv()
149{
150 if (serInit)
151 {
152 nxscope_ser_deinit(&nxsIntf);
153 serInit = false;
154 }
155
156 return OK;
157}
158
159int CProtoNxscopeSerial::startPriv()
160{
161 return OK;
162}
163
164int CProtoNxscopeSerial::stopPriv()
165{
166 if (serInit)
167 {
168 nxscope_ser_deinit(&nxsIntf);
169 serInit = false;
170 }
171
172 return OK;
173}
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemNext(size_t &offset) const
Get config item at current offset and advance past it.
CDescObject & getDesc()
Get descriptor object for this object.
Definition object.cxx:190
@ PROTO_CLASS_NXSCOPE_SERIAL
NxScope real-time visualization (serial interface).
Definition common.hxx:47
@ PROTO_NXSCOPE_SERIAL_CFG_BAUD
Baud rate.
Definition serial.hxx:29
@ PROTO_NXSCOPE_SERIAL_CFG_IOBIND2
I/O bindings with names.
Definition serial.hxx:27
@ PROTO_NXSCOPE_SERIAL_CFG_IOBIND
I/O bindings.
Definition serial.hxx:26
@ PROTO_NXSCOPE_SERIAL_CFG_PATH
Serial device path.
Definition serial.hxx:28
struct nxscope_intf_s nxsIntf
NXScope interface structure (from logging library).
Definition nxscope.hxx:79
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
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.