1 | #ifndef __APPLICATION_H
|
---|
2 | #define __APPLICATION_H
|
---|
3 | //-----------------------------------------------------------------------------
|
---|
4 |
|
---|
5 | #include "typedefs.h"
|
---|
6 | //-----------------------------------------------------------------------------
|
---|
7 |
|
---|
8 | #define RESISTANCE_CHANNELS 64
|
---|
9 | #define RESISTANCE_REGS 8
|
---|
10 | #define AD7719_READINGS_UNTIL_SETTLED 3 // when set to 3 --> we wait 480ms per sensor reading
|
---|
11 | #define VOLTAGE_CHANNELS 84
|
---|
12 | #define VOLTAGE_REGS 11
|
---|
13 | #define ADC_READINGS_UNTIL_SETTLED 1
|
---|
14 | #define ADC_VALUES_LEN_BYTE 168
|
---|
15 | #define AD7719_VALUES_LEN_BYTE 512
|
---|
16 |
|
---|
17 | typedef struct {
|
---|
18 | U08 ad7719_readings_since_last_muxing;
|
---|
19 | U08 ad7719_current_channel;
|
---|
20 | U32 ad7719_current_reading;
|
---|
21 | U08 ad7719_enables[RESISTANCE_REGS];
|
---|
22 | U08 ad7719_channels_ready[RESISTANCE_REGS];
|
---|
23 | U32 ad7719_values[RESISTANCE_CHANNELS];
|
---|
24 | U16 ad7719_values_checksum;
|
---|
25 |
|
---|
26 | U08 adc_readings_since_last_muxing;
|
---|
27 | U08 adc_current_channel;
|
---|
28 | U16 adc_current_reading;
|
---|
29 | U08 adc_enables[VOLTAGE_REGS];
|
---|
30 | U08 adc_channels_ready[VOLTAGE_REGS];
|
---|
31 | U16 adc_values[VOLTAGE_CHANNELS];
|
---|
32 | U16 adc_values_checksum;
|
---|
33 |
|
---|
34 | // ----- NEW --------
|
---|
35 | bool ad7719_measured_all;
|
---|
36 | bool adc_measured_all;
|
---|
37 |
|
---|
38 | } FSCRegisterType;
|
---|
39 |
|
---|
40 | typedef struct {
|
---|
41 | U08 app_reset_source;
|
---|
42 | U32 time_sec;
|
---|
43 | U16 time_ms;
|
---|
44 | } VolatileRegisterType;
|
---|
45 |
|
---|
46 | extern FSCRegisterType gReg;
|
---|
47 | extern volatile VolatileRegisterType gVolReg;
|
---|
48 |
|
---|
49 |
|
---|
50 | //-----------------------------------------------------------------------------
|
---|
51 |
|
---|
52 | // in order to check the user interface on a hardware near level.
|
---|
53 | // user can issue 'heartbeat command'.
|
---|
54 | // then this üpin is toggled with the 'main-while-loop-frequency'
|
---|
55 | // --> nice check for this frequency as well
|
---|
56 | #define HEARTBEATPIN PB3
|
---|
57 |
|
---|
58 | // SPI DEFINITIONS
|
---|
59 | // Port Definitions
|
---|
60 | #define SPI_PRT PORTB
|
---|
61 | #define SPI_DDR DDRB
|
---|
62 |
|
---|
63 | // Bit Definitions
|
---|
64 | #define SPI_SCLK PB7
|
---|
65 | #define SPI_MOSI PB5
|
---|
66 | #define SPI_MISO PB6
|
---|
67 |
|
---|
68 | #define SPI_E_CS PB4
|
---|
69 | #define SPI_AD_CS PD3
|
---|
70 | #define SPI_M_CS PD4
|
---|
71 | #define SPI_A_CS PD5
|
---|
72 |
|
---|
73 | #define W5100_INPUT_CHECK_TIME 25 // defines how often the W5100 should be asked if something arrived... in ms
|
---|
74 | #define ADC_READINGS_UNTIL_MEAN 40
|
---|
75 |
|
---|
76 |
|
---|
77 | void app_init(void); // Initialize application
|
---|
78 | void app_set_watchdog_prescaler(tWDT_PRESCALE wdt_prescale); // Set watchdog prescale
|
---|
79 |
|
---|
80 | // definition of some functions:
|
---|
81 | // these function are implemented in this file, this is not good coding style.
|
---|
82 | // sooner or later, they will be moved into more apropriate files.
|
---|
83 | void set_adc_enable_register();
|
---|
84 | void set_ad7719_enable_register();
|
---|
85 | U08 increase_adc (U08 channel);
|
---|
86 | U08 increase_ad7719 (U08 channel);
|
---|
87 | void check_what_measurement_was_finished() ;
|
---|
88 |
|
---|
89 |
|
---|
90 | bool check_if_adc_measurement_done();
|
---|
91 | bool check_if_ad7719_measurement_done();
|
---|
92 | bool check_if_measured_all();
|
---|
93 |
|
---|
94 | void reset_resistance_done();
|
---|
95 | void reset_resistance_values();
|
---|
96 | void reset_voltage_done();
|
---|
97 | void reset_voltage_values();
|
---|
98 | void reset_done();
|
---|
99 |
|
---|
100 | void write_status_via_eth();
|
---|
101 | U16 fletcher16( U08 const *data, U16 bytes );
|
---|
102 |
|
---|
103 | #endif
|
---|