示例#1
0
/**************************************************************************************************
* @fn          sblExec
*
* @brief       Infinite SBL execute loop that jumps upon receiving a code enable.
*
* input parameters
*
* None.
*
* output parameters
*
* None.
*
* @return      None.
**************************************************************************************************
*/
static void sblExec(void)
{
  halUARTCfg_t uartConfig;
  uartConfig.callBackFunc = sblRxCB;
  HalUARTInitSPI();
  
  if (bootloaderCommunicationRequested() || (!sbImgValid()))
  {
    while (1)
    {
      /* Read , parse, and respond to incoming bytes*/
      sblRxCB(0, 0);
      
      /* exit loop if image is successfully verified and enabled */
      if (sblReset)
      {
        break;
      }  
    }
  }
  
  /* Some delay to send final response to master */
  for(uint32 i = 0; i < ENABLE_RSP_DELAY; i++)
  {
    ASM_NOP;
  }
  
  /* Some delay to send final response to master */
  HalUARTUnInitSPI();
  
  /* Jump to application image */
  EnterNvmApplication((uint32)sbl_header_ptr->vectorTableAddress);
}
示例#2
0
/**************************************************************************************************
 * @fn          sblExec
 *
 * @brief       Infinite SBL execute loop that jumps upon receiving a code enable.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void sblExec(void)
{
  uint32 dlyCnt = 0;

  while (1)
  {
    HalUARTPollUSB();

    if (sbExec() && sbImgValid())
    {
      SB_TURN_ON_LED1();
      SB_TURN_ON_LED2();
      // Delay to allow the SB_ENABLE_CMD response to be flushed.
      for (dlyCnt = 0; dlyCnt < 0x40000; dlyCnt++)
      {
        HalUARTPollUSB();
      }

      sblJump();
    }
    else if (dlyCnt++ & 0x4000)
    {
      SB_TOGGLE_LED1();
    }
  }
}
示例#3
0
/**************************************************************************************************
 * @fn          main
 *
 * @brief       ISR for the reset vector.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
void main(void)
{
  uint8 time_spent_validating;
  uint8 bootloaderForcedByMainApp = FALSE;
  uint32 mainAppCommandLocal = mainAppCommand;

  mainAppCommand = MAIN_APP_CMD_NONE;
    
  if (mainAppCommandLocal == MAIN_APP_CMD_FORCE_BOOTLOADER)
  {
    bootloaderForcedByMainApp = TRUE;
  }
  else if ((mainAppCommandLocal == MAIN_APP_CMD_PASS_THROUGH) || ((SLEEPSTA & LRESET) == RESETWD))
  /* If reset due to WatchDog Timer - Transfer control to the main application immediately.
     WatchDog Timer reset causes the hardware to disconnect the USB. Without this jump here,
     the SBL code will try to initiaize the CDC too early, which causes undesired behavior
     on the host (e.g. on beaglebone black - the host gets stuck) */
  {
    asm("LJMP 0x2000\n");
  }

  sblInit();

  if ((!bootloaderForcedByMainApp) && sbImgValid(&time_spent_validating))
  {
    if (sblWait(SBL_WAIT_TIME > time_spent_validating ? SBL_WAIT_TIME - time_spent_validating : 0))
    {
      if (znpCfg1 == ZNP_CFG1_SPI)
      {
        HalUARTUnInitSPI();
      }
      else
      {
        sbReportState(SB_STATE_EXECUTING_IMAGE);
		
        while(sblIsUartTxPending())
        {
          sbUartPoll();
        }
        
        SLEEP(0x2600); //Give the last bytes in the HW TX fifo (if any) enough time to be transmitted

        HalUARTUnInitISR();
      }
      magicByte = SB_STACK_VALUE;

      // Simulate a reset for the Application code by an absolute jump to location 0x2000.
      asm("LJMP 0x2000\n");
      HAL_SYSTEM_RESET();
    }
  }

  sblExec();
  HAL_SYSTEM_RESET();
}
示例#4
0
/**************************************************************************************************
 * @fn          main
 *
 * @brief       ISR for the reset vector.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
void main(void)
{
  sblInit();

  if (sbImgValid())
  {
    if (sblWait())
    {
      HalUARTUnInitUSB();
      // Simulate a reset for the Application code by an absolute jump to location 0x2000.
      asm("LJMP 0x2000\n");
      HAL_SYSTEM_RESET();
    }
  }

  sblExec();
  HAL_SYSTEM_RESET();
}
示例#5
0
/**************************************************************************************************
 * @fn          main
 *
 * @brief       C-code main functionality.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
void main(void)
{
  vddWait(VDD_MIN_RUN);
  HAL_BOARD_INIT();

  // make sure the DMA channel is selected before we attempt to
  // to write anything to flash.
  sblInit();
  
  if (sbImgValid())
  {
    if ((SB_UART_DELAY == 0) || ResetWasWatchDog)
    {
      sblJump();
    }

    sblWait();
  }

  vddWait(VDD_MIN_NV);
  sblExec();
  HAL_SYSTEM_RESET();
}
示例#6
0
/**************************************************************************************************
 * @fn          main
 *
 * @brief       C-code main functionality.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
void main(void)
{
  vddWait(VDD_MIN_RUN);
  HAL_BOARD_INIT();

  if (sbImgValid())
  {
    if ((SB_UART_DELAY == 0) || ResetWasWatchDog)
    {
      sblJump();
    }

    sblInit();
    sblWait();
  }
  else
  {
    sblInit();
  }

  vddWait(VDD_MIN_NV);
  sblExec();
  HAL_SYSTEM_RESET();
}
示例#7
0
/**************************************************************************************************
 * @fn          main
 *
 * @brief       C-code main functionality.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
void main(void)
{
  uint8 time_spent_validating;
  uint8 bootloaderForcedByMainApp = FALSE;
  uint32 mainAppCommandLocal = mainAppCommand;

  vddWait(VDD_MIN_RUN);

  mainAppCommand = MAIN_APP_CMD_NONE;
    
  if (mainAppCommandLocal == MAIN_APP_CMD_FORCE_BOOTLOADER)
  {
    bootloaderForcedByMainApp = TRUE;
  }
  else if ((mainAppCommandLocal == MAIN_APP_CMD_PASS_THROUGH) || ((SLEEPSTA & LRESET) == RESETWD))
  {
    // If reset due to WatchDog Timer - Transfer control to the main application immediately.
    // WatchDog Timer reset causes the hardware to disconnect the USB. Withought this jump here,
    // the SBL code will try to initiaize the CDC too early, which causes undesired behavior on the host
    // (e.g. on beaglebone black - the host gets stuck)
    asm("LJMP 0x2000\n");
  }

  sblInit(bootloaderForcedByMainApp);
  
  HAL_TURN_ON_LED1();
  HAL_TURN_ON_LED2();
  
  if ((!bootloaderForcedByMainApp) && (sbImgValid(&time_spent_validating)))
  {
    HAL_TURN_OFF_LED2();
    
    if (sblWait(SBL_WAIT_TIME > time_spent_validating ? SBL_WAIT_TIME - time_spent_validating : 0))
    {
      HAL_TURN_OFF_LED1();
      
      sbReportState(SB_STATE_EXECUTING_IMAGE);
      
      while(sblIsUartTxPending())
      {
        sbUartPoll();
      }
      
      SLEEP(0x2600); //Give the last bytes in the HW TX fifo (if any) enough time to be transmitted

      while (SB1_PRESS || SB2_PRESS);
      
      sblUnInit();
      
      // Simulate a reset for the Application code by an absolute jump to location 0x2000.
      asm("LJMP 0x2000\n");
    }
  }
  
  HAL_TURN_OFF_LED1();
  HAL_TURN_ON_LED2();
  
  vddWait(VDD_MIN_NV);
  sblExec();

  sblUnInit();

  asm("LJMP 0x2000\n");
}