software and system v1
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
# Sensor Drivers Overview
|
||||
## ASF Sensor Hub (Sub-Hub) Embedded System
|
||||
|
||||
**Document ID:** COMP-SENSOR-DRIVERS-OVERVIEW-001
|
||||
**Version:** 1.0
|
||||
**Date:** 2025-02-01
|
||||
**Platform:** ESP32-S3, ESP-IDF v5.4
|
||||
|
||||
---
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
The Sensor Drivers provide hardware-specific implementations for each sensor type, implementing the Sensor Abstraction Layer (SAL) interface. Each driver abstracts sensor-specific protocols and provides a uniform interface to the Sensor Manager.
|
||||
|
||||
**Primary Goal:** Enable Sensor Manager to operate sensors without hardware-specific knowledge.
|
||||
|
||||
---
|
||||
|
||||
## 2. Sensor Driver Architecture
|
||||
|
||||
```
|
||||
Sensor Manager
|
||||
↓
|
||||
Sensor Abstraction Layer (SAL) Interface
|
||||
↓
|
||||
Sensor Drivers (This Layer)
|
||||
↓
|
||||
OSAL Wrappers (I2C, SPI, UART, ADC)
|
||||
↓
|
||||
Hardware (Sensors)
|
||||
```
|
||||
|
||||
**Dependency Rule:** Sensor drivers MUST use OSAL wrappers, not direct ESP-IDF access.
|
||||
|
||||
---
|
||||
|
||||
## 3. Sensor Driver List
|
||||
|
||||
| Component ID | Sensor Type | Interface | Driver Name |
|
||||
|--------------|-------------|-----------|-------------|
|
||||
| C-SENSOR-DRV-TEMP | Temperature | I2C | SHT40 Temperature Driver |
|
||||
| C-SENSOR-DRV-HUM | Humidity | I2C | SHT40 Humidity Driver |
|
||||
| C-SENSOR-DRV-CO2 | CO₂ | I2C | SCD40 CO2 Driver |
|
||||
| C-SENSOR-DRV-NH3 | NH₃ | Analog/ADC | NH3 Analog Driver |
|
||||
| C-SENSOR-DRV-VOC | VOC | I2C | SGP40 VOC Driver |
|
||||
| C-SENSOR-DRV-PM | Particulate Matter | UART | SPS30 PM Driver |
|
||||
| C-SENSOR-DRV-LIGHT | Light Intensity | I2C | TSL2591 Light Driver |
|
||||
|
||||
---
|
||||
|
||||
## 4. Common SAL Interface
|
||||
|
||||
All sensor drivers implement the following SAL interface:
|
||||
|
||||
```c
|
||||
/**
|
||||
* @brief Initialize sensor
|
||||
* @param config Sensor configuration
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool sensor_driver_init(const sensor_config_t* config);
|
||||
|
||||
/**
|
||||
* @brief Read sensor value
|
||||
* @param value Output sensor value
|
||||
* @param timestamp Output timestamp
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool sensor_driver_read(float* value, uint64_t* timestamp);
|
||||
|
||||
/**
|
||||
* @brief Check sensor health
|
||||
* @return true if healthy, false if failed
|
||||
*/
|
||||
bool sensor_driver_is_healthy(void);
|
||||
|
||||
/**
|
||||
* @brief Get sensor metadata
|
||||
* @param metadata Output metadata structure
|
||||
* @return true on success
|
||||
*/
|
||||
bool sensor_driver_get_metadata(sensor_metadata_t* metadata);
|
||||
|
||||
/**
|
||||
* @brief Reset sensor
|
||||
* @return true on success
|
||||
*/
|
||||
bool sensor_driver_reset(void);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize sensor
|
||||
*/
|
||||
void sensor_driver_deinit(void);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Sensor State Management
|
||||
|
||||
All sensor drivers track sensor state:
|
||||
|
||||
- **INIT:** Initialization state
|
||||
- **WARMUP:** Sensor warming up (not yet stable)
|
||||
- **STABLE:** Sensor operational and stable
|
||||
- **DEGRADED:** Sensor operational but degraded
|
||||
- **FAILED:** Sensor failed, not operational
|
||||
|
||||
---
|
||||
|
||||
## 6. Error Handling
|
||||
|
||||
### 6.1 Error Detection
|
||||
|
||||
- Communication errors (I2C/SPI/UART failures)
|
||||
- Sensor timeout errors
|
||||
- Out-of-range values
|
||||
- Sensor disconnection detection
|
||||
|
||||
### 6.2 Error Reporting
|
||||
|
||||
- Return error codes from driver functions
|
||||
- Report to Diagnostics Manager
|
||||
- Update sensor state to FAILED or DEGRADED
|
||||
|
||||
---
|
||||
|
||||
## 7. Configuration
|
||||
|
||||
### 7.1 Configuration Sources
|
||||
|
||||
- **Machine Constants:** Sensor-specific calibration and configuration
|
||||
- **Hardware Detection:** Sensor presence detection
|
||||
- **Runtime Configuration:** Dynamic parameter adjustment
|
||||
|
||||
### 7.2 Configuration Parameters
|
||||
|
||||
- Sensor address (I2C/SPI)
|
||||
- Calibration parameters
|
||||
- Measurement range
|
||||
- Sampling rate
|
||||
- Warmup duration
|
||||
|
||||
---
|
||||
|
||||
## 8. Dependencies
|
||||
|
||||
### 8.1 OSAL Dependencies
|
||||
|
||||
- **OSAL-I2C:** I2C sensors (Temperature, Humidity, CO2, VOC, Light)
|
||||
- **OSAL-UART:** UART sensors (PM)
|
||||
- **OSAL-ADC:** Analog sensors (NH3)
|
||||
|
||||
### 8.2 Application Dependencies
|
||||
|
||||
- **Logger:** Error logging
|
||||
- **Diagnostics Manager:** Error reporting
|
||||
- **Time Utils:** Timestamp generation
|
||||
|
||||
---
|
||||
|
||||
## 9. Testing Strategy
|
||||
|
||||
### 9.1 Unit Testing
|
||||
|
||||
- Mock OSAL wrappers
|
||||
- Test error handling
|
||||
- Test state transitions
|
||||
- Test calibration application
|
||||
|
||||
### 9.2 Integration Testing
|
||||
|
||||
- Test with real sensors
|
||||
- Test communication protocols
|
||||
- Test error recovery
|
||||
- Test warmup behavior
|
||||
|
||||
---
|
||||
|
||||
## 10. Traceability
|
||||
|
||||
### 10.1 System Requirements
|
||||
|
||||
- **SR-DAQ-001:** Multi-sensor data acquisition
|
||||
- **SR-DAQ-002:** Sensor slot mapping
|
||||
- **SR-DAQ-003:** Sensor presence detection
|
||||
- **SR-HW-001:** Sensor Abstraction Layer
|
||||
|
||||
### 10.2 Software Requirements
|
||||
|
||||
- **SWR-DAQ-001:** Support multiple sensor types
|
||||
- **SWR-DAQ-002:** Sensor driver abstraction
|
||||
- **SWR-DAQ-003:** Sensor presence detection
|
||||
- **SWR-HW-001:** SAL implementation
|
||||
|
||||
---
|
||||
|
||||
**Document Status:** Complete
|
||||
**Next Review:** Before implementation
|
||||
@@ -0,0 +1,151 @@
|
||||
# Temperature Sensor Driver (SHT40)
|
||||
## Sensor Drivers Layer
|
||||
|
||||
**Component ID:** C-SENSOR-DRV-TEMP
|
||||
**Version:** 1.0
|
||||
**Date:** 2025-02-01
|
||||
**Location:** `sensor_drivers/temperature_sht40/`
|
||||
**Sensor:** Sensirion SHT40 (Temperature)
|
||||
|
||||
---
|
||||
|
||||
## 1. Component Overview
|
||||
|
||||
The SHT40 Temperature Driver provides hardware-specific implementation for the Sensirion SHT40 temperature sensor, implementing the Sensor Abstraction Layer (SAL) interface. This driver handles I2C communication, sensor initialization, and temperature reading.
|
||||
|
||||
**Primary Purpose:** Enable Sensor Manager to read temperature from SHT40 sensor.
|
||||
|
||||
---
|
||||
|
||||
## 2. Responsibilities
|
||||
|
||||
### 2.1 In-Scope
|
||||
|
||||
- SHT40 sensor initialization
|
||||
- Temperature reading via I2C
|
||||
- Sensor health monitoring
|
||||
- Sensor calibration application
|
||||
- Sensor state management
|
||||
- Error detection and reporting
|
||||
|
||||
### 2.2 Out-of-Scope
|
||||
|
||||
- Humidity reading (handled by separate SHT40 Humidity driver)
|
||||
- Data filtering (handled by Sensor Manager)
|
||||
- Data persistence (handled by Data Persistence)
|
||||
|
||||
---
|
||||
|
||||
## 3. SAL Interface Implementation
|
||||
|
||||
Implements standard SAL interface:
|
||||
- `sensor_driver_init()` - Initialize SHT40
|
||||
- `sensor_driver_read()` - Read temperature
|
||||
- `sensor_driver_is_healthy()` - Check sensor health
|
||||
- `sensor_driver_get_metadata()` - Get sensor capabilities
|
||||
- `sensor_driver_reset()` - Reset sensor
|
||||
- `sensor_driver_deinit()` - Deinitialize sensor
|
||||
|
||||
---
|
||||
|
||||
## 4. SHT40 Specifics
|
||||
|
||||
### 4.1 I2C Communication
|
||||
|
||||
- **I2C Address:** 0x44 (7-bit)
|
||||
- **Protocol:** I2C standard mode (100kHz) or fast mode (400kHz)
|
||||
- **Command Format:** 2-byte commands
|
||||
- **Data Format:** 2-byte temperature data + 1-byte CRC
|
||||
|
||||
### 4.2 Measurement Characteristics
|
||||
|
||||
- **Range:** -40°C to +125°C
|
||||
- **Accuracy:** ±0.2°C (typical)
|
||||
- **Resolution:** 0.01°C
|
||||
- **Response Time:** < 2 seconds
|
||||
- **Warmup Time:** 5 seconds (from power-on)
|
||||
|
||||
### 4.3 Commands
|
||||
|
||||
- `0xFD` - High precision measurement
|
||||
- `0xE0` - Soft reset
|
||||
- `0x89` - Serial number read
|
||||
|
||||
---
|
||||
|
||||
## 5. State Management
|
||||
|
||||
```
|
||||
[INIT]
|
||||
↓ sensor_driver_init()
|
||||
[WARMUP] (5 seconds)
|
||||
↓ Warmup complete
|
||||
[STABLE]
|
||||
↓ Error detected
|
||||
[DEGRADED]
|
||||
↓ Multiple errors
|
||||
[FAILED]
|
||||
↓ sensor_driver_reset()
|
||||
[INIT]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. Error Handling
|
||||
|
||||
### 6.1 Error Detection
|
||||
|
||||
- I2C communication errors
|
||||
- CRC validation errors
|
||||
- Out-of-range temperature values
|
||||
- Sensor timeout errors
|
||||
|
||||
### 6.2 Error Recovery
|
||||
|
||||
- Automatic retry (3 attempts)
|
||||
- Sensor reset on persistent errors
|
||||
- State transition to DEGRADED or FAILED
|
||||
- Diagnostic event reporting
|
||||
|
||||
---
|
||||
|
||||
## 7. Dependencies
|
||||
|
||||
- **OSAL-I2C:** I2C communication
|
||||
- **Logger:** Error logging
|
||||
- **Diagnostics Manager:** Error reporting
|
||||
- **Time Utils:** Timestamp generation
|
||||
|
||||
---
|
||||
|
||||
## 8. Configuration
|
||||
|
||||
### 8.1 Machine Constants
|
||||
|
||||
- I2C bus number
|
||||
- I2C device address (0x44)
|
||||
- Calibration offset
|
||||
- Calibration scale factor
|
||||
- Measurement precision mode
|
||||
|
||||
### 8.2 Runtime Configuration
|
||||
|
||||
- Warmup duration: 5 seconds
|
||||
- Measurement interval: 1 second
|
||||
- Retry count: 3
|
||||
- Timeout: 100ms
|
||||
|
||||
---
|
||||
|
||||
## 9. Traceability
|
||||
|
||||
- **SR-DAQ-001:** Temperature sensor support
|
||||
- **SR-DAQ-002:** SHT40 sensor slot assignment
|
||||
- **SR-DQC-001:** SHT40 presence detection
|
||||
- **SWR-DAQ-001:** Temperature sensor acquisition
|
||||
- **SWR-HW-001:** SAL implementation
|
||||
|
||||
---
|
||||
|
||||
**Document Status:** Complete
|
||||
**Next Review:** Before implementation
|
||||
Reference in New Issue
Block a user