Exemplo n.º 1
0
//****************************************************************************
//
//! Instructs the scheduler to update its task table and make calls to
//! functions needing called.
//!
//! This function must be called periodically by the client to allow the
//! scheduler to make calls to any configured task functions if it is their
//! time to be called.  The call must be made at least as frequently as the
//! most frequent task configured in the g_psSchedulerTable array.
//!
//! Although the scheduler makes use of the SysTick interrupt, all calls to
//! functions configured in \e g_psSchedulerTable are made in the context of
//! SchedulerRun().
//!
//! \return None.
//
//****************************************************************************
void
SchedulerRun(void)
{
    unsigned long ulLoop;
    tSchedulerTask *psTask;

    //
    // Loop through each task in the task table.
    //
    for(ulLoop = 0; ulLoop < g_ulSchedulerNumTasks; ulLoop++)
    {
        //
        // Get a pointer to the task information.
        //
        psTask = &g_psSchedulerTable[ulLoop];

        //
        // Is this task active and, if so, is it time to call it's function?
        //
        if(psTask->bActive && (SchedulerElapsedTicksGet(psTask->ulLastCall) >=
           psTask->ulFrequencyTicks))
        {
            //
            // Remember the timestamp at which we make the function call.
            //
            psTask->ulLastCall = g_ulSchedulerTickCount;

            //
            // Call the task function, passing the provided parameter.
            //
            psTask->pfnFunction(psTask->pvParam);
        }
    }
}
//*****************************************************************************
//
// This function is the display "task" that is called periodically by the
// Scheduler from the application main processing loop.
// This function displays a cycle of several messages on the display.
//
// Odd values are used for timeouts for some of the displayed messaged.  For
// example a message may be shown for 5.3 seconds.  This is done to keep the
// changes on the display out of sync with the LED blinking which occurs
// once per second.
//
//*****************************************************************************
void
DisplayTask(void *pvParam)
{
    static unsigned long ulState = 0;
    static unsigned long ulLastTick = 0;
    static unsigned long ulTimeout = 0;

    //
    // Check to see if the timeout has expired and it is time to change the
    // display.
    //
    if(SchedulerElapsedTicksGet(ulLastTick) > ulTimeout)
    {
        //
        // Save the current tick value to use for comparison next time through
        //
        ulLastTick = SchedulerTickCountGet();

        //
        // Switch based on the display task state
        //
        switch(ulState)
        {
            //
            // In this state, the scrolling TI logo is initialized, and the
            // state changed to next state.  A short timeout is used so that
            // the scrolling image will start next time through this task.
            //
            case 0:
            {
                ScrollImage(g_pucTILogo, sizeof(g_pucTILogo) / 2);
                ulTimeout = 1;
                ulState = 1;
                break;
            }

            //
            // In this state the TI logo is scrolled across the screen with
            // a scroll rate of this task period (each time this task is
            // called by the scheduler it advances the scroll by one pixel
            // column).
            //
            case 1:
            {
                if(ScrollImage(g_pucTILogo, 0))
                {
                    //
                    // If the scrolling is done, then advance the state and
                    // set the timeout for 1.3 seconds (next state will start
                    // in 1.3 seconds).
                    //
                    ulTimeout = 130;
                    ulState = 2;
                }
                break;
            }

            //
            // This state shows the text "STELLARIS" on the display for 5.3
            // seconds.
            //
            case 2:
            {
                Display96x16x1StringDraw("STELLARIS", 21, 0);
                ulTimeout = 530;
                ulState = 3;
                break;
            }

            //
            // This state clears the screen for 1.3 seconds.
            //
            case 3:
            {
                Display96x16x1Clear();
                ulTimeout = 130;
                ulState = 4;
                break;
            }

            //
            // This state shows "EVALBOT" for 5.3 seconds.
            //
            case 4:
            {
                Display96x16x1StringDraw("EVALBOT", 27, 0);
                ulTimeout = 530;
                ulState = 5;
                break;
            }

            //
            // This state clears the screen for 1.3 seconds.
            //
            case 5:
            {
                Display96x16x1Clear();
                ulTimeout = 130;
                ulState = 0;
                break;
            }

            //
            // The default state should not occur, but if it does, then reset
            // back to the beginning state.
            //
            default:
            {
                ulTimeout = 130;
                ulState = 0;
                break;
            }
        }
    }
}