⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 polltask.c

📁 IT projecotr reference design.
💻 C
字号:
/****************************************************************************/
/*             TEXAS INSTRUMENTS PROPRIETARY INFORMATION                    */
/*                                                                          */
/*  (c) Copyright, Texas Instruments Incorporated, 2006.                    */
/*      All Rights Reserved.                                                */
/*                                                                          */
/*  Property of Texas Instruments Incorporated. Restricted Rights -         */
/*  Use, duplication, or disclosure is subject to restrictions set          */
/*  forth in TI's program license agreement and associated documentation.   */
/****************************************************************************/

/****************************************************************************/
/* pollTask.c                                                               */
/*                                                                          */
/* Periodic polling task.                                                   */
/****************************************************************************/

#include "common.h"
#include "ddp2230_rtos_include.h"
#include "tmr.h"

#include "main.h"
#include "sysmon.h"
#include "taskParm.h"
#include "dbmessage.h"
#include "pollTask.h"
#include "watchdog.h"
#include "heartbeat.h"
#include "keypad.h"
#include "illumination.h"
#include "environment.h"
#include "testpoints.h"


                        /****************************************************/
                        /* Polled function array.                           */
                        /****************************************************/
    
static const PP_CALLBACK pollFunc[] =
{
    watchdog_poll,
    heartbeat_poll,
    keypad_poll,
    illum_poll,
    enviro_poll
};

static const int pollFuncCount = sizeof( pollFunc ) / sizeof( PP_CALLBACK );

                        /****************************************************/
                        /*Local data.                                       */
                        /****************************************************/
                        
static const char pollTaskName[] = "pollTask";

static uint16 pollTime[ pollFuncCount ];              /* polling time array */
static  int16 interval[ pollFuncCount ];          /* polling interval array */
static uint32 pollTaskID;                                /* polling task ID */
static uint08 tmrID;                                  /* interrupt timer ID */
static uint32 eventID;                                    /* timer event ID */

static uint16 tick;                                         /* tick counter */

                        /****************************************************/
                        /* Local functions.                                 */
                        /****************************************************/
    
void pollTask( void );

 
 
/****************************************************************************/
/* Timer interrupt handler.                                                 */ 
/****************************************************************************/

static void intHandler( uint08 Int_Level )
{
    RTA_EventSetFromISR( eventID );                /* set application event */ 
    TMR_EnableDelayTimerInt( tmrID, TRUE );              /* re-enable timer */
} 



/****************************************************************************/
/* Module reset function.                                                   */
/*                                                                          */
/* id:   reset type.                                                        */
/****************************************************************************/

EXEC_CC_ENUM pollTask_init( void )
{
    int idx;
        
                        /****************************************************/
                        /* Initialize polling times. Stagger the initial    */
                        /* polling times to spread out the processing done  */
                        /* in any one polling interval.                     */
                        /****************************************************/

    for( idx = 0; idx < pollFuncCount; idx++ )
    {
        pollTime[ idx ] = idx;                      /* initial polling time */
        interval[ idx ] = 0;                    /* initial polling interval */
    }
       
                        /****************************************************/
                        /* Allocate resources and start the polling task.   */
                        /****************************************************/

    if( RTA_SUCCESS != RTA_EventCreate( &eventID, "PTEV" ))
    {
        dbmsg_trace( DBM_ALWAYS, "Can't create polling task event...\r\n" );
        return EXEC_CC_FATAL;
    }

    if( PASS != TMR_Create( intHandler, RTOS_MS_PER_TICK * 1000, TRUE, &tmrID ))
    {
        dbmsg_trace( DBM_ALWAYS, "Can't create polling task timer...\r\n" );
        return EXEC_CC_FATAL;
    }

    if( RTA_SUCCESS != RTA_TaskCreate( pollTask, &pollTaskID, 
                PRIORITY_POLLTASK, STACK_POLLTASK, "POLL", 0 ))
    {
        dbmsg_trace( DBM_ALWAYS, "Can't create polling task...\r\n" );
        return EXEC_CC_FATAL;
    }

    return EXEC_CC_PASS;
}


 
/****************************************************************************/
/* Polling task.                                                            */
/****************************************************************************/

void pollTask( void )
{
    int idx;                                                 /* table index */
    
                        /****************************************************/
                        /* Delay initial startup to allow remainder of the  */
                        /* application to initialize.                       */
                        /****************************************************/

    RTA_TaskDelay( TMR_ConvertMSToTicks( POLL_STARTUP_DELAY ));

                        /****************************************************/
                        /* Polling loop.                                    */
                        /****************************************************/
    for(;;)
    {
        
        RTA_EventWaitForSetThenClear( eventID, 0 );  /* wait for timer tick */
        TPM_SendSWTestMuxSignal( TP_POLLTASK, TRUE );        /* timing test */
        tick++;                                          /* bump tick count */

        for( idx = 0; idx < pollFuncCount; idx++ )
        {
            if((int16)( tick -  pollTime[idx] ) >= interval[idx] )
            {
                pollTime[idx] += ( interval[idx] = (*pollFunc[idx])( tick ));
            }
        }
        
        TPM_SendSWTestMuxSignal( TP_POLLTASK, FALSE );       /* timing test */
    }
}



/****************************************************************************/
/* Return task information.                                                 */
/****************************************************************************/

void pollTask_info( TASKINFO_STRUCT *info )
{
    info -> taskID    = pollTaskID;
    info -> stackSize = STACK_POLLTASK;
    info -> taskName  = pollTaskName;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -