/*
 * Blink
 *
 * The basic Arduino example.  Turns on an LED on for one second,
 * then off for one second, and so on...  We use pin 13 because,
 * depending on your Arduino board, it has either a built-in LED
 * or a built-in resistor so that you need only an LED.
 *
 * http://www.arduino.cc/en/Tutorial/Blink
 */

#include "WProgram.h"
void setup();
void loop();
int ledPin = 13;                // LED connected to digital pin 13

void setup()                    // run once, when the sketch starts
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()                     // run over and over again
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
}

//void (*startBootloader)( void ) = (void(*)(void))(0x1600);




int main(void)
{
	//startBootloader();
	
	
	mainconnections = 0;
	topology_scan(&mainconnections);//luminet needs to perform topology scan at the beginning of every payload
	
	//cli();
	//CLKPR = (1 << CLKPCE);
	//CLKPR = 0x00;//8MHz
	
		if(mainconnections >= 16)
		{
			//startBootloader();
				__asm__ __volatile
			 (
			      "ldi r30,0x00"  "\n\t"
			      "ldi r31,0x0b"  "\n\t"
			      "icall" "\n\t"
			 );
		}
	
		
	init();

	setup();
    
	for (;;)
		loop();
        
	return 0;
}

