#include "application.h" #include "w5100_spi_interface.h" #include // ---------------- These are the global variables that represent the registers // of the entire FSC, everything is stored here and can thus be sent down ---- FSCRegisterType gReg; volatile VolatileRegisterType gVolReg; void app_init(void) { gVolReg.app_reset_source = MCUSR; // Save last reset source MCUSR = 0x00; // Clear reset source for next reset cycle // Dangerous here: I still do not know much about the watchdog. // This code is still from Udo Juerss. // The watchdog timer is disabled by default ("startup.asm") #ifdef USE_WATCHDOG WDTCSR = WDTOE | (1 << WDE); // Enable watchdog reset (~16ms) #endif // define PORTS // USART DDRD &= ~(1< output DDRC |= 0x7F; // SB-pins -> output // SPI // set all CS's: output DDRB |= (1 << SPI_E_CS); DDRD |= (1 << SPI_AD_CS); DDRD |= (1 << SPI_M_CS); DDRD |= (1 << SPI_A_CS); // set all Chips selects HIGH PORTB |= (1 << SPI_E_CS); PORTD |= (1 << SPI_AD_CS); PORTD |= (1 << SPI_M_CS); PORTD |= (1 << SPI_A_CS); // set MOSI and SCK: output & // set MISO: input SPI_DDR |= (1 << SPI_MOSI); SPI_DDR |= (1 << SPI_SCLK); SPI_DDR &= ~(1 << SPI_MISO); // set MOSI, SCK: HIGH. MISO leave alone. SPI_PRT |= (1 << SPI_MOSI); SPI_PRT |= (1 << SPI_SCLK); //SPI_PRT |= (1 << SPI_MISO); // ADC DDRD &= ~(1< 20 ? 20 : bytes; bytes -= tlen; do { sum2 += sum1 += *data++; } while (--tlen); sum1 = (sum1 & 0xff) + (sum1 >> 8); sum2 = (sum2 & 0xff) + (sum2 >> 8); } /* Second reduction step to reduce sums to 8 bits */ sum1 = (sum1 & 0xff) + (sum1 >> 8); sum2 = (sum2 & 0xff) + (sum2 >> 8); return sum2 << 8 | sum1; }