1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 09:52:43 +01:00
RIOT/tests/drivers
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
..
ad7746 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
adcxx1c tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ads101x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
adt7310 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
adxl345 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
aip31068 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
apa102 tests/driver_lpd8808: tests/driver_apa102: rename STEP constant 2023-05-14 21:08:30 +02:00
apds99xx tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
apds99xx_full tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
at tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
at24cxxx tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
at24mac tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
at25xxx tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
at30tse75x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
at86rf2xx tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
at86rf2xx_aes tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
at86rf215 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ata8520e tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
atwinc15x0 tests/drivers: fix broken symlinks and paths 2023-05-12 16:36:40 +02:00
bh1750 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
bh1900nux tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
bme680 treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
bmp180 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
bmx055 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
bmx280 treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
bq2429x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
candev tests/candev: move to tests/drivers 2023-05-12 14:24:40 +02:00
cc110x boards/olimex-msp430-h2618: add new board 2023-06-08 23:42:50 +02:00
cc2420 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
cc2538_rf tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ccs811 treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
ccs811_full treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
cst816s tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
dac_dds tests/driver_dac_dds: make use of imath 2023-06-05 19:09:02 +02:00
dcf77 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
dfplayer tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
dht drivers/dht: busy wait reimplementation 2023-06-20 12:07:48 +02:00
disp_dev tests: move remaining driver related applications to tests/drivers 2023-05-10 11:58:32 +02:00
dose tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ds18 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ds75lx tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ds1307 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ds3231 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ds3234 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
dsp0401 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
dynamixel tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
edbg_eui tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
enc28j60 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
encx24j600 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
epd_bw_spi tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
epd_bw_spi_disp_dev tests/drivers/epd_bw_spi_disp_dev: fix accidental use of FPU 2023-05-31 18:13:32 +02:00
esp_eth tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ethos tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
feetech tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ft5x06 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
fxos8700 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
gp2y10xx tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
grove_ledbar tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
hd44780 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
hdc1000 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
hih6130 drivers/hih6130: avoid using floats 2023-06-08 14:33:38 +02:00
hm330x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
hmc5883l treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
hsc tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
hts221 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ili9341 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ina2xx tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ina3221 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
io1_xplained tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ir_nec tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
isl29020 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
isl29125 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
itg320x treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
jc42 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
kw2xrf tests/drivers: fix broken symlinks and paths 2023-05-12 16:36:40 +02:00
l3g4200d tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
l3gxxxx treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
lc709203f treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
lis2dh12 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
lis3dh tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
lis3mdl tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
lm75 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
lpd8808 tests/driver_lpd8808: tests/driver_apa102: rename STEP constant 2023-05-14 21:08:30 +02:00
lpsxxx tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
lsm6dsl tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
lsm303dlhc tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ltc4150 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
mag3110 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
matrix_keypad tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
mcp47xx tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
mfrc522 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
mhz19 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
mma8x5x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
mma7660 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
motor_driver tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
mpl3115a2 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
mpu9x50 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
mq3 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
mrf24j40 tests/drivers: fix broken symlinks and paths 2023-05-12 16:36:40 +02:00
mtd_at24cxxx tests: move remaining driver related applications to tests/drivers 2023-05-10 11:58:32 +02:00
mtd_at25xxx tests: move remaining driver related applications to tests/drivers 2023-05-10 11:58:32 +02:00
mtd_flashpage tests: update tests for MSP430 CPU 2023-06-19 14:49:55 +02:00
mtd_mapper tests: move remaining driver related applications to tests/drivers 2023-05-10 11:58:32 +02:00
mtd_raw tests: move remaining driver related applications to tests/drivers 2023-05-10 11:58:32 +02:00
my9221 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
nrf24l01p_lowlevel tests/drivers/nrf24l01p_lowlevel: add Kconfig config 2023-05-24 10:18:54 +02:00
nrf24l01p_ng boards/olimex-msp430-h1611: new board 2023-05-16 15:03:12 +02:00
nrf802154 tests/drivers/nrf802154: build for nrf52840dk by default 2023-05-12 16:36:40 +02:00
nrfmin tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
nvram_spi tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
opt3001 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
pca9633 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
pca9685 treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
pcd8544 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
pcf857x treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
ph_oem tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
pir tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
pn532 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
pulse_counter tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
qmc5883l tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
rn2xx3 treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
sam0_eth tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
saul tests: move remaining driver related applications to tests/drivers 2023-05-10 11:58:32 +02:00
saul_drivers tests: move remaining driver related applications to tests/drivers 2023-05-10 11:58:32 +02:00
scd30 treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
sdcard_spi tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
sdp3x treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
sds011 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
seesaw_soil tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
servo tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
sgp30 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
sht1x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
sht2x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
sht3x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
shtcx treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
si70xx tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
si114x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
si1133 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
sm_pwm_01c tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
soft_spi tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
soft_uart tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
sps30 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
srf02 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
srf04 treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
srf08 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
st7735 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
stm32_eth tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
stmpe811 treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
sx126x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
sx127x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
sx1280 treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
tcs37727 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
tmp00x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
touch_dev tests: move remaining driver related applications to tests/drivers 2023-05-10 11:58:32 +02:00
tps6274x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
tsl2561 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
tsl4531x tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
vcnl40x0 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
veml6070 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
vl6180x treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
w5100 tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
ws281x treewide: fix path to external_board_dirs test in doc 2023-05-13 18:31:05 +02:00
xbee tests/drivers: fix broken symlinks and paths 2023-05-12 16:36:40 +02:00
Makefile.drivers_common tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00