/* Soil Sensor Firmware * Sense/Net (RS-485) Bus * Sensiplicity Systems * * Copyright 2015 * * Department of Botany and Plant Pathology * Center for Genome Research and Biocomputing * Oregon State University * Corvallis, OR 97331 * * This program is not free software; you can not redistribute it and/or * modify it at all. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include /* This module contains an autonomous set of interrupts that manages * the Sense/Net bus. Measurement data should be stored in MeasurementData. * Perform writes to MeasurementData inside an ATOMIC_BLOCK(ATOMIC_RESTORESTATE){} to * prevent corruption! * * This modules uses timer 2. */ struct measurement_data_t { uint16_t humidity; /* Ambient relative humidity. 0=0%, 4096=100% */ int16_t temp_ambient; /* Ambient temperature, in 1/16 (.125) degrees Celsius. */ int16_t temp_soil_z0; /* Soil temperature of zone 0, in 1/16 (.125) degrees Celsius. */ int16_t temp_soil_z1; /* Soil temperature of zone 0, in 1/16 (.125) degrees Celsius. */ int16_t temp_soil_z2; /* Soil temperature of zone 0, in 1/16 (.125) degrees Celsius. */ int16_t temp_soil_z3; /* Soil temperature of zone 0, in 1/16 (.125) degrees Celsius. */ uint32_t light; /* Current light level, in nW/cm^2 */ uint8_t volt_idle; /* Idle supply voltage, in 1/32 volt increments. (160 = 5V). */ uint32_t uptime; /* Number of seconds since this sensor was powered on. * This field is set internally by this module. */ uint32_t mtime; /* Uptime value at the time of measurement. */ uint8_t zones; /* Number of zones present on this sensor node. */ uint16_t moisture_z0; /* Moisture level in zone 0. Calibration TBD. */ uint16_t moisture_z1; /* Moisture level in zone 1. Calibration TBD. */ uint16_t moisture_z2; /* Moisture level in zone 2. Calibration TBD. */ uint16_t moisture_z3; /* Moisture level in zone 3. Calibration TBD. */ }; extern volatile struct measurement_data_t MeasurementData; /* If !0, the LED should be blinked by the main() function. */ extern volatile uint8_t LEDBlink; /* Initialize the pins, peripherals, and interrupts for the UART. */ void init_bus(void); /* Transmit the given buffer over the RS-485 bus. Don't call this function * while data is being received. */ void send(uint8_t *s, uint16_t length);