示例#1
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
 *  the loaded application code.
 */
int main(void)
{
	/* David Cox
	 * In my application is needs internal pullups activated on special pins on these ports as soon as possible.
	 */
	PORTB = 0xFF;
	PORTC = 0xFF;
	PORTF = 0xFF;

	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Turn on first LED on the board to indicate that the bootloader has started */
	LEDs_SetAllLEDs(LEDS_LED1);

	/* Enable global interrupts so that the USB stack can function */
	GlobalInterruptEnable();

	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
	}

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Unlock the forced application start mode of the bootloader if it is restarted */
	MagicBootKey = MAGIC_BOOT_KEY;

	/* Enable the watchdog and force a timeout to reset the AVR */
	wdt_enable(WDTO_250MS);

	for (;;);
}
示例#2
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
 *  the loaded application code.
 */
int main(void)
{
	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Turn on first LED on the board to indicate that the bootloader has started */
	PORTD ^= (1 << LED_RED);

	/* Enable global interrupts so that the USB stack can function */
	sei();

	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
	}

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();
	
	/* Unlock the forced application start mode of the bootloader if it is restarted */
	MagicBootKey = MAGIC_BOOT_KEY;

	/* Enable the watchdog and force a timeout to reset the AVR */
	wdt_enable(WDTO_250MS);

	for (;;);
}
示例#3
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
 *  the loaded application code.
 */
int main(void)
{
	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Turn on first LED on the board to indicate that the bootloader has started */
	LEDs_SetAllLEDs(LEDS_LED1);

	/* Enable global interrupts so that the USB stack can function */
	GlobalInterruptEnable();

	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
	}

	/* Wait a short time to end all USB transactions and then disconnect */
	_delay_us(1000);

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Unlock the forced application start mode of the bootloader if it is restarted */
	MagicBootKey = MAGIC_BOOT_KEY;

	/* Enable the watchdog and force a timeout to reset the AVR */
	wdt_enable(WDTO_250MS);

	for (;;);
}
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
 *  the loaded application code.
 */
int main(void)
{
	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Turn on first LED on the board to indicate that the bootloader has started */
	LEDs_SetAllLEDs(LEDS_LED1);

	/* Enable global interrupts so that the USB stack can function */
	GlobalInterruptEnable();

	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
		/* Time out and start the sketch if one is present */
		if (Timeout > TIMEOUT_PERIOD){
		RunBootloader = false;}

	}

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Unlock the forced application start mode of the bootloader if it is restarted */
	MagicBootKey = MAGIC_BOOT_KEY;

	/* Enable the watchdog and force a timeout to reset the AVR */
	wdt_enable(WDTO_250MS);

	for (;;);
}
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until it times out or is instructed to exit.
 */
int main(void)
{
	/* Save the value of the boot key memory before it is overwritten */
	uint16_t bootKeyPtrVal = *bootKeyPtr;
	*bootKeyPtr = 0;

	/* Check the reason for the reset so we can act accordingly */
	uint8_t  mcusr_state = MCUSR;		// store the initial state of the Status register
	MCUSR = 0;							// clear all reset flags	

	/* Watchdog may be configured with a 15 ms period so must disable it before going any further */
	wdt_disable();

#if DEVICE_PID == 0x606C   // Only on the BlinkyTape
	// Put the user button (B6) in input_pullup mode, so we can read the button state
	DDRB	&= ~(1<<DDB6);
	PORTB	|= (1<<DDB6);
#endif
	
	if (mcusr_state & (1<<EXTRF)) {
		// External reset -  we should continue to self-programming mode.
#if DEVICE_PID == 0x606C   // Only on the BlinkyTape
	} else if (!(PINB & (1<<DDB6))) {
		// User button held low- Jump into the bootloader, in case the application is borked.
#endif
	} else if ((mcusr_state & (1<<PORF)) && (pgm_read_word(0) != 0xFFFF)) {		
		// After a power-on reset skip the bootloader and jump straight to sketch 
		// if one exists.	
		StartSketch();
	} else if ((mcusr_state & (1<<WDRF)) && (bootKeyPtrVal != bootKey) && (pgm_read_word(0) != 0xFFFF)) {	
		// If it looks like an "accidental" watchdog reset then start the sketch.
		StartSketch();
	}
	
	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Enable global interrupts so that the USB stack can function */
	sei();
	
	Timeout = 0;
	
	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
		/* Time out and start the sketch if one is present */
		if (Timeout > TIMEOUT_PERIOD)
			RunBootloader = false;

		LEDPulse();
	}

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Jump to beginning of application space to run the sketch - do not reset */	
	StartSketch();
}
示例#6
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until it times out or is instructed to exit.
 */
int main(void)
{
	/* Save the value of the boot key memory before it is overwritten */
	uint16_t bootKeyPtrVal = *bootKeyPtr;
	*bootKeyPtr = 0;

	/* Check the reason for the reset so we can act accordingly */
	uint8_t  mcusr_state = MCUSR;		// store the initial state of the Status register
	MCUSR = 0;							// clear all reset flags	

	/* Watchdog may be configured with a 15 ms period so must disable it before going any further */
	wdt_disable();

	// init HWB pin, wait a ms to allow caps to charge
	HWB_SETUP();
	_delay_ms(1);
	
	if ((mcusr_state & (1<<EXTRF)) && HWB_STATUS() && (pgm_read_word(0) != 0xFFFF)) {
		// External reset -  start the sketch if there is one and HWB jumper is not installed (HWB pin is read high)
		StartSketch();
	} else if ((mcusr_state & (1<<PORF)) && (pgm_read_word(0) != 0xFFFF)) {		
		// After a power-on reset skip the bootloader and jump straight to sketch 
		// if one exists.	
		StartSketch();
	} else if ((mcusr_state & (1<<WDRF)) && (bootKeyPtrVal != bootKey) && (pgm_read_word(0) != 0xFFFF)) {	
		// If it looks like an "accidental" watchdog reset then start the sketch.
		StartSketch();
	}
	// so only start programmimg mode when reset came from autoreset = watchdog reset and bootkey matches

	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Enable global interrupts so that the USB stack can function */
	sei();
	
	Timeout = 0;
	
	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
		/* Time out and start the sketch if one is present */
		if (Timeout > TIMEOUT_PERIOD)
			RunBootloader = false;

		LEDPulse();
	}

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Jump to beginning of application space to run the sketch - do not reset */	
	StartSketch();
}
示例#7
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	sei();

	for (;;)
	{
		CDC_Task();
		USB_USBTask();
	}
}
示例#8
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		CDC_Task();
		USB_USBTask();
	}
}
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
 *  the loaded application code.
 */
int main(void)
{
	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Turn on first LED on the board to indicate that the bootloader has started */
	LEDs_SetAllLEDs(LEDS_LED1);

	/* Fill in the UUID Report */
	/* Bootloader ID */
	UUIDReport[0] = BOOTLOADER_ID_SIG >> 8;
	UUIDReport[1] = BOOTLOADER_ID_SIG & 0xFF;
	/* Bootloader Version */
	UUIDReport[2] = BOOTLOADER_VERSION_SIG >> 8;
	UUIDReport[3] = BOOTLOADER_VERSION_SIG & 0xFF;
	/* Device ID */
	for (size_t i = 4; i < UUID_SIZE; i++)
	{
		UUIDReport[i] = eeprom_read_byte((uint8_t*)(intptr_t)(i));
	}

	/* Enable global interrupts so that the USB stack can function */
	GlobalInterruptEnable();

	while (RunBootloader)
	{
		MIDI_Task();
		CDC_Task();
		MIDI_Device_USBTask(&Keyboard_MIDI_Interface);
		USB_USBTask();
	}

	/* Wait a short time to end all USB transactions and then disconnect */
	_delay_us(1000);

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Unlock the forced application start mode of the bootloader if it is restarted */
	MagicBootKey = MAGIC_BOOT_KEY;

	/* Enable the watchdog and force a timeout to reset the AVR */
	wdt_enable(WDTO_250MS);

	for (;;);
}
示例#10
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  starts the scheduler to run the application tasks.
 */
int main(void)
{
	SetupHardware();

	/* Ring buffer Initialization */
	Buffer_Initialize(&Rx_Buffer);
	Buffer_Initialize(&Tx_Buffer);

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	
	for (;;)
	{
		CDC_Task();
        PENPROG_Task();
		USB_USBTask();
	}
}
示例#11
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously 
 *  runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
 *  the loaded application code.
 */
int main(void)
{
	/* Setup hardware required for the bootloader */
	SetupHardware();

	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
	}
	
	/* Reset all configured hardware to their default states for the user app */
	ResetHardware();

	/* Start the user application */
	AppPtr_t AppStartPtr = (AppPtr_t)0x0000;
	AppStartPtr();	
}
示例#12
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until it times out or is instructed to exit.
 */
int main(void)
{
	/* Save the value of the boot key memory before it is overwritten */
	uint16_t bootKeyPtrVal = *bootKeyPtr;
	*bootKeyPtr = 0;

	/* Check the reason for the reset so we can act accordingly */
	uint8_t  mcusr_state = MCUSR;		// store the initial state of the Status register
	MCUSR = 0;							// clear all reset flags	

	/* Watchdog may be configured with a 15 ms period so must disable it before going any further */
	wdt_disable();
	
	/* Jump to bootloader only if correct key is present in eeprom */
	if ((eeprom_read_word((uint16_t*)EEP_BOOTKEY_ADDR) != BOOTLOADER_BOOTKEY) && (eeprom_read_word((uint16_t*)EEP_BACKUP_BOOTKEY_ADDR) != BOOTLOADER_BOOTKEY))
	{
		StartSketch();
	}

	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Enable global interrupts so that the USB stack can function */
	sei();
	
	Timeout = 0;
	
	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
		/* Time out and start the sketch if one is present */
		if (Timeout > TIMEOUT_PERIOD)
			RunBootloader = false;

		LEDPulse();
	}

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Jump to beginning of application space to run the sketch - do not reset */	
	StartSketch();
}
示例#13
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously 
 *  runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
 *  the loaded application code.
 */
