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

📄 ir.c

📁 M3355的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <platform.h>
#if (_TRANSFER_ALI_BOARD_ == _TRANSFER_ALI_BOARD_DISABLE_)
#else
/*====================================================================
 *
 *  Copyright (C) 1997 Acer Labs, Inc.  All Rights Reserved.
 *
 *  File:   ir.c
 *
 *  Contents: Get IR key code and translate the customer special key code
 *            to Ali physical key code
 *
 *  History:
 *   Date           By         Reason
 *  ===========    =========   ======
 *  21-Jun-1999    Elisa Lee
 *  22-Apr-2001    Dick Ma     Reform
 *      27-Aug-2002             Tom gao         Modify and add it into M3325
 ********************************************************************/

#include <comsub.h>
#include <ui.h>
#include "ir.h"
#include "frntp.h"
#include <platform.h>

extern unsigned long KeyTable[];				//30124-01jf
extern unsigned char IR_Custom_Code1  , IR_Custom_Code2 ;	//30124-01jf
//extern BYTE IR_Custom_Code1_standby  , IR_Custom_Code2_standby ;//for standby ;	//30124-01jf
/* Private variable */
static DWORD IR_PreCount = 0,IR_NowCount = 0,IR_Between_CNT;
static BYTE bRepeatCount = 0;
static WORD IR_StepFlag = 0;
static DWORD LAST_IR_CODE;
/* Public variable */
DWORD volatile IR_FreeCNT = 0;
BYTE IR_Error_Flag = 0;
static BYTE IR_Key_code = 0;
static DWORD IR_code=0;
/* Private Function */
DWORD IR_Check_Code(DWORD);



#ifndef NEW_REFERENCE_BOARD
#define HEAD_HIGH	155
#define HEAD_LOW	316
#define BIT1_HIGH	53
#define BIT0_HIGH	16
#define BIT_LOW		21
#else
#define HEAD_HIGH	284
#define HEAD_LOW	580
#define BIT1_HIGH	106
#define BIT0_HIGH	28
#define BIT_LOW		40
#endif

/*----------------------------------------------------------------------
 * Function_Name: IR_IRQ()
 *
 * Description: irq service routine,
 *              receive the remote control signal from IRQ then send MSG to UI
 *
 * Arguments:
 *
 * Return Value: void
 *
 *----------------------------------------------------------------------*/
#if 0
void ShowChar(int i)
{
    switch (i)
    {
    case 0:
        alert('0');
        break;
    case 1:
        alert('1');
        break;
    case 2:
        alert('2');
        break;
    case 3:
        alert('3');
        break;
    case 4:
        alert('4');
        break;
    case 5:
        alert('5');
        break;
    case 6:
        alert('6');
        break;
    case 7:
        alert('7');
        break;
    case 8:
        alert('8');
        break;
    case 9:
        alert('9');
        break;
    }
}
#endif
void DisplayDigit(int x)
{
    int d0, d1, d2, d3, d4, d5, d6, d7;

}

