Files
templates/c/ds18b20/tests/fake_onewire.h
Andrey Kruchinkin 873ac438f3 feat(ds18b20): термометры DS18B20 поверх программной 1-Wire
Перенесён из репозитория ds18b20, который подключался сабмодулем в
KONOR_ds18b20. История библиотеки осталась там; сюда пришло состояние
на момент переезда.

Ядро на C99 без stm32f10x.h и динамической памяти. Порт — пять функций
(Init, DelayUs, Reset, WriteBit, ReadBit); реализация для STM32F1 идёт
в комплекте в ports/stm32f1. Хостовые тесты на модели шины с виртуальными
датчиками проходят: tests/test_ds18b20.c.
2026-08-23 01:15:34 +03:00

42 lines
1.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file fake_onewire.h
* @brief Модель шины 1-Wire с виртуальными датчиками для host-тестов.
*/
#ifndef FAKE_ONEWIRE_H
#define FAKE_ONEWIRE_H
#include <stdint.h>
#define FAKE_MAX_DEVICES 8U
/** Виртуальный датчик: ROM, scratchpad и управляемые отказы. */
typedef struct {
uint8_t rom[8];
uint8_t scratchpad[9];
uint8_t present; /**< 0 - датчик снят с шины. */
uint8_t parasite; /**< 1 - отвечает как паразитно питаемый. */
uint8_t accept_writes; /**< 0 - молча игнорирует запись. */
uint8_t corrupt_crc; /**< 1 - портит CRC8 scratchpad. */
} fake_device_t;
typedef struct {
fake_device_t devices[FAKE_MAX_DEVICES];
uint8_t count;
uint32_t reset_count;
uint32_t convert_count;
uint32_t copy_count;
uint32_t delay_us_total;
} fake_bus_t;
/** Подключает модель к порту; после вызова работают функции OneWire_*. */
void fake_bus_attach(fake_bus_t *bus);
/** Заполняет датчик: семь байт ROM без CRC, температура и тип питания. */
void fake_device_init(fake_device_t *device, const uint8_t rom7[7],
int16_t raw, uint8_t parasite);
uint8_t fake_bus_crc8(const uint8_t *data, uint32_t size);
#endif /* FAKE_ONEWIRE_H */