コード例 #1
0
//*****************************************************************************
//
//! Waits for the value of a counter to reach or exceed a target value.
//!
//! \param pulCount is a pointer to the counter variable whose value is to be
//! polled until it reaches or exceeds the supplied target value.
//! \param ulTarget is the value that /b *pulCount must reach before the
//! the function will return /e true.
//! \param ulTimeoutMs is the maximum time that the function will wait for
//! the target to be reached before returning /e false.
//!
//! This function polls the value of a variable supplied in /b pulCount,
//! waiting for it to reach or exceed /b ulTarget. If the target is reached
//! within /b ulTimeoutMs milliseconds, the function returns /e true. If the
//! timeout is reached before the target value is reached, /e false is
//! returned.
//!
//! \return Returns /e true if the target value is reached or exceeded or
//! /e false if the function times out before this occurs.
//
//*****************************************************************************
tBoolean
UTUtilsWaitForCount(volatile unsigned long *pulCount,
                    unsigned long ulTarget,
                    unsigned long ulTimeoutMs)
{
    unsigned long ulTimeToEnd;
    static unsigned long ulSysTimeStart;
    
    //
    // When should we stop polling?
    //
    ulSysTimeStart = UTUtilsGetSysTime();

    ulTimeToEnd = ulSysTimeStart + ulTimeoutMs;

    //
    // Keep checking for the target value being reached until we run out
    // of time.
    //

    //
    // This is not completely safe since it will not handle rollover well
    // but this will only be a problem if the function is called during a
    // ulTimeoutMs millisecond window 49.7 days after the application
    // starts. If it takes us a month and a half to run our testcase, we
    // have far bigger things to worry about than this.
    //
    
    while(UTUtilsGetSysTime() < ulTimeToEnd)
    {
        //
        // Read the counter and see if it got to the target value yet
        //
        if(*pulCount >= ulTarget)
        {
            //
            // Target reached so return true
            //
           return(true);
        }
    }

    return(false);
}
コード例 #2
0
ファイル: systick_if.c プロジェクト: Balu1991/Wifly_Light
//*****************************************************************************
//
//! Waits for the value of a counter to reach or exceed a target value.
//!
//! \param pulCount is a pointer to the counter variable whose value is to be
//! polled until it reaches or exceeds the supplied target value.
//! \param ulTarget is the value that /b *pulCount must reach before the
//! the function will return /e true.
//! \param ulTimeoutMs is the maximum time that the function will wait for
//! the target to be reached before returning /e false.
//!
//! This function polls the value of a variable supplied in /b pulCount,
//! waiting for it to reach or exceed /b ulTarget. If the target is reached
//! within /b ulTimeoutMs milliseconds, the function returns /e true. If the
//! timeout is reached before the target value is reached, /e false is
//! returned.
//!
//! \return Returns /e true if the target value is reached or exceeded or
//! /e false if the function times out before this occurs.
//
//*****************************************************************************
tBoolean
UTUtilsWaitForCount(volatile unsigned long *pulCount,
                    unsigned long ulTarget,
                    unsigned long ulTimeoutMs)
{
    unsigned long ulTimeToEnd;
    static unsigned long ulSysTimeStart;
    
    //
    // When should we stop polling?
    //
    ulSysTimeStart = UTUtilsGetSysTime();

    ulTimeToEnd = ulSysTimeStart + ulTimeoutMs;

    //
    // Keep checking for the target value being reached until we run out
    // of time.
    //

    //
    // This is not completely safe since it will not handle rollover well
    // but this will only be a problem if the function is called during a
    // ulTimeoutMs millisecond window 49.7 days after the application
    // starts. If it takes us a month and a half to run our testcase, we
    // have far bigger things to worry about than this.
    //
    

    while(UTUtilsGetSysTime() < ulTimeToEnd)
    {
        //
        // Read the counter and see if it got to the target value yet
        //
        if(*pulCount >= ulTarget)
        {
            //
            // Target reached so return true
            //
          
           return(true);
        }
    }

    //
    // Grab the systick value on exit (this is purely for debug purposes).
    //
    
    

    //
    // If we drop out of the loop, we timed out and the target value was not
    // reached. Return false.
    //
    /*printf("Timeout after %dmS. Count is %d, waiting for %d\n\r",
                      TICKS_TO_MILLISECONDS(ulTimeStart - ulTimeEnd),
                      *pulCount,
                      ulTarget);
    printf("Systime start %d, end %d, difference %dmS\n\r",
                      ulSysTimeStart, ulSysTimeEnd,
                      ulSysTimeEnd - ulSysTimeStart);*/

    return(false);
}