STIMA
3
|
#include "i2c-leaf-config.h"
#include <debug.h>
#include <i2c_config.h>
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>
#include <i2c_utility.h>
#include <rmap_utility.h>
#include <eeprom_utility.h>
#include <Wire.h>
#include <TimeLib.h>
#include <typedef.h>
#include <registers-leaf.h>
#include <debug_config.h>
#include <SdFat.h>
#include <StreamUtils.h>
#include <ArduinoLog.h>
Go to the source code of this file.
Classes | |
struct | configuration_t |
EEPROM saved configuration. More... | |
struct | leaf_wetness_t |
Leaf wetness data. More... | |
struct | readable_data_t |
Readable data through i2c bus. More... | |
struct | writable_data_t |
Writable data through i2c bus. More... | |
Enumerations | |
enum | state_t { INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , REBOOT , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END } |
Main loop finite state machine. More... | |
enum | leaf_reading_state_t { LEAF_READING_INIT , LEAF_READING_READ , LEAF_READING_END , LEAF_READING_WAIT_STATE } |
Functions | |
void | init_logging () |
Init logging system. More... | |
void | init_power_down (uint32_t *time_ms, uint32_t debouncing_ms) |
Enter power down mode. More... | |
void | init_wdt (uint8_t wdt_timer) |
Init watchdog. More... | |
void | init_system (void) |
Init system. More... | |
void | init_buffers (void) |
Init buffers. More... | |
void | init_tasks (void) |
Init tasks variable and state. More... | |
void | init_pins (void) |
Init hardware pins. More... | |
void | init_wire (void) |
Init wire (i2c) library and performs checks on the bus. More... | |
void | init_spi (void) |
Init SPI library. More... | |
void | init_rtc (void) |
Init RTC module. More... | |
void | init_sensors (void) |
Create and setup sensors. More... | |
void | print_configuration (void) |
Print current configuration. More... | |
void | load_configuration (void) |
Load configuration from EEPROM. More... | |
void | save_configuration (bool) |
Save configuration to EEPROM. More... | |
void | commands (void) |
Performs specific operations based on the received command. More... | |
void | reset_samples_buffer (void) |
Reset samples buffers to default value. More... | |
void | reset_report_buffer (void) |
void | reset_buffer (void) |
Reset sample and observations buffers to default value. More... | |
void | exchange_buffers (void) |
Exchange reader and writer pointer to buffer. More... | |
template<typename sample_g , typename observation_g , typename value_v > | |
void | addSample (sample_g *sample, observation_g *observation, value_v value) |
template<typename observation_g , typename value_v > | |
value_v | readCurrentObservation (observation_g *buffer) |
template<typename observation_g , typename value_v > | |
void | writeCurrentObservation (observation_g *buffer, value_v value) |
template<typename observation_g , typename length_v > | |
void | resetObservation (observation_g *buffer, length_v length) |
template<typename observation_g , typename length_v > | |
void | resetBackPmObservation (observation_g *buffer, length_v length) |
template<typename observation_g , typename length_v > | |
void | incrementObservation (observation_g *buffer, length_v length) |
template<typename observation_g , typename length_v , typename value_v > | |
void | addObservation (observation_g *buffer, length_v length, value_v value) |
template<typename observation_g , typename length_v , typename value_v > | |
value_v | readBackObservation (observation_g *buffer, length_v length) |
void | samples_processing (bool is_force_processing) |
Main routine for processing the samples to calculate an observation. More... | |
void | leaf_reading_task (void) |
Sensors reading Task. Read data from sensors. More... | |
void | command_task (void) |
Command Task. Execute the command received on i2c bus by reading i2c received data buffer. More... | |
void | i2c_request_interrupt_handler (void) |
I2C request interrupt handler. More... | |
void | i2c_receive_interrupt_handler (void) |
I2C receive interrupt handler. More... | |
Variables | |
configuration_t | configuration |
Configuration data. | |
volatile readable_data_t | readable_data_1 |
First readable i2c register. | |
volatile readable_data_t | readable_data_2 |
Second readable i2c register. | |
volatile readable_data_t * | readable_data_read_ptr |
Pointer for read data in i2c readable register. | |
volatile readable_data_t * | readable_data_write_ptr |
Pointer for write data in i2c readable register. | |
volatile readable_data_t * | readable_data_temp_ptr |
Temporary pointer for exchange read and write pointer for i2c readable register. | |
writable_data_t | writable_data |
Writable i2c register. | |
writable_data_t * | writable_data_ptr |
Pointer for read and write data in i2c writable register. | |
volatile uint8_t | readable_data_address |
Address of readable i2c register. | |
volatile uint8_t | readable_data_length |
Number of bytes to read at readable_data_address. | |
volatile uint8_t | i2c_rx_data [I2C_MAX_DATA_LENGTH] |
Buffer for i2c received data. | |
volatile uint8_t | lastcommand |
last command received. More... | |
volatile uint8_t | i2c_error |
Number of i2c error. | |
volatile uint8_t | i2c_time |
Time in seconds from last I2C reset. | |
volatile uint8_t | ready_tasks_count |
Number of tasks ready to execute. | |
uint32_t | awakened_event_occurred_time_ms |
System time (in millisecond) when the system has awakened from power down. | |
bool | is_start |
Execute start command. | |
bool | is_stop |
Execute stop command. | |
bool | is_test_read |
Received command is in continuous mode. | |
bool | is_leaf_init |
bool | is_leaf_wet |
uint8_t | samples_count |
Number of samples to be acquired for make one observation. | |
bool | do_buffers_reset |
Force a buffers reset. | |
volatile uint16_t | timer_counter_ms |
Timer counter variable for execute timed task with time multiple of base Timer1 time. | |
state_t | state |
Current main loop state. | |
leaf_reading_state_t | leaf_reading_state |
volatile bool | inside_transaction |
Status of command transaction. | |
volatile uint16_t | transaction_time |
Timer counter variable for compute command transaction timeout. | |
volatile bool | is_event_leaf_reading |
Enable or disable the Sensors reading task. | |
volatile bool | is_event_command_task |
Enable or disable the Command task. | |
enum leaf_reading_state_t |
enum state_t |
Main loop finite state machine.
void command_task | ( | void | ) |
Command Task. Execute the command received on i2c bus by reading i2c received data buffer.
Execute the command received on i2c bus by reading i2c received data buffer.
void commands | ( | void | ) |
Performs specific operations based on the received command.
CONTINUOUS TEST
CONTINUOUS START
CONTINUOUS STOP
CONTINUOUS START-STOP
ONESHOT START
ONESHOT STOP
ONESHOT START-STOP
CONTINUOUS START
CONTINUOUS STOP
CONTINUOUS START-STOP
ONESHOT START
ONESHOT STOP
ONESHOT START-STOP
CONTINUOUS TEST
CONTINUOUS START
CONTINUOUS STOP
CONTINUOUS START-STOP
ONESHOT START
ONESHOT STOP
ONESHOT START-STOP
CONTINUOUS TEST
CONTINUOUS START
CONTINUOUS STOP
CONTINUOUS START-STOP
ONESHOT START
ONESHOT STOP
ONESHOT START-STOP
CONTINUOUS TEST
CONTINUOUS START
CONTINUOUS STOP
CONTINUOUS START-STOP
ONESHOT START
ONESHOT STOP
ONESHOT START-STOP
CONTINUOUS START
CONTINUOUS STOP
CONTINUOUS START-STOP
ONESHOT START
ONESHOT STOP
ONESHOT START-STOP
void exchange_buffers | ( | void | ) |
Exchange reader and writer pointer to buffer.
void i2c_receive_interrupt_handler | ( | void | ) |
I2C receive interrupt handler.
void i2c_request_interrupt_handler | ( | void | ) |
I2C request interrupt handler.
write readable_data_length bytes of data stored in readable_data_read_ptr (base) + readable_data_address (offset) on i2c bus
write crc8
write readable_data_length bytes of data stored in readable_data_read_ptr (base) + readable_data_address (offset) on i2c bus
write crc8
write readable_data_length bytes of data stored in readable_data_read_ptr (base) + readable_data_address (offset) on i2c bus
write readable_data_length bytes of data stored in readable_data_read_ptr (base) + readable_data_address (offset) on i2c bus
write crc8
write readable_data_length bytes of data stored in readable_data_read_ptr (base) + readable_data_address (offset) on i2c bus
write crc8
write readable_data_length bytes of data stored in readable_data_read_ptr (base) + readable_data_address (offset) on i2c bus
void init_buffers | ( | void | ) |
Init buffers.
copy readable_data_2 in readable_data_1
copy readable_data_2 in readable_data_1
copy readable_data_write in readable_data_read
copy readable_data_write in readable_data_read
copy readable_data_write in readable_data_read
copy readable_data_2 in readable_data_1
copy readable_data_write in readable_data_read
void init_logging | ( | void | ) |
Init logging system.
void init_pins | ( | void | ) |
Init hardware pins.
void init_power_down | ( | uint32_t * | time_ms, |
uint32_t | debouncing_ms | ||
) |
Enter power down mode.
time_ms | pointer to a variable to save the last instant you entered power down. |
debouncing_ms | delay to power down. |
void init_rtc | ( | void | ) |
Init RTC module.
void init_sensors | ( | void | ) |
Create and setup sensors.
void init_spi | ( | void | ) |
Init SPI library.
void init_system | ( | void | ) |
Init system.
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
void init_tasks | ( | void | ) |
Init tasks variable and state.
no tasks ready
no tasks ready
reset samples_count value
no tasks ready
no tasks ready
no tasks ready
no tasks ready
void init_wdt | ( | uint8_t | wdt_timer | ) |
Init watchdog.
wdt_timer | a time value for init watchdog (WDTO_xxxx). |
void init_wire | ( | void | ) |
Init wire (i2c) library and performs checks on the bus.
clear the I2C bus first before calling Wire.begin()
void leaf_reading_task | ( | void | ) |
Sensors reading Task. Read data from sensors.
void load_configuration | ( | void | ) |
Load configuration from EEPROM.
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
void print_configuration | ( | void | ) |
Print current configuration.
void reset_buffer | ( | void | ) |
Reset sample and observations buffers to default value.
void reset_samples_buffer | ( | void | ) |
Reset samples buffers to default value.
void samples_processing | ( | bool | is_force_processing | ) |
Main routine for processing the samples to calculate an observation.
is_force_processing | if is true, force the calculation of the observation provided there is a minimum number of samples. |
if true, a new bins and pm observation was calculated
assign new value for samples_count
reset samples's buffer values
void save_configuration | ( | bool | is_default | ) |
Save configuration to EEPROM.
is_default | if true save default configuration; if false save current configuration. |
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
lastcommand |
last command received.
command to be executed.