Beispiel #1
0
void
systick_isr(void)
{
  for (;;) {
    flash_led(0x01);
    flash_led(0x02);
    busywait(800);
  }
}
Beispiel #2
0
int main(void)
{
    // use the system led flasher to flash one of the leds
    flash_led(LED1);

    appdata_t appdata;

    log_init(&appdata.log, "main");

	// initialise filesystem
    sdcard_mount(&sddisk, 0);

	// initialize the test usart device
	log_info(&appdata.log, "init %s on %s...", TEST_USART_DEV, "TEST_USART");
	usart_create_dev(TEST_USART_DEV, TEST_USART, USART_FULLDUPLEX, 115200, TEST_USART_BUFSIZE);

	// start up the application
    pthread_t app_thread;
	pthread_attr_t app_attr;
	pthread_attr_init(&app_attr);
	pthread_attr_setstacksize(&app_attr, 384);
	pthread_attr_setdetachstate(&app_attr, PTHREAD_CREATE_DETACHED);
	pthread_create(&app_thread, &app_attr, (void*(*)(void*))test_task, &appdata);
	pthread_attr_destroy(&app_attr);

	pthread_exit(0);
    return 0;
}
Beispiel #3
0
int main(void)
{
    flash_led(LED1);

    // init logger
	log_init(&mainlog, "main");

	lcd_init();
	graphics_init();
	touch_panel_init();
	lcd_backlight_init();
	lcd_backlight_auto_off(false);
	lcd_backlight_enable();
	set_background_colour(BLACK);

	panel_meter_init(&panelmeter, buffer, BOX_LOCATION, BOX_SIZE, true, "%.3f", "C", BOX_MAIN_FONT, BOX_UNIT_FONT);
	panel_meter_enable_touch(&panelmeter, (touch_callback_t)touch_key_callback, panelmeter_touch_appdata);

	float val = 0;
	while(1)
	{
		printf("val %.3f\n", (double)val);
		panel_meter_update(&panelmeter, val);
		val += 0.1;
		sleep(1);
	}

	pthread_exit(0);

    return 0;
}
Beispiel #4
0
int main(void) {
    // LED on pin 4
    DDRB = (1 << DDB4);

    // power down mode
    // the watchdog interrupt wakes up the MCU
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);

    setup_watchdog();

    for (;;) {
        // put MCU in sleep mode (sleep_enable(), sleep_cpu(), sleep_disable())
        sleep_mode();

        // MCU is sleeping...

        // WDT interrupt wakes MCU
        // and execution resumes here
        // blink LED every 3 seconds
        if (wdi_counter == 3) {
            flash_led();

            // reset wdi_counter
            wdi_counter = 0;
        }

        // when loop starts over, MCU is put to sleep again
    }

    return 0;
}
Beispiel #5
0
int main(void)
{
    flash_led(LED1);

    // init logger
	log_init(&log, "main");

	// init filesystem
    sdcard_mount(&sddisk, 0);

	// init networking
	net_config(&netconf, DEFAULT_RESOLV_CONF_PATH, DEFAULT_NETIF_CONF_PATH);
	net_init(&netconf);

	log_info(&log, "device init done...");

	install_builtin_cmds(&shell);
	install_fs_cmds(&shell);
	install_net_cmds(&shell);
	install_os_cmds(&shell);
	register_command(&shell, &sh_custom_cmd, NULL, NULL, NULL);

	start_shell_threaded_server(&shell, NULL, DEFAULT_SHELL_CONFIG_PATH, true, -1, -1, 512);

	log_info(&log, "service init done...");

	pthread_exit(0);

    return 0;
}
Beispiel #6
0
void
notmain()
{
	int timeout;

	flash_led(1, RED|GRN, 4);

	init_timeoutq();
    pfv_t faddr;
    faddr = &blink_led;

	create_timeoutq_event( ONE_SEC, 5 * ONE_SEC, blink_led, RED );
	create_timeoutq_event( 4 * ONE_SEC, 5 * ONE_SEC, blink_led, GRN );
	create_timeoutq_event( 7 * ONE_SEC , 5 * ONE_SEC, blink_led, GRN | RED);

	while (1) 
	{
		if (handle_timeoutq_event()) {
            //blink_led( RED );
			//continue;
		}
		timeout = bring_timeoutq_current();
		wait(timeout);
	}

}
Beispiel #7
0
void period_blink( unsigned int color )
{
	while(1)
	{
		flash_led( 1, color, 1 );
		oldwait(50);
	}
}
Beispiel #8
0
/* 功能:LED控制
 * 参数:同上
 * 返回值:无
 * */
