├── .gitignore
├── CMakeLists.txt
├── Kconfig.uwb
├── LICENSE
├── README.md
├── VERSION
├── drivers
├── CMakeLists.txt
├── Kconfig
├── battery
│ ├── CMakeLists.txt
│ ├── Kconfig
│ └── battery.c
├── dw1000
│ ├── CMakeLists.txt
│ ├── Kconfig
│ ├── decadriver
│ │ ├── CMakeLists.txt
│ │ ├── deca_device.c
│ │ └── deca_params_init.c
│ └── platform
│ │ ├── CMakeLists.txt
│ │ ├── deca_mutex.c
│ │ ├── deca_range_tables.c
│ │ ├── deca_sleep.c
│ │ ├── deca_spi.c
│ │ └── port.c
└── sensor
│ ├── CMakeLists.txt
│ ├── Kconfig
│ ├── ms8607
│ ├── CMakeLists.txt
│ ├── Kconfig
│ ├── ms8607.c
│ ├── ms8607_i2c.c
│ └── ms8607_i2c.h
│ └── veml6030
│ ├── CMakeLists.txt
│ ├── Kconfig
│ └── veml6030.c
├── include
├── drivers
│ └── dw1000
│ │ ├── compiler.h
│ │ ├── deca_device_api.h
│ │ ├── deca_param_types.h
│ │ ├── deca_regs.h
│ │ ├── deca_spi.h
│ │ ├── deca_types.h
│ │ ├── deca_version.h
│ │ └── port.h
├── json.hpp
└── meshposition.h
├── media
└── forum.png
├── samples
├── 01_hello_leds
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── prj.conf
│ ├── readme.md
│ ├── sample.yaml
│ └── src
│ │ └── main.c
├── 02_listener
│ ├── CMakeLists.txt
│ ├── README.md
│ ├── prj.conf
│ └── src
│ │ └── main.c
├── 03_twr_initiator
│ ├── CMakeLists.txt
│ ├── README.md
│ ├── overlay-debug.conf
│ ├── overlay-tracing.conf
│ ├── overlay-usb.conf
│ ├── prj.conf
│ └── src
│ │ └── main.cpp
├── 04_twr_responder
│ ├── CMakeLists.txt
│ ├── README.md
│ ├── captures
│ │ ├── 1 MHz, 5 M Samples [10].logicdata
│ │ ├── 1 MHz, 5 M Samples [13].logicdata
│ │ ├── SFD timeout.logicdata
│ │ ├── default-.logicdata
│ │ ├── initiator.logicdata
│ │ ├── optimized delay 1000-1000.logicdata
│ │ ├── reduced to 1000 us ok.logicdata
│ │ ├── sfd errors.logicdata
│ │ └── twr init-resp.logicdata
│ ├── logs
│ │ ├── bad_init_alone.txt
│ │ ├── bad_init_alone_2.txt
│ │ ├── bad_init_alone_3.txt
│ │ ├── badfix_init_alone.txt
│ │ ├── good_init_alone.txt
│ │ ├── good_init_reg.txt
│ │ └── good_resp_reg.txt
│ ├── overlay-debug.conf
│ ├── overlay-tracing.conf
│ ├── overlay-usb.conf
│ ├── prj.conf
│ └── src
│ │ └── main.cpp
├── 05_listener_sm
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── overlay-debug.conf
│ ├── overlay-tracing.conf
│ ├── overlay-usb.conf
│ ├── prj.conf
│ ├── readme.md
│ ├── sample.yaml
│ └── src
│ │ └── main.cpp
├── 06_uwb_node_sm
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── overlay-debug.conf
│ ├── overlay-tracing.conf
│ ├── overlay-usb.conf
│ ├── prj.conf
│ ├── readme.md
│ ├── sample.yaml
│ └── src
│ │ └── main.cpp
├── CMakeLists.txt
└── Kconfig
├── subsys
├── CMakeLists.txt
├── Kconfig
└── meshposition
│ ├── CMakeLists.txt
│ ├── Kconfig
│ ├── mesh_twr.cpp
│ └── meshposition.cpp
├── west.yml
└── zephyr
└── module.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.d
3 | *.cmd
4 | *.log
5 | *.pyc
6 | *.swp
7 | *.swo
8 | *~
9 | build
10 | build-*
11 | build_*
12 | cscope.*
13 | .dir
14 |
15 | /*.patch
16 |
17 | tags
18 | .project
19 | .cproject
20 | .xxproject
21 | .envrc
22 | .vscode
23 | sanity-out*
24 | twister-out*
25 |
26 | doc/_build
27 | doc/nrf/_doxygen/
28 | doc/nrf/_samples/
29 | doc/*_warnings.txt
30 | doc/*_doc.log
31 |
32 | ext/lib/bin/supl
33 | ext/lib/bin/libsupl.zip
34 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Point to root directory.
2 | set(HSM_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "root directory")
3 |
4 | zephyr_include_directories(include)
5 |
6 | add_subdirectory(samples)
7 | add_subdirectory(drivers)
8 | add_subdirectory(subsys)
9 |
--------------------------------------------------------------------------------
/Kconfig.uwb:
--------------------------------------------------------------------------------
1 |
2 | menu "Home Smart Mesh"
3 |
4 | rsource "samples/Kconfig"
5 | rsource "drivers/Kconfig"
6 | rsource "subsys/Kconfig"
7 |
8 | endmenu
9 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # sdk-uwb-zephyr
2 | Zephyr sdk for uwb module DWM1001C based on nRF52832 and DW1000 Transceiver
3 | # discussions
4 | get support, give feedback or simply chat to brainstorm about ideas on the forum
5 |
6 | https://github.com/nRFMesh/sdk-uwb-zephyr/discussions
7 | # Framework doc
8 | https://www.homesmartmesh.com/docs/networks/ultrawideband/
9 |
10 | # usage
11 | ```bash
12 | west init -m https://github.com/nRFMesh/sdk-uwb-zephyr --mr main
13 | ```
14 |
15 | # takeover
16 | driver zephyr port from https://github.com/foldedtoad/dwm1001.git
17 |
18 | * `uwb\drivers\dw1000\decadriver`
19 | * `uwb\drivers\dw1000\platform`
20 |
--------------------------------------------------------------------------------
/VERSION:
--------------------------------------------------------------------------------
1 | 1.0.0
2 |
--------------------------------------------------------------------------------
/drivers/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_subdirectory_ifdef(CONFIG_SENSOR sensor)
2 | add_subdirectory_ifdef(CONFIG_BATTERY battery)
3 | add_subdirectory_ifdef(CONFIG_DW1000 dw1000)
4 |
--------------------------------------------------------------------------------
/drivers/Kconfig:
--------------------------------------------------------------------------------
1 | menu "Device Drivers"
2 |
3 | rsource "sensor/Kconfig"
4 |
5 | rsource "battery/Kconfig"
6 |
7 | rsource "dw1000/Kconfig"
8 |
9 | endmenu
10 |
--------------------------------------------------------------------------------
/drivers/battery/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: Apache-2.0
2 |
3 | zephyr_library()
4 |
5 | zephyr_library_sources_ifdef(CONFIG_BATTERY battery.c)
6 |
--------------------------------------------------------------------------------
/drivers/battery/Kconfig:
--------------------------------------------------------------------------------
1 | config BATTERY
2 | bool "BATTERY ADC VDD"
3 | depends on ADC
4 | help
5 | Enable driver for measuring Battery through ADC VDD Channel.
6 |
--------------------------------------------------------------------------------
/drivers/battery/battery.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | LOG_MODULE_REGISTER(battery, LOG_LEVEL_INF);
9 |
10 | #define ADC_CHANNEL 0
11 | #define ADC_RESOLUTION 12
12 | #define ADC_GAIN ADC_GAIN_1_6
13 | #define ADC_REFERENCE ADC_REF_INTERNAL
14 | #define ADC_ACQUISITION_TIME ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS,40)
15 |
16 | const struct device *dev_adc;
17 | static int16_t sample;
18 | int32_t adc_vref;
19 | struct adc_channel_cfg channel_cfg = {
20 | .gain = ADC_GAIN,
21 | .reference = ADC_REFERENCE,
22 | .acquisition_time = ADC_ACQUISITION_TIME,
23 | .channel_id = ADC_CHANNEL,
24 | #ifdef CONFIG_ADC_CONFIGURABLE_INPUTS
25 | .differential = 0,
26 | .input_positive = SAADC_CH_PSELN_PSELN_VDD
27 | #else
28 | .differential = 0
29 | #endif
30 | };
31 |
32 | struct adc_sequence sequence = {
33 | .channels = BIT(ADC_CHANNEL),
34 | .buffer = &sample,
35 | /* buffer size in bytes, not number of samples */
36 | .buffer_size = sizeof(sample),
37 | .resolution = ADC_RESOLUTION,
38 | };
39 |
40 | void battery_init()
41 | {
42 | dev_adc = device_get_binding(DT_LABEL(DT_NODELABEL(adc)));
43 | if (!device_is_ready(dev_adc)) {
44 | LOG_ERR("ADC device not found\n");
45 | return;
46 | }
47 |
48 | adc_channel_setup(dev_adc, &channel_cfg);
49 | adc_vref = adc_ref_internal(dev_adc);
50 |
51 | LOG_INF("battery_init() vref = %d",adc_vref);
52 | }
53 |
54 | void battery_start()
55 | {
56 | int err = adc_read(dev_adc, &sequence);
57 | if (err != 0) {
58 | LOG_ERR("ADC reading failed with error %d.\n", err);
59 | return;
60 | }else{
61 | LOG_INF("battery_start> adc_read()");
62 | }
63 | }
64 |
65 | int32_t battery_get_mv()
66 | {
67 | int32_t raw_value = sample;
68 | LOG_INF("battery_get_mv() raw = %d",raw_value);
69 | int32_t mv_value = raw_value;
70 | adc_raw_to_millivolts(adc_vref, ADC_GAIN,ADC_RESOLUTION, &mv_value);
71 | return mv_value;
72 | }
73 |
--------------------------------------------------------------------------------
/drivers/dw1000/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_subdirectory(decadriver)
3 | add_subdirectory(platform)
4 |
--------------------------------------------------------------------------------
/drivers/dw1000/Kconfig:
--------------------------------------------------------------------------------
1 | menuconfig DW1000
2 | bool "DW1000 Tranceiver"
3 | help
4 | Include DW1000 Tranceiver drivers in config
5 |
--------------------------------------------------------------------------------
/drivers/dw1000/decadriver/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: Apache-2.0
2 |
3 | zephyr_library()
4 |
5 | zephyr_library_sources_ifdef(CONFIG_DW1000 deca_device.c)
6 | zephyr_library_sources_ifdef(CONFIG_DW1000 deca_params_init.c)
7 |
--------------------------------------------------------------------------------
/drivers/dw1000/decadriver/deca_params_init.c:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file deca_params_init.c
3 | * @brief DW1000 configuration parameters
4 | *
5 | * @attention
6 | *
7 | * Copyright 2013 (c) Decawave Ltd, Dublin, Ireland.
8 | *
9 | * All rights reserved.
10 | *
11 | *
12 | * -------------------------------------------------------------------------------------------------------------------
13 | **/
14 | #include
15 | #include
16 |
17 | #include
18 | #include
19 | #include
20 |
21 |
22 | //-----------------------------------------
23 | // map the channel number to the index in the configuration arrays below
24 | // 0th element is chan 1, 1st is chan 2, 2nd is chan 3, 3rd is chan 4, 4th is chan 5, 5th is chan 7
25 | const uint8 chan_idx[NUM_CH_SUPPORTED] = {0, 0, 1, 2, 3, 4, 0, 5};
26 |
27 | //-----------------------------------------
28 | const uint32 tx_config[NUM_CH] =
29 | {
30 | RF_TXCTRL_CH1,
31 | RF_TXCTRL_CH2,
32 | RF_TXCTRL_CH3,
33 | RF_TXCTRL_CH4,
34 | RF_TXCTRL_CH5,
35 | RF_TXCTRL_CH7,
36 | };
37 |
38 | //Frequency Synthesiser - PLL configuration
39 | const uint32 fs_pll_cfg[NUM_CH] =
40 | {
41 | FS_PLLCFG_CH1,
42 | FS_PLLCFG_CH2,
43 | FS_PLLCFG_CH3,
44 | FS_PLLCFG_CH4,
45 | FS_PLLCFG_CH5,
46 | FS_PLLCFG_CH7
47 | };
48 |
49 | //Frequency Synthesiser - PLL tuning
50 | const uint8 fs_pll_tune[NUM_CH] =
51 | {
52 | FS_PLLTUNE_CH1,
53 | FS_PLLTUNE_CH2,
54 | FS_PLLTUNE_CH3,
55 | FS_PLLTUNE_CH4,
56 | FS_PLLTUNE_CH5,
57 | FS_PLLTUNE_CH7
58 | };
59 |
60 | //bandwidth configuration
61 | const uint8 rx_config[NUM_BW] =
62 | {
63 | RF_RXCTRLH_NBW,
64 | RF_RXCTRLH_WBW
65 | };
66 |
67 |
68 | const agc_cfg_struct agc_config =
69 | {
70 | AGC_TUNE2_VAL,
71 | { AGC_TUNE1_16M , AGC_TUNE1_64M } //adc target
72 | };
73 |
74 | //DW non-standard SFD length for 110k, 850k and 6.81M
75 | const uint8 dwnsSFDlen[NUM_BR] =
76 | {
77 | DW_NS_SFD_LEN_110K,
78 | DW_NS_SFD_LEN_850K,
79 | DW_NS_SFD_LEN_6M8
80 | };
81 |
82 | // SFD Threshold
83 | const uint16 sftsh[NUM_BR][NUM_SFD] =
84 | {
85 | {
86 | DRX_TUNE0b_110K_STD,
87 | DRX_TUNE0b_110K_NSTD
88 | },
89 | {
90 | DRX_TUNE0b_850K_STD,
91 | DRX_TUNE0b_850K_NSTD
92 | },
93 | {
94 | DRX_TUNE0b_6M8_STD,
95 | DRX_TUNE0b_6M8_NSTD
96 | }
97 | };
98 |
99 | const uint16 dtune1[NUM_PRF] =
100 | {
101 | DRX_TUNE1a_PRF16,
102 | DRX_TUNE1a_PRF64
103 | };
104 |
105 | const uint32 digital_bb_config[NUM_PRF][NUM_PACS] =
106 | {
107 | {
108 | DRX_TUNE2_PRF16_PAC8,
109 | DRX_TUNE2_PRF16_PAC16,
110 | DRX_TUNE2_PRF16_PAC32,
111 | DRX_TUNE2_PRF16_PAC64
112 | },
113 | {
114 | DRX_TUNE2_PRF64_PAC8,
115 | DRX_TUNE2_PRF64_PAC16,
116 | DRX_TUNE2_PRF64_PAC32,
117 | DRX_TUNE2_PRF64_PAC64
118 | }
119 | };
120 |
121 | const uint16 lde_replicaCoeff[PCODES] =
122 | {
123 | 0, // No preamble code 0
124 | LDE_REPC_PCODE_1,
125 | LDE_REPC_PCODE_2,
126 | LDE_REPC_PCODE_3,
127 | LDE_REPC_PCODE_4,
128 | LDE_REPC_PCODE_5,
129 | LDE_REPC_PCODE_6,
130 | LDE_REPC_PCODE_7,
131 | LDE_REPC_PCODE_8,
132 | LDE_REPC_PCODE_9,
133 | LDE_REPC_PCODE_10,
134 | LDE_REPC_PCODE_11,
135 | LDE_REPC_PCODE_12,
136 | LDE_REPC_PCODE_13,
137 | LDE_REPC_PCODE_14,
138 | LDE_REPC_PCODE_15,
139 | LDE_REPC_PCODE_16,
140 | LDE_REPC_PCODE_17,
141 | LDE_REPC_PCODE_18,
142 | LDE_REPC_PCODE_19,
143 | LDE_REPC_PCODE_20,
144 | LDE_REPC_PCODE_21,
145 | LDE_REPC_PCODE_22,
146 | LDE_REPC_PCODE_23,
147 | LDE_REPC_PCODE_24
148 | };
149 |
150 |
151 |
152 |
153 |
--------------------------------------------------------------------------------
/drivers/dw1000/platform/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: Apache-2.0
2 |
3 | zephyr_library()
4 |
5 | zephyr_library_sources_ifdef(CONFIG_DW1000 deca_mutex.c)
6 | zephyr_library_sources_ifdef(CONFIG_DW1000 deca_range_tables.c)
7 | zephyr_library_sources_ifdef(CONFIG_DW1000 deca_sleep.c)
8 | zephyr_library_sources_ifdef(CONFIG_DW1000 deca_spi.c)
9 | zephyr_library_sources_ifdef(CONFIG_DW1000 port.c)
10 |
11 |
--------------------------------------------------------------------------------
/drivers/dw1000/platform/deca_mutex.c:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file deca_mutex.c
3 | * @brief IRQ interface / mutex implementation
4 | *
5 | * @attention
6 | *
7 | * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
8 | *
9 | * All rights reserved.
10 | *
11 | */
12 |
13 | #include
14 | #include
15 | // ---------------------------------------------------------------------------
16 | //
17 | // NB: The purpose of this file is to provide for microprocessor interrupt enable/disable, this is used for
18 | // controlling mutual exclusion from critical sections in the code where interrupts and background
19 | // processing may interact. The code using this is kept to a minimum and the disabling time is also
20 | // kept to a minimum, so blanket interrupt disable may be the easiest way to provide this. But at a
21 | // minimum those interrupts coming from the decawave device should be disabled/re-enabled by this activity.
22 | //
23 | // In porting this to a particular microprocessor, the implementer may choose to use #defines in the
24 | // deca_irq.h include file to map these calls transparently to the target system. Alternatively the
25 | // appropriate code may be embedded in the functions provided below.
26 | //
27 | // This mutex dependent on HW port.
28 | // If HW port uses EXT_IRQ line to receive ready/busy status from DW1000 then mutex should use this signal
29 | // If HW port not use EXT_IRQ line (i.e. SW polling) then no necessary for decamutex(on/off)
30 | //
31 | // For critical section use this mutex instead
32 | // __save_intstate()
33 | // __restore_intstate()
34 | // ---------------------------------------------------------------------------
35 |
36 |
37 | /*! ------------------------------------------------------------------------------------------------------------------
38 | * Function: decamutexon()
39 | *
40 | * Description: This function should disable interrupts. This is called at the start of a critical section
41 | * It returns the irq state before disable, this value is used to re-enable in decamutexoff call
42 | *
43 | * Note: The body of this function is defined in deca_mutex.c and is platform specific
44 | *
45 | * input parameters:
46 | *
47 | * output parameters
48 | *
49 | * returns the state of the DW1000 interrupt
50 | */
51 | decaIrqStatus_t decamutexon(void)
52 | {
53 | //TODO
54 | return 0 ; // return state before disable, value is used to re-enable in decamutexoff call
55 | }
56 |
57 | /*! ------------------------------------------------------------------------------------------------------------------
58 | * Function: decamutexoff()
59 | *
60 | * Description: This function should re-enable interrupts, or at least restore their state as returned(&saved) by decamutexon
61 | * This is called at the end of a critical section
62 | *
63 | * Note: The body of this function is defined in deca_mutex.c and is platform specific
64 | *
65 | * input parameters:
66 | * @param s - the state of the DW1000 interrupt as returned by decamutexon
67 | *
68 | * output parameters
69 | *
70 | * returns the state of the DW1000 interrupt
71 | */
72 | void decamutexoff(decaIrqStatus_t s) // put a function here that re-enables the interrupt at the end of the critical section
73 | {
74 | //TODO
75 | }
76 |
--------------------------------------------------------------------------------
/drivers/dw1000/platform/deca_range_tables.c:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file deca_range_tables.c
3 | * @brief DW1000 range correction tables
4 | *
5 | * @attention
6 | *
7 | * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
8 | *
9 | * All rights reserved.
10 | *
11 | */
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 |
18 | #define NUM_16M_OFFSET (37)
19 | #define NUM_16M_OFFSETWB (68)
20 | #define NUM_64M_OFFSET (26)
21 | #define NUM_64M_OFFSETWB (59)
22 |
23 | const uint8 chan_idxnb[NUM_CH_SUPPORTED] = {0, 0, 1, 2, 0, 3, 0, 0}; //only channels 1,2,3 and 5 are in the narrow band tables
24 | const uint8 chan_idxwb[NUM_CH_SUPPORTED] = {0, 0, 0, 0, 0, 0, 0, 1}; //only channels 4 and 7 are in in the wide band tables
25 |
26 | //---------------------------------------------------------------------------------------------------------------------------
27 | // Range Bias Correction TABLES of range values in integer units of 25 CM, for 8-bit unsigned storage, MUST END IN 255 !!!!!!
28 | //---------------------------------------------------------------------------------------------------------------------------
29 |
30 | // offsets to nearest centimeter for index 0, all rest are +1 cm per value
31 |
32 | #define CM_OFFSET_16M_NB (-23) // for normal band channels at 16 MHz PRF
33 | #define CM_OFFSET_16M_WB (-28) // for wider band channels at 16 MHz PRF
34 | #define CM_OFFSET_64M_NB (-17) // for normal band channels at 64 MHz PRF
35 | #define CM_OFFSET_64M_WB (-30) // for wider band channels at 64 MHz PRF
36 |
37 |
38 | //---------------------------------------------------------------------------------------------------------------------------
39 | // range25cm16PRFnb: Range Bias Correction table for narrow band channels at 16 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
40 | //---------------------------------------------------------------------------------------------------------------------------
41 |
42 | const uint8 range25cm16PRFnb[4][NUM_16M_OFFSET] =
43 | {
44 | // ch 1 - range25cm16PRFnb
45 | {
46 | 1,
47 | 3,
48 | 4,
49 | 5,
50 | 7,
51 | 9,
52 | 11,
53 | 12,
54 | 13,
55 | 15,
56 | 18,
57 | 20,
58 | 23,
59 | 25,
60 | 28,
61 | 30,
62 | 33,
63 | 36,
64 | 40,
65 | 43,
66 | 47,
67 | 50,
68 | 54,
69 | 58,
70 | 63,
71 | 66,
72 | 71,
73 | 76,
74 | 82,
75 | 89,
76 | 98,
77 | 109,
78 | 127,
79 | 155,
80 | 222,
81 | 255,
82 | 255
83 | },
84 |
85 | // ch 2 - range25cm16PRFnb
86 | {
87 | 1,
88 | 2,
89 | 4,
90 | 5,
91 | 6,
92 | 8,
93 | 9,
94 | 10,
95 | 12,
96 | 13,
97 | 15,
98 | 18,
99 | 20,
100 | 22,
101 | 24,
102 | 27,
103 | 29,
104 | 32,
105 | 35,
106 | 38,
107 | 41,
108 | 44,
109 | 47,
110 | 51,
111 | 55,
112 | 58,
113 | 62,
114 | 66,
115 | 71,
116 | 78,
117 | 85,
118 | 96,
119 | 111,
120 | 135,
121 | 194,
122 | 240,
123 | 255
124 | },
125 |
126 | // ch 3 - range25cm16PRFnb
127 | {
128 | 1,
129 | 2,
130 | 3,
131 | 4,
132 | 5,
133 | 7,
134 | 8,
135 | 9,
136 | 10,
137 | 12,
138 | 14,
139 | 16,
140 | 18,
141 | 20,
142 | 22,
143 | 24,
144 | 26,
145 | 28,
146 | 31,
147 | 33,
148 | 36,
149 | 39,
150 | 42,
151 | 45,
152 | 49,
153 | 52,
154 | 55,
155 | 59,
156 | 63,
157 | 69,
158 | 76,
159 | 85,
160 | 98,
161 | 120,
162 | 173,
163 | 213,
164 | 255
165 | },
166 |
167 | // ch 5 - range25cm16PRFnb
168 | {
169 | 1,
170 | 1,
171 | 2,
172 | 3,
173 | 4,
174 | 5,
175 | 6,
176 | 6,
177 | 7,
178 | 8,
179 | 9,
180 | 11,
181 | 12,
182 | 14,
183 | 15,
184 | 16,
185 | 18,
186 | 20,
187 | 21,
188 | 23,
189 | 25,
190 | 27,
191 | 29,
192 | 31,
193 | 34,
194 | 36,
195 | 38,
196 | 41,
197 | 44,
198 | 48,
199 | 53,
200 | 59,
201 | 68,
202 | 83,
203 | 120,
204 | 148,
205 | 255
206 | }
207 | }; // end range25cm16PRFnb
208 |
209 |
210 | //---------------------------------------------------------------------------------------------------------------------------
211 | // range25cm16PRFwb: Range Bias Correction table for wide band channels at 16 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
212 | //---------------------------------------------------------------------------------------------------------------------------
213 |
214 | const uint8 range25cm16PRFwb[2][NUM_16M_OFFSETWB] =
215 | {
216 | // ch 4 - range25cm16PRFwb
217 | {
218 | 7,
219 | 7,
220 | 8,
221 | 9,
222 | 9,
223 | 10,
224 | 11,
225 | 11,
226 | 12,
227 | 13,
228 | 14,
229 | 15,
230 | 16,
231 | 17,
232 | 18,
233 | 19,
234 | 20,
235 | 21,
236 | 22,
237 | 23,
238 | 24,
239 | 26,
240 | 27,
241 | 28,
242 | 30,
243 | 31,
244 | 32,
245 | 34,
246 | 36,
247 | 38,
248 | 40,
249 | 42,
250 | 44,
251 | 46,
252 | 48,
253 | 50,
254 | 52,
255 | 55,
256 | 57,
257 | 59,
258 | 61,
259 | 63,
260 | 66,
261 | 68,
262 | 71,
263 | 74,
264 | 78,
265 | 81,
266 | 85,
267 | 89,
268 | 94,
269 | 99,
270 | 104,
271 | 110,
272 | 116,
273 | 123,
274 | 130,
275 | 139,
276 | 150,
277 | 164,
278 | 182,
279 | 207,
280 | 238,
281 | 255,
282 | 255,
283 | 255,
284 | 255,
285 | 255
286 | },
287 |
288 | // ch 7 - range25cm16PRFwb
289 | {
290 | 4,
291 | 5,
292 | 5,
293 | 5,
294 | 6,
295 | 6,
296 | 7,
297 | 7,
298 | 7,
299 | 8,
300 | 9,
301 | 9,
302 | 10,
303 | 10,
304 | 11,
305 | 11,
306 | 12,
307 | 13,
308 | 13,
309 | 14,
310 | 15,
311 | 16,
312 | 17,
313 | 17,
314 | 18,
315 | 19,
316 | 20,
317 | 21,
318 | 22,
319 | 23,
320 | 25,
321 | 26,
322 | 27,
323 | 29,
324 | 30,
325 | 31,
326 | 32,
327 | 34,
328 | 35,
329 | 36,
330 | 38,
331 | 39,
332 | 40,
333 | 42,
334 | 44,
335 | 46,
336 | 48,
337 | 50,
338 | 52,
339 | 55,
340 | 58,
341 | 61,
342 | 64,
343 | 68,
344 | 72,
345 | 75,
346 | 80,
347 | 85,
348 | 92,
349 | 101,
350 | 112,
351 | 127,
352 | 147,
353 | 168,
354 | 182,
355 | 194,
356 | 205,
357 | 255
358 | }
359 | }; // end range25cm16PRFwb
360 |
361 | //---------------------------------------------------------------------------------------------------------------------------
362 | // range25cm64PRFnb: Range Bias Correction table for narrow band channels at 64 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
363 | //---------------------------------------------------------------------------------------------------------------------------
364 |
365 | const uint8 range25cm64PRFnb[4][NUM_64M_OFFSET] =
366 | {
367 | // ch 1 - range25cm64PRFnb
368 | {
369 | 1,
370 | 2,
371 | 2,
372 | 3,
373 | 4,
374 | 5,
375 | 7,
376 | 10,
377 | 13,
378 | 16,
379 | 19,
380 | 22,
381 | 24,
382 | 27,
383 | 30,
384 | 32,
385 | 35,
386 | 38,
387 | 43,
388 | 48,
389 | 56,
390 | 78,
391 | 101,
392 | 120,
393 | 157,
394 | 255
395 | },
396 |
397 | // ch 2 - range25cm64PRFnb
398 | {
399 | 1,
400 | 2,
401 | 2,
402 | 3,
403 | 4,
404 | 4,
405 | 6,
406 | 9,
407 | 12,
408 | 14,
409 | 17,
410 | 19,
411 | 21,
412 | 24,
413 | 26,
414 | 28,
415 | 31,
416 | 33,
417 | 37,
418 | 42,
419 | 49,
420 | 68,
421 | 89,
422 | 105,
423 | 138,
424 | 255
425 | },
426 |
427 | // ch 3 - range25cm64PRFnb
428 | {
429 | 1,
430 | 1,
431 | 2,
432 | 3,
433 | 3,
434 | 4,
435 | 5,
436 | 8,
437 | 10,
438 | 13,
439 | 15,
440 | 17,
441 | 19,
442 | 21,
443 | 23,
444 | 25,
445 | 27,
446 | 30,
447 | 33,
448 | 37,
449 | 44,
450 | 60,
451 | 79,
452 | 93,
453 | 122,
454 | 255
455 | },
456 |
457 | // ch 5 - range25cm64PRFnb
458 | {
459 | 1,
460 | 1,
461 | 1,
462 | 2,
463 | 2,
464 | 3,
465 | 4,
466 | 6,
467 | 7,
468 | 9,
469 | 10,
470 | 12,
471 | 13,
472 | 15,
473 | 16,
474 | 17,
475 | 19,
476 | 21,
477 | 23,
478 | 26,
479 | 30,
480 | 42,
481 | 55,
482 | 65,
483 | 85,
484 | 255
485 | }
486 | }; // end range25cm64PRFnb
487 |
488 | //---------------------------------------------------------------------------------------------------------------------------
489 | // range25cm64PRFwb: Range Bias Correction table for wide band channels at 64 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
490 | //---------------------------------------------------------------------------------------------------------------------------
491 |
492 | const uint8 range25cm64PRFwb[2][NUM_64M_OFFSETWB] =
493 | {
494 | // ch 4 - range25cm64PRFwb
495 | {
496 | 7,
497 | 8,
498 | 8,
499 | 9,
500 | 9,
501 | 10,
502 | 11,
503 | 12,
504 | 13,
505 | 13,
506 | 14,
507 | 15,
508 | 16,
509 | 16,
510 | 17,
511 | 18,
512 | 19,
513 | 19,
514 | 20,
515 | 21,
516 | 22,
517 | 24,
518 | 25,
519 | 27,
520 | 28,
521 | 29,
522 | 30,
523 | 32,
524 | 33,
525 | 34,
526 | 35,
527 | 37,
528 | 39,
529 | 41,
530 | 43,
531 | 45,
532 | 48,
533 | 50,
534 | 53,
535 | 56,
536 | 60,
537 | 64,
538 | 68,
539 | 74,
540 | 81,
541 | 89,
542 | 98,
543 | 109,
544 | 122,
545 | 136,
546 | 146,
547 | 154,
548 | 162,
549 | 178,
550 | 220,
551 | 249,
552 | 255,
553 | 255,
554 | 255
555 | },
556 |
557 | // ch 7 - range25cm64PRFwb
558 | {
559 | 4,
560 | 5,
561 | 5,
562 | 5,
563 | 6,
564 | 6,
565 | 7,
566 | 7,
567 | 8,
568 | 8,
569 | 9,
570 | 9,
571 | 10,
572 | 10,
573 | 10,
574 | 11,
575 | 11,
576 | 12,
577 | 13,
578 | 13,
579 | 14,
580 | 15,
581 | 16,
582 | 16,
583 | 17,
584 | 18,
585 | 19,
586 | 19,
587 | 20,
588 | 21,
589 | 22,
590 | 23,
591 | 24,
592 | 25,
593 | 26,
594 | 28,
595 | 29,
596 | 31,
597 | 33,
598 | 35,
599 | 37,
600 | 39,
601 | 42,
602 | 46,
603 | 50,
604 | 54,
605 | 60,
606 | 67,
607 | 75,
608 | 83,
609 | 90,
610 | 95,
611 | 100,
612 | 110,
613 | 135,
614 | 153,
615 | 172,
616 | 192,
617 | 255
618 | }
619 | }; // end range25cm64PRFwb
620 |
621 |
622 | /*! ------------------------------------------------------------------------------------------------------------------
623 | * Function: dwt_getrangebias()
624 | *
625 | * Description: This function is used to return the range bias correction need for TWR with DW1000 units.
626 | *
627 | * input parameters:
628 | * @param chan - specifies the operating channel (e.g. 1, 2, 3, 4, 5, 6 or 7)
629 | * @param range - the calculated distance before correction
630 | * @param prf - this is the PRF e.g. DWT_PRF_16M or DWT_PRF_64M
631 | *
632 | * output parameters
633 | *
634 | * returns correction needed in meters
635 | */
636 | double dwt_getrangebias(uint8 chan, float range, uint8 prf)
637 | {
638 | //first get the lookup index that corresponds to given range for a particular channel at 16M PRF
639 | int i = 0 ;
640 | int chanIdx ;
641 | int cmoffseti ; // integer number of CM offset
642 |
643 | double mOffset ; // final offset result in metres
644 |
645 | // NB: note we may get some small negitive values e.g. up to -50 cm.
646 |
647 | int rangeint25cm = (int) (range * 4.00) ; // convert range to integer number of 25cm values.
648 |
649 | if (rangeint25cm > 255) rangeint25cm = 255 ; // make sure it matches largest value in table (all tables end in 255 !!!!)
650 |
651 | if (prf == DWT_PRF_16M)
652 | {
653 | switch(chan)
654 | {
655 | case 4:
656 | case 7:
657 | {
658 | chanIdx = chan_idxwb[chan];
659 | while (rangeint25cm > range25cm16PRFwb[chanIdx][i]) i++ ; // find index in table corresponding to range
660 | cmoffseti = i + CM_OFFSET_16M_WB ; // nearest centimeter correction
661 | }
662 | break;
663 | default:
664 | {
665 | chanIdx = chan_idxnb[chan];
666 | while (rangeint25cm > range25cm16PRFnb[chanIdx][i]) i++ ; // find index in table corresponding to range
667 | cmoffseti = i + CM_OFFSET_16M_NB ; // nearest centimeter correction
668 | }
669 | }//end of switch
670 | }
671 | else // 64M PRF
672 | {
673 | switch(chan)
674 | {
675 | case 4:
676 | case 7:
677 | {
678 | chanIdx = chan_idxwb[chan];
679 | while (rangeint25cm > range25cm64PRFwb[chanIdx][i]) i++ ; // find index in table corresponding to range
680 | cmoffseti = i + CM_OFFSET_64M_WB ; // nearest centimeter correction
681 | }
682 | break;
683 | default:
684 | {
685 | chanIdx = chan_idxnb[chan];
686 | while (rangeint25cm > range25cm64PRFnb[chanIdx][i]) i++ ; // find index in table corresponding to range
687 | cmoffseti = i + CM_OFFSET_64M_NB ; // nearest centimeter correction
688 | }
689 | }//end of switch
690 | } // end else
691 |
692 |
693 | mOffset = (float) cmoffseti ; // offset result in centimmetres
694 |
695 | mOffset *= 0.01 ; // convert to metres
696 |
697 | return (mOffset) ;
698 | }
699 |
--------------------------------------------------------------------------------
/drivers/dw1000/platform/deca_sleep.c:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file deca_sleep.c
3 | * @brief platform dependent sleep implementation
4 | *
5 | * @attention
6 | *
7 | * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
8 | *
9 | * All rights reserved.
10 | *
11 | * @author DecaWave
12 | */
13 |
14 | #include
15 |
16 | #include
17 | #include
18 |
19 | /* Wrapper function to be used by decadriver. Declared in deca_device_api.h */
20 | void deca_sleep(unsigned int time_ms)
21 | {
22 | k_msleep(time_ms);
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/drivers/dw1000/platform/deca_spi.c:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file deca_spi.c
3 | * @brief SPI access functions
4 | *
5 | * @attention
6 | *
7 | * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
8 | * Copyright 2019 (c) Frederic Mes, RTLOC.
9 | * Copyright 2019 (c) Callender-Consulting LLC.
10 | *
11 | * All rights reserved.
12 | *
13 | * @author DecaWave
14 | */
15 |
16 | #include
17 | #include
18 | #include
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #define LOG_LEVEL 3
28 | #include
29 | LOG_MODULE_REGISTER(deca_spi);
30 |
31 | const struct device * spi;
32 | struct spi_config * spi_cfg;
33 | struct spi_config spi_cfgs [4] = {0};
34 |
35 | #define SPI_CFGS_COUNT ((sizeof(spi_cfgs)/sizeof(spi_cfgs[0])))
36 |
37 | uint8_t tx_buf [255];
38 | uint8_t rx_buf [255];
39 |
40 | struct spi_buf bufs [2];
41 |
42 | struct spi_buf_set tx;
43 | struct spi_buf_set rx;
44 |
45 | static struct spi_cs_control cs_ctrl;
46 |
47 | /*
48 | *****************************************************************************
49 | *
50 | * DW1000 SPI section
51 | *
52 | *****************************************************************************
53 | */
54 |
55 | /*
56 | * Function: openspi()
57 | *
58 | * Low level abstract function to open and initialise access to the SPI device.
59 | * returns 0 for success, or -1 for error
60 | */
61 | int openspi(void)
62 | {
63 | /* Propagate CS config into all spi_cfgs[] elements */
64 | cs_ctrl.gpio_dev = device_get_binding(DT_LABEL(DT_PHANDLE_BY_IDX(DT_NODELABEL(spi2), cs_gpios, 0)));
65 | if (!cs_ctrl.gpio_dev) {
66 | printk("%s: GPIO binding failed.\n", __func__);
67 | return -1;
68 | }
69 | cs_ctrl.gpio_pin = DT_PHA(DT_NODELABEL(spi2), cs_gpios, pin);
70 | cs_ctrl.delay = 0U;
71 | cs_ctrl.gpio_dt_flags = DT_PHA(DT_NODELABEL(spi2), cs_gpios, flags);
72 | for (int i=0; i < SPI_CFGS_COUNT; i++) {
73 | spi_cfgs[i].cs = &cs_ctrl;
74 | }
75 |
76 | spi_cfg = &spi_cfgs[0];
77 |
78 | spi = device_get_binding(DT_LABEL(DT_NODELABEL(spi2)));
79 | if (!spi) {
80 | printk("%s: SPI binding failed.\n", __func__);
81 | return -1;
82 | }
83 | spi_cfg->operation = SPI_WORD_SET(8);
84 | spi_cfg->frequency = 2000000;
85 |
86 | memset(&tx_buf[0], 0, 255);
87 | memset(&rx_buf[0], 0, 255);
88 | bufs[0].buf = &tx_buf[0];
89 | bufs[1].buf = &rx_buf[0];
90 | tx.buffers = &bufs[0];
91 | rx.buffers = &bufs[1];
92 | tx.count = 1;
93 | rx.count = 1;
94 |
95 | return 0;
96 | }
97 |
98 | void set_spi_speed_slow(void)
99 | {
100 | spi_cfg = &spi_cfgs[0];
101 | spi_cfg->operation = SPI_WORD_SET(8);
102 | spi_cfg->frequency = 2000000;
103 |
104 | memset(&tx_buf[0], 0, 255);
105 | memset(&rx_buf[0], 0, 255);
106 | }
107 |
108 | void set_spi_speed_fast(void)
109 | {
110 | spi_cfg = &spi_cfgs[1];
111 | spi_cfg->operation = SPI_WORD_SET(8);
112 | spi_cfg->frequency = 8000000;
113 |
114 | memset(&tx_buf[0], 0, 255);
115 | memset(&rx_buf[0], 0, 255);
116 | }
117 |
118 | /*
119 | * Function: closespi()
120 | *
121 | * Low level abstract function to close the the SPI device.
122 | * returns 0 for success, or -1 for error
123 | */
124 | int closespi(void)
125 | {
126 | //TODO
127 | return 0;
128 | }
129 |
130 | /*
131 | * Function: writetospi()
132 | *
133 | * Low level abstract function to write to the SPI
134 | * Takes two separate byte buffers for write header and write data
135 | * returns 0 for success
136 | */
137 | int writetospi(uint16 headerLength,
138 | const uint8 * headerBuffer,
139 | uint32 bodyLength,
140 | const uint8 * bodyBuffer)
141 | {
142 | decaIrqStatus_t stat;
143 |
144 | #if 0
145 | LOG_HEXDUMP_INF(headerBuffer, headerLength, "writetospi: Header");
146 | LOG_HEXDUMP_INF(bodyBuffer, bodyLength, "writetospi: Body");
147 | #endif
148 |
149 | stat = decamutexon();
150 |
151 | memcpy(&tx_buf[0], headerBuffer, headerLength);
152 | memcpy(&tx_buf[headerLength], bodyBuffer, bodyLength);
153 |
154 | bufs[0].len = headerLength + bodyLength;
155 | bufs[1].len = headerLength + bodyLength;
156 |
157 | spi_transceive(spi, spi_cfg, &tx, &rx);
158 |
159 | decamutexoff(stat);
160 |
161 | return 0;
162 | }
163 |
164 | /*
165 | * Function: readfromspi()
166 | *
167 | * Low level abstract function to read from the SPI
168 | * Takes two separate byte buffers for write header and read data
169 | * returns the offset into read buffer where first byte of read data
170 | * may be found, or returns 0
171 | */
172 | int readfromspi(uint16 headerLength,
173 | const uint8 * headerBuffer,
174 | uint32 readLength,
175 | uint8 * readBuffer)
176 | {
177 | decaIrqStatus_t stat;
178 |
179 | stat = decamutexon();
180 |
181 | memset(&tx_buf[0], 0, headerLength + readLength);
182 | memcpy(&tx_buf[0], headerBuffer, headerLength);
183 |
184 | bufs[0].len = headerLength + readLength;
185 | bufs[1].len = headerLength + readLength;
186 |
187 | spi_transceive(spi, spi_cfg, &tx, &rx);
188 |
189 | memcpy(readBuffer, rx_buf + headerLength, readLength);
190 |
191 | decamutexoff(stat);
192 |
193 | #if 0
194 | LOG_HEXDUMP_INF(headerBuffer, headerLength, "readfromspi: Header");
195 | LOG_HEXDUMP_INF(readBuffer, readLength, "readfromspi: Body");
196 | #endif
197 |
198 | return 0;
199 | }
200 |
--------------------------------------------------------------------------------
/drivers/dw1000/platform/port.c:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file port.c
3 | * @brief HW specific definitions and functions for portability
4 | *
5 | * @attention
6 | *
7 | * Copyright 2016 (c) DecaWave Ltd, Dublin, Ireland.
8 | * Copyright 2019 (c) Frederic Mes, RTLOC.
9 | *
10 | *
11 | * All rights reserved.
12 | *
13 | * @author DecaWave
14 | */
15 |
16 | #include
17 | #include
18 | #include
19 |
20 | // zephyr includes
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | static const struct device * gpio_dev;
30 | static struct gpio_callback gpio_cb;
31 |
32 | /****************************************************************************//**
33 | *
34 | * APP global variables
35 | *
36 | *******************************************************************************/
37 |
38 | /****************************************************************************//**
39 | *
40 | * Port private variables and function prototypes
41 | *
42 | *******************************************************************************/
43 | static volatile uint32_t signalResetDone;
44 |
45 | /****************************************************************************//**
46 | *
47 | * Time section
48 | *
49 | *******************************************************************************/
50 |
51 | /* @fn usleep
52 | * @brief precise usleep() delay
53 | * */
54 | #pragma GCC optimize ("O0")
55 | int usleep(unsigned long usec)
56 | {
57 | int i,j;
58 | #pragma GCC ivdep
59 | for(i=0;i
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 |
26 | #include "ms8607_i2c.h"
27 |
28 | LOG_MODULE_REGISTER(MS8607, CONFIG_SENSOR_LOG_LEVEL);
29 |
30 | #define SENSOR_LOG_LEVEL_OFF 0
31 | #define SENSOR_LOG_LEVEL_ERROR 1
32 | #define SENSOR_LOG_LEVEL_WARNING 2
33 | #define SENSOR_LOG_LEVEL_INFO 3
34 | #define SENSOR_LOG_LEVEL_DEBUG 4
35 |
36 |
37 |
38 | struct ms8607_data *drv_data;
39 |
40 | void delay_ms(uint32_t time)
41 | {
42 | k_sleep(K_MSEC(time));
43 | }
44 |
45 | void i2c_master_init(const struct device *dev)
46 | {
47 | drv_data = dev->data;
48 | LOG_INF("ms8607_init> i2c_master_init()");
49 | }
50 |
51 | enum status_code i2c_master_read_packet_wait(struct i2c_master_packet *const packet)
52 | {
53 | if (i2c_read(drv_data->i2c , packet->data, packet->data_length, packet->address)) {
54 | return STATUS_ERR_TIMEOUT;
55 | }
56 |
57 | return STATUS_OK;
58 | }
59 |
60 | enum status_code i2c_master_write_packet_wait(struct i2c_master_packet *const packet)
61 | {
62 | if(i2c_write(drv_data->i2c , packet->data, packet->data_length, packet->address)){
63 | return STATUS_ERR_TIMEOUT;
64 | }
65 |
66 | return STATUS_OK;
67 | }
68 |
69 | enum status_code i2c_master_write_packet_wait_no_stop(struct i2c_master_packet *const packet)
70 | {
71 | struct i2c_msg msg;
72 |
73 | msg.buf = packet->data;
74 | msg.len = packet->data_length;
75 | msg.flags = I2C_MSG_WRITE;// | I2C_MSG_STOP removed
76 |
77 | if(i2c_transfer(drv_data->i2c, &msg, 1, packet->address)){
78 | return STATUS_ERR_TIMEOUT;
79 | }
80 |
81 | return STATUS_OK;
82 | }
83 |
84 |
85 | #ifdef __cplusplus
86 | }
87 | #endif
88 |
--------------------------------------------------------------------------------
/drivers/sensor/ms8607/ms8607_i2c.h:
--------------------------------------------------------------------------------
1 | /**
2 | * \brief MS8607 Temperature sensor driver source file
3 | *
4 | * Copyright (c) 2016 Measurement Specialties. All rights reserved.
5 | *
6 | * For details on programming, refer to ms8607 datasheet :
7 | * http://www.meas-spec.com/downloads/MS8607D.pdf
8 | *
9 | */
10 |
11 | #ifndef MS8607_I2C_H_INCLUDED
12 | #define MS8607_I2C_H_INCLUDED
13 |
14 | #include
15 | #include
16 |
17 | enum i2c_transfer_direction {
18 | I2C_TRANSFER_WRITE = 0,
19 | I2C_TRANSFER_READ = 1,
20 | };
21 |
22 | enum status_code {
23 | STATUS_OK = 0x00,
24 | STATUS_ERR_OVERFLOW = 0x01,
25 | STATUS_ERR_TIMEOUT = 0x02,
26 | };
27 |
28 | struct i2c_master_packet {
29 | // Address to slave device
30 | uint16_t address;
31 | // Length of data array
32 | uint16_t data_length;
33 | // Data array containing all data to be transferred
34 | uint8_t *data;
35 | };
36 |
37 | struct ms8607_data {
38 | const struct device *i2c;
39 | uint16_t sample;
40 | float humidity;
41 | float pressure;
42 | float temperature;
43 | };
44 |
45 |
46 | void delay_ms(uint32_t time);
47 | void i2c_master_init(const struct device *dev);
48 | enum status_code i2c_master_read_packet_wait(struct i2c_master_packet *const packet);
49 | enum status_code i2c_master_write_packet_wait(struct i2c_master_packet *const packet);
50 | enum status_code i2c_master_write_packet_wait_no_stop(struct i2c_master_packet *const packet);
51 |
52 |
53 |
54 | #endif /* MS8607_I2C_H_INCLUDED */
55 |
--------------------------------------------------------------------------------
/drivers/sensor/veml6030/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: Apache-2.0
2 |
3 | zephyr_library()
4 |
5 | zephyr_library_sources_ifdef(CONFIG_VEML6030 veml6030.c)
6 |
--------------------------------------------------------------------------------
/drivers/sensor/veml6030/Kconfig:
--------------------------------------------------------------------------------
1 | # VEML6030 light sensor configuration options
2 |
3 | # Copyright (c) 2016 Intel Corporation
4 | # SPDX-License-Identifier: Apache-2.0
5 |
6 | config VEML6030
7 | bool "VEML6030 Light Sensor"
8 | depends on I2C
9 | help
10 | Enable driver for VEML6030 light sensors.
11 |
--------------------------------------------------------------------------------
/drivers/sensor/veml6030/veml6030.c:
--------------------------------------------------------------------------------
1 | #define DT_DRV_COMPAT vishay_veml6030
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 |
12 | LOG_MODULE_REGISTER(VEML6030, CONFIG_SENSOR_LOG_LEVEL);
13 |
14 | #define SENSOR_LOG_LEVEL_OFF 0
15 | #define SENSOR_LOG_LEVEL_ERROR 1
16 | #define SENSOR_LOG_LEVEL_WARNING 2
17 | #define SENSOR_LOG_LEVEL_INFO 3
18 | #define SENSOR_LOG_LEVEL_DEBUG 4
19 |
20 | const float ref_gain_25_ms_1_8 = 1.8432;
21 | float lut_gain[] = {1,2,0.125,0.25};
22 | uint16_t lut_integration_ms[] = {100,200,400,800,0,0,0,0,50,0,0,0,25,0,0,0};
23 |
24 | // * Strategy tries to diminish gain first
25 | // * avoids edges by roughly ~ 2%, the last value within range would not tell if it is correct or saturated
26 | // * (8) takes UINT32_MAX because that's the lowest possible gain and integration time
27 | float modes_illum[] = {
28 | 230.0, // (0)
29 | 460.0, // (1)
30 | 1840.0, // (2)
31 | 3680.0, // (3)
32 | 7360.0, // (4)
33 | 14720.0, // (5)
34 | 29440.0, // (6)
35 | 58880.0, // (7)
36 | 200000.0, // (8)
37 | };
38 | uint16_t modes_flags[] = {
39 | VEML6030_ALS_CONF_ALS_IT_800_ms | VEML6030_ALS_CONF_ALS_GAIN_x2, // (0)
40 | VEML6030_ALS_CONF_ALS_IT_800_ms | VEML6030_ALS_CONF_ALS_GAIN_x1, // (1)
41 | VEML6030_ALS_CONF_ALS_IT_800_ms | VEML6030_ALS_CONF_ALS_GAIN_x1_4, // (2)
42 | VEML6030_ALS_CONF_ALS_IT_800_ms | VEML6030_ALS_CONF_ALS_GAIN_x1_8, // (3)
43 | VEML6030_ALS_CONF_ALS_IT_400_ms | VEML6030_ALS_CONF_ALS_GAIN_x1_8, // (4)
44 | VEML6030_ALS_CONF_ALS_IT_200_ms | VEML6030_ALS_CONF_ALS_GAIN_x1_8, // (5)
45 | VEML6030_ALS_CONF_ALS_IT_100_ms | VEML6030_ALS_CONF_ALS_GAIN_x1_8, // (6)
46 | VEML6030_ALS_CONF_ALS_IT_50_ms | VEML6030_ALS_CONF_ALS_GAIN_x1_8, // (7)
47 | VEML6030_ALS_CONF_ALS_IT_25_ms | VEML6030_ALS_CONF_ALS_GAIN_x1_8, // (8)
48 | };
49 |
50 | float reg_to_lum_lux(uint16_t val, uint16_t it_ms, float gain)
51 | {
52 | float resolution = 1.8432 / ((gain/0.125) * (it_ms/25));
53 | //uint32_t res = resolution * 1000;
54 | //if(gain == 0.125)LOG_DBG("gain = 0.125");
55 | //else if(gain == 0.25)LOG_DBG("gain = 0.25");
56 | //else if(gain == 1)LOG_DBG("gain = 1");
57 | //else if(gain == 2)LOG_DBG("gain = 2");
58 | //else LOG_DBG("gain = %d uGain",(int)(gain*1000));
59 | //LOG_DBG("integration time = %d ; resolution = %d mRes",it_ms,res);
60 | float lum_lux = val;
61 | float x = lum_lux * resolution;
62 | //y = 6.0135E-13x4 - 9.3924E-09x3 + 8.1488E-05x2 + 1.0023E+00x
63 | //correction will always be applied to avoid edges
64 | const float C0 = 1.0023;
65 | const float C1 = 8.1488E-05;
66 | const float C2 = -9.3924E-09;
67 | const float C3 = 6.0135E-13;
68 | float x_2 = x * x;
69 | float x_3 = x_2 * x;
70 | float x_4 = x_3 * x;
71 | float y = x_4 * C3 + x_3 * C2 + x_2 * C1 + x * C0;
72 | //printf("measure = %f ; corrected measure = %f",x,y);
73 | return y;
74 | }
75 |
76 | uint8_t get_optimal_mode(uint16_t sample,float lum_lux)
77 | {
78 | //actually, on saturation, set the highest mode to avoid slow raming up
79 | if(sample == 65535){
80 | return 8;
81 | }
82 | else
83 | {
84 | uint8_t index = 0;
85 | while((lum_lux > modes_illum[index])&&(index<8))
86 | {
87 | index++;
88 | }
89 | return index;
90 | }
91 | }
92 |
93 | static int veml6030_reg_read(struct veml6030_data *drv_data, uint8_t reg,uint16_t *val)
94 | {
95 | uint8_t valb[2];
96 | if (i2c_burst_read(drv_data->i2c , VEML6030_I2C_ADDRESS, reg, valb, 2)) {
97 | return -EIO;
98 | }
99 |
100 | (*val) = valb[1];
101 | (*val) = ((*val)<<8) + valb[0];
102 |
103 | return 0;
104 | }
105 |
106 | static int veml6030_reg_write(struct veml6030_data *drv_data, uint8_t reg,uint16_t val)
107 | {
108 | uint8_t bdata[2];
109 | bdata[0] = (uint8_t)(val&0xFF);
110 | bdata[1] = (uint8_t)(val>>8);
111 |
112 | return i2c_burst_write(drv_data->i2c , VEML6030_I2C_ADDRESS, reg, bdata, 2);
113 | }
114 |
115 | static int veml6030_reg_update(struct veml6030_data *drv_data, uint8_t reg,uint8_t mask, uint8_t val)
116 | {
117 | uint16_t old_val = 0U;
118 | uint16_t new_val = 0U;
119 |
120 | if (veml6030_reg_read(drv_data, reg, &old_val) != 0) {
121 | return -EIO;
122 | }
123 |
124 | new_val = old_val & ~mask;
125 | new_val |= val & mask;
126 |
127 | return veml6030_reg_write(drv_data, reg, new_val);
128 | }
129 |
130 | static int veml6030_attr_set( const struct device *dev,enum sensor_channel chan,
131 | enum sensor_attribute attr,const struct sensor_value *val)
132 | {
133 | struct veml6030_data *drv_data = dev->data;
134 |
135 | if (veml6030_reg_update(drv_data, VEML6030_REG_ALS_CONF, VEML6030_ALS_CONF_ALS_SD_MASK, VEML6030_ALS_CONF_ALS_SD_ON))
136 | {
137 | return -EIO;
138 | }
139 |
140 | return 0;
141 | }
142 |
143 | static int veml6030_sample_fetch(const struct device *dev,enum sensor_channel chan)
144 | {
145 | struct veml6030_data *drv_data = dev->data;
146 | uint16_t val;
147 |
148 | __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_LIGHT);
149 |
150 | drv_data->sample = 0U;
151 |
152 | if(veml6030_reg_read(drv_data , VEML6030_REG_ALS, &val)){
153 | return -EIO;
154 | }
155 | drv_data->sample = val;
156 | return 0;
157 | }
158 |
159 | static int veml6030_channel_get(const struct device *dev,enum sensor_channel chan,struct sensor_value *val)
160 | {
161 | struct veml6030_data *drv_data = dev->data;
162 |
163 | if (chan != SENSOR_CHAN_LIGHT) {
164 | return -ENOTSUP;
165 | }
166 | float resolution = 1.8432 / ((drv_data->gain/0.125) * (drv_data->integration_ms/25));
167 | val->val1 = drv_data->sample * resolution; //tunc
168 | val->val2 = (drv_data->sample * resolution * 1000000) - (val->val1 * 1000000); //fraction - millionth
169 |
170 | return 0;
171 | }
172 |
173 | static const struct sensor_driver_api veml6030_driver_api = {
174 | .attr_set = veml6030_attr_set,
175 | .sample_fetch = veml6030_sample_fetch,
176 | .channel_get = veml6030_channel_get,
177 | };
178 |
179 | static int veml6030_power_update(struct veml6030_data *drv_data, uint16_t val)
180 | {
181 | uint16_t old_config = 0U;
182 | uint16_t new_config = 0U;
183 |
184 | if (veml6030_reg_read(drv_data, VEML6030_REG_ALS_CONF, &old_config) != 0) {
185 | return -EIO;
186 | }
187 | //update params needed in every config update - here in power with existing config from sensors only
188 | uint16_t integration_bits = old_config & VEML6030_ALS_CONF_ALS_IT_MASK;
189 | uint16_t gain_bits = old_config & VEML6030_ALS_CONF_ALS_GAIN_MASK;
190 | drv_data->config_it_gain = integration_bits | gain_bits;
191 | drv_data->integration_ms = lut_integration_ms[integration_bits>>6];
192 | drv_data->gain = lut_gain[gain_bits>>11];
193 |
194 | new_config = old_config & ~VEML6030_ALS_CONF_ALS_SD_MASK;
195 | new_config |= val & VEML6030_ALS_CONF_ALS_SD_MASK;
196 |
197 | return veml6030_reg_write(drv_data, VEML6030_REG_ALS_CONF, new_config);
198 | }
199 |
200 | static int veml6030_it_gain_update(struct veml6030_data *drv_data, uint16_t val)
201 | {
202 | uint16_t old_config = 0U;
203 | uint16_t new_config = 0U;
204 | int ret = 0;
205 |
206 | if (veml6030_reg_read(drv_data, VEML6030_REG_ALS_CONF, &old_config) != 0) {
207 | LOG_ERR("veml6030_reg_read() failed");
208 | return -EIO;
209 | }
210 | uint16_t mask = (VEML6030_ALS_CONF_ALS_IT_MASK | VEML6030_ALS_CONF_ALS_GAIN_MASK);
211 | new_config = old_config & ~mask;
212 | new_config |= val & mask;
213 |
214 | uint16_t integration_bits = new_config & VEML6030_ALS_CONF_ALS_IT_MASK;
215 | uint16_t gain_bits = new_config & VEML6030_ALS_CONF_ALS_GAIN_MASK;
216 | drv_data->config_it_gain = integration_bits | gain_bits;
217 | drv_data->integration_ms = lut_integration_ms[integration_bits>>6];
218 | drv_data->gain = lut_gain[gain_bits>>11];
219 |
220 | ret = veml6030_reg_write(drv_data, VEML6030_REG_ALS_CONF, new_config);
221 | if(ret){
222 | LOG_ERR("veml6030_reg_write() failed");
223 | }
224 | return ret;
225 | }
226 |
227 | int veml6030_power_on(const struct device *dev)
228 | {
229 | struct veml6030_data *drv_data = dev->data;
230 | int ret = veml6030_power_update(drv_data,VEML6030_ALS_CONF_ALS_SD_ON);
231 | if (ret) {
232 | LOG_ERR("veml6030_power_update() failed");
233 | }
234 | return ret;
235 | }
236 |
237 | int veml6030_power_off(const struct device *dev)
238 | {
239 | struct veml6030_data *drv_data = dev->data;
240 | int ret = veml6030_power_update(drv_data,VEML6030_ALS_CONF_ALS_SD_OFF);
241 | if (ret) {
242 | LOG_ERR("veml6030_power_update() failed");
243 | }
244 | return ret;
245 | }
246 |
247 | int veml6030_init(const struct device *dev)
248 | {
249 | struct veml6030_data *drv_data = dev->data;
250 | LOG_INF("veml6030_init()");
251 | drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
252 | if (drv_data->i2c == NULL) {
253 | LOG_ERR("Failed to get pointer to %s device!",DT_INST_BUS_LABEL(0));
254 | return -EINVAL;
255 | }
256 |
257 | return 0;
258 | }
259 |
260 | static struct veml6030_data veml6030_drv_data;
261 |
262 | DEVICE_DT_INST_DEFINE(0, veml6030_init, device_pm_control_nop,
263 | &veml6030_drv_data, NULL, POST_KERNEL,
264 | CONFIG_SENSOR_INIT_PRIORITY, &veml6030_driver_api);
265 |
266 | float veml6030_fetch_lux(const struct device *dev)
267 | {
268 | struct veml6030_data *drv_data = dev->data;
269 | if (veml6030_sample_fetch(dev, SENSOR_CHAN_LIGHT) != 0) {
270 | LOG_ERR("sensor: sample fetch fail.");
271 | return 0;
272 | }
273 |
274 | return reg_to_lum_lux(drv_data->sample,drv_data->integration_ms, drv_data->gain);
275 | }
276 |
277 | //a measure might not be good (e.g. saturated) if not taken with optimal config that is checked after the measure has taken place
278 | float veml6030_auto_measure(const struct device *dev)
279 | {
280 | struct veml6030_data *drv_data = dev->data;
281 | float measure_lux = 0;
282 |
283 | veml6030_power_on(dev);//4 ms min after power on => will update the drv_data ->integration_ms and ->gain
284 |
285 | bool optimal_measure = false;// no measure yet
286 | while(!optimal_measure)
287 | {
288 | k_sleep(K_MSEC(2*drv_data->integration_ms+5));//wait the integration time +5 ms clock drift safety : x2 as x1 fail with reading 0
289 | measure_lux = veml6030_fetch_lux(dev);
290 | uint8_t optimal_mode = get_optimal_mode(drv_data->sample,measure_lux);
291 | if(modes_flags[optimal_mode] == drv_data->config_it_gain)//optimal mode already selected
292 | {
293 | optimal_measure = true;
294 | }
295 | else
296 | {
297 | printf("auto_measure>sample %d not optimal ; gain = %.3f ; it = %d ms\n",
298 | drv_data->sample, drv_data->gain, drv_data->integration_ms);
299 | //update both integration and gain to the new optimal value
300 | veml6030_it_gain_update(drv_data,modes_flags[optimal_mode]);
301 | printf("auto_measure>new params => gain = %f ; it = %d\n",drv_data->gain,drv_data->integration_ms);
302 | optimal_measure = false;
303 | }
304 | }
305 |
306 | veml6030_power_off(dev);
307 | drv_data->lum_lux = measure_lux;
308 | drv_data->lum_lux = measure_lux;
309 | return measure_lux;
310 | }
311 |
--------------------------------------------------------------------------------
/include/drivers/dw1000/compiler.h:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file compiler.h
3 | * @brief
4 | *
5 | * @attention
6 | *
7 | * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
8 | *
9 | * All rights reserved.
10 | *
11 | * @author DecaWave
12 | */
13 |
14 | #ifndef COMPILER_H_
15 | #define COMPILER_H_
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 |
22 | #ifdef __GNUC__
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | // #include
29 | #include
30 | #include
31 |
32 | #ifndef CLOCKS_PER_SEC
33 | #define CLOCKS_PER_SEC 1000
34 | #endif
35 |
36 | #ifndef TRUE
37 | #define TRUE true
38 | #endif
39 | #ifndef FALSE
40 | #define FALSE false
41 | #endif
42 |
43 | #ifndef __align4
44 | #define __align4 __attribute__((aligned (4)))
45 | #endif
46 | #ifndef __weak
47 | #define __weak __attribute__((weak))
48 | #endif
49 | #ifndef __always_inline
50 | #define __always_inline __attribute__((always_inline))
51 | #endif
52 |
53 | #endif
54 |
55 |
56 | #ifdef __cplusplus
57 | }
58 | #endif
59 |
60 | #endif /* COMPILER_H_ */
61 |
--------------------------------------------------------------------------------
/include/drivers/dw1000/deca_device_api.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nRFMesh/sdk-uwb-zephyr/284334860839b077e5aa922071986c837ac0e0e3/include/drivers/dw1000/deca_device_api.h
--------------------------------------------------------------------------------
/include/drivers/dw1000/deca_param_types.h:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file deca_param_types.h
3 | * @brief Decawave general type definitions for configuration structures
4 | *
5 | * @attention
6 | *
7 | * Copyright 2013 (c) Decawave Ltd, Dublin, Ireland.
8 | *
9 | * All rights reserved.
10 | *
11 | */
12 | #ifndef _DECA_PARAM_TYPES_H_
13 | #define _DECA_PARAM_TYPES_H_
14 |
15 | #ifdef __cplusplus
16 | extern "C" {
17 | #endif
18 | #include "deca_types.h"
19 |
20 | #define NUM_BR 3
21 | #define NUM_PRF 2
22 | #define NUM_PACS 4
23 | #define NUM_BW 2 //2 bandwidths are supported
24 | #define NUM_SFD 2 //supported number of SFDs - standard = 0, non-standard = 1
25 | #define NUM_CH 6 //supported channels are 1, 2, 3, 4, 5, 7
26 | #define NUM_CH_SUPPORTED 8 //supported channels are '0', 1, 2, 3, 4, 5, '6', 7
27 | #define PCODES 25 //supported preamble codes
28 |
29 |
30 | typedef struct {
31 | uint32 lo32;
32 | uint16 target[NUM_PRF];
33 | } agc_cfg_struct ;
34 |
35 | extern const agc_cfg_struct agc_config ;
36 |
37 | //SFD threshold settings for 110k, 850k, 6.8Mb standard and non-standard
38 | extern const uint16 sftsh[NUM_BR][NUM_SFD];
39 |
40 | extern const uint16 dtune1[NUM_PRF];
41 |
42 | #define XMLPARAMS_VERSION (1.17f)
43 |
44 | extern const uint32 fs_pll_cfg[NUM_CH];
45 | extern const uint8 fs_pll_tune[NUM_CH];
46 | extern const uint8 rx_config[NUM_BW];
47 | extern const uint32 tx_config[NUM_CH];
48 | extern const uint8 dwnsSFDlen[NUM_BR]; //length of SFD for each of the bitrates
49 | extern const uint32 digital_bb_config[NUM_PRF][NUM_PACS];
50 | extern const uint8 chan_idx[NUM_CH_SUPPORTED];
51 |
52 | #define TEMP_COMP_FACTOR_CH2 (327) //(INT) (0.0798 * 4096)
53 | #define TEMP_COMP_FACTOR_CH5 (607) //(INT) (0.1482 * 4096)
54 | #define SAR_TEMP_TO_CELCIUS_CONV (1.14)
55 | #define SAR_VBAT_TO_VOLT_CONV (1.0/173)
56 |
57 | #define DCELCIUS_TO_SAR_TEMP_CONV ((int)((0.10/1.14)*256))
58 | #define MVOLT_TO_SAR_VBAT_CONV (173.0/1000)
59 |
60 | #define MIXER_GAIN_STEP (0.5)
61 | #define DA_ATTN_STEP (2.5)
62 |
63 | #define MIX_DA_FACTOR (DA_ATTN_STEP/MIXER_GAIN_STEP)
64 |
65 | #define PEAK_MULTPLIER (0x60) //3 -> (0x3 * 32) & 0x00E0
66 | #define N_STD_FACTOR (13)
67 | #define LDE_PARAM1 (PEAK_MULTPLIER | N_STD_FACTOR)
68 |
69 | #define LDE_PARAM3_16 (0x1607)
70 | #define LDE_PARAM3_64 (0x0607)
71 |
72 | extern const uint16 lde_replicaCoeff[PCODES];
73 |
74 | #ifdef __cplusplus
75 | }
76 | #endif
77 |
78 | #endif
79 |
80 |
81 |
--------------------------------------------------------------------------------
/include/drivers/dw1000/deca_regs.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nRFMesh/sdk-uwb-zephyr/284334860839b077e5aa922071986c837ac0e0e3/include/drivers/dw1000/deca_regs.h
--------------------------------------------------------------------------------
/include/drivers/dw1000/deca_spi.h:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file deca_spi.h
3 | * @brief SPI access functions
4 | *
5 | * @attention
6 | *
7 | * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
8 | *
9 | * All rights reserved.
10 | *
11 | * @author DecaWave
12 | */
13 |
14 | #ifndef _DECA_SPI_H_
15 | #define _DECA_SPI_H_
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | #include "deca_types.h"
22 |
23 | #define DECA_MAX_SPI_HEADER_LENGTH (3) // max number of bytes in header (for formating & sizing)
24 |
25 | /*! ------------------------------------------------------------------------------------------------------------------
26 | * Function: openspi()
27 | *
28 | * Low level abstract function to open and initialise access to the SPI device.
29 | * returns 0 for success, or -1 for error
30 | */
31 | int openspi(void) ;
32 |
33 | /*! ------------------------------------------------------------------------------------------------------------------
34 | * Function: closespi()
35 | *
36 | * Low level abstract function to close the the SPI device.
37 | * returns 0 for success, or -1 for error
38 | */
39 | int closespi(void) ;
40 |
41 | void set_spi_speed_slow();
42 | void set_spi_speed_fast();
43 |
44 | #ifdef __cplusplus
45 | }
46 | #endif
47 |
48 | #endif /* _DECA_SPI_H_ */
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/include/drivers/dw1000/deca_types.h:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file deca_types.h
3 | * @brief Decawave general type definitions
4 | *
5 | * @attention
6 | *
7 | * Copyright 2013 (c) Decawave Ltd, Dublin, Ireland.
8 | *
9 | * All rights reserved.
10 | *
11 | */
12 |
13 | #ifndef _DECA_TYPES_H_
14 | #define _DECA_TYPES_H_
15 |
16 | #ifdef __cplusplus
17 | extern "C" {
18 | #endif
19 |
20 | #ifndef uint8
21 | #ifndef _DECA_UINT8_
22 | #define _DECA_UINT8_
23 | typedef unsigned char uint8;
24 | #endif
25 | #endif
26 |
27 | #ifndef uint16
28 | #ifndef _DECA_UINT16_
29 | #define _DECA_UINT16_
30 | typedef unsigned short uint16;
31 | #endif
32 | #endif
33 |
34 | #ifndef uint32
35 | #ifndef _DECA_UINT32_
36 | #define _DECA_UINT32_
37 | typedef unsigned long uint32;
38 | #endif
39 | #endif
40 |
41 | #ifndef int8
42 | #ifndef _DECA_INT8_
43 | #define _DECA_INT8_
44 | typedef signed char int8;
45 | #endif
46 | #endif
47 |
48 | #ifndef int16
49 | #ifndef _DECA_INT16_
50 | #define _DECA_INT16_
51 | typedef signed short int16;
52 | #endif
53 | #endif
54 |
55 | #ifndef int32
56 | #ifndef _DECA_INT32_
57 | #define _DECA_INT32_
58 | typedef signed long int32;
59 | #endif
60 | #endif
61 |
62 | #ifndef NULL
63 | #define NULL ((void *)0UL)
64 | #endif
65 |
66 | #ifdef __cplusplus
67 | }
68 | #endif
69 |
70 | #endif /* DECA_TYPES_H_ */
71 |
72 |
73 |
--------------------------------------------------------------------------------
/include/drivers/dw1000/deca_version.h:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file deca_version.h
3 | * @brief Defines the version info for the DW1000 device driver including its API
4 | *
5 | * @attention
6 | *
7 | * Copyright 2013 (c) Decawave Ltd, Dublin, Ireland.
8 | *
9 | * All rights reserved.
10 | *
11 | */
12 |
13 | #ifndef _DECA_VERSION_H_
14 | #define _DECA_VERSION_H_
15 |
16 | //
17 | // The DW1000 device driver is separately version numbered to any version the application using it may have
18 | //
19 | // Two symbols are defined here: one hexadecimal value and one string that includes the hex bytes.
20 | // Both should be updated together in a consistent way when the software is being modified.
21 | //
22 | // The format of the hex version is 0xAABBCC and the string ends with AA.BB.CC, where...
23 | //
24 | // Quantity CC is updated for minor changes/bug fixes that should not need user code changes
25 | // Quantity BB is updated for changes/bug fixes that may need user code changes
26 | // Quantity AA is updated for major changes that will need user code changes
27 | //
28 |
29 | #define DW1000_DRIVER_VERSION 0x050100
30 | #define DW1000_DEVICE_DRIVER_VER_STRING "DW1000 Device Driver Version 05.01.00"
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/include/drivers/dw1000/port.h:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file port.h
3 | * @brief HW specific definitions and functions for portability
4 | *
5 | * @attention
6 | *
7 | * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
8 | *
9 | * All rights reserved.
10 | *
11 | * @author DecaWave
12 | */
13 |
14 |
15 | #ifndef PORT_H_
16 | #define PORT_H_
17 |
18 | #ifdef __cplusplus
19 | extern "C" {
20 | #endif
21 |
22 | #include
23 | #include
24 | #include "compiler.h"
25 |
26 | /* DW1000 IRQ handler declaration. */
27 | // static port_deca_isr_t port_deca_isr;
28 |
29 | /* DW1000 IRQ handler type. */
30 | typedef void (*port_deca_isr_t)(void);
31 |
32 |
33 | /*! ------------------------------------------------------------------------------------------------------------------
34 | * @fn port_set_deca_isr()
35 | *
36 | * @brief This function is used to install the handling function for DW1000 IRQ.
37 | *
38 | * NOTE:
39 | *
40 | * @param deca_isr function pointer to DW1000 interrupt handler to install
41 | *
42 | * @return none
43 | */
44 | void port_set_deca_isr(port_deca_isr_t deca_isr);
45 |
46 |
47 |
48 | /*****************************************************************************************************************//*
49 | **/
50 |
51 | /****************************************************************************//**
52 | *
53 | * Types definitions
54 | *
55 | *******************************************************************************/
56 | typedef uint64_t uint64 ;
57 |
58 | typedef int64_t int64 ;
59 |
60 |
61 | #ifndef FALSE
62 | #define FALSE 0
63 | #endif
64 |
65 | #ifndef TRUE
66 | #define TRUE 1
67 | #endif
68 |
69 | typedef enum
70 | {
71 | LED_PC6, //LED_P0.x
72 | LED_PC7, //LED_P0.x
73 | LED_PC8, //LED_P0.x
74 | LED_PC9, //LED_P0.x
75 | LED_ALL,
76 | LEDn
77 | } led_t;
78 |
79 | /****************************************************************************//**
80 | *
81 | * MACRO
82 | *
83 | *******************************************************************************/
84 |
85 | //TODO
86 | #define DW1000_RSTn
87 | #define DW1000_RSTn_GPIO
88 |
89 |
90 | #define DECAIRQ
91 | #define DECAIRQ_GPIO
92 |
93 | #define TA_BOOT1
94 | #define TA_BOOT1_GPIO
95 |
96 | #define TA_RESP_DLY
97 | #define TA_RESP_DLY_GPIO
98 |
99 | #define TA_SW1_3
100 | #define TA_SW1_4
101 | #define TA_SW1_5
102 | #define TA_SW1_6
103 | #define TA_SW1_7
104 | #define TA_SW1_8
105 | #define TA_SW1_GPIO
106 |
107 | /****************************************************************************//**
108 | *
109 | * MACRO function
110 | *
111 | *******************************************************************************/
112 |
113 | //TODO
114 | #define GPIO_ResetBits(x,y)
115 | #define GPIO_SetBits(x,y)
116 | #define GPIO_ReadInputDataBit(x,y)
117 |
118 |
119 | /* NSS pin is SW controllable */
120 | #define port_SPIx_set_chip_select()
121 | #define port_SPIx_clear_chip_select()
122 |
123 | /* NSS pin is SW controllable */
124 | #define port_SPIy_set_chip_select()
125 | #define port_SPIy_clear_chip_select()
126 |
127 | /****************************************************************************//**
128 | *
129 | * port function prototypes
130 | *
131 | *******************************************************************************/
132 |
133 | #define S1_SWITCH_ON (1)
134 | #define S1_SWITCH_OFF (0)
135 |
136 |
137 | void port_set_dw1000_slowrate(void);
138 | void port_set_dw1000_fastrate(void);
139 |
140 | #ifdef __cplusplus
141 | }
142 | #endif
143 |
144 | #endif /* PORT_H_ */
145 |
146 | /*
147 | * Taken from the Linux Kernel
148 | *
149 | */
150 |
151 | #ifndef _LINUX_CIRC_BUF_H
152 | #define _LINUX_CIRC_BUF_H 1
153 |
154 | struct circ_buf {
155 | char *buf;
156 | int head;
157 | int tail;
158 | };
159 |
160 | /* Return count in buffer. */
161 | #define CIRC_CNT(head,tail,size) (((head) - (tail)) & ((size)-1))
162 |
163 | /* Return space available, 0..size-1. We always leave one free char
164 | as a completely full buffer has head == tail, which is the same as
165 | empty. */
166 | #define CIRC_SPACE(head,tail,size) CIRC_CNT((tail),((head)+1),(size))
167 |
168 | /* Return count up to the end of the buffer. Carefully avoid
169 | accessing head and tail more than once, so they can change
170 | underneath us without returning inconsistent results. */
171 | #define CIRC_CNT_TO_END(head,tail,size) \
172 | ({int end = (size) - (tail); \
173 | int n = ((head) + end) & ((size)-1); \
174 | n < end ? n : end;})
175 |
176 | /* Return space available up to the end of the buffer. */
177 | #define CIRC_SPACE_TO_END(head,tail,size) \
178 | ({int end = (size) - 1 - (head); \
179 | int n = (end + (tail)) & ((size)-1); \
180 | n <= end ? n : end+1;})
181 |
182 | #endif /* _LINUX_CIRC_BUF_H */
183 |
184 |
--------------------------------------------------------------------------------
/include/meshposition.h:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 |
6 | using json = nlohmann::json;
7 |
8 | enum struct msg_id_t: uint8_t{
9 | ping = 1, //
10 | reset = 2, //no payload
11 | alive = 3, //uint32_t counter
12 | address_request = 4, //
13 | address_assign = 5, //uint8_t address
14 | string = 6, //std::string
15 | twr_1_poll = 7, // struct
16 | twr_2_resp = 8, // struct
17 | twr_3_final = 9, // struct
18 | ack = 255 //
19 | };
20 |
21 | typedef struct
22 | {
23 | msg_id_t id;
24 | uint8_t sequence;
25 | uint8_t source;
26 | uint8_t dest;
27 | }header_t;
28 |
29 | typedef struct
30 | {
31 | header_t header;
32 | uint16_t crc;
33 | }msg_header_t;
34 |
35 | typedef struct
36 | {
37 | header_t header;
38 | uint32_t poll_tx_ts;
39 | uint32_t resp_rx_ts;
40 | uint32_t final_tx_ts;
41 | uint16_t crc;
42 | }msg_twr_final_t;
43 |
44 | void mp_start();
45 |
46 | void mp_conf_to_json(dwt_config_t &conf,json &jconf);
47 | void mp_json_to_conf(json &jconf,dwt_config_t &conf);
48 |
49 | json mp_status_to_json(uint32_t status_reg);
50 | void mp_status_print(uint32_t status_reg);
51 |
52 | void mp_start(dwt_config_t &config);
53 | uint32_t mp_get_status();
54 | void mp_rx_now(uint16_t timeout = 0);
55 | void mp_rx_after_tx(uint32_t delay_us,uint16_t timeout);
56 |
57 | void mp_request(msg_header_t &header);
58 | void mp_request(uint8_t* data, uint16_t size);
59 |
60 | bool mp_receive(msg_id_t id);
61 | bool mp_receive(msg_id_t id,msg_header_t&header);
62 | bool mp_receive(msg_id_t id,msg_twr_final_t& final_msg);
63 | bool mp_receive(uint8_t* data, uint16_t expected_size);
64 |
65 | void mp_send(uint8_t* data, uint16_t size);
66 | bool mp_send_at(uint8_t* data, uint16_t size, uint64_t tx_time, uint8_t flag=0);
67 | bool mp_request_at(uint8_t* data, uint16_t size, uint64_t tx_time);
68 |
69 | //low level API
70 | uint32_t mp_poll_rx();
71 | uint64_t get_tx_timestamp_u64(void);
72 | uint64_t get_rx_timestamp_u64(void);
73 |
74 | //------------------------------------- twr -------------------------------------
75 | void uwb_ping(uint8_t sequence,uint8_t pinger,uint8_t target);
76 | void uwb_ping_rx(uint8_t sequence,uint8_t pinger,uint8_t target,json &res);
77 | void uwb_cir_acc(uint8_t source);
78 |
79 | #ifdef CONFIG_MP_GPIO_DEBUG
80 | void twr_gpio_init(const struct device *gpio_dev);
81 | #endif
82 | void twr_respond(uint8_t sequence,uint8_t source_initiator,uint8_t dest_responder,json &res);
83 | void twr_intiate(uint8_t sequence,uint8_t source_initiator,uint8_t dest_responder);
84 |
--------------------------------------------------------------------------------
/media/forum.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nRFMesh/sdk-uwb-zephyr/284334860839b077e5aa922071986c837ac0e0e3/media/forum.png
--------------------------------------------------------------------------------
/samples/01_hello_leds/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 |
--------------------------------------------------------------------------------
/samples/01_hello_leds/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | cmake_minimum_required(VERSION 3.13.1)
3 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
4 | project(adc_battery)
5 |
6 | target_sources(app PRIVATE src/main.c)
7 |
--------------------------------------------------------------------------------
/samples/01_hello_leds/prj.conf:
--------------------------------------------------------------------------------
1 | CONFIG_GPIO=y
2 | CONFIG_SERIAL=n
3 |
4 | CONFIG_NEWLIB_LIBC=y
5 | CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
6 |
7 | # Logging
8 | CONFIG_LOG=y
9 | CONFIG_LOG_BACKEND_RTT=y
10 | CONFIG_LOG_BACKEND_UART=n
11 | CONFIG_BOOT_BANNER=y
12 | CONFIG_USE_SEGGER_RTT=y
13 | CONFIG_CONSOLE=y
14 | CONFIG_UART_CONSOLE=n
15 | CONFIG_RTT_CONSOLE=y
16 |
17 |
--------------------------------------------------------------------------------
/samples/01_hello_leds/readme.md:
--------------------------------------------------------------------------------
1 | ## usage
2 | ```bash
3 | west build -t guiconfig
4 | west build -b decawave_dwm1001_dev -- -DCONF_FILE=prj.conf
5 | west flash
6 | ```
7 |
--------------------------------------------------------------------------------
/samples/01_hello_leds/sample.yaml:
--------------------------------------------------------------------------------
1 | sample:
2 | name: Hello leds etst sample
3 |
--------------------------------------------------------------------------------
/samples/01_hello_leds/src/main.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
8 |
9 | #define LED0_NODE DT_ALIAS(led0)
10 | #define LED0 DT_GPIO_LABEL(LED0_NODE, gpios)
11 | #define LED0_PIN DT_GPIO_PIN(LED0_NODE, gpios)
12 |
13 | #define LED1_NODE DT_ALIAS(led1)
14 | #define LED1 DT_GPIO_LABEL(LED1_NODE, gpios)
15 | #define LED1_PIN DT_GPIO_PIN(LED1_NODE, gpios)
16 |
17 | #define LED2_NODE DT_ALIAS(led2)
18 | #define LED2 DT_GPIO_LABEL(LED2_NODE, gpios)
19 | #define LED2_PIN DT_GPIO_PIN(LED2_NODE, gpios)
20 |
21 | #define LED3_NODE DT_ALIAS(led3)
22 | #define LED3 DT_GPIO_LABEL(LED3_NODE, gpios)
23 | #define LED3_PIN DT_GPIO_PIN(LED3_NODE, gpios)
24 |
25 |
26 |
27 | void main(void)
28 | {
29 | LOG_INF("Hello world leds sample");
30 |
31 | const struct device *dev = device_get_binding(LED0);
32 |
33 | gpio_pin_configure(dev, LED0_PIN, GPIO_OUTPUT_ACTIVE);
34 | gpio_pin_configure(dev, LED1_PIN, GPIO_OUTPUT_ACTIVE);
35 | gpio_pin_configure(dev, LED2_PIN, GPIO_OUTPUT_ACTIVE);
36 | gpio_pin_configure(dev, LED3_PIN, GPIO_OUTPUT_ACTIVE);
37 | gpio_pin_set(dev, LED0_PIN, 0);
38 | gpio_pin_set(dev, LED1_PIN, 0);
39 | gpio_pin_set(dev, LED2_PIN, 0);
40 | gpio_pin_set(dev, LED3_PIN, 0);
41 | k_sleep(K_MSEC(1000));
42 | gpio_pin_set(dev, LED0_PIN, 1);
43 | gpio_pin_set(dev, LED1_PIN, 1);
44 | gpio_pin_set(dev, LED2_PIN, 1);
45 | gpio_pin_set(dev, LED3_PIN, 1);
46 | k_sleep(K_MSEC(1000));
47 |
48 | int count = 0;
49 | while (1) {
50 | LOG_INF("leds> hello %d",count++);
51 | gpio_pin_set(dev, LED0_PIN, 0);
52 | k_sleep(K_MSEC(1000));
53 | gpio_pin_set(dev, LED0_PIN, 1);
54 | gpio_pin_set(dev, LED1_PIN, 0);
55 | k_sleep(K_MSEC(1000));
56 | gpio_pin_set(dev, LED1_PIN, 1);
57 | gpio_pin_set(dev, LED2_PIN, 0);
58 | k_sleep(K_MSEC(1000));
59 | gpio_pin_set(dev, LED2_PIN, 1);
60 | gpio_pin_set(dev, LED3_PIN, 0);
61 | k_sleep(K_MSEC(1000));
62 | gpio_pin_set(dev, LED3_PIN, 1);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/samples/02_listener/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | cmake_minimum_required(VERSION 3.13.1)
3 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
4 | project(uwb_listener)
5 |
6 | target_sources(app PRIVATE src/main.c)
7 |
--------------------------------------------------------------------------------
/samples/02_listener/README.md:
--------------------------------------------------------------------------------
1 | ## usage
2 | ```bash
3 | west build -t guiconfig
4 | west build -b decawave_dwm1001_dev -- -DCONF_FILE=prj.conf
5 | west flash
6 | ```
7 |
--------------------------------------------------------------------------------
/samples/02_listener/prj.conf:
--------------------------------------------------------------------------------
1 | CONFIG_DW1000=y
2 |
3 | CONFIG_DEBUG=y
4 | CONFIG_SPI=y
5 | CONFIG_GPIO=y
6 | CONFIG_PRINTK=y
7 |
8 | CONFIG_USE_SEGGER_RTT=y
9 | CONFIG_SEGGER_RTT_MAX_NUM_UP_BUFFERS=3
10 | CONFIG_SEGGER_RTT_MAX_NUM_DOWN_BUFFERS=3
11 | CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=1024
12 | CONFIG_SEGGER_RTT_BUFFER_SIZE_DOWN=16
13 | CONFIG_SEGGER_RTT_PRINTF_BUFFER_SIZE=64
14 | CONFIG_SEGGER_RTT_MODE_NO_BLOCK_SKIP=y
15 |
16 | CONFIG_LOG_BACKEND_RTT=y
17 | CONFIG_LOG_BACKEND_RTT_MODE_BLOCK=y
18 | CONFIG_LOG_BACKEND_RTT_OUTPUT_BUFFER_SIZE=16
19 | CONFIG_LOG_BACKEND_RTT_RETRY_CNT=4
20 | CONFIG_LOG_BACKEND_RTT_RETRY_DELAY_MS=5
21 | CONFIG_LOG_BACKEND_RTT_BUFFER=0
22 |
23 | CONFIG_LOG=y
24 | CONFIG_LOG_DEFAULT_LEVEL=3
25 | CONFIG_LOG_OVERRIDE_LEVEL=0
26 | CONFIG_LOG_MAX_LEVEL=4
27 | CONFIG_LOG_FUNC_NAME_PREFIX_DBG=y
28 |
29 | CONFIG_LOG_PRINTK=y
30 | CONFIG_LOG_PRINTK_MAX_STRING_LENGTH=128
31 | CONFIG_LOG_MODE_OVERFLOW=y
32 | CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=10
33 | CONFIG_LOG_PROCESS_THREAD=y
34 | CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=1000
35 | CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=768
36 | CONFIG_LOG_BUFFER_SIZE=6144
37 | CONFIG_LOG_DETECT_MISSED_STRDUP=y
38 | CONFIG_LOG_STRDUP_MAX_STRING=32
39 | CONFIG_LOG_STRDUP_BUF_COUNT=4
40 |
41 | CONFIG_LOG_BACKEND_SHOW_COLOR=n
42 |
--------------------------------------------------------------------------------
/samples/02_listener/src/main.c:
--------------------------------------------------------------------------------
1 | /*! ----------------------------------------------------------------------------
2 | * @file main.c
3 | * @brief RX using SNIFF mode example code
4 | *
5 | * @attention
6 | *
7 | * Copyright 2016 (c) Decawave Ltd, Dublin, Ireland.
8 | * Copyright 2019 (c) Frederic Mes, RTLOC.
9 | *
10 | * All rights reserved.
11 | *
12 | * @author Decawave
13 | */
14 | #include
15 |
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | // zephyr includes
22 | #include
23 | #include
24 |
25 | #define STACKSIZE 1024
26 | #define PRIORITY 99
27 | #define DELAY_TIME K_MSEC(1000)
28 |
29 | #define LOG_LEVEL 3
30 | #include
31 | LOG_MODULE_REGISTER(main);
32 |
33 | /* Example application name and version to display on console. */
34 | #define APP_NAME "SIMPLE RX v1.3\n"
35 |
36 | static dwt_config_t config = {
37 | 5, /* Channel number. */
38 | DWT_PRF_64M, /* Pulse repetition frequency. */
39 | DWT_PLEN_128, /* Preamble length. Used in TX only. */
40 | DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */
41 | 9, /* TX preamble code. Used in TX only. */
42 | 9, /* RX preamble code. Used in RX only. */
43 | 1, /* 0 to use standard SFD, 1 to use non-standard SFD. */
44 | DWT_BR_6M8, /* Data rate. */
45 | DWT_PHRMODE_EXT, /* PHY header mode. */
46 | (129) /* SFD timeout (preamble length + 1 + SFD length - PAC size).
47 | * Used in RX only. */
48 | };
49 |
50 | /* Buffer to store received frame. See NOTE 1 below. */
51 | #define FRAME_LEN_MAX 127
52 | static uint8 rx_buffer[FRAME_LEN_MAX];
53 |
54 | /* Hold copy of status register state here for reference so that it can be
55 | examined at a debug breakpoint.
56 | */
57 | static uint32 status_reg = 0;
58 |
59 | /* Hold copy of frame length of frame received (if good) so that it can be
60 | examined at a debug breakpoint.
61 | */
62 | static uint16 frame_len = 0;
63 |
64 | void sniff_ms(int time)
65 | {
66 | int start = k_uptime_get();
67 | int finish = start + time;
68 |
69 | while (k_uptime_get() < finish) {
70 | for (int i = 0 ; i < FRAME_LEN_MAX; i++ )
71 | {
72 | rx_buffer[i] = 0;
73 | }
74 | dwt_rxenable(DWT_START_RX_IMMEDIATE);
75 | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) &
76 | (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR))) { /* spin */ };
77 |
78 | if (status_reg & SYS_STATUS_RXFCG) {
79 | frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFL_MASK_1023;
80 | if (frame_len <= FRAME_LEN_MAX) {
81 | dwt_readrxdata(rx_buffer, frame_len, 0);
82 | int time_stamp = k_uptime_get();
83 | printf("%d> ",time_stamp);
84 | int i;
85 | for (i = 0 ; i < frame_len; i++ )
86 | {
87 | printf("%02x ",rx_buffer[i]);
88 | }
89 | printf("\r\n");
90 | }
91 | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG);
92 | }
93 | else {
94 | printf("0x%04lX\r\n",status_reg);
95 | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);
96 | }
97 | }
98 |
99 | }
100 |
101 | void main_thread(void * id, void * unused1, void * unused2)
102 | {
103 | printk("%s\n", __func__);
104 | printk(APP_NAME);
105 | openspi();
106 |
107 | port_set_dw1000_slowrate();
108 |
109 | if (dwt_initialise(DWT_LOADNONE) == DWT_ERROR) {
110 | printk("INIT FAILED");
111 | k_sleep(K_MSEC(500));
112 | while (1) { /* spin */};
113 | }
114 | port_set_dw1000_fastrate();
115 |
116 | dwt_configure(&config);
117 |
118 | printf("configured : chan %u, rxCode %u, nsSFD %u\r\n",
119 | config.chan, config.rxCode, config.nsSFD);
120 |
121 | dwt_setleds(1);
122 |
123 | k_yield();
124 |
125 | while (1) {
126 | sniff_ms(10000);
127 | }
128 | }
129 |
130 | K_THREAD_DEFINE(main_id, STACKSIZE, main_thread,
131 | NULL, NULL, NULL, PRIORITY, 0, 0);
132 |
133 |
134 | /*****************************************************************************
135 | * NOTES:
136 | *
137 | * 1. The device ID is a hard coded constant in the blink to keep the example
138 | * simple but for a real product every device should have a unique ID.
139 | * For development purposes it is possible to generate a DW1000 unique ID
140 | * by combining the Lot ID & Part Number values programmed into the
141 | * DW1000 during its manufacture. However there is no guarantee this will
142 | * not conflict with someone else's implementation. We recommended that
143 | * customers buy a block of addresses from the IEEE Registration Authority
144 | * for their production items. See "EUI" in the DW1000 User Manual.
145 | * 2. In this example, LDE microcode is not loaded upon calling dwt_initialise().
146 | * This will prevent the IC from generating an RX timestamp.
147 | * If time-stamping is required, DWT_LOADUCODE parameter should be used.
148 | * See two-way ranging examples (e.g. examples 5a/5b).
149 | * 3. In a real application, for optimum performance within regulatory limits,
150 | * it may be necessary to set TX pulse bandwidth and TX power, (using
151 | * the dwt_configuretxrf API call) to per device calibrated values saved in
152 | * the target system or the DW1000 OTP memory.
153 | * 4. dwt_writetxdata() takes the full size of tx_msg as a parameter but only
154 | * copies (size - 2) bytes as the check-sum at the end of the frame is
155 | * automatically appended by the DW1000. This means that our tx_msg could
156 | * be two bytes shorter without losing any data (but the sizeof would not
157 | * work anymore then as we would still have to indicate the full length of
158 | * the frame to dwt_writetxdata()).
159 | * 5. We use polled mode of operation here to keep the example as simple as
160 | * possible but the TXFRS status event can be used to generate an interrupt.
161 | * Please refer to DW1000 User Manual for more details on "interrupts".
162 | * 6. The user is referred to DecaRanging ARM application (distributed with
163 | * EVK1000 product) for additional practical example of usage, and to the
164 | * DW1000 API Guide for more details on the DW1000 driver functions.
165 | ****************************************************************************/
166 |
--------------------------------------------------------------------------------
/samples/03_twr_initiator/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.13.1)
2 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
3 | project(twr_initiator)
4 |
5 | target_sources(app PRIVATE src/main.cpp)
6 |
--------------------------------------------------------------------------------
/samples/03_twr_initiator/README.md:
--------------------------------------------------------------------------------
1 | # initiator
2 | ## usage
3 | ```bash
4 | west build -t guiconfig -b decawave_dwm1001_dev
5 |
6 | west build -b decawave_dwm1001_dev -- -DCONF_FILE=prj.conf
7 | west build -b decawave_dwm1001_dev -- -DCONF_FILE="prj.conf overlay-debug.conf"
8 | west build -b decawave_dwm1001_dev -- -DCONF_FILE="prj.conf overlay-tracing.conf"
9 | west build -b decawave_dwm1001_dev -- -DCONF_FILE="prj.conf overlay-usb.conf"
10 |
11 | west flash
12 |
13 | west flash --snr 760130093
14 | ```
15 |
--------------------------------------------------------------------------------
/samples/03_twr_initiator/overlay-debug.conf:
--------------------------------------------------------------------------------
1 | CONFIG_BOOT_BANNER=y
2 | CONFIG_USE_SEGGER_RTT=y
3 | CONFIG_RTT_CONSOLE=y
4 | # Log => RTT, Shell => RTT
5 |
6 | # Log
7 | CONFIG_LOG=y
8 | CONFIG_LOG_BACKEND_RTT=n
9 | CONFIG_LOG_BACKEND_UART=y
10 |
11 | # Shell
12 | CONFIG_SHELL=y
13 | CONFIG_SHELL_BACKEND_RTT=y
14 | CONFIG_SHELL_BACKEND_SERIAL=n
15 |
16 |
--------------------------------------------------------------------------------
/samples/03_twr_initiator/overlay-tracing.conf:
--------------------------------------------------------------------------------
1 | #Tracing
2 | CONFIG_TRACING=y
3 | CONFIG_SEGGER_SYSTEMVIEW=y
4 | CONFIG_THREAD_NAME=y
5 | CONFIG_SEGGER_SYSTEMVIEW_BOOT_ENABLE=y
6 |
7 | # careful adjustment as long as there is enough SRAM use it for tracing 128 KB
8 | CONFIG_SEGGER_SYSVIEW_RTT_BUFFER_SIZE=131072
9 |
--------------------------------------------------------------------------------
/samples/03_twr_initiator/overlay-usb.conf:
--------------------------------------------------------------------------------
1 | # Logging
2 | CONFIG_LOG=y
3 | CONFIG_LOG_BACKEND_RTT=n
4 | CONFIG_LOG_BACKEND_UART=y
5 | CONFIG_BOOT_BANNER=y
6 | CONFIG_USE_SEGGER_RTT=n
7 | CONFIG_CONSOLE=y
8 | CONFIG_UART_CONSOLE=n
9 | CONFIG_RTT_CONSOLE=n
10 |
11 | #USB related configs
12 | CONFIG_USB=y
13 | CONFIG_USB_DEVICE_STACK=y
14 | CONFIG_USB_DEVICE_PRODUCT="Zephyr testusb sample"
15 | CONFIG_USB_UART_CONSOLE=y
16 |
17 | CONFIG_UART_INTERRUPT_DRIVEN=y
18 | CONFIG_UART_LINE_CTRL=y
19 | CONFIG_UART_CONSOLE_ON_DEV_NAME="CDC_ACM_0"
20 |
--------------------------------------------------------------------------------
/samples/03_twr_initiator/prj.conf:
--------------------------------------------------------------------------------
1 | CONFIG_SPEED_OPTIMIZATIONS=y
2 |
3 | #UWB Tranceiver
4 | CONFIG_MESHPOSITION=y
5 | CONFIG_DW1000=y
6 | CONFIG_SPI=y
7 | CONFIG_GPIO=y
8 |
9 | #nRF Backend Networking
10 | CONFIG_ESB=y
11 | CONFIG_SIMPLEMESH=y
12 |
13 | #C++
14 | CONFIG_CPLUSPLUS=y
15 | CONFIG_LIB_CPLUSPLUS=y
16 | CONFIG_STD_CPP11=n
17 | CONFIG_STD_CPP17=y
18 |
19 | # Console (printk printf)
20 | CONFIG_CONSOLE=y
21 | CONFIG_UART_CONSOLE=y
22 | CONFIG_RTT_CONSOLE=n
23 | CONFIG_STDOUT_CONSOLE=y
24 |
25 | #printf
26 | CONFIG_NEWLIB_LIBC=y
27 | CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
28 | CONFIG_PRINTK=y
29 |
30 | #Stack
31 | CONFIG_MAIN_STACK_SIZE=2048
32 |
--------------------------------------------------------------------------------
/samples/03_twr_initiator/src/main.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2019 - Frederic Mes, RTLOC
3 | * Copyright (c) 2015 - Decawave Ltd, Dublin, Ireland.
4 | * Copyright (c) 2021 - Home Smart Mesh
5 | *
6 | * This file is part of Zephyr-DWM1001.
7 | *
8 | * Zephyr-DWM1001 is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * Zephyr-DWM1001 is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with Zephyr-DWM1001. If not, see .
20 | *
21 | */
22 |
23 | #include
24 |
25 | #include
26 | #include
27 | #include
28 |
29 | // zephyr includes
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include