Example #1
0
// ---------------------------------------------------------------------------
BOOL CPU_GPIO_SetDebounce(INT64 debounceTimeMilliseconds)
{
    if (debounceTimeMilliseconds > 0 && debounceTimeMilliseconds < 10000)
    {
        g_debounceTicks = CPU_MillisecondsToTicks((UINT32)debounceTimeMilliseconds);
        return TRUE;
    }
    return FALSE;
}
Example #2
0
BOOL AT91_GPIO_Driver::SetDebounce( INT64 debounceTimeMilliseconds )
{   
    if(debounceTimeMilliseconds < c_MinDebounceTimeMs || c_MaxDebounceTimeMs < debounceTimeMilliseconds )
    {
        return FALSE;
    }

    g_AT91_GPIO_Driver.m_DebounceTicks = CPU_MillisecondsToTicks( (UINT32)debounceTimeMilliseconds );

    return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
//  SetDebounce
///////////////////////////////////////////////////////////////////////////////
BOOL LPC22XX_GPIO_Driver::SetDebounce( INT64 debounceTimeMilliseconds )
{   
// TODO: Need to implement
//hal_printf( "SetDebounce\r\n");

    if(debounceTimeMilliseconds < c_MinDebounceTimeMs || c_MaxDebounceTimeMs < debounceTimeMilliseconds )
    {
        return FALSE;
    }

    g_LPC22XX_GPIO_Driver.m_DebounceTicks = CPU_MillisecondsToTicks( (UINT32)debounceTimeMilliseconds );

    return TRUE;
}
BOOL AT91_GPIO_Driver::SetDebounce( INT64 debounceTimeMilliseconds )
{   
#if !defined(PLATFORM_ARM_SAM7_ANY)
    if(debounceTimeMilliseconds < c_MinDebounceTimeMs || c_MaxDebounceTimeMs < debounceTimeMilliseconds )
    {
        return FALSE;
    }

    g_AT91_GPIO_Driver.m_DebounceTicks = CPU_MillisecondsToTicks( (UINT32)debounceTimeMilliseconds );

    return TRUE;
#else
    // cannot specify the debounce time
    return FALSE;
#endif
}
void ApplicationEntryPoint()
{
    INT32 timeout       = 20000; // 20 second timeout
    bool  enterBootMode = false;

    // crypto API needs to allocate memory. Initialize simple heap for it. 
    UINT8* BaseAddress;                                 
    UINT32 SizeInBytes;                                 
                                                        
    HeapLocation         ( BaseAddress, SizeInBytes );  
    SimpleHeap_Initialize( BaseAddress, SizeInBytes );  

    g_eng.Initialize( HalSystemConfig.DebuggerPorts[ 0 ] );

    // internal reset and stop check
    enterBootMode = g_PrimaryConfigManager.IsBootLoaderRequired( timeout );

    // ODM defined method to enter bootloader mode
    if(!enterBootMode)
    {
        enterBootMode = WaitForTinyBooterUpload( timeout );
    }
    if(!enterBootMode)   
    {
        if(!g_eng.EnumerateAndLaunch())
        {
            timeout       = -1;
            enterBootMode = true;
        }
    }

    if(enterBootMode)
    {
        LCD_Clear();
        
        hal_fprintf( STREAM_LCD, "TinyBooter v%d.%d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION);
        hal_fprintf( STREAM_LCD, "%s Build Date:\r\n\t%s %s\r\n", HalName, __DATE__, __TIME__ );

        DebuggerPort_Initialize( HalSystemConfig.DebuggerPorts[ 0 ] );

        TinyBooter_OnStateChange( State_EnterBooterMode, NULL );

        DebuggerPort_Flush( HalSystemConfig.DebugTextPort  );
        hal_printf( "TinyBooter v%d.%d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION);
        hal_printf( "%s Build Date: %s %s\r\n", HalName, __DATE__, __TIME__ );
#if defined(__GNUC__)
        hal_printf("GNU Compiler version %d\r\n", __GNUC__);
#elif defined(_ARC)
        hal_printf("ARC Compiler version %d\r\n", _ARCVER);
#elif defined(__ADSPBLACKFIN__)
        hal_printf( "Blackfin Compiler version %d\r\n", __VERSIONNUM__ );
#elif defined(__RENESAS__)
        hal_printf( "Renesas Compiler version %d\r\n", __RENESAS_VERSION__ );
#else
        hal_printf( "ARM Compiler version %d\r\n", __ARMCC_VERSION );
#endif
        DebuggerPort_Flush( HalSystemConfig.DebugTextPort );

        //
        // Send "presence" ping.
        //
        {
            CLR_DBG_Commands::Monitor_Ping cmd;

            cmd.m_source = CLR_DBG_Commands::Monitor_Ping::c_Ping_Source_TinyBooter;

            g_eng.m_controller.SendProtocolMessage( CLR_DBG_Commands::c_Monitor_Ping, WP_Flags::c_NonCritical, sizeof(cmd), (UINT8*)&cmd );
        }
    
        UINT64 ticksStart = HAL_Time_CurrentTicks();

        //
        // Wait for somebody to press a button; if no button press comes in, lauch the image
        //
        do
        {
            const UINT32 c_EventsMask = SYSTEM_EVENT_FLAG_COM_IN |
                                        SYSTEM_EVENT_FLAG_USB_IN |
                                        SYSTEM_EVENT_FLAG_BUTTON;

            UINT32 events = ::Events_WaitForEvents( c_EventsMask, timeout );

            if(events != 0)
            {
                Events_Clear( events );
            }

            if(events & SYSTEM_EVENT_FLAG_BUTTON)
            {
                TinyBooter_OnStateChange( State_ButtonPress, (void*)&timeout );
            }
            
            if(events & (SYSTEM_EVENT_FLAG_COM_IN | SYSTEM_EVENT_FLAG_USB_IN))
            {
                g_eng.ProcessCommands();
            }

            if(LOADER_ENGINE_ISFLAGSET(&g_eng, Loader_Engine::c_LoaderEngineFlag_ValidConnection))
            {
                LOADER_ENGINE_CLEARFLAG(&g_eng, Loader_Engine::c_LoaderEngineFlag_ValidConnection);
                
                TinyBooter_OnStateChange( State_ValidCommunication, (void*)&timeout );

                ticksStart = HAL_Time_CurrentTicks();
            }
            else if((timeout != -1) && (HAL_Time_CurrentTicks()-ticksStart) > CPU_MillisecondsToTicks((UINT32)timeout))
            {
                TinyBooter_OnStateChange( State_Timeout, NULL );
                g_eng.EnumerateAndLaunch();
            }
        } while(true);
    }

    ::CPU_Reset();
}
Example #6
0
UINT32 Events_WaitForEvents( UINT32 sleepLevel, UINT32 WakeupSystemEvents, UINT32 Timeout_Milliseconds )
{
    NATIVE_PROFILE_PAL_EVENTS();
    // do NOT call this routine with interrupts disabled,
    // as we can die here, since flags are only set in ISRs
    ASSERT_IRQ_MUST_BE_ON();

    // schedule an interrupt for this far in the future
    // timeout is in milliseconds, convert to Sleep Counts

    UINT64 CountsRemaining = CPU_MillisecondsToTicks( Timeout_Milliseconds );

#if defined(HAL_PROFILE_ENABLED)
    Events_WaitForEvents_Calls++;
#endif

    {
        GLOBAL_LOCK(irq);

        // then check to make sure the events haven't happened on the way in
        // we must do this before we sleep!

        UINT64 Expire           = HAL_Time_CurrentTicks() + CountsRemaining;
        BOOL   RunContinuations = TRUE;

        while(true)
        {
            UINT32 Events = Events_MaskedRead( WakeupSystemEvents ); if(Events) return Events;

            if(Expire <= HAL_Time_CurrentTicks()) return 0;


            // first check and possibly run any continuations
            // but only if we have slept after stalling
            if(RunContinuations && !SystemState_QueryNoLock( SYSTEM_STATE_NO_CONTINUATIONS ))
            {
                // restore interrupts before running a continuation
                irq.Release();

                // if we stall on time, don't check again until after we sleep
                RunContinuations = HAL_CONTINUATION::Dequeue_And_Execute();

                irq.Acquire();
            }
            else
            {
                // try stalled continuations again after sleeping
                RunContinuations = TRUE;

                //lcd_printf("\fSleep=%6lld   ", CountsRemaining);
                //lcd_printf(  "Events=%08x", Events_MaskedRead(0xffffffff));

#if defined(HAL_TIMEWARP)
                if(s_timewarp_lastButton < HAL_Time_TicksToTime( HAL_Time_CurrentTicks() ))
                {
                    CountsRemaining = Expire - HAL_Time_CurrentTicks();

                    if(CountsRemaining > 0)
                    {
                        s_timewarp_compensate += (CountsRemaining * 10*1000*1000) / CPU_TicksPerSecond();
                    }
                    return 0;
                }
#endif

                ASSERT_IRQ_MUST_BE_OFF();

                HAL_COMPLETION::WaitForInterrupts( Expire, sleepLevel, WakeupSystemEvents );

                irq.Probe(); // See if we have to serve any pending interrupts.                
            }
        }
    }
}