void led_control_req(char *pskb)
{
        struct LedControl *pLed     = (struct LedControl *)pskb;

        /* 消息处理*/
        pLed->LedControlMsg.MsgId   = ARM_PC_LEDS_CONTROL_RSP;
        pLed->LedControlMsg.MsgLen  = sizeof(*pLed)
                                        - sizeof(pLed->LedControlMsg);

        if (pLed->Flag == 1) {
                pLed->Result = flash_led(pLed->FlashTime);
        } else {
                pLed->Result = stop_led();
        }
}
Beispiel #9
0
int main(void)
{
    uint8_t i, r1, g1, b1, r2, b2, g2;

    pwm_setup();
    flash_led();

    r1 = g1 = b1 = 0;
	while (1)
    {
        r2 = random() % 255;
        g2 = random() % 255;
        b2 = random() % 255;
        fade(r1, g1, b1, r2, g2, b2, 100, 10);
        r1 = r2;
        g1 = g2;
        b1 = b2;
	}
	return 0;
}
Beispiel #10
0
/* 功能:LED控制
 * 参数:MCM请求消息
 * 返回值:无
 * */
void led_control_req(s8 *pskb)
{

        struct stru_led_control_req *prLedCtrlReq       = (struct stru_led_control_req *)pskb;
        struct stru_led_control_rsp rLedCtrlRsp;
        
        /* 消息处理*/
        rLedCtrlRsp.struMsgHeader.u16MsgType            = O_MAINMCM_LED_RSP;
        rLedCtrlRsp.struMsgHeader.u16MsgLength          = sizeof(rLedCtrlRsp) - sizeof(rLedCtrlRsp.struMsgHeader);
        rLedCtrlRsp.struMsgHeader.u8TransType          = prLedCtrlReq->struMsgHeader.u8TransType;
        if (prLedCtrlReq->u8LedCmd == 1) {
                rLedCtrlRsp.bSuccessful = flash_led(prLedCtrlReq->u32BlinkTime);
        } else {
                rLedCtrlRsp.bSuccessful = stop_led();
        }
        
        /* 反馈消息到MCM*/
        send_rsp_message(&rLedCtrlRsp, 
                                sizeof(rLedCtrlRsp), 
                                prLedCtrlReq->struMsgHeader.u8TransType);
}
Beispiel #11
0
int main(void)
{
	flash_led(LED1);

	log_init(&log, "main");

    // init filesystem
    sdcard_mount(&sddisk, 0);

	// start demo app
    pthread_t app_thread;
	pthread_attr_t app_attr;
	pthread_attr_init(&app_attr);
	pthread_attr_setstacksize(&app_attr, 384);
	pthread_attr_setdetachstate(&app_attr, PTHREAD_CREATE_DETACHED);
	pthread_create(&app_thread, &app_attr, (void*(*)(void*))test, NULL);
	pthread_attr_destroy(&app_attr);

	pthread_exit(0);
	return 0;
}
Beispiel #12
0
int main(void)
{
    flash_led(LED1);
    // init logger
    log_init(&mainlog, "main");

    lcd_init();
    graphics_init();
    touch_panel_init();
    lcd_backlight_init();

    set_background_colour(BACKGROUND);
    lcd_backlight_auto_off(true);
    lcd_backlight_enable();
    lcd_backlight_timeout(30000);
    statusbar_init();

    // init filesystem
    sdfs_init();
    log_info(&mainlog, "wait for filesystem...");
    while(!sdfs_ready());

    // init networking
    net_config(&netconf, DEFAULT_RESOLV_CONF_PATH, DEFAULT_NETIF_CONF_PATH);
    net_init(&netconf);

    log_info(&mainlog, "device init done...");

    init_heater_cooler();

    log_info(&mainlog, "service init done...");

    while(1)
    {
        usleep(250000);
        update_heater_cooler();
    }

    return 0;
}
Beispiel #13
0
void
flash_lonum( unsigned int num )
{
	if (num == 0) {
		flash_led(1, GRN, 2);
		flash_led(1, RED, 2);
	} else if (num == 1) {
		flash_led(1, GRN, 4);
	} else if (num == 2) {
		flash_led(1, RED, 4);
	} else if (num == 3) {
		flash_led(1, RED | GRN, 4);
	} else {
		flash_led(3, RED | GRN, 100);
	}
}
Beispiel #14
0
/* main program starts here */
int main(void) {
  uint8_t ch;

  /*
   * Making these local and in registers prevents the need for initializing
   * them, and also saves space because code no longer stores to memory.
   * (initializing address keeps the compiler happy, but isn't really
   *  necessary, and uses 4 bytes of flash.)
   */
  register uint16_t address = 0;
  register pagelen_t  length;

  // After the zero init loop, this is the first code to run.
  //
  // This code makes the following assumptions:
  //  No interrupts will execute
  //  SP points to RAMEND
  //  r1 contains zero
  //
  // If not, uncomment the following instructions:
  // cli();
  asm volatile ("clr __zero_reg__");
#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
  SP=RAMEND;  // This is done by hardware reset
#endif

  /*
   * modified Adaboot no-wait mod.
   * Pass the reset reason to app.  Also, it appears that an Uno poweron
   * can leave multiple reset flags set; we only want the bootloader to
   * run on an 'external reset only' status
   */
  ch = MCUSR;
  MCUSR = 0;
  if (ch & (_BV(WDRF) | _BV(BORF) | _BV(PORF)))
      appStart(ch);

#if LED_START_FLASHES > 0
  // Set up Timer 1 for timeout counter
  TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
#endif

#ifndef SOFT_UART
#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
  UCSRA = _BV(U2X); //Double speed mode USART
  UCSRB = _BV(RXEN) | _BV(TXEN);  // enable Rx & Tx
  UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);  // config USART; 8N1
  UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#else
  UART_SRA = _BV(U2X0); //Double speed mode USART0
  UART_SRB = _BV(RXEN0) | _BV(TXEN0);
  UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);
  UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#endif
