Beispiel #1
0
void CCommandProcessor::BusyWait ( const char * const paramBegin )
{
  const char * const delayEnd      = SkipCharsNotInSet( paramBegin, SPACE_AND_TAB );
  const char * const extraArgBegin = SkipCharsInSet   ( delayEnd,   SPACE_AND_TAB );

  if ( *paramBegin == 0 || *extraArgBegin != 0 )
  {
    PrintStr( "Invalid arguments." EOL );
    return;
  }

  const unsigned delayMs = ParseUnsignedIntArg( paramBegin );

  if ( delayMs == 0 || delayMs > 60 * 1000 )
  {
    PrintStr( "Invalid arguments." EOL );
    return;
  }

  const uint32_t oneMsIterationCount = GetBusyWaitLoopIterationCountFromUs( 1000 );

  for ( uint32_t i = 0; i < delayMs; ++i )
  {
    BusyWaitLoop( oneMsIterationCount );
  }

  Printf( "Waited %u ms." EOL, unsigned( delayMs ) );
}
Beispiel #2
0
extern "C" void BareMetalSupport_Reset_Handler ( void )
{
    SetupCpuClock();

    // Delay the start-up sequence, so that an external JTAG debugger has a chance
    // to stop the firmware near the beginning.
    //
    // How much busy wait time you need to spend here depends on how fast your JTAG adapter is.
    // With my slow Bus Pirate (at 'normal' speed, instead of 'fast'), and with a non-optimised
    // JtagDue firmware, I need around 34 ms. If you have a fast JTAG probe, you can probably
    // lower this time in order to get faster overall boot times.
    //
    // If you do not need to debug the firmware from the very beginning, or if you do not place
    // breakpoints somewhere during the initialisation code, then you can comment-out this busy wait.
    const unsigned BUSY_WAIT_LOOP_US = 36 * 1000;
    BusyWaitLoop( GetBusyWaitLoopIterationCountFromUs( BUSY_WAIT_LOOP_US ) );


    // Relocate the initialised data from flash to SRAM.

    const uint32_t * relocSrc  = (const uint32_t *)&_etext;
          uint32_t * relocDest = (      uint32_t *)&_srelocate;

    if ( relocSrc != relocDest )
    {
        while ( relocDest < (const uint32_t *) &_erelocate )
        {
            *relocDest++ = *relocSrc++;
        }
    }


    // Clear the zero segment (BSS).

    for ( uint32_t * zeroSegPtr = (uint32_t *)&_szero;  zeroSegPtr < (const uint32_t *) &_ezero;  ++zeroSegPtr )
    {
      *zeroSegPtr = 0;
    }


    // Set the vector table base address.
    const uint32_t * const pVecSrc = (const uint32_t *) & _sfixed;
    SCB->VTOR = ((uint32_t) pVecSrc & SCB_VTOR_TBLOFF_Msk);

    if (((uint32_t) pVecSrc >= IRAM0_ADDR) && ((uint32_t) pVecSrc < NFC_RAM_ADDR))
    {
        SCB->VTOR |= (1UL) << SCB_VTOR_TBLBASE_Pos;
    }


    // The CPU starts at 4 MHz, and that should be the default value of variable SystemCoreClock.
    // We have set the CPU clock above, so update this variable here. Its value is needed
    // in order to calculate the clock delay to get the correct UART speed.

    assert( SystemCoreClock == 4000000 );

    SystemCoreClockUpdate();

    #ifndef NDEBUG
      assert( SystemCoreClock == CPU_CLOCK );
      assert( SystemCoreClock == CHIP_FREQ_CPU_MAX );
    #endif


    // Initialize the C/C++ support by calling all registered constructors.
    __libc_init_array();

    // From this point on, all C/C++ support has been initialised, and the user code can run.

    RunUserCode();

    // If you want to check for memory leaks and so on, you may need to call the destructors here:
    //   __libc_fini_array();

    Panic("RunUserCode() returned unexpectedly.");
}