/* flaneth - flash and ethernet - dartboard mod
 * version 0.1 date 2008-11-09
 * Copyright (C) 2007-2008 Stefan Schuermans <stefan@schuermans.info>
 * Copyleft: GNU public license V2 - http://www.gnu.org/copyleft/gpl.html
 * a BlinkenArea project - http://www.blinkenarea.org/
 */

#include <avr/interrupt.h>
#include <avr/wdt.h>

#include "arp.h"
#include "bus.h"
#include "cf.h"
#include "dart.h"
#include "debug.h"
#include "eeprom.h"
#include "http.h"
#include "random.h"
#include "rtl8019.h"
#include "status.h"
#include "tcp.h"
#include "timing.h"
#include "uart.h"

// main code entry point
int main( void )
{
  wdt_reset( );
#ifdef DEBUG
  wdt_disable( );
#else
  wdt_enable( WDTO_60MS );
#endif
  wdt_reset( );

  // initialize uart to be able to use stdio
  UartInit( );

  debug_printf( "" );
  debug_printf( "flaneth" );

  debug_init_printf( "init" );

  // initialize low level modules
  BusInit( );

  // initialize middle level modules
  CfInit( );
  DartInit( );
  RtlInit( );
  StatusInit( );
  TimingInit( );

  // initialize high level modules
  ArpInit( );
  HttpInit( );
  TcpInit( );

  // use entropy collected during initialization
  RandomTask( );

  debug_init_printf( "config" );

  // get configuration from EEPROM
  EepromGetConfig( );

  // enable interrupts
  sei( );

  debug_init_printf( "start" );

  // main loop
  while( 1 )
  {
    wdt_reset( );
    CfTask( );
    wdt_reset( );
    DartTask( );
    wdt_reset( );
    EepromTask( );
    wdt_reset( );
    RandomTask( );
    wdt_reset( );
    RtlTask( );
    wdt_reset( );
    TimingTask( );
  }

  return 0;
}

