1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-28 23:09:46 +01:00
RIOT/sys
bors[bot] 561e19303d
Merge #19718 #19737 #19746
19718: drivers/dht: busy wait reimplementation r=benpicco a=hugueslarrive

### Contribution description

In PR #19674, I also provided quick and dirty fixes to restore functionality on esp8266 and enable operation on AVR. While reviewing PR #18591, it became apparent to me that this driver needed a refresh, particularly its migration to ztimer.

The cause of the malfunction on esp8266 was that since the default switch to ztimer as the backend for xtimer, XTIMER_BACKOFF was no longer taken into account. Therefore, the correction I provided in PR #19674 simply made explicit what was previously done implicitly with xtimer and now needs to be done explicitly with ztimer (spinning instead of sleeping).

Moreover, it was unnecessarily complex to measure the pulse duration in a busy-wait implementation, which required 2 calls to ztimer_now() and  32-bit operations expensive on 8-bit architecture. Instead, it is sufficient to read the state of the bus at the threshold moment.

Finally, in practice, it is possible to reduce the read interval (down to less than 0.5s for DHT22) by "harassing" the DHT with start signals until it responds.

This re-implementation brings the following improvements:
- Many backports from `@maribu's` IRQ based implementation (#18591):
  - Use of ztimer
  - Use of errno.h
  - Use of a dht_data structure to pass arguments, to facilitate integration
  - Adaptation of the bit parsing technique to parse bits into the data array
- Reintroduction of DHT11/DHT22 differentiation.
- Separation of `dht_read()` steps into functions for better readability and the ability to share certain functions among different implementations
- Sensor presence check in `dht_init()`
- ~~Automatic adjustment to a minimum data hold time~~
- Default input mode changed to open drain (a pull-up resistor should be placed close to the output if necessary but not close to the input)
- AVR support without platform-specific handling by avoiding  ztimer_spin() and using the overflow of an 8-bit variable as a pre-timeout to minimize time-consuming ztimer_now() calls

Regarding the changes in the start signal sequence and the removal of the `_reset()` function:
![nano_dht_read_2](https://github.com/RIOT-OS/RIOT/assets/67432403/95966813-2b5f-4a0f-a388-8ac630526ab2)

~~In the previous implementation, there was an unnecessary spike at the beginning of the signal sequence, corresponding to START_HIGH_TIME. This spike has been removed in the re-implementation, as it is unnecessary. Instead, the MCU now simply pulls the signal low for START_LOW_TIME and then releases the bus, which is sufficient for initiating communication with the DHT sensor.~~ Actually, it is necessary to raise the bus level; otherwise, the _wait_for_level() called immediately after to check the response of the DHT may read the port before the signal level is raised, resulting in a false positive.

Additionally, the previous implementation had an issue where the MCU switched back to output mode and went high immediately after reading the 40 bits of data. However, the DHT sensor was still transmitting 2 or 3 additional bytes of '0' at that point, causing a conflict. This issue has been resolved in the re-implementation:
![nano_dht_read_optimized](https://github.com/RIOT-OS/RIOT/assets/67432403/ff124839-5ec5-4df3-bab7-5348d8160a25)

~~Regarding the optimization for AVR, I have performed measurements of `_wait_for_level()` until timeout (85 loops):~~
~~- on esp8266-esp-12x: 264 µs, which is 3.11 µs per loop~~
~~- on nucleo-f303k8: 319 µs, which is 3.75 µs per loop~~
~~- on arduino-nano: 3608 µs, which is 42.45 µs per loop~~
~~Duration measurements on the Arduino Nano:~~


19737: dist/tools/openocd: start debug-server in background and wait r=benpicco a=fabian18



19746: buildsystem: Always expose CPU_RAM_BASE & SIZE flags r=benpicco a=Teufelchen1

### Contribution description

Hello 🐧 

This moves the definition of `CPU_RAM_BASE/SIZE` from being only available in certain situation to be always available.
Reason for change is to simplify common code in the cpu folder.

In cooperation with `@benpicco` 

### Testing procedure

Passing CI


### Issues/PRs references

First usage will be in the PMP driver. Although there is more code in RIOT that could be refactored to use these defines instead of hacks / hardcoded values.

Co-authored-by: Hugues Larrive <hlarrive@pm.me>
Co-authored-by: Fabian Hüßler <fabian.huessler@ml-pa.com>
Co-authored-by: Teufelchen1 <bennet.blischke@outlook.com>
2023-06-20 10:40:01 +00:00
..
analog_util sys/analog_util/dac_util: fix truncation bug 2022-12-09 13:58:12 -05:00
app_metadata
arduino sys/arduino: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:45 +02:00
auto_init Merge #18620 #19296 #19504 #19506 2023-04-25 15:46:11 +00:00
base64
benchmark sys/benchmark: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:55 +02:00
bhp sys/bhp_msg: add IPC based Bottom Half Processor 2022-08-19 12:01:30 +02:00
bitfield sys/bitfield: don't set unrelated bits in bf_{set, clear}_all() 2023-03-17 00:08:10 +01:00
bloom
bus sys/bus: model Kconfig 2022-03-11 09:24:12 +01:00
can sys/can: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:53 +02:00
cb_mux
checksum sys/checksum: add CRC-16 implementation without lookup table 2022-10-06 17:43:20 +02:00
chunked_ringbuffer
clif sys: add Kconfig support for clif 2023-05-19 15:03:42 +02:00
coding sys/coding: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:46 +02:00
color sys/color: fix rgb2hsv function 2023-06-05 13:00:23 +02:00
congure sys/congure: move dependency resolution in its own Makefile.dep 2023-06-15 10:27:38 +02:00
cpp11-compat sys/cpp11-compat: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:50 +02:00
cpp_new_delete
crypto sys/crypto: make AES_KEY struct private 2023-02-20 18:22:00 +01:00
cxx_ctor_guards
debug_irq_disable cpu/cortexm_common: measure time spent with IRQ disabled 2022-11-24 21:27:20 +01:00
div
ecc sys/ecc: model in Kconfig 2023-05-24 09:53:33 +02:00
eepreg sys/eepreg: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:46 +02:00
embunit
entropy_source sys/entropy_source: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:53 +02:00
event sys/event: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:55 +02:00
evtimer sys/evtimer: move dependency resolution in its own Makefile.dep 2023-06-15 10:27:37 +02:00
fido2 sys/fido2: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:57 +02:00
fmt Merge #19027 2023-02-17 20:09:53 +00:00
frac
fs vfs: drop unused abs_path parameter 2022-09-29 22:01:37 +02:00
fuzzing fuzzing: Add uri_parser fuzzer setup 2022-12-19 13:03:45 +01:00
hashes core/lib: Add macros/utils.h header 2023-01-07 09:47:44 +01:00
include Merge #19697 #19725 2023-06-13 19:08:40 +00:00
iolist sys/iolist: introduce iolist_to_buffer() 2022-05-02 23:23:52 +02:00
isrpipe sys/isrpipe: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:48 +02:00
libc sys/string_utils: add memchk() 2023-05-30 20:39:10 +02:00
log_color sys/log_color: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:50 +02:00
log_printfnoformat sys/log: modularize log into log_color and log_printfnoformat 2022-10-12 12:21:29 +02:00
luid sys/luid: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:49 +02:00
malloc_thread_safe sys/malloc_tracing: add module to trace dyn memory management 2022-11-15 12:59:46 +01:00
matstat
memarray
mineplex
net gnrc/rpl: fix incorrect addition overflow check 2023-06-17 02:25:11 -04:00
newlib_syscalls_default cpu/mips: Remove all mips 2022-09-27 13:42:37 +02:00
od sys/od: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:48 +02:00
oneway-malloc
phydat sys/phydat: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:52 +02:00
picolibc_syscalls_default sys/picolibc_syscalls_default: Fix read/write return for picolibc >= 1.8 2023-03-03 12:04:48 -08:00
pipe sys/pipe: model in Kconfig 2023-05-24 09:53:35 +02:00
pm_layered sys/pm_layered: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:52 +02:00
posix sys/posix/sockets: set sin6_scope_id in _ep_to_sockaddr() 2023-05-23 22:04:12 +02:00
preprocessor sys/preprocessor: add Kconfig file 2022-10-17 10:38:14 +02:00
progress_bar
ps
puf_sram sys/puf_sram: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:54 +02:00
random sys/random: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:54 +02:00
riotboot sys/riotboot: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:56 +02:00
rtc_utils
rust_riotmodules rust_riotmodules: pub use instead of extern crate 2022-07-10 21:27:13 +02:00
rust_riotmodules_standalone Rust: Update riot-wrappers 2023-04-25 09:20:58 +02:00
saul_reg sys/saul_reg: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:51 +02:00
sched_round_robin sys/sched_round_robin: move deps resolution in its own Makefile.dep 2023-06-15 10:24:51 +02:00
schedstatistics sys/schedstatistics: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:50 +02:00
sema sys/sema*: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:49 +02:00
sema_inv sys/sema*: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:49 +02:00
senml sys/senml: cleanup dependency resolution 2023-06-15 10:24:52 +02:00
seq
shell Merge #18156 2023-06-13 12:11:07 +00:00
shell_lock sys/shell_lock: lock shell on EOF 2023-05-26 15:04:36 +02:00
ssp sys/ssp: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:47 +02:00
stdio_nimble treewide: fix path to shell related tests in doc 2023-05-13 18:27:58 +02:00
stdio_null Merge #18459 #18724 #19081 #19082 #19136 2023-01-13 13:50:55 +00:00
stdio_rtt sys/stdio_rtt: move documentation in doc.txt 2023-02-05 15:49:20 +01:00
stdio_semihosting core/init: call vfs_bind_stdio() in early_init() 2023-01-08 22:26:13 +01:00
stdio_uart core/init: call vfs_bind_stdio() in early_init() 2023-01-08 22:26:13 +01:00
stdio_udp sys/stdio_udp: add stdio over UDP 2023-01-13 11:08:22 +01:00
suit sys/suit: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:57 +02:00
test_utils sys/test_utils: fix path to rmutex test in doc 2023-05-13 18:27:58 +02:00
timex
tiny_strerror sys/tiny_strerror: make use of flash_utils.h 2023-02-27 23:25:13 +01:00
trace sys/trace: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:47 +02:00
trickle sys/trickle: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:48 +02:00
tsrb
universal_address
uri_parser sys/uri_parser: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:57 +02:00
usb pkg/tinyusb: sys: fix stdio buffered inclusion in Kconfig 2023-06-17 15:12:31 +02:00
usb_board_reset sys/usb_board_reset: allow to enable it also for stdio_usb_serial_jtag 2023-02-06 16:19:11 +01:00
ut_process sys/ut_process: move dependency resolution in its own Makefile.dep 2023-06-15 10:27:38 +02:00
uuid sys/uuid: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:56 +02:00
vfs sys/vfs*: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:54 +02:00
vfs_util sys/vfs*: move dependency resolution in its own Makefile.dep 2023-06-15 10:24:54 +02:00
xtimer sys/xtimer: switch default backend to ztimer 2022-03-18 08:23:00 +01:00
zptr
ztimer sys/evtimer: remove support for xtimer backend 2023-05-24 09:53:33 +02:00
ztimer64
doc.txt sys/doc.txt: add sys_compression doxygen group 2023-02-27 15:09:08 +01:00
Kconfig sys/shell_lock: model in Kconfig 2023-05-24 09:53:35 +02:00
Kconfig.newlib sys/syscalls: add libc_gettimeofday 2022-03-24 11:36:49 +01:00
Kconfig.picolibc pkg/tinyusb: sys: fix stdio buffered inclusion in Kconfig 2023-06-17 15:12:31 +02:00
Kconfig.stdio pkg/tinyusb: sys: fix stdio buffered inclusion in Kconfig 2023-06-17 15:12:31 +02:00
Makefile sys/preprocessor: add preprocessor module 2022-10-17 10:38:14 +02:00
Makefile.dep sys/usbus: move dependency resolution in its own Makefile.dep 2023-06-15 10:27:38 +02:00
Makefile.include buildsystem: Always expose CPU_RAM_BASE & SIZE flags 2023-06-20 12:16:06 +02:00