#endif

  // Set up watchdog to trigger after 1s
  watchdogConfig(WATCHDOG_1S);

#if (LED_START_FLASHES > 0) || defined(LED_DATA_FLASH)
  /* Set LED pin as output */
  LED_DDR |= _BV(LED);
#endif

#ifdef SOFT_UART
  /* Set TX pin as output */
  UART_DDR |= _BV(UART_TX_BIT);
#endif

#if LED_START_FLASHES > 0
  /* Flash onboard LED to signal entering of bootloader */
  flash_led(LED_START_FLASHES * 2);
#endif

  /* Forever loop: exits by causing WDT reset */
  for (;;) {
    /* get character from UART */
    ch = getch();

    if(ch == STK_GET_PARAMETER) {
      unsigned char which = getch();
      verifySpace();
      /*
       * Send optiboot version as "SW version"
       * Note that the references to memory are optimized away.
       */
      if (which == 0x82) {
	  putch(optiboot_version & 0xFF);
      } else if (which == 0x81) {
	  putch(optiboot_version >> 8);
      } else {
Beispiel #15
0
/* main program starts here */
int main(void) {
  uint8_t ch;
  uint16_t pmask;

  /*
   * Making these local and in registers prevents the need for initializing
   * them, and also saves space because code no longer stores to memory.
   * (initializing address keeps the compiler happy, but isn't really
   *  necessary, and uses 4 bytes of flash.)
   */
  register uint16_t address = 0;
  register uint16_t length;

  // After the zero init loop, this is the first code to run.
  //
  // This code makes the following assumptions:
  //  No interrupts will execute
  //  SP points to RAMEND
  //  r1 contains zero
  //
  // If not, uncomment the following instructions:
  // cli();
  asm volatile ("clr __zero_reg__");
  SP=RAMEND;  // This is done by hardware reset

  // Adaboot no-wait mod
  ch = MCUSR;
  MCUSR = 0;
  if (ch & (_BV(WDRF) | _BV(BORF) | _BV(PORF)))
	appStart(ch);

  // WDT clock by 32KHz IRC
  PMCR = 0x80;
  PMCR = 0x93;

#if EXT_OSC == 1
#warning Using external crystal now!!!
  // for case of 16MHz crystall, no clock divider
  PMCR = 0x80;
  PMCR = 0x97;
  for(ch = 0xf; ch > 0; --ch);
  PMCR = 0x80;
  PMCR = 0xb7;

  CLKPR = 0x80;
  CLKPR = 0x00;

  // external crsyall flag
  VDTCR = 0x80;
  VDTCR = 0x4C;
#else
  // system clock: 16MHz system clock
  CLKPR = 0x80;
  CLKPR = 0x01;
#endif

#if LED_START_FLASHES > 0
  // Set up Timer 1 for timeout counter
  TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
#endif

#ifndef SOFT_UART
#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
  UCSRA = _BV(U2X); //Double speed mode USART
  UCSRB = _BV(RXEN) | _BV(TXEN);  // enable Rx & Tx
  UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);  // config USART; 8N1
  UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#else
  //UART_SRA = _BV(U2X0); //Double speed mode USART0
  ch = PMXCR | 0x03;
  PMXCR = 0x80;
  PMXCR = ch;

  UART_SRB = _BV(RXEN0) | _BV(TXEN0);
  UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);
  UART_SRL = (uint8_t)( F_CPU / (BAUD_RATE * 16L) - 1 );
  //UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#endif
#endif

  // Set up watchdog to trigger after 500ms
  watchdogConfig(WATCHDOG_16MS);

#if (LED_START_FLASHES > 0) || defined(LED_DATA_FLASH)
  /* Set LED pin as output */
  LED_DDR |= _BV(LED);
#endif

#ifdef SOFT_UART
  /* Set TX pin as output */
  UART_DDR |= _BV(UART_TX_BIT);
#endif

#if LED_START_FLASHES > 0
  /* Flash onboard LED to signal entering of bootloader */
  flash_led(LED_START_FLASHES * 2);
#endif

  // page erased flag
  pmask = 0;

  /* Forever loop */
  for (;;) {
    /* get character from UART */
    ch = getch();

    if(ch == STK_GET_PARAMETER) {
      unsigned char which = getch();
      verifySpace();
      if (which == 0x82) {
	/*
	 * Send optiboot version as "minor SW version"
	 */
	putch(OPTIBOOT_MINVER);
      } else if (which == 0x81) {
	  putch(OPTIBOOT_MAJVER);
      } else {
	/*
	 * GET PARAMETER returns a generic 0x03 reply for
         * other parameters - enough to keep Avrdude happy
	 */
	putch(0x03);
      }
    }
    else if(ch == STK_SET_DEVICE) {
      // SET DEVICE is ignored
      getNch(20);
    }
    else if(ch == STK_SET_DEVICE_EXT) {
      // SET DEVICE EXT is ignored
      getNch(5);
    }
    else if(ch == STK_LOAD_ADDRESS) {
      // LOAD ADDRESS
      uint16_t newAddress;
      newAddress = getch();
      newAddress = (newAddress & 0xff) | (getch() << 8);
#ifdef RAMPZ
      // Transfer top bit to RAMPZ
      RAMPZ = (newAddress & 0x8000) ? 1 : 0;
#endif
      newAddress += newAddress; // Convert from word address to byte address
      address = newAddress;
      verifySpace();
    }
    else if(ch == STK_UNIVERSAL) {
      // UNIVERSAL command is ignored
      getNch(4);
      putch(0x00);
    }
    /* Write memory, length is big endian and is in bytes */
    else if(ch == STK_PROG_PAGE) {
      // PROGRAM PAGE - we support flash programming only, not EEPROM
      uint8_t *bufPtr;
      uint8_t bval;
      uint16_t len;
      length = (uint16_t)getch() << 8; /* getlen() */
      length += getch();
      bval = getch();

      // If we are in RWW section, immediately start page erase
      //if (address < NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);

      // While that is going on, read in page contents
      bufPtr = buff;
      len = length;
      do *bufPtr++ = getch();
      while (--len);

      EEARL = 0; 
      EEARH = address >> 8;
      ch = EEARH >> 2;	// 1KB page size

      if((0 == (pmask & (((uint16_t)1 << ch)))) && bval == 'F') { 
	pmask |= ((uint16_t)1 << ch);
      	// do page erase here
      	EECR = 0x94;
      	EECR = 0x92;
      	asm("nop"); asm("nop");      
      }

      // Read command terminator, start reply
      verifySpace();

      // If only a partial page is to be programmed, the erase might not be complete.
      // So check that here
      //boot_spm_busy_wait();
      if (bval == 'E') {
	  for(len = 0; len < length; len++) {
	    if(address >= 512)
		    break;
	    EEARL = address++;
	    EEARH = address >> 8;
	    EEDR = buff[len];
	    EECR = 0x04;
	    EECR = 0x02;
	  }
      } else {
#ifdef VIRTUAL_BOOT_PARTITION
	if ((uint16_t)(void*)address == 0) {
	  // This is the reset vector page. We need to live-patch the code so the
	  // bootloader runs.
	  //
	  // Move RESET vector to WDT vector
	  uint16_t vect = buff[0] | (buff[1] << 8);
	  rstVect = vect;
	  wdtVect = buff[8] | (buff[9] << 8);
	  vect -= 4;
	  buff[8] = vect & 0xff;
	  buff[9] = vect >> 8;

	  // Add jump to bootloader at RESET vector
	  buff[0] = 0xff;
	  buff[1] = 0xcd; // jmp 
	}
#endif
      	// Write from programming buffer
	bufPtr = buff;
      	for(length = 0; length < SPM_PAGESIZE; length+=2) {
	      EEARL = 0; EEDR = *bufPtr++;
	      EEARL = 1; EEDR = *bufPtr++;
	      EEARL = (address + length) & 0xff;
	      EECR = 0xA4;
	      EECR = 0xA2;
	}
      }
/* main program starts here */
int main(void) {
  uint8_t ch;

  /*
   * Making these local and in registers prevents the need for initializing
   * them, and also saves space because code no longer stores to memory.
   * (initializing address keeps the compiler happy, but isn't really
   *  necessary, and uses 4 bytes of flash.)
   */
  register uint16_t address = 0;
  register uint8_t  length;

  // After the zero init loop, this is the first code to run.
  //
  // This code makes the following assumptions:
  //  No interrupts will execute
  //  SP points to RAMEND
  //  r1 contains zero
  //
  // If not, uncomment the following instructions:
  // cli();
  asm volatile ("clr __zero_reg__");
#ifdef __AVR_ATmega8__
  SP=RAMEND;  // This is done by hardware reset
#endif

  // Adaboot no-wait mod
  ch = MCUSR;
  MCUSR = 0;
  if (!(ch & _BV(EXTRF))) appStart();

#if LED_START_FLASHES > 0
  // Set up Timer 1 for timeout counter
  TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
#endif
#ifndef SOFT_UART
#ifdef __AVR_ATmega8__
  UCSRA = _BV(U2X); //Double speed mode USART
  UCSRB = _BV(RXEN) | _BV(TXEN);  // enable Rx & Tx
  UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);  // config USART; 8N1
  UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#else
  UCSR0A = _BV(U2X0); //Double speed mode USART0
  UCSR0B = _BV(RXEN0) | _BV(TXEN0);
  UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
  UBRR0L = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#endif
#endif

  // Set up watchdog to trigger after 500ms
  watchdogConfig(WATCHDOG_1S);

  /* Set LED pin as output */
  LED_DDR |= _BV(LED);

#ifdef SOFT_UART
  /* Set TX pin as output */
  UART_DDR |= _BV(UART_TX_BIT);
#endif

#if LED_START_FLASHES > 0
  /* Flash onboard LED to signal entering of bootloader */
  flash_led(LED_START_FLASHES * 2);
#endif

  /* Forever loop */
  for (;;) {
    /* get character from UART */
    ch = getch();

    if(ch == STK_GET_PARAMETER) {
      unsigned char which = getch();
      verifySpace();
      if (which == 0x82) {
        /*
         * Send optiboot version as "minor SW version"
         */
        putch(OPTIBOOT_MINVER);
      } else if (which == 0x81) {
          putch(OPTIBOOT_MAJVER);
      } else {
        /*
         * GET PARAMETER returns a generic 0x03 reply for
         * other parameters - enough to keep Avrdude happy
         */
        putch(0x03);
      }
    }
    else if(ch == STK_SET_DEVICE) {
      // SET DEVICE is ignored
      getNch(20);
    }
    else if(ch == STK_SET_DEVICE_EXT) {
      // SET DEVICE EXT is ignored
      getNch(5);
    }
    else if(ch == STK_LOAD_ADDRESS) {
      // LOAD ADDRESS
      uint16_t newAddress;
      newAddress = getch();
      newAddress = (newAddress & 0xff) | (getch() << 8);
#ifdef RAMPZ
      // Transfer top bit to RAMPZ
      RAMPZ = (newAddress & 0x8000) ? 1 : 0;
#endif
      newAddress += newAddress; // Convert from word address to byte address
      address = newAddress;
      verifySpace();
    }
    else if(ch == STK_UNIVERSAL) {
      // UNIVERSAL command is ignored
      getNch(4);
      putch(0x00);
    }
    /* Write memory, length is big endian and is in bytes */
    else if(ch == STK_PROG_PAGE) {
      // PROGRAM PAGE - we support flash programming only, not EEPROM
      uint8_t *bufPtr;
      uint16_t addrPtr;

      getch();                  /* getlen() */
      length = getch();
      getch();

      // If we are in RWW section, immediately start page erase
      if (address < NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);

      // While that is going on, read in page contents
      bufPtr = buff;
      do *bufPtr++ = getch();
      while (--length);

      // If we are in NRWW section, page erase has to be delayed until now.
      // Todo: Take RAMPZ into account
      if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);

      // Read command terminator, start reply
      verifySpace();

      // If only a partial page is to be programmed, the erase might not be complete.
      // So check that here
      boot_spm_busy_wait();

#ifdef VIRTUAL_BOOT_PARTITION
      if ((uint16_t)(void*)address == 0) {
        // This is the reset vector page. We need to live-patch the code so the
        // bootloader runs.
        //
        // Move RESET vector to WDT vector
        uint16_t vect = buff[0] | (buff[1]<<8);
        rstVect = vect;
        wdtVect = buff[8] | (buff[9]<<8);
        vect -= 4; // Instruction is a relative jump (rjmp), so recalculate.
        buff[8] = vect & 0xff;
        buff[9] = vect >> 8;

        // Add jump to bootloader at RESET vector
        buff[0] = 0x7f;
        buff[1] = 0xce; // rjmp 0x1d00 instruction
      }
#endif

      // Copy buffer into programming buffer
      bufPtr = buff;
      addrPtr = (uint16_t)(void*)address;
      ch = SPM_PAGESIZE / 2;
      do {
        uint16_t a;
        a = *bufPtr++;
        a |= (*bufPtr++) << 8;
        __boot_page_fill_short((uint16_t)(void*)addrPtr,a);
        addrPtr += 2;
      } while (--ch);

      // Write from programming buffer
      __boot_page_write_short((uint16_t)(void*)address);
      boot_spm_busy_wait();

#if defined(RWWSRE)
      // Reenable read access to flash
      boot_rww_enable();
#endif

    }
Beispiel #17
0
int shinkos2145_cmdline_arg(void *vctx, int argc, char **argv)
{
	struct shinkos2145_ctx *ctx = vctx;
	int i, j = 0;

	if (!ctx)
		return -1;

	/* Reset arg parsing */
	optind = 1;
	opterr = 0;
	while ((i = getopt(argc, argv, GETOPT_LIST_GLOBAL "b:c:C:eFil:L:mr:R:suU:X:")) >= 0) {
		switch(i) {
		GETOPT_PROCESS_GLOBAL
		case 'b':
			if (optarg[0] == '1')
				j = button_set(ctx, BUTTON_ENABLED);
			else if (optarg[0] == '0')
				j = button_set(ctx, BUTTON_DISABLED);
			else
				return -1;
			break;
		case 'c':
			j = get_tonecurve(ctx, TONECURVE_USER, optarg);
			break;
		case 'C':
			j = set_tonecurve(ctx, TONECURVE_USER, optarg);
			break;
		case 'e':
			j = get_errorlog(ctx);
			break;
		case 'F':
			j = flash_led(ctx);
			break;
		case 'i':
			j = get_fwinfo(ctx);
			break;
		case 'l':
			j = get_tonecurve(ctx, TONECURVE_CURRENT, optarg);
			break;
		case 'L':
			j = set_tonecurve(ctx, TONECURVE_CURRENT, optarg);
			break;
		case 'm':
			j = get_mediainfo(ctx);
			break;
		case 'r':
			j = reset_curve(ctx, RESET_USER_CURVE);
			break;
		case 'R':
			j = reset_curve(ctx, RESET_PRINTER);
			break;
		case 's':
			j = get_status(ctx);
			break;
		case 'u':
			j = get_user_string(ctx);
			break;
		case 'U':
			j = set_user_string(ctx, optarg);
			break;
		case 'X':
			j = cancel_job(ctx, optarg);
			break;
		default:
			break;  /* Ignore completely */
		}

		if (j) return j;
	}

	return 0;
}
Beispiel #18
0
/* main program starts here */
int main(void) {
  uint8_t ch;
  uint8_t WaitTime = WATCHDOG_1S;  // Set watchdog to trigger after 1 second by default - value set to the watchdog later!


  /*
   * Making these local and in registers prevents the need for initializing
   * them, and also saves space because code no longer stores to memory.
   * (initializing address keeps the compiler happy, but isn't really
   *  necessary, and uses 4 bytes of flash.)
   */
  register uint16_t address = 0;
  register pagelen_t  length;

  // After the zero init loop, this is the first code to run.
  //
  // This code makes the following assumptions:
  //  No interrupts will execute
  //  SP points to RAMEND
  //  r1 contains zero
  //
  // If not, uncomment the following instructions:

  // Following lines enabled by Mark Griffiths to allow jumping directly to the boot loader from user code.
  cli();
  asm volatile ("clr __zero_reg__");
//#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
  SP=RAMEND;  // This is done by hardware reset
//#endif

  /*
   * modified Adaboot no-wait mod.
   * Pass the reset reason to app.  Also, it appears that an Uno poweron
   * can leave multiple reset flags set; we only want the bootloader to
   * run on an 'external reset only' status
   */
//  ch = MCUSR;
//  MCUSR = 0;
//  if (ch & (_BV(WDRF) | _BV(BORF) | _BV(PORF)))
//      appStart(ch);

  // Modified no wait mod by Mark Griffiths 8th of April 2015
  // This modification allows the majority of the reset flags to be kept 
  // unmodified in the MCUSR register for use by user sketches!

  // Previous method saved the MCUSR data in r2, but because it cleared 
  // MCUSR before attempting to update the flash memory, there was no way
  // for user code to distinguish between an external reset and a watchdog 
  // reset.  It also required extra code and an extra byte of RAM in the 
  // user sketch.

  ch = MCUSR;

  if (ch == 0) {
      WaitTime = WATCHDOG_8S;   // If no Reset Flags are set, it must mean that the user code jumped to the boot loader!  Wait 8 seconds for the firmware to be updated!
  } else {
      if ((ch & (_BV(WDRF) | _BV(EXTRF))) != _BV(EXTRF)) {    // To run the boot loader, External Reset Flag must be set and the Watchdog Flag MUST be cleared!  Otherwise jump straight to user code.
          MCUSR = ~(_BV(WDRF));
          appStart(ch);
      }
  }

#if LED_START_FLASHES > 0
  // Set up Timer 1 for timeout counter
  TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
#endif

#ifndef SOFT_UART
#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
  UCSRA = _BV(U2X); //Double speed mode USART
  UCSRB = _BV(RXEN) | _BV(TXEN);  // enable Rx & Tx
  UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);  // config USART; 8N1
  UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#else
  UART_SRA = _BV(U2X0); //Double speed mode USART0
  UART_SRB = _BV(RXEN0) | _BV(TXEN0);
  UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);
  UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#endif
#endif

  
  watchdogConfig(WaitTime);

#if (LED_START_FLASHES > 0) || defined(LED_DATA_FLASH)
  /* Set LED pin as output */
  LED_DDR |= _BV(LED);
#endif

#ifdef SOFT_UART
  /* Set TX pin as output */
  UART_DDR |= _BV(UART_TX_BIT);
#endif

#if LED_START_FLASHES > 0
  /* Flash onboard LED to signal entering of bootloader */
  flash_led(LED_START_FLASHES * 2);
#endif

  /* Forever loop: exits by causing WDT reset */
  for (;;) {
    /* get character from UART */
    ch = getch();

    if(ch == STK_GET_PARAMETER) {
      unsigned char which = getch();
      verifySpace();
      /*
       * Send optiboot version as "SW version"
       * Note that the references to memory are optimized away.
       */
      if (which == 0x82) {
	  putch(optiboot_version & 0xFF);
      } else if (which == 0x81) {
	  putch(optiboot_version >> 8);
      } else {
Beispiel #19
0
void
blink_led(unsigned int color)
{
	flash_led( 1, color, 1 );
	return;
}