Changeset 17629 for firmware


Ignore:
Timestamp:
Mar 18, 2014, 4:23:51 PM (5 years ago)
Author:
dneise
Message:
a lot of changes for the new firmware version.
Mostly the global registers were changed
Location:
firmware/FSC/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • firmware/FSC/src/application.c

    r10910 r17629  
    1 //-----------------------------------------------------------------------------
    2 
    31#include "application.h"
    4 #include "usart.h"
    5 #include <avr/wdt.h>
    6 
    7 // in order to implement the "registers" I work with a quite long
    8 //  char-array like this:
    9 
    10 U08 FSCregister[FSC_REGISTER_LENGTH];
    11 // but this register is not only accessible by
    12 // FSCregister[i], but as well by special pointers like this:
    13 U32 *status                                                     = (U32*)&FSCregister[0];
    14 U32 *time_sec                                                   = (U32*)&(FSCregister[4]);
    15 U16 *time_ms                                                    = (U16*)&(FSCregister[6]);
    16 U16 *FR_period                                                  = (U16*)&(FSCregister[8]);
    17 U16 *ref_resistor                                               = (U16*)&(FSCregister[10]);
    18 
    19 
    20 U32 *ad7719_values                                              = (U32*)&FSCregister[68];
    21 U08 *ad7719_enables                                     = &FSCregister[30];
    22 U08 *ad7719_channels_ready                              = &FSCregister[49];
    23 U08 *ad7719_readings_since_last_muxing  = &FSCregister[14];
    24 U08 *ad7719_current_channel                     = &FSCregister[15];
    25 U32 *ad7719_current_reading                     = (U32*)&FSCregister[16];
    26 
    27 U16 *adc_values                                                 = (U16*) &FSCregister[324];
    28 U08 *adc_enables                                                = &FSCregister[38];
    29 U08 *adc_channels_ready                                 = &FSCregister[57];
    30 U08 *adc_readings_since_last_muxing     = &FSCregister[20];
    31 U08 *adc_current_channel                                = &FSCregister[21];
    32 U16 *adc_current_reading                                = (U16*) &FSCregister[22];
    33 
    34 // using these pointers one can manipulate measurement values like this:
    35 // res_value[3] = 453212;
    36 // and then readout the most significant byte of this same value by accessing:
    37 // FSCregister[92];
    38 // I like this very much for asking the boards status ... this is just a copy of the registers,
    39 // into the W5100 TX FIFO.
    40 // submitting the measurement values is just a partial copy...
    41 
    42 //-----------------------------------------------------------------------------
    43 
    44 //-----------------------------------------------------------------------------
    45 
    46 volatile U08 app_reset_source;
    47 //-----------------------------------------------------------------------------
     2#include "w5100_spi_interface.h"
     3#include <avr/wdt.h>
     4
     5// ---------------- These are the global variables that represent the registers
     6// of the entire FSC, everything is stored here and can thus be sent down ----
     7FSCRegisterType gReg;
     8volatile VolatileRegisterType gVolReg;
     9
     10
     11
    4812
    4913void app_init(void) {
    50   app_reset_source = MCUSR; // Save last reset source
    51   MCUSR = 0x00; // Clear reset source for next reset cycle
    52 
    53 
    54         // Dangerous here: I still do not know much about the watchdog.
    55         // This code is still from Udo Juerss.
    56 
    57   // The watchdog timer is disabled by default ("startup.asm")
    58         #ifdef USE_WATCHDOG
    59          WDTCSR = WDTOE | (1 << WDE); // Enable watchdog reset (~16ms)
    60         #endif
    61 
    62         // define PORTS
    63         // USART
    64         DDRD &= ~(1<<PD0);                              // PD0 = RXD is input
    65         DDRD |= 1<<PD1;                                         // PD1 = TXD is output
    66        
    67 
    68         // SPARE OUT/-INPUTS
    69         DDRB |= (1<<PB2) | (1<<PB3);    // set Out1_spare & out2_spare as outputs
    70         DDRA &= ~(1<<PA7);                              // set In1_spare as input
    71         DDRC &= ~(1<<PC7);                              // set In2_spare as input
    72         //PORTA |= (1<<PA7);                            // swtich on pullup on In1_spare
    73         //PORTC |= (1<<PC7);                            // swtich on pullup on In2_spare
    74 
    75         // ATmega internal ADC input
    76         DDRA &= ~(1<<PA6);
    77 
    78         // MUXER ADDRESS OUTs
    79         DDRA |= 0x3F; // SA-pins -> output
    80         DDRC |= 0x7F; // SB-pins -> output
    81 
    82         // SPI
    83         // set all CS's: output
    84         DDRB |= (1 << SPI_E_CS);
    85         DDRD |= (1 << SPI_AD_CS) |(1 << SPI_M_CS) |(1 << SPI_A_CS);
    86 
    87         // set all Chips selects HIGH
    88         PORTB |= (1 << SPI_E_CS);
    89         PORTD |= (1 << SPI_AD_CS) |(1 << SPI_M_CS) |(1 << SPI_A_CS);
    90 
    91         // set MOSI and SCK: output & // set MISO: input
    92         SPI_DDR |= (1 << SPI_MOSI);
    93         SPI_DDR |= (1 << SPI_SCLK);
    94         SPI_DDR &= ~(1 << SPI_MISO);
    95 
    96         // set MOSI, SCK: HIGH. MISO leave alone.
    97         SPI_PRT |= (1 << SPI_MOSI);
    98         SPI_PRT |= (1 << SPI_SCLK);
    99         //SPI_PRT |= (1 << SPI_MISO);
    100 
    101         // ADC
    102         DDRD &= ~(1<<PD6);                                      // PD6 is AD_READY input
    103         DDRD |= 1<<PD7;                                                 // PD7 is AD_RESET output
    104 
    105         // ACCELEROMETER
    106         DDRD &= ~(1<<PD2);                                      // PD2 is ACC_READY input
    107 
    108         //MAX6662   <--- not assembled
    109         // DDRB &= ~(1<<PB0);                   // PB0 is over temperature alert input
    110         // DDRB &= ~(1<<PB1);                           // PB1 is general temperature altert input
    111 }
    112 
    113 
    114 
    115 //-----------------------------------------------------------------------------
    116 
    117 void app_set_watchdog_prescaler(tWDT_PRESCALE wdt_prescale) // Set watchdog prescale
    118 {
     14    gVolReg.app_reset_source = MCUSR; // Save last reset source
     15    MCUSR = 0x00; // Clear reset source for next reset cycle
     16
     17    // Dangerous here: I still do not know much about the watchdog.
     18    // This code is still from Udo Juerss.
     19    // The watchdog timer is disabled by default ("startup.asm")
     20    #ifdef USE_WATCHDOG
     21        WDTCSR = WDTOE | (1 << WDE); // Enable watchdog reset (~16ms)
     22    #endif
     23
     24    // define PORTS
     25    // USART
     26    DDRD &= ~(1<<PD0);              // PD0 = RXD is input
     27    DDRD |= 1<<PD1;                 // PD1 = TXD is output
     28
     29    // SPARE OUT/-INPUTS
     30    DDRB |= (1<<PB2);           // set Out1_spare as output
     31    DDRB |= (1<<PB3);           // set Out2_spare as output
     32    DDRA &= ~(1<<PA7);          // set In1_spare as input
     33    DDRC &= ~(1<<PC7);          // set In2_spare as input
     34    //PORTA |= (1<<PA7);        // swtich on pullup on In1_spare
     35    //PORTC |= (1<<PC7);        // swtich on pullup on In2_spare
     36
     37    // ATmega internal ADC input
     38    DDRA &= ~(1<<PA6);
     39
     40    // MUXER ADDRESS OUTs
     41    DDRA |= 0x3F; // SA-pins -> output
     42    DDRC |= 0x7F; // SB-pins -> output
     43
     44    // SPI
     45    // set all CS's: output
     46    DDRB |= (1 << SPI_E_CS);
     47    DDRD |= (1 << SPI_AD_CS);
     48    DDRD |= (1 << SPI_M_CS);
     49    DDRD |= (1 << SPI_A_CS);
     50
     51    // set all Chips selects HIGH
     52    PORTB |= (1 << SPI_E_CS);
     53    PORTD |= (1 << SPI_AD_CS);
     54    PORTD |= (1 << SPI_M_CS);
     55    PORTD |= (1 << SPI_A_CS);
     56
     57    // set MOSI and SCK: output & // set MISO: input
     58    SPI_DDR |= (1 << SPI_MOSI);
     59    SPI_DDR |= (1 << SPI_SCLK);
     60    SPI_DDR &= ~(1 << SPI_MISO);
     61
     62    // set MOSI, SCK: HIGH. MISO leave alone.
     63    SPI_PRT |= (1 << SPI_MOSI);
     64    SPI_PRT |= (1 << SPI_SCLK);
     65    //SPI_PRT |= (1 << SPI_MISO);
     66
     67    // ADC
     68    DDRD &= ~(1<<PD6);      // PD6 is AD_READY input
     69    DDRD |= 1<<PD7;         // PD7 is AD_RESET output
     70
     71    // ACCELEROMETER
     72    DDRD &= ~(1<<PD2);      // PD2 is ACC_READY input
     73
     74    //MAX6662   <--- not assembled
     75    // DDRB &= ~(1<<PB0);   // PB0 is over temperature alert input
     76    // DDRB &= ~(1<<PB1);   // PB1 is general temperature altert input
     77}
     78
     79// Set watchdog prescale
     80void app_set_watchdog_prescaler(tWDT_PRESCALE wdt_prescale) {
     81
    11982  U08 sreg_backup = SREG; // Copy status register to variable
    12083  U08 wdtcsr_value = WDE + wdt_prescale; // Set new prescale value to variable
     
    12891}
    12992
    130 void set_ad7719_enable_register() {
    131 
    132         usart_write_str((pU08)"\n set enable bits of AD7719 Port ");
    133         if ((usart_received_chars>=5) &&
    134         (usart_rx_buffer[2] >= 'A' && usart_rx_buffer[2] <= 'H'))
    135         {
    136         usart_write_char(usart_rx_buffer[2]);
    137         usart_write_str((pU08)" to ");
    138         usart_write_U08_hex(usart_rx_buffer[4]);
    139         usart_write_char('\n');
    140                 ad7719_enables[usart_rx_buffer[2]-'A']=usart_rx_buffer[4];
    141                 ad7719_channels_ready[usart_rx_buffer[2]-'A']=0x00;
    142         }
    143         else if  ((usart_received_chars=3) &&
    144         (usart_rx_buffer[1] >= 'A' && usart_rx_buffer[1] <= 'H'))
    145         {
    146                 usart_write_char(usart_rx_buffer[1]);
    147                 if (usart_rx_buffer[2]!='0') {
    148                         usart_write_str((pU08)" to 0xFF\n");
    149                         ad7719_enables[usart_rx_buffer[1]-'A']=0xFF;
    150                 } else
    151                 {
    152                         usart_write_str((pU08)" to 0x00\n");
    153                         ad7719_enables[usart_rx_buffer[1]-'A']=0x00;
    154                 }
    155                 ad7719_channels_ready[usart_rx_buffer[1]-'A']=0x00;     
    156         }
    157         else
    158         {
    159                 usart_write_str((pU08)"\n something wrong\n");
    160                 usart_write_str((pU08)"usart_rx_buffer_index: ");
    161                 usart_write_U08(usart_received_chars, 3);
    162                 usart_write_str((pU08)"\n usart_rx_buffer[2]: ");
    163                 usart_write_char(usart_rx_buffer[2]);
    164                 usart_write_str((pU08)"\n usart_rx_buffer[4]: ");
    165                 usart_write_U08_hex(usart_rx_buffer[4]);
    166                 usart_write_char('\n');
    167         }
    168 }
    169 
    170 void set_adc_enable_register() {
    171         // TODO
    172         usart_write_str((pU08)"setting of ATmega internal ADC enable registers is not supported. yet.\n");
    173 }
    174 
    175 U08     increase_adc (U08 channel){
    176 U08 effective_channel;
    177         for ( U08 increase = 1 ; increase <= VOLTAGE_CHANNELS; increase++)
    178         {
    179                 effective_channel = (channel + increase) % (VOLTAGE_CHANNELS);
    180                 if (adc_enables[effective_channel/8] & (1<<effective_channel%8)) {
    181                         if (debug_mode)
    182                         {
    183                                 usart_write_U08(effective_channel,3);
    184                                 usart_write_crlf();
    185                         }
    186                         return effective_channel;
    187                 }
    188         }
    189         if (debug_mode)
    190         {
    191                 usart_write_U08(channel,3);
    192                 usart_write_crlf();
    193         }
    194         return channel;
    195 } // end if increase_adc;
    196 
    197 U08     increase_ad7719 (U08 channel){
    198 U08 effective_channel;
    199         for ( U08 increase = 1 ; increase <= RESISTANCE_CHANNELS; increase++)
    200         {
    201                 effective_channel = (channel + increase) % (RESISTANCE_CHANNELS);
    202                 if (ad7719_enables[effective_channel/8] & (1<<effective_channel%8))
    203                         return effective_channel;
    204         }
    205         return channel;
    206 } // end if increase_adc;
    207 
    208 void check_if_measured_all() {
    209         adc_measured_all = true;
    210         for ( U08 i=0; i<(VOLTAGE_REGS); ++i ) {
    211                 if ((adc_enables[i] ^ adc_channels_ready[i]) != 0x00) {
    212                         adc_measured_all = false;
    213                         break;
    214                 }
    215         }
    216         ad7719_measured_all = true;
    217         for ( U08 i=0; i<(RESISTANCE_CHANNELS/8); ++i ) {
    218                 if ((ad7719_enables[i] ^ ad7719_channels_ready[i]) != 0x00) {
    219                         ad7719_measured_all = false;
    220                         break;
    221                 }
    222         }
    223 
    224 
    225 }
    226 
    227 // an U08 array containts bitmaps, which encode, which channel is enabled and which is not.
    228 // a measurement is done, when all (or more) enabled channels were already measured.
    229 // a similar U08 array contains a bitmap, encoding which channels are already done.
    230 //  note: "or more" above is important, if we check to strictly,
    231 //      we will never finish, in case a disabled channel get measured by any mistake...
    232 //
    233 //      lets assume:
    234 //      enabled = 1110.0011             1110.0011
    235 //      done    = 1111.0011             0111.0010
    236 //
    237 //      and             = 1110.0011             0110.0010
    238 //      nand    = 0001.0011             1001.1101
    239 //      or              = 1111.0011             1111.0011
    240 //      xor             = 0001.0000             1001.0001
    241 //     
    242 //                                                                                     
    243 // (en xor done) and enabled =
    244 //      xor             = 0001.0000             1001.0001
    245 //      enabled = 1110.0011             1110.0011
    246 //                        ---------             ---------
    247 //                        0000.0000             1000.0001
    248 // if this statement evaluates to zero,
    249 bool check_if_adc_measurement_done(){
    250         adc_measured_all = true;
    251         for ( U08 i=0; i<VOLTAGE_REGS; ++i ) {
    252                 if (( (adc_enables[i] ^ adc_channels_ready[i]) & adc_enables[i] )  != 0x00) {
    253                         adc_measured_all = false;
    254                         break;
    255                 }
    256         }
    257         return adc_measured_all;
    258 }
    259 
    260 bool check_if_ad7719_measurement_done(){
    261         ad7719_measured_all = true;
    262         for ( U08 i=0; i<RESISTANCE_CHANNELS/8; ++i ) {
    263                 if (( (ad7719_enables[i] ^ ad7719_channels_ready[i]) & ad7719_enables[i]) != 0x00) {
    264                         ad7719_measured_all = false;
    265                         break;
    266                 }
    267         }
    268         return ad7719_measured_all;
    269 }
     93
     94//U08* en = gReg.adc_enables;
     95//U08 size = VOLTAGE_CHANNELS;
     96U08 increase (U08 channel, U08* enables_ptr, U08 size){
     97    for ( U08 increase = 1 ; increase <= size; increase++) {
     98        U08 effective_channel = (channel + increase) % size;
     99        if (enables_ptr[effective_channel/8] & (1<<effective_channel%8)) {
     100            return effective_channel;
     101        }
     102    }
     103    return channel;
     104}
     105U08 increase_ad7719 (U08 channel) {
     106    return increase( channel, gReg.ad7719_enables, RESISTANCE_CHANNELS);
     107}
     108U08 increase_adc (U08 channel) {
     109    return increase( channel, gReg.adc_enables, VOLTAGE_CHANNELS);
     110}
     111
     112
     113/* Explaination of bit banging:
     114 * an U08 array containts bitmaps, which encode, which channel is enabled and which is not.
     115 * a measurement is done, when all (or more) enabled channels were already measured.
     116 * a similar U08 array contains a bitmap, encoding which channels are already done.
     117 * note: "or more" above is important, if we check to strictly,
     118 * we will never finish, in case a disabled channel get measured by any mistake...
     119 *
     120 * lets assume:
     121 * enabled  = 1110.0011     1110.0011
     122 * done     = 1111.0011     0111.0010
     123 *
     124 * and      = 1110.0011     0110.0010
     125 * nand     = 0001.0011     1001.1101
     126 * or       = 1111.0011     1111.0011
     127 * xor      = 0001.0000     1001.0001
     128 *
     129 * (en xor done) and enabled =
     130 * xor      = 0001.0000     1001.0001
     131 * enabled  = 1110.0011     1110.0011
     132 *            ---------     ---------
     133 *            0000.0000     1000.0001
     134 * if this statement evaluates to zero,
     135 *
     136 *
     137 * size = VOLTAGE_REGS | RESISTANCE_REGS
     138 * en = gReg.adc_enables | gReg.ad7719_enables
     139 * dry = gReg.adc_channels_ready | gReg.ad7719_channels_ready
     140 */
     141bool check_if_measurement_done(U08* en, U08*rdy, U08 size) {
     142    U08 temp = true;
     143    for ( U08 i=0; i<size; ++i ) {
     144        if (((en[i]^rdy[i])&en[i]) != 0x00) {
     145            temp = false;
     146            break;
     147        }
     148    }
     149    return temp;
     150}
     151bool check_if_adc_measurement_done() {  // operates on global gReg
     152    return gReg.adc_measured_all = check_if_measurement_done(
     153                                        gReg.adc_enables,
     154                                        gReg.adc_channels_ready,
     155                                        VOLTAGE_REGS);
     156}
     157bool check_if_ad7719_measurement_done() {  // operates on global gReg
     158    return gReg.ad7719_measured_all = check_if_measurement_done(
     159                                        gReg.ad7719_enables,
     160                                        gReg.ad7719_channels_ready,
     161                                        RESISTANCE_REGS);
     162}
     163bool check_if_measured_all() {          // operates on global gReg
     164    return check_if_adc_measurement_done() && check_if_ad7719_measurement_done();
     165}
     166
     167void reset_voltage_done(){              // operates on global gReg
     168    for (U08 i=0; i < (VOLTAGE_REGS); i++){
     169        gReg.adc_channels_ready[i] = 0;
     170    }
     171}
     172void reset_voltage_values(){            // operates on global gReg
     173    for (U08 i=0; i < VOLTAGE_CHANNELS; i++){
     174        gReg.adc_values[i] = 0;
     175    }
     176}
     177void reset_resistance_done(){           // operates on global gReg
     178    for (U08 i=0; i < (RESISTANCE_REGS); i++){
     179        gReg.ad7719_channels_ready[i] = 0;
     180    }
     181}
     182void reset_resistance_values(){         // operates on global gReg
     183    for (U08 i=0; i < RESISTANCE_CHANNELS; i++){
     184        gReg.ad7719_values[i] = 0;
     185    }
     186}
     187void reset_done(){
     188    reset_resistance_done();
     189    reset_voltage_done();
     190}
     191
     192
     193void write_status_via_eth() {
     194    gReg.ad7719_values_checksum = fletcher16( (U08*)gReg.ad7719_values, RESISTANCE_CHANNELS * sizeof(U32) );
     195    gReg.adc_values_checksum = fletcher16( (U08*)gReg.adc_values, VOLTAGE_CHANNELS * sizeof(U16) );
     196   
     197    U16 bytes_to_be_sent = sizeof(gReg);
     198    U16 bytes_already_sent = 0;
     199    U16 bytes_really_sent_away = 0;
     200    while (bytes_to_be_sent){
     201        bytes_really_sent_away = w5100_set_TX( (U08*)&gReg+bytes_already_sent, bytes_to_be_sent);
     202        bytes_to_be_sent -= bytes_really_sent_away;
     203        bytes_already_sent += bytes_really_sent_away;
     204    }
     205    bytes_to_be_sent = sizeof(gVolReg);
     206    bytes_already_sent = 0;
     207    bytes_really_sent_away = 0;
     208    while (bytes_to_be_sent){
     209        bytes_really_sent_away = w5100_set_TX( (U08*)&gVolReg+bytes_already_sent, bytes_to_be_sent);
     210        bytes_to_be_sent -= bytes_really_sent_away;
     211        bytes_already_sent += bytes_really_sent_away;
     212    }
     213}
     214
     215
     216U16 fletcher16( U08 const *data, U16 bytes ) {
     217    U16 sum1 = 0xff, sum2 = 0xff;
     218
     219    while (bytes) {
     220            U16 tlen = bytes > 20 ? 20 : bytes;
     221            bytes -= tlen;
     222            do {
     223                    sum2 += sum1 += *data++;
     224            } while (--tlen);
     225            sum1 = (sum1 & 0xff) + (sum1 >> 8);
     226            sum2 = (sum2 & 0xff) + (sum2 >> 8);
     227    }
     228    /* Second reduction step to reduce sums to 8 bits */
     229    sum1 = (sum1 & 0xff) + (sum1 >> 8);
     230    sum2 = (sum2 & 0xff) + (sum2 >> 8);
     231    return sum2 << 8 | sum1;
     232}
  • firmware/FSC/src/application.h

    r10910 r17629  
    55#include "typedefs.h"
    66//-----------------------------------------------------------------------------
    7 // in order to implement the "registers" I work with a quite long
    8 //  char-array like this:
    9 # define FSC_REGISTER_LENGTH 492
    10 extern U08 FSCregister[FSC_REGISTER_LENGTH];
    11 // but this register is not only accessible by
    12 // FSCregister[i], but as well by special pointers like this:
    13 extern U32 *status                                                      ;
    14 extern U32 *time_sec                                                    ;
    15 extern U16 *time_ms                                                     ;
    16 extern U16 *FR_period                                                   ;
    17 extern U16 *ref_resistor                                                ;
    187
    19 extern U32 *ad7719_values                                               ;
     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
    2015#define AD7719_VALUES_LEN_BYTE 512
    21 extern U08 *ad7719_enables                                      ;
    22 extern U08 *ad7719_channels_ready                               ;
    23 extern U08 *ad7719_readings_since_last_muxing   ;
    24 extern U08 *ad7719_current_channel                      ;
    25 extern U32 *ad7719_current_reading                      ;
    2616
    27 extern U16 *adc_values                                          ;
    28 #define ADC_VALUES_LEN_BYTE 168
    29 extern U08 *adc_enables                                                 ;
    30 extern U08 *adc_channels_ready                          ;
    31 extern U08 *adc_readings_since_last_muxing      ;
    32 extern U08 *adc_current_channel                                 ;
    33 extern U16 *adc_current_reading                                 ;
    34 // using these pointers one can manipulate measurement values like this:
    35 // res_value[3] = 453212;
    36 // and then readout the most significant byte of this same value by accessing:
    37 // FSCregister[92];
    38 // I like this very much for asking the boards status ... this is just a copy of the registers,
    39 // into the W5100 TX FIFO.
    40 // submitting the measurement values is just a partial copy...
     17typedef 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
     40typedef struct {
     41    U08 app_reset_source;
     42    U32 time_sec;
     43    U16 time_ms;
     44} VolatileRegisterType;
     45
     46extern FSCRegisterType gReg;
     47extern volatile VolatileRegisterType gVolReg;
     48
    4149
    4250//-----------------------------------------------------------------------------
     
    5866#define SPI_MISO PB6
    5967
    60 #define SPI_E_CS PB4           
    61 #define SPI_AD_CS PD3           
    62 #define SPI_M_CS PD4           
    63 #define SPI_A_CS PD5           
    64 
    65 //#ifdef ____WENNICHSWIRKLICHWILL
    66 #ifndef ___MAIN_WORKFLOW_GLOBAL_VARS
    67 #define ___MAIN_WORKFLOW_GLOBAL_VARS
    68         #define RESISTANCE_CHANNELS 64
    69         #define AD7719_READINGS_UNTIL_SETTLED 3 // bei3:480ms
    70        
    71         #define VOLTAGE_CHANNELS 84
    72         #define VOLTAGE_REGS 11
    73         #define ADC_READINGS_UNTIL_SETTLED 1
    74 #endif
     68#define SPI_E_CS PB4
     69#define SPI_AD_CS PD3
     70#define SPI_M_CS PD4
     71#define SPI_A_CS PD5
    7572
    7673#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
    7775
    78 // MAIN WORKFLOW GLOBAL VARIABLES
    79 
    80         extern bool heartbeat_enable;
    81 
    82 
    83        
    84 // TIMER global variable
    85         extern volatile U32 local_ms;
    86 
    87 // AD7719 global variables
    88         extern bool ad7719_measured_all;
    89         extern bool ad7719_values_printed;
    90         extern bool ad7719_print_endless;
    91 
    92 // ATMEGA ADC global variables
    93         #define adc_readings_until_mean 40
    94         extern bool adc_measured_all;
    95         extern bool adc_values_printed;
    96         extern bool adc_print_endless;
    97 
    98         extern bool once_told_you;
    99         extern bool debug_mode;
    100 
    101 
    102 
    103 //-----------------------------------------------------------------------------
    104 extern volatile U08 app_reset_source;
    105 //-----------------------------------------------------------------------------
    10676
    10777void app_init(void); // Initialize application
    10878void app_set_watchdog_prescaler(tWDT_PRESCALE wdt_prescale); // Set watchdog prescale
    109 
    110 //methods in main ... declared here ... don't ask why ...
     79 
    11180// definition of some functions:
    112 // these function are implemented in this file, this is not doog coding style.
     81// these function are implemented in this file, this is not good coding style.
    11382// sooner or later, they will be moved into more apropriate files.
    11483void set_adc_enable_register();
     
    11786U08     increase_ad7719 (U08 channel);
    11887void check_what_measurement_was_finished() ;
    119 void check_if_measured_all() ;
     88
    12089
    12190bool check_if_adc_measurement_done();
    12291bool check_if_ad7719_measurement_done();
    123 // end of function definition:
    124 //-----------------------------------------------------------------------------
     92bool check_if_measured_all();
    12593
     94void reset_resistance_done();
     95void reset_resistance_values();
     96void reset_voltage_done();
     97void reset_voltage_values();
     98void reset_done();
    12699
    127 
    128 //-----------------------------------------------------------------------------
     100void write_status_via_eth();
     101U16 fletcher16( U08 const *data, U16 bytes );
    129102
    130103#endif
Note: See TracChangeset for help on using the changeset viewer.