int main(void)
{
	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Enable global interrupts so that the USB stack can function */
	sei();

	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
	}
	
	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Enable the watchdog and force a timeout to reset the AVR */
	wdt_enable(WDTO_250MS);

	for (;;);
}
示例#14
0
//////////////////////////////////////////////////
// Display routines
void
display_char(char data)
{

#ifdef HAS_USB
  if(USB_IsConnected && (output_enabled & OUTPUT_USB)) {
    if(USB_Tx_Buffer->nbytes >= USB_Tx_Buffer->size)
      CDC_Task();
    rb_put(USB_Tx_Buffer, data);
    if(data == '\n')
      CDC_Task();
  }
#endif


#ifdef HAS_LCD
  if(output_enabled & OUTPUT_LCD) {
    static uint8_t buf[TITLE_LINECHARS+1];
    static uint8_t off = 0, cmdmode = 0;
    if(data == '\r')
      return;

    if(data == '\n') {
      buf[off] = 0;
      off = 0;
      if(cmdmode) {
        callfn((char *)buf);
      } else 
        lcd_putline(0, (char*)buf);
      cmdmode = 0;
    } else {
      // 
      if(off < TITLE_LINECHARS)   // or cmd: up to 12Byte: F12346448616c6c6f
        buf[off++] = data;

      if(cmdmode && cmdmode++ == 2) {
        off -= 2;
        fromhex((char *)buf+off, buf+off, 1);   // replace the hexnumber
        off++;
        cmdmode = 1;
      }
    }

    // Check if its a message for us: F<HC>..., and set cmdmode
    if(!cmdmode && off == 5 && buf[0] == 'F') {
      uint8_t hb[2];
      fromhex((char*)buf+1, hb, 2);
      if(hb[0] == fht_hc[0] && hb[1] == fht_hc[1]) {
        cmdmode = 1;
        off = 0;
      }
    }
  }
#endif

#ifdef HAS_FS
  if(output_enabled & OUTPUT_LOG) {
    static uint8_t buf[LOG_NETTOLINELEN+1];
    static uint8_t off = 0;
    if(data == '\r')
      return;

    if(data == '\n') {
      buf[off] = 0;
      off = 0;
      Log((char*)buf);
    } else {
      if(off < LOG_NETTOLINELEN)
        buf[off++] = data;
    }
  }
#endif
}
示例#15
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until it times out or is instructed to exit.
 */
