Exemplo n.º 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);
}
Exemplo n.º 2
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();
}