void IR_IRQ(void)
{
    unsigned long int LastCNT=0;
    //gamble return for LA_FP_IR
#if (_TRANSFER_ALI_BOARD_ == _TRANSFER_ALI_BOARD_DISABLE_)
    return;
#endif
    if(MachineState == C_MACHINE_ST_INITIAL)//30608-01jf protect for m3355
    {	//30608-01jf protect for m3355
    }
    else//30608-01jf protect for m3355
    {//30608-01jf protect for m3355

#if (_TRANSFER_ALI_BOARD_ == _TRANSFER_ALI_BOARD_DISABLE_)
#if(_IR_catch_array_testing == Enable) //20030507 Tom Yang

        static  int testcount = 0;
#endif//20030507 Tom Yang
#endif

#if 0
        //writeGPIORW(readGPIORW() | (0x00020000) | 0x80000000);
        //writeGPIODAT(readGPIODAT() & 0x7fffffff | (0x00020000));/* set GPIO ports to High */
        //writeGPIODAT(readGPIODAT() & 0x7fffffff & (~(0x00020000)));/* set GPIO ports to Low */
        asm volatile(".set noreorder
                     li  $2, 0xff101004
                     lw  $3, 0x0($2)
                     or  $3, $3,  0x00020000
                     sw  $3, 0x0($2)
                     nop
                     nop
                     nop
                     li  $4, 0xff101000
                     lw  $5, 0x0($4)
                     and $6, $5,  0x00020000
                     beq $6, $0, set_hi
                     set_lo:
                     and $5, $5,  0xFFFDFFFF
                     sw  $5, 0x0($4)
                     nop
                     nop
                     nop
                     j    endir
                     set_hi:
                     or  $5, $5,  0x00020000
                     sw  $5, 0x0($4)
                     nop
                     nop
                     nop
                     endir:
                     .set    reorder
                     "
                     ::);

#endif






        //	IR_Custom_Code1_standby =IR_Custom_Code1; 	//30124-01jf
        //	IR_Custom_Code2_standby =IR_Custom_Code2;	//30124-01jf

        IR_FreeCNT = getWDTcnt();
        IR_FreeCNT/=141; /*2250/16=140.625*/
        IR_NowCount=IR_FreeCNT;/*Get count Between two interrupts*/
        IR_Between_CNT=IR_NowCount-IR_PreCount;

#if (_TRANSFER_ALI_BOARD_ == _TRANSFER_ALI_BOARD_DISABLE_)
#if(_IR_catch_array_testing == Enable) //20030507 Tom Yang

        if(IR_print_flag == 0)
        {
            arrayA[testcount] = IR_FreeCNT ;
            arrayB[testcount] = IR_Between_CNT ;
            arrayC[testcount] = (real_IR_count++);
            testcount++;

            if(testcount >= 40)
            {
                testcount=0;
                IR_print_flag = 1;
            }
        }
#endif//20030507 Tom Yang
#endif

#if 1/////////////////////////////////////////////////////////////////////////////////

        if((IR_Between_CNT <= 18)||((IR_Between_CNT <= 230)&&(IR_Between_CNT >= 90)))//for cover CPU status 20030507 Tom Yang with experience value
        {
            ;
        }
        else //for cover CPU status 20030507 Tom Yang
        {
            IR_PreCount=IR_NowCount;

#if (_TRANSFER_ALI_BOARD_ == _TRANSFER_ALI_BOARD_DISABLE_)
#if(_IR_catch_array_testing== Enable) //20030507 Tom Yang

            pass_count++;
#endif//20030507 Tom Yang
#endif

            //        if(MachineState == C_MACHINE_ST_INITIAL)//30312-01jf
            //        {	//30312-01jf
            //        }
            //        else//30312-01jf
            //        {//30312-01jf

            if (IR_StepFlag == 0)
            {
                static unsigned char start_flag = 0;

                if ((IR_Between_CNT>=Start_CNT_Low_Band)&&(IR_Between_CNT<=Start_CNT_Hi_Band))
                {
                    IR_StepFlag=1;   /*goto Step1 when next interrupt*/
                    IR_Error_Flag=0; /*init the value*/
                }

                else if ((IR_Between_CNT>=Repeat_CNT_Low_Band)&&(IR_Between_CNT<=Repeat_CNT_Hi_Band))
                {
                    if(LAST_IR_CODE == C_KEY_STEP)
                    {
                        if (bRepeatCount <= 15)   /* wait about 0.2 second  *///HQK 6 7
                            /* 1(sec)/0.108(ms) = 9 */
                            bRepeatCount++;
                        else
                        {GET_IR_CODE = LAST_IR_CODE;}
                    }
                }

                else if(start_flag==1) /* garbage signal testing */
                {
                    IR_Between_CNT += LastCNT;
                    if ((IR_Between_CNT>=Start_CNT_Low_Band)&&(IR_Between_CNT<=Start_CNT_Hi_Band))
                    {
                        IR_StepFlag=1;   /*goto Step1 when next interrupt*/
                        IR_Error_Flag=0; /*init the value*/
                    }
                    start_flag=0;
                    LastCNT=0;
                }
                else if (IR_Between_CNT<=Start_CNT_Hi_Band)
                {
                    start_flag=1;   /* starting garbage signal test */
                    LastCNT=IR_Between_CNT;
                }
                else if (IR_Between_CNT>2500)/*timeout*/
                {
                    IR_Error_Flag=1;
                }
            }
            else if ((IR_StepFlag>=1)&&(IR_StepFlag<=32))/*Get IR_Key*/
            {
                if ((IR_Between_CNT>=_0_CNT_Low_Band) && (IR_Between_CNT <= _0_CNT_Hi_Band))
                {
                    IR_code = IR_code>>1;   /* get bit 0 */
                    IR_StepFlag++;
                }
                else if ((IR_Between_CNT>=_1_CNT_Low_Band)&&(IR_Between_CNT<=_1_CNT_Hi_Band))
                {
                    IR_code = IR_code>>1;    /* get bit 1 */
                    IR_code |= 0x80000000;
                    IR_StepFlag++;
                }
                else
                {
                    IR_StepFlag=0;
                    IR_Error_Flag=1;
                }

                if (IR_StepFlag==33)
                {
                    IR_StepFlag=0;/* Clear IR_StepFlag */
                    IR_Key_code = IR_Check_Code(IR_code);/*check key is valid and return key data code*/
                    if (IR_Error_Flag == 0)
                    {
#if 0 //sean Keycounter

                        tmpGET_IR_CODE = KeyTable[IR_Key_code];
                        if( KeyPassOnCheck||(KeyCounter<MAXKEYCOUNTER)||(tmpGET_IR_CODE==C_KEY_OPEN) )
                        {
                            LAST_IR_CODE = GET_IR_CODE = tmpGET_IR_CODE;
                            bRepeatCount = 0;
                        }
#endif
                        LAST_IR_CODE = GET_IR_CODE = KeyTable[IR_Key_code];
                        bRepeatCount = 0;
                    }
#if 1//sean Keycounter
                    else
                    {
                        GET_IR_CODE = 254;
                        IR_Key_code = 254;
                    }
#endif

                }
            }
            //        }//30312-01jf

        }
#endif///////////////////////////////////////////////////////////////////////////////////0

    }//30608-01jf protect for m3355
}

