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

📄 irremote.c

📁 IT projecotr reference design.
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************/
/*             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.   */
/****************************************************************************/

/****************************************************************************/
/* irRemote.c                                                               */
/*                                                                          */
/* Application interface to IR remote control.                              */
/****************************************************************************/


#include "common.h"
#include "ddp2230_rtos_include.h"
#include "gpio.h"
#include "int.h"
#include "ir.h"
#include "tmr.h"

#include "sysmon.h"
#include "global.h"
#include "taskparm.h"
#include "dbmessage.h"
#include "irRemote.h"
#include "guiApp.h"


/****************************************************************************/
/* Local constants and declarations.                                        */
/****************************************************************************/
 
#define STARTUP_DELAY       1000             /* startup delay, milliseconds */


                        /****************************************************/
                        /* IR protocol decoder definitions.                 */
                        /****************************************************/

#include "irButton.h"                                /* NEC button protocol */
#include "irRemotePoint.h"             /* remotePoint mouse/button protocol */


const IR_PROTOIF_STRUCT *irProto[] =
{
   &NECButtonProtocol,                             /* defined in irButton.h */
   &RPMouseProtocol                            /* define in irRemotePoint.h */
};

static const int pCount = sizeof( irProto ) / sizeof( IR_PROTOIF_STRUCT* );


                        /****************************************************/
                        /* Local variables.                                 */
                        /****************************************************/

const char irRemoteTaskName[] = "IRRemoteTask";

static uint32 irEventID;                           /* IR interrupt event ID */
static uint32 irTaskID;                                          /* task ID */
static uint32 msTimer;                                 /* millisecond timer */

BOOL   overFlag0;                                      /* FIFO overrun flag */
BOOL   overFlag1;                                      /* FIFO overrun flag */

static uint08 config;                                 /* IR port 0/1 enable */

static uint32 priorTime = 0;                       /* time of prior message */


                        /****************************************************/
                        /* Local functions.                                 */
                        /****************************************************/

static void irfunc_Task( void );

static void irPortZeroHandler( uint08 placeholder );
static void irPortOneHandler ( uint08 placeholder );


static BOOL   irScanEvent( UIREP *report, BOOL *newKey );
static BOOL   irScanOne( IRPORT port, UIREP *report, BOOL overFlag );
static uint32 irDeltaMsTimer( void );



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

void irRemote_info( TASKINFO_STRUCT *info )
{
    info -> taskID    = irTaskID;
    info -> stackSize = STACK_IRREMOTE;
    info -> taskName  = irRemoteTaskName;
}



/****************************************************************************/
/* Module reset function.                                                   */
/****************************************************************************/

EXEC_CC_ENUM irfunc_init( void )
{
    IRINIT istruct;                     /* IR port initialization structure */

    config = gpConfiguration -> Peripherals.IRConfig;
     
    IR_Reset( IR_PORT0 );                                    /* Reset ports */
    IR_Reset( IR_PORT1 );

                        /****************************************************/
                        /* Set hardware initialization data common to both  */
                        /* IO ports.                                        */
                        /****************************************************/
     
    istruct.edge_selection      = GIR_EDGE_CFG_EDGE_TO_EDGE;
    istruct.noise_rejection     = GIR_NOISE_REJECT_LIMIT2;
    istruct.sample_rate_divider = IR_DIVIDER;
    istruct.EOFD_Trig           = IR_EOFRAME / IRSAMPLEPERIOD;
    istruct.EOFD_Code_Enable    = TRUE;
    istruct.EOFD_Code           = IRMSGSYNC;
    
                        /****************************************************/
                        /* IR port zero initialization.                     */
                        /****************************************************/
     
    istruct.port   = IR_PORT0;
    istruct.enable = FALSE;
    
    if( 0x01 == ( 0x01 & config ))
    {
        istruct.enable = TRUE;
        GPIO_EnableAlternativeFunction( GPIO_IR0_IN, TRUE );
    }

    if( PASS != IR_Init( &istruct ))
        return EXEC_CC_API;
    
    if( PASS != INT_InstallISR( (INT_ISR_Func)irPortZeroHandler, INT_GIR0 )) 
        return EXEC_CC_API;
        
                        /****************************************************/
                        /* IR port one initialization.                      */
                        /****************************************************/
     
    istruct.port   = IR_PORT1;
    istruct.enable = FALSE;
    
    if( 0x02 == ( 0x02 & config ))
    {
        istruct.enable = TRUE;
        GPIO_EnableAlternativeFunction( GPIO_IR1_IN, TRUE );
    }
    
    if( PASS != IR_Init( &istruct ))
        return EXEC_CC_API;
    
    if( PASS != INT_InstallISR( (INT_ISR_Func)irPortOneHandler, INT_GIR1 )) 
        return EXEC_CC_API; 
    
                        /****************************************************/
                        /* Create IR task event and start task.             */
                        /****************************************************/
    
    if( RTA_SUCCESS != RTA_EventCreate( &irEventID, "irEv" )) 
    return EXEC_CC_RTOSERR;
    
    RTA_EventClear( irEventID );
    
    if( RTA_SUCCESS != RTA_TaskCreate( (void(*)(void))irfunc_Task, &irTaskID, 
        PRIORITY_IRREMOTE, STACK_IRREMOTE, "IRrm", 0 ))
            return EXEC_CC_RTOSERR;

    return EXEC_CC_PASS;
}



/****************************************************************************/
/* IR task.                                                                 */
/****************************************************************************/

static void irfunc_Task( void )
{
    UIREP  report;                                 /* User interface report */
    int    pindex;                                /* protocol decoder index */
    BOOL   newKey;                                  /* new key-decoded flag */
    
                        /****************************************************/
                        /* Delay completion of task initialization to allow */
                        /* time for the application to settle down, then    */
                        /* start the scanner.                               */
                        /****************************************************/
    
    RTA_TaskDelay( TMR_ConvertMSToTicks( STARTUP_DELAY ));
    
    INT_DisableSingleIRQ( INT_GIR0 );
    INT_DisableSingleIRQ( INT_GIR1 );
    
                        /****************************************************/
                        /* Start the receiver and protocol decoders.        */
                        /****************************************************/
    
    for( pindex = 0; pindex < pCount; pindex++ )
    {
      (*irProto[ pindex ] -> startFunc)( IR_PORT0 );
      (*irProto[ pindex ] -> startFunc)( IR_PORT1 );
    }

                        /****************************************************/
                        /* Enable half full, overflow, and EOF interrupts.  */
                        /****************************************************/
    
    IR_EnableInterrupt( IR_PORT0, 0x0b );
    IR_EnableInterrupt( IR_PORT1, 0x0b );
        
    INT_EnableSingleIRQ( INT_GIR0 );
    INT_EnableSingleIRQ( INT_GIR1 );

    overFlag0 = FALSE;                                   /* no FIFO overrun */
    overFlag1 = FALSE;                                   /* no FIFO overrun */
    
                        /****************************************************/
                        /* Handle IR message events.                        */
                        /****************************************************/
    
    for(;;)
    {
        RTA_EventWait( irEventID, TRUE, 0 );              /* wait for event */
        RTA_EventClear( irEventID );                         /* clear event */
        
        if( irScanEvent( &report, &newKey ))           /* if message decode */
        {

⌨️ 快捷键说明

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