int main(void)
{
	/* Save the value of the boot key memory before it is overwritten */
	uint8_t bootKeyPtrVal = *bootKeyPtr;
	*bootKeyPtr = 0;

	/* Check the reason for the reset so we can act accordingly */
	uint8_t  mcusr_state = MCUSR;		// store the initial state of the Status register
	MCUSR = 0;							// clear all reset flags

	/* Watchdog may be configured with a 15 ms period so must disable it before going any further */
	// MAH 8/15/12- I removed this because wdt_disable() is the first thing SetupHardware() does- why
	//  do it twice right in a row?
	//wdt_disable();

	/* Setup hardware required for the bootloader */
	// MAH 8/15/12- Moved this up to before the bootloader go/no-go decision tree so I could use the
	//  timer in that decision tree. Removed the USBInit() call from it; if I'm not going to stay in
	//  the bootloader, there's no point spending the time initializing the USB.
	// SetupHardware();
	wdt_disable();

	// Disable clock division
	clock_prescale_set(clock_div_1);

	// Relocate the interrupt vector table to the bootloader section
	MCUCR = (1 << IVCE);
	MCUCR = (1 << IVSEL);

	LED_SETUP();
	CPU_PRESCALE(0);
	L_LED_OFF();
	TX_LED_OFF();
	RX_LED_OFF();

	// Initialize TIMER1 to handle bootloader timeout and LED tasks.
	// With 16 MHz clock and 1/64 prescaler, timer 1 is clocked at 250 kHz
	// Our chosen compare match generates an interrupt every 1 ms.
	// This interrupt is disabled selectively when doing memory reading, erasing,
	// or writing since SPM has tight timing requirements.

	OCR1AH = 0;
	OCR1AL = 250;
	TIMSK1 = (1 << OCIE1A);					// enable timer 1 output compare A match interrupt
	TCCR1B = ((1 << CS11) | (1 << CS10));	// 1/64 prescaler on timer 1 input


	// MAH 8/15/12- this replaces bulky pgm_read_word(0) calls later on, to save memory.
	if (pgm_read_word(0) != 0xFFFF) sketchPresent = true;

// MAH 26 Oct 2012- The "bootload or not?" section has been modified since the code released
//  with Arduino 1.0.1. The simplest modification is the replacement of equivalence checks on
//  the reset bits with masked checks, so if more than one reset occurs before the register is
//  checked, the check doesn't fail and fall through to the bootloader unnecessarily.

// The second, more in depth modification addresses behavior after an external reset (i.e.,
//  user pushes the reset button). The Leonardo treats all external resets as requests to
//  re-enter the bootloader and wait for code to be loaded. It remains in bootloader mode for
//  8 seconds before continuing on to the sketch (if one is present). By defining RESET_DELAY
//  equal to 1, this behavior will persist.

// However, if RESET_DELAY is defined to 0, the reset timeout before loading the sketch drops
//  to 750ms. If, during that 750ms, another external reset occurs, THEN an 8-second delay
//  in the bootloader will occur.

	// This is the "no-8-second-delay" code. If this is the first time through the loop, we
	//  don't expect to see the bootKey in memory.
	if ( (mcusr_state & (1<<EXTRF)) && (bootKeyPtrVal != bootKey) ) {
		*bootKeyPtr = bootKey;   // Put the bootKey in memory so if we get back to this
		                         //  point again, we know to jump into the bootloader
		sei();  // Enable interrupts, so we can use timer1 to track our time in the bootloader
		while (RunBootloader)
		{
			if (resetTimeout > EXT_RESET_TIMEOUT_PERIOD) // resetTimeout is getting incremeted
				RunBootloader = false;                   //  in the timer1 ISR.
		}
		// If we make it past that while loop, it's sketch loading time!
		*bootKeyPtr = 0;   // clear out the bootKey; from now on, we want to treat a reset like
						   //  a normal reset.
		cli();             // Disable interrupts, in case no sketch is present.
		RunBootloader = true;  // We want to hang out in the bootloader if no sketch is present.
		if (sketchPresent) StartSketch(); // If a sketch is present, go! Otherwise, wait around
										  //  in the bootloader until one is uploaded.
	}
	// On a power-on reset, we ALWAYS want to go to the sketch. If there is one.
	//  This is a place where the old code had an equivalence and now there is a mask.
	else if ( (mcusr_state & (1<<PORF)) && sketchPresent) {
		StartSketch();
	}
	// On a watchdog reset, if the bootKey isn't set, and there's a sketch, we should just
	//  go straight to the sketch.
	//  This is a place where the old code had an equivalence and now there is a mask.
	else if ( (mcusr_state & (1<<WDRF) ) && (bootKeyPtrVal != bootKey) && sketchPresent) {
		// If it looks like an "accidental" watchdog reset then start the sketch.
		StartSketch();
	}

	/* Initialize USB Subsystem */
	USB_Init();

	/* Enable global interrupts so that the USB stack can function */
	sei();

	Timeout = 0;

	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
		/* Time out and start the sketch if one is present */
		if (Timeout > TIMEOUT_PERIOD)
			RunBootloader = false;

		// MAH 8/15/12- This used to be a function call- inlining it saves a few bytes.
		LLEDPulse++;
		uint8_t p = LLEDPulse >> 8;
		if (p > 127)
			p = 254-p;
		p += p;
		if (((uint8_t)LLEDPulse) > p)
			L_LED_OFF();
		else
			L_LED_ON();
	}

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Jump to beginning of application space to run the sketch - do not reset */
	StartSketch();
}
示例#16
0
void USBVirtualSerial::println(const char *str) {
    for (uint16_t i = 0; i < strlen(str); i++) RingBuffer_Insert(&HostTXSerial_Buffer, str[i]);
    RingBuffer_Insert(&HostTXSerial_Buffer, '\r');
    RingBuffer_Insert(&HostTXSerial_Buffer, '\n');
    CDC_Task();
}
示例#17
0
void USBVirtualSerial::println(uint8_t val, uint8_t format) {
    RingBuffer_Insert(&HostTXSerial_Buffer, val);
    RingBuffer_Insert(&HostTXSerial_Buffer, '\r');
    RingBuffer_Insert(&HostTXSerial_Buffer, '\n');
    CDC_Task();
}
示例#18
0
文件: CUR.c 项目: Diggen85/a-culfw
int
main(void)
{
  wdt_enable(WDTO_2S); 
  clock_prescale_set(clock_div_1);         // Disable Clock Division

  // if we had been restarted by watchdog check the REQ BootLoader byte in the
  // EEPROM ...
  if (bit_is_set(MCUSR,WDRF) && erb(EE_REQBL)) {
     ewb( EE_REQBL, 0 ); // clear flag
     start_bootloader();
  }

  // Setup the timers. Are needed for watchdog-reset
  OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250
  TCCR0B = _BV(CS02);       
  TCCR0A = _BV(WGM01);
  TIMSK0 = _BV(OCIE0A);

  TCCR1A = 0;
  TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8

#ifdef CURV3
  // Timer3 is used by the LCD backlight (PWM)
  TCCR3A =  _BV(COM3A1)| _BV(WGM30);       // Fast PWM, 8-bit, clear on match
  TCCR3B =  _BV(WGM32) | _BV(CS31);        // Prescaler 8MHz/8: 3.9KHz 
#endif

  MCUSR &= ~(1 << WDRF);                   // Enable the watchdog

  led_init();
  spi_init();
  eeprom_init();
  USB_Init();
  fht_init();
  tx_init();
  joy_init();                   // lcd init is done manually from menu_init
  bat_init();
  df_init(&df);
  fs_init(&fs, df, 0);          // needs df_init
  rtc_init();                   // does i2c_init too
  log_init();                   // needs fs_init & rtc_init
  menu_init();                  // needs fs_init
  input_handle_func = analyze_ttydata;
  log_enabled = erb(EE_LOGENABLED);
  display_channel = DISPLAY_USB|DISPLAY_LCD|DISPLAY_RFROUTER;
  rf_router_init();

  checkFrequency(); 
  LED_OFF();

  for(;;) {
    USB_USBTask();
    CDC_Task();
    RfAnalyze_Task();
    Minute_Task();
    FastRF_Task();
    rf_router_task();
    JOY_Task();
  }
}
示例#19
0
void main_usb(void) 
#endif
{
   USB_STATUS           status = USB_OK;
   _usb_host_handle     host_handle;   
   /* Initialize the current platform. Call for the _bsp_platform_init which is specific to each processor family */
   _bsp_platform_init();
#if 0 /* << EST */
#ifdef MCU_MK70F12
  sci2_init();
#else
  sci1_init();
#endif
   TimerInit();
#endif
   
   /* Init polling global variable */
   POLL_init(); 

   DisableInterrupts;
   #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
   usb_int_dis();
   #endif	   
   /*
   ** It means that we are going to act like host, so we initialize the
   ** host stack. This call will allow USB system to allocate memory for
   ** data structures, it uses later (e.g pipes etc.).
   */
   status = _usb_host_init (
         HOST_CONTROLLER_NUMBER,   /* Use value in header file */
         MAX_FRAME_SIZE,            /* Frame size per USB spec  */
         &host_handle);             /* Returned pointer */
   if (status != USB_OK) 
   {
#if 0 /* << EST */
      printf("\nUSB Host Initialization failed. STATUS: %%x",(unsigned int) status);
      fflush(stdout);
#endif
      exit(3);
   }
   status = _usb_host_driver_info_register (
                                    host_handle,
                                    (void *)DriverInfoTable
                                    );
   if (status != USB_OK) 
   {
#if 0 /* << EST */
     printf("\nDriver Registration failed. STATUS: %%x", (unsigned int)status);
      fflush(stdout);
#endif
      exit(4);
   }    
  
  EnableInterrupts;
  #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
  usb_int_en();
  #endif	  

#if 0 /* << EST */
  printf("\fInitialization passed. Plug-in CDC device to USB port.\nUse ttyb: as the in/out port for CDC device data.\n");
#endif  
  _usb_event_init(&device_registered);
  uart2usb_num = usb2uart_num = 0; /* reset number of bytes in buffers */

#if 0 /* << EST */
  f_usb = (FILE_CDC_PTR)malloc(sizeof(FILE_CDC));
  memset(f_usb, 0, sizeof(FILE_CDC));
#else
  f_usb = (FILE_CDC_PTR)USB_mem_alloc_zero(sizeof(FILE_CDC));
#endif
    
  f_usb->DEV_PTR = (IO_DEVICE_STRUCT_PTR)USB_mem_alloc_word_aligned(sizeof(IO_DEVICE_STRUCT));
  
  for(;;) 
  {
    Poll(); 
    CDC_Task();
#if 0 /* << EST */
    __RESET_WATCHDOG(); /* feeds the dog */
#endif
  } /* loop forever */
  /* please make sure that you never leave main */
#ifdef __GNUC__
  return 0;
#endif
}
示例#20
0
文件: main.c 项目: kaiman1234/a-culfw
//------------------------------------------------------------------------------
/// Application entry point. Configures the DBGU, PIT, TC0, LEDs and buttons
/// and makes LED\#1 blink in its infinite loop, using the Wait function.
/// \return Unused (ANSI-C compatibility).
//------------------------------------------------------------------------------
int main(void)
{


  // DBGU configuration
  TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
  TRACE_INFO_WP("\n\r");
  TRACE_INFO("Getting new Started Project --\n\r");
  TRACE_INFO("%s\n\r", BOARD_NAME);
  TRACE_INFO("Compiled: %s %s --\n\r", __DATE__, __TIME__);

  //Configure Reset Controller
  AT91C_BASE_RSTC->RSTC_RMR= 0xa5<<24;

  // Configure EMAC PINS
  PIO_Configure(emacRstPins, PIO_LISTSIZE(emacRstPins));

  // Execute reset
  RSTC_SetExtResetLength(0xd);
  RSTC_ExtReset();

  // Wait for end hardware reset
  while (!RSTC_GetNrstLevel());

  TRACE_INFO("init Flash\n\r");
  flash_init();

  TRACE_INFO("init Timer\n\r");
  // Configure timer 0
  ticks=0;
  extern void ISR_Timer0();
  AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC0);
  AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
  AT91C_BASE_TC0->TC_IDR = 0xFFFFFFFF;
  AT91C_BASE_TC0->TC_SR;
  AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV5_CLOCK | AT91C_TC_CPCTRG;
  AT91C_BASE_TC0->TC_RC = 375;
  AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;
  AIC_ConfigureIT(AT91C_ID_TC0, AT91C_AIC_PRIOR_LOWEST, ISR_Timer0);
  AIC_EnableIT(AT91C_ID_TC0);
  AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;

  // Configure timer 1
  extern void ISR_Timer1();
  AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC1);
  AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;	//Stop clock
  AT91C_BASE_TC1->TC_IDR = 0xFFFFFFFF;		//Disable Interrupts
  AT91C_BASE_TC1->TC_SR;						//Read Status register
  AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV4_CLOCK | AT91C_TC_CPCTRG;  // Timer1: 2,666us = 48MHz/128
  AT91C_BASE_TC1->TC_RC = 0xffff;
  AT91C_BASE_TC1->TC_IER = AT91C_TC_CPCS;
  AIC_ConfigureIT(AT91C_ID_TC1, 1, ISR_Timer1);
  AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;

  led_init();

  TRACE_INFO("init EEprom\n\r");
  eeprom_init();

  rb_reset(&TTY_Rx_Buffer);
  rb_reset(&TTY_Tx_Buffer);

  input_handle_func = analyze_ttydata;

  LED_OFF();
  LED2_OFF();
  LED3_OFF();

  spi_init();
  fht_init();
  tx_init();

  #ifdef HAS_ETHERNET

  ethernet_init();

  #endif

  TRACE_INFO("init USB\n\r");
  CDCDSerialDriver_Initialize();
  USBD_Connect();

  wdt_enable(WDTO_2S);

  fastrf_on=0;

  display_channel = DISPLAY_USB;

  TRACE_INFO("init Complete\n\r");

  checkFrequency();

  // Main loop
  while (1) {

    CDC_Task();
    Minute_Task();
    RfAnalyze_Task();

    #ifdef HAS_FASTRF
      FastRF_Task();
    #endif
    #ifdef HAS_RF_ROUTER
      rf_router_task();
    #endif
    #ifdef HAS_ASKSIN
      rf_asksin_task();
    #endif
    #ifdef HAS_MORITZ
      rf_moritz_task();
    #endif
    #ifdef HAS_RWE
      rf_rwe_task();
    #endif
    #ifdef HAS_MBUS
      rf_mbus_task();
    #endif
    #ifdef HAS_MAICO
      rf_maico_task();
    #endif

    #ifdef HAS_ETHERNET
      Ethernet_Task();
    #endif

#ifdef DBGU_UNIT_IN
    if(DBGU_IsRxReady()){
      unsigned char volatile * const ram = (unsigned char *) AT91C_ISRAM;
      unsigned char x;

      x=DBGU_GetChar();
      switch(x) {

      case 'd':
        puts("USB disconnect\n\r");
        USBD_Disconnect();
        break;
      case 'c':
        USBD_Connect();
        puts("USB Connect\n\r");
        break;
      case 'r':
        //Configure Reset Controller
        AT91C_BASE_RSTC->RSTC_RMR=AT91C_RSTC_URSTEN | 0xa5<<24;
        break;
      case 'S':
        USBD_Disconnect();

        my_delay_ms(250);
        my_delay_ms(250);

        //Reset
        *ram = 0xaa;
        AT91C_BASE_RSTC->RSTC_RCR = AT91C_RSTC_PROCRST | AT91C_RSTC_PERRST | AT91C_RSTC_EXTRST   | 0xA5<<24;
        while (1);
        break;
      default:
        rb_put(&TTY_Tx_Buffer, x);
      }
    }
#endif

    if (USBD_GetState() == USBD_STATE_CONFIGURED) {
      if( USBState == STATE_IDLE ) {
        CDCDSerialDriver_Read(usbBuffer,
                              DATABUFFERSIZE,
                              (TransferCallback) UsbDataReceived,
                              0);
        LED3_ON();
        USBState=STATE_RX;
      }
    }
    if( USBState == STATE_SUSPEND ) {
      TRACE_INFO("suspend  !\n\r");
      USBState = STATE_IDLE;
    }
    if( USBState == STATE_RESUME ) {
      TRACE_INFO("resume !\n\r");
      USBState = STATE_IDLE;
    }

  }
}
示例#21
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until it times out or is instructed to exit.
 */
int main(void)
{
	/* Save the value of the boot key memory before it is overwritten */
	uint8_t bootKeyPtrVal = *bootKeyPtr;
	*bootKeyPtr = 0;

	/* Check the reason for the reset so we can act accordingly */
	uint8_t  mcusr_state = MCUSR;		// store the initial state of the Status register
	MCUSR = 0;							// clear all reset flags	

	/* Watchdog may be configured with a 15 ms period so must disable it before going any further */
	// MAH 8/15/12- I removed this because wdt_disable() is the first thing SetupHardware() does- why
	//  do it twice right in a row?
	//wdt_disable();
	
	/* Setup hardware required for the bootloader */
	// MAH 8/15/12- Moved this up to before the bootloader go/no-go decision tree so I could use the
	//  timer in that decision tree. Removed the USBInit() call from it; if I'm not going to stay in
	//  the bootloader, there's no point spending the time initializing the USB.
	// SetupHardware();
	wdt_disable();

	// Disable clock division 
	clock_prescale_set(clock_div_1);

	// Relocate the interrupt vector table to the bootloader section
	MCUCR = (1 << IVCE);
	MCUCR = (1 << IVSEL);
	
	LED_SETUP();
	CPU_PRESCALE(0); 
	L_LED_OFF();
	TX_LED_OFF();
	RX_LED_OFF();
	
	// Initialize TIMER1 to handle bootloader timeout and LED tasks.  
	// With 16 MHz clock and 1/64 prescaler, timer 1 is clocked at 250 kHz
	// Our chosen compare match generates an interrupt every 1 ms.
	// This interrupt is disabled selectively when doing memory reading, erasing,
	// or writing since SPM has tight timing requirements. 

	OCR1AH = 0;
	OCR1AL = 250;
	TIMSK1 = (1 << OCIE1A);					// enable timer 1 output compare A match interrupt
	TCCR1B = ((1 << CS11) | (1 << CS10));	// 1/64 prescaler on timer 1 input
	
	
	// MAH 8/15/12- this replaces bulky pgm_read_word(0) calls later on, to save memory.
	if (pgm_read_word(0) != 0xFFFF) sketchPresent = true;
	
	// MAH 8/15/12- quite a bit changed in this section- let's just pretend nothing has been reserved
	//  and all comments throughout are from me.
	// First case: external reset, bootKey NOT in memory. We'll put the bootKey in memory, then spin
	//  our wheels for about 750ms, then proceed to the sketch, if there is one. If, during that 750ms,
	//  another external reset occurs, on the next pass through this decision tree, execution will fall
	//  through to the bootloader.
	if ( (mcusr_state & (1<<EXTRF)) && (bootKeyPtrVal != bootKey) ) {
		*bootKeyPtr = bootKey;
		sei();
		while (RunBootloader) 
		{
			if (resetTimeout > EXT_RESET_TIMEOUT_PERIOD)
				RunBootloader = false;
		}
		cli();
		*bootKeyPtr = 0;
		RunBootloader = true;
		if (sketchPresent) StartSketch();
	} 
	// On a power-on reset, we ALWAYS want to go to the sketch. If there is one.
	else if ( (mcusr_state & (1<<PORF)) && sketchPresent) {	
		StartSketch();
	} 
	// On a watchdog reset, if the bootKey isn't set, and there's a sketch, we should just
	//  go straight to the sketch.
	else if ( (mcusr_state & (1<<WDRF) ) && (bootKeyPtrVal != bootKey) && sketchPresent) {	
		// If it looks like an "accidental" watchdog reset then start the sketch.
		StartSketch();
	}
	
	// END ALL COMMENTS ON THIS SECTION FROM MAH.
	
	/* Initialize USB Subsystem */
	USB_Init();

	/* Enable global interrupts so that the USB stack can function */
	sei();
	
	Timeout = 0;
	
	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
		/* Time out and start the sketch if one is present */
		if (Timeout > TIMEOUT_PERIOD)
			RunBootloader = false;
			
		// MAH 8/15/12- This used to be a function call- inlining it saves a few bytes.
		LLEDPulse++;
		uint8_t p = LLEDPulse >> 8;
		if (p > 127)
			p = 254-p;
		p += p;
		if (((uint8_t)LLEDPulse) > p)
			L_LED_OFF();
		else
			L_LED_ON();
	}

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Jump to beginning of application space to run the sketch - do not reset */	
	StartSketch();
}
示例#22
0
文件: CUL.c 项目: jknofe/a-culfw
int
main(void)
{
  wdt_enable(WDTO_2S);
#if defined(CUL_ARDUINO)
  clock_prescale_set(clock_div_1); 		// for 8MHz clock div schould be 1
#endif

  MARK433_PORT |= _BV( MARK433_BIT ); // Pull 433MHz marker
  MARK915_PORT |= _BV( MARK915_BIT ); // Pull 915MHz marker

  // if we had been restarted by watchdog check the REQ BootLoader byte in the
  // EEPROM ...
  if(bit_is_set(MCUSR,WDRF) && erb(EE_REQBL)) {
    ewb( EE_REQBL, 0 ); // clear flag
    start_bootloader();
  }


  // Setup the timers. Are needed for watchdog-reset
  OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250
  TCCR0B = _BV(CS02);
  TCCR0A = _BV(WGM01);
  TIMSK0 = _BV(OCIE0A);

  TCCR1A = 0;
  TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8

  MCUSR &= ~(1 << WDRF);                   // Enable the watchdog

  led_init();
  spi_init();
  eeprom_init();
  USB_Init();
  fht_init();
  tx_init();
  input_handle_func = analyze_ttydata;
#ifdef HAS_RF_ROUTER
  rf_router_init();
  display_channel = (DISPLAY_USB|DISPLAY_RFROUTER);
#else
  display_channel = DISPLAY_USB;
#endif

  checkFrequency(); 
  LED_OFF();

  for(;;) {
    USB_USBTask();
    CDC_Task();
    RfAnalyze_Task();
    Minute_Task();
#ifdef HAS_FASTRF
    FastRF_Task();
#endif
#ifdef HAS_RF_ROUTER
    rf_router_task();
#endif
#ifdef HAS_ASKSIN
    rf_asksin_task();
#endif
#ifdef HAS_MORITZ
    rf_moritz_task();
#endif
#ifdef HAS_RWE
    rf_rwe_task();
#endif
#ifdef HAS_RFNATIVE
    native_task();
#endif
#ifdef HAS_KOPP_FC
    kopp_fc_task();
#endif
#ifdef HAS_MBUS
    rf_mbus_task();
#endif
#ifdef HAS_ZWAVE
    rf_zwave_task();
#endif

  }
}
示例#23
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until it times out or is instructed to exit.
 */
int main(void)
{
	/* Save the value of the boot key memory before it is overwritten */
	uint16_t bootKeyPtrVal = *bootKeyPtr;
	*bootKeyPtr = 0;

	/* Check the reason for the reset so we can act accordingly */
	uint8_t  mcusr_state = MCUSR;							// store the initial state of the Status register
	MCUSR &= ~((1 << PORF) | (1 << EXTRF) | (1 << WDRF));	// clear reset flags that are used by the bootloader

	/* Watchdog may be configured with a 15 ms period so must disable it before going any further */
	wdt_disable();
	

	if (pgm_read_word(0) != 0xFFFF)
	{
		// There is a sketch (otherwise, skip these checks and just run the bootloader).
		
		if (mcusr_state & (1 << PORF))
		{
			// After power-on reset, clear BORF so sketch can tell it wasn't a brown-out reset,
			// then start the sketch.
			MCUSR &= ~(1 << BORF);
			StartSketch();
		}
		else if (mcusr_state & (1 << EXTRF))
		{
			// External reset.
			if (bootKeyPtrVal != bootKey)
			{
				// First reset button press. Set boot key for 750 ms so second reset button press
				// can be detected, then start the sketch if there isn't another reset.
				*bootKeyPtr = bootKey;
				_delay_ms(750);
				*bootKeyPtr = 0;
				StartSketch();
			}
			else
			{
				 // Second reset button press; boot key was already set. Fall through to bootloader.
			}
		}
		else if ((mcusr_state & (1 << WDRF)) && (bootKeyPtrVal == bootKey))
		{
			// Watchdog reset triggered by sketch to start bootloader. Fall through.
		}
		else
		{
			// Reset happened for some other reason; start the sketch.
			StartSketch();
		}
	}

	// Clear remaining reset flags so the sketch doesn't see info about an old reset when it runs later.
	MCUSR = 0;
	
	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Enable global interrupts so that the USB stack can function */
	sei();
	
	Timeout = 0;
	
	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
		/* Time out and start the sketch if one is present */
		if (Timeout > TIMEOUT_PERIOD)
			RunBootloader = false;

		LEDPulse();
	}

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Jump to beginning of application space to run the sketch - do not reset */	
	StartSketch();
}
示例#24
0
文件: CUN.c 项目: Talustus/culfw
int
main(void)
{
  //ewb((uint8_t*)0x80, erb((uint8_t*)0x80)+1);
  wdt_enable(WDTO_2S);                     // Avoid an early reboot
  clock_prescale_set(clock_div_1);         // Disable Clock Division:1->8MHz
#ifdef HAS_XRAM
  init_memory_mapped(); // First initialize the RAM
#endif

  // if we had been restarted by watchdog check the REQ BootLoader byte in the
  // EEPROM
  if(bit_is_set(MCUSR,WDRF) && erb(EE_REQBL)) {
    ewb( EE_REQBL, 0 ); // clear flag
    start_bootloader();
  }
  while(tx_report);                     // reboot if the bss is not initialized

  // Setup the timers. Are needed for watchdog-reset
  OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250
  TCCR0B = _BV(CS02);       
  TCCR0A = _BV(WGM01);
  TIMSK0 = _BV(OCIE0A);

  TCCR1A = 0;
  TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8

  MCUSR &= ~(1 << WDRF);                   // Enable the watchdog

  led_init();                              // So we can debug 
  spi_init();
  eeprom_init();
  USB_Init();
  fht_init();
  tx_init();
  ethernet_init();
#ifdef HAS_FS
  df_init(&df);
  fs_init(&fs, df, 0);          // needs df_init
  log_init();                   // needs fs_init & rtc_init
  log_enabled = erb(EE_LOGENABLED);
#endif
  input_handle_func = analyze_ttydata;
  display_channel = DISPLAY_USB;

  LED_OFF();

  for(;;) {
    USB_USBTask();
    CDC_Task();
    RfAnalyze_Task();
    Minute_Task();
    FastRF_Task();
    rf_router_task();
#ifdef HAS_ASKSIN
    rf_asksin_task();
#endif
#ifdef HAS_ETHERNET
    Ethernet_Task();
#endif
  }
}