/*----------------------------------------------------------------------
 * Function_Name: IR_Check_Code()
 *
 * Description: check the customer code and get remote control key code
 *
 * Arguments:
 *     unsigned long int: IN, the code read from IRQ
 *
 * Return Value:
 *     unsigned long int: remote control key code
 *
 *----------------------------------------------------------------------*/
DWORD IR_Check_Code(unsigned long int IR_KeyCode)
{
    unsigned char IR_byte3, IR_byte2, IR_byte1, IR_byte0;

    IR_byte0 = BYTE0(IR_KeyCode);

    if (IR_byte0 == IR_Custom_Code1)
    {
        IR_byte1 = BYTE1(IR_KeyCode);

        if (IR_byte1 == IR_Custom_Code2)
        {
            IR_byte2 = BYTE2(IR_KeyCode);
            IR_byte3 = ~BYTE3(IR_KeyCode);
            if (IR_byte2 == IR_byte3)
            {
                return IR_byte2;
            }
        }
    }
    IR_Error_Flag = 1;
    return 0;
}


#endif



#if 0 //IRC
/*====================================================================
 *
 *  Copyright (C) 1997 Acer Labs, Inc.  All Rights Reserved.
 *
 *  File:   ir.c
 *
 *  Contents: Get IR key code and translate the customer special key code
 *            to Ali physical key code
 *
 *  History:
 *   Date           By         Reason
 *  ===========    =========   ======
 *  21-Jun-1999    Elisa Lee
 *  22-Apr-2001    Dick Ma     Reform
 *      27-Aug-2002             Tom gao         Modify and add it into M3325
 ********************************************************************/

#include <comsub.h>
#include <ui.h>
#include "ir.h"
#include "frntp.h"

#define Uchar	unsigned char
#define Uint	unsigned int
/* Address for Irc of M6311 */
#define IRCR	((volatile int *)0xFF400000)
#define IRSR	((volatile int *)0xFF400004)
#define IRDR	((volatile int *)0xFF400008)

#define	GPIODAT	   0xff101000
#define GPIORW	   0xff101004

/* Basic I/O marco */
#define inb(a)      (*((volatile Uchar *)(a)))
#define inh(a)      (*((volatile Ushort *)(a)))
#define inw(a)	    (*((volatile Uint *)(a)))
#define outb(a,v)      (*((volatile Uchar *)(a))=(v))
#define outh(a,v)      (*((volatile Ushort *)(a))=(v))
#define outw(a,v)      (*((volatile Uint *)(a))=(v))


/* Private variable */
static DWORD IR_PreCount = 0,IR_NowCount = 0,IR_Between_CNT;
static BYTE bRepeatCount = 0;
static WORD IR_StepFlag = 0;
static DWORD LAST_IR_CODE;
/* Public variable */
DWORD volatile IR_FreeCNT = 0;
static BYTE IR_Error_Flag = 0;
static DWORD IR_Key_code = 0;
static DWORD IR_code=0;
/* Private Function */
static DWORD IR_Check_Code(DWORD);

//#define DATABUFSIZE 	1024
#define DATABUFSIZE 	512

#define HEAD_HIGH	1302
#define HEAD_LOW	2604
#define BIT1_HIGH	163
#define BIT0_HIGH	489
#define BIT_LOW		162
#define HEAD_REPEAT_HIGH 651

int	bufferin=0, bufferout=0;
unsigned char Get_Repeat_Code=0;/* get repeat */
unsigned char cuscode1,cuscode2,datacode1,datacode2;
unsigned char rlc_buffer[DATABUFSIZE]={0xff};
unsigned char infra_buffer[DATABUFSIZE]={0xff};

unsigned char gKeyCode[32];
//unsigned long GET_IR_CODE; /* unsigned long 4 byte */

DWORD interruptcount = 0,findh=0,count1=0;
unsigned char gCount;

int HeadType;
int GETIRCODE = 0;
int gHead=0;
int low=0;
int stateL=0;
int stateH=0;
int gHCoordinateF;
int gHCoordinateB;
int gLCoordinateF;
int gLCoordinateB;
#define true    1
#define false   0
int     getcount(void);
unsigned char getdata(void);

BOOL Getirscancode(void);
BOOL FindHead(void);
BOOL FindLow(void);
BOOL JudgeHigh(unsigned short a);
BOOL FindHigh(void);
BOOL JudgeLow(unsigned short a);
void InitKeyCode(void);
BOOL GetKeyCode(void);
void GetChar(void);

/*----------------------------------------------------------------------
 * Function_Name: IR_IRQ()
 *
 * Description: irq service routine,
 *              receive the remote control signal from IRQ then send MSG to UI
 *
 * Arguments:
 *
 * Return Value: void
 *

⌨️ 快捷键说明

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