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

📄 rc6_ir.c

📁 Zoran V966 DVD 解码 Soc芯片的源程序
💻 C
📖 第 1 页 / 共 2 页
字号:

#include "Config.h"		// Global Configuration - do not remove!

#ifdef D_REMOTE_RC6_FORMAT

#include "Kernel\ker_api.h"
#include "Kernel\eventdef.h"
#include "CPU\cpu_api.h"
#include "Playcore\Timing\Timing.h"
#include "Playcore\Coremain\coremain.h"
#include "Playcore\Coremain\coredefs.h"
#include "Playcore\Coremain\coregdef.h"
#include "Devices\Remote\ir_api.h"
#include "Devices\Remote\ir_ll.h"
#include "Devices\Remote\rc6_ir\rc6_ir.h"
#include "UI_Manager\UI_Input\ui_input_ir.h"
#if defined(D_HOLD_SKIP_2S_AS_FAST_SCAN)||defined(D_HOLD_STOP_3S_AS_EJECT_KEY)
#include "Kernel\Timers\Timers.h"
#include "CoreAPI\CoreAPI.h"
#ifdef I96_CPU_POWER_DOWN
#include "Dec_Power.h"
#endif

#define IRKC_NULL 0xFF
#define HOLDKEY_TIMEOUT_TIME 220 //millisecond, the time slice between two repeated skip key

#define HOLDKEY_CLEAR_TIMEOUT_TIME  300000UL

static UINT8 hHoldTimer = NULL; //the handler of the timer
static BYTE	lastKey = 0xFF; //to remember what is pressed and held
#endif

#ifdef D_HOLD_STOP_3S_AS_EJECT_KEY
#define STOPKEY_DELAY  0x1c //counter value for about 3 seconds
#endif

#ifdef D_HOLD_SKIP_2S_AS_FAST_SCAN
#define SKIPKEY_DELAY  0x12 //counter value for about 2 seconds
#define SKIPKEY_DELAY_FAST 0x8 //counter value for about 1 seconds
#endif //D_HOLD_SKIP_2S_AS_FAST_SCAN

extern CONST WORD g_ir_system_code;
extern CONST WORD g_ir_power_key_code;
extern CONST WORD g_ir_eject_key_code;

#ifdef I96_CPU_POWER_DOWN
extern BOOL bPowerUpKeyPressed;
extern BOOL bWakeFromPowerDown;
#endif

#define RC6_GROUPSIZE	        8			// bits
#define RC6_CODESIZE		8			// bits



#define RC6_SHORTPULSE 444UL
#define RC6_JITTER     220UL //200UL
#define RC6_LONGPULSE  888UL
#define RC6_HEADPULSE (6*RC6_SHORTPULSE)


// State of the remote key decoder
#define ERROR		   0
#define IDLE	    	1
#define HEADER1      2
#define HEADER2      3
#define HEADER3      4
#define MODE         5
#define REVERSE      6
#define DECODE		   7
#define RESYNC		   8

#define REPEAT_DELAY	5    // pre-delay before repeating.
#define REPEAT_STEP 2     // delay between repeated events.



#if defined(D_HOLD_SKIP_2S_AS_FAST_SCAN)||defined(D_HOLD_STOP_3S_AS_EJECT_KEY)
/**********************************************************************************
 * Name			:	HoldSkipTimerIR
 * Purpose		:	The timeout function for hold skip key, when timeout happens, it will send out
 *                                the skip key user pressed.
 * Input			:   
 * Return Value	:
 * Description		:
 * Comments		:
**********************************************************************************/
#pragma argsused
static void HoldSkipTimerIR(UINT8 hTimer)
{
	if (IRKC_SKIPB == lastKey || IRKC_SKIPF == lastKey || IRKC_STOP == lastKey)
	send_remote_event((WORD)KEY_SOURCE_IR|lastKey);
	
	//clear the timer
	if (hHoldTimer != NULL)
	{
		timer_service_delete(hHoldTimer); //use htimer to kill itself
		hHoldTimer = NULL;
	}
	lastKey = IRKC_NULL;
}
#endif //D_HOLD_SKIP_2S_AS_FAST_SCAN

void ir_init(void)
{
	ir_interrupt_init( FALLING_EDGE );
}


#ifdef ENABLE_REDUCE_CPU_FREQUENCY_FOR_STANDBY
#define NEW_RC6_JITTER    100UL
#define NEW_RC6_HEADPULSE 630UL
extern BYTE g_ReduceCPUFrequency;
#endif


void ir_isr( void )
{
	static BYTE interruptTypeFlag = 0;
	static BYTE state = IDLE;
	static BYTE bitCount;
	//static BYTE decode;
	static BYTE group;
	static BYTE code;
	static BYTE oldcode;
	static BYTE bit = 0;
	static BYTE check = 0;
	static BYTE repeating = 0;
	static BYTE repeatDelay = REPEAT_DELAY;	// Repeat code counter
	static BYTE repeatStep=0;

	static DWORD timeCountOld;
  	
	/* henry start */
	//static BYTE    model;                /* mode value */
	static BYTE    border;              /*indicator of a border of long cycle*/
	static BYTE    start;               /* indicator of starting next segment */
	/* henry end */
        
	DWORD timeCount;
	DWORD deltaTime;

	BYTE validRepeat = 0;
	BYTE key = 0;

/* for the Philips project */
#if defined(D_HOLD_SKIP_2S_AS_FAST_SCAN)||defined(D_HOLD_STOP_3S_AS_EJECT_KEY)
	static BYTE	holdkey_repeatDelay = 0;
#endif

#ifdef I96_CPU_POWER_DOWN
    if (bWakeFromPowerDown == TRUE)
    {
        DEC_PowerCpu(TRUE);       
    }
#endif

	timeCount =cpu_gen_timer();

	//deltaTime = timeCount - timeCountOld;
	deltaTime = timing_get_diff(timeCountOld, timeCount);

	timeCountOld = timeCount;

#if defined(D_HOLD_SKIP_2S_AS_FAST_SCAN)||defined(D_HOLD_STOP_3S_AS_EJECT_KEY)
	if (deltaTime > HOLDKEY_CLEAR_TIMEOUT_TIME)
	{
		//If longer than 1s without key input
		lastKey = IRKC_NULL;
	}
#endif       

	if (!interruptTypeFlag)
	{
		ir_interrupt_set_edge( RISING_EDGE );
		interruptTypeFlag = 1;
	}
	else
	{
		ir_interrupt_set_edge( FALLING_EDGE );
		interruptTypeFlag = 0;
	}

	switch (state) {

		case ERROR:
			// to be filled later when it is needed.
			state = IDLE;
			
		case IDLE:
			bitCount = 0;
			//model = 0;
			group = 0;
			code = 0;
			border = 0;
			start = 0;
			bit = 1;
                         
			if(interruptTypeFlag == 1)
				state = HEADER1;
			else
				state = ERROR;
			break;
			
		case HEADER1:
			if(deltaTime - RC6_JITTER < RC6_HEADPULSE && RC6_HEADPULSE < deltaTime + RC6_JITTER)
				state = HEADER2;
#ifdef ENABLE_REDUCE_CPU_FREQUENCY_FOR_STANDBY
			else if (g_ReduceCPUFrequency != 1 && deltaTime - NEW_RC6_JITTER < NEW_RC6_HEADPULSE && deltaTime + NEW_RC6_JITTER > NEW_RC6_HEADPULSE)
			{
				state = HEADER2;
			}
#endif
			else
				state = ERROR;
			break;
		        
		case HEADER2:
			if(deltaTime - RC6_JITTER < RC6_LONGPULSE && RC6_LONGPULSE < deltaTime + RC6_JITTER)
				state = HEADER3;
			else
				state = ERROR;
			break;
	        
		case HEADER3:
			if(deltaTime - RC6_JITTER < RC6_SHORTPULSE && RC6_SHORTPULSE < deltaTime + RC6_JITTER)                                                	
				state = MODE;
			else
				state = ERROR;
			break;
                        
		case MODE:
			if(deltaTime - RC6_JITTER < RC6_LONGPULSE && RC6_LONGPULSE < deltaTime + RC6_JITTER)
			{                         
				if(border)
				{
					state = ERROR;
					border = 0;
					break;
				}
				bit = !bit;
				bitCount++;
				//model <<= 1;
				//model |= bit & 1;
			}        
			else if(deltaTime - RC6_JITTER < RC6_SHORTPULSE && RC6_SHORTPULSE < deltaTime + RC6_JITTER)
			{
				if(border)
				{
					border = 0;
					bitCount++;
					//model <<= 1;
					//model |= bit & 1;
				}
				else
					border = 1;
			}
			else 
			{
				state = ERROR;
				break;
			}        
			if(bitCount == 3)
			{
				state = REVERSE;
				start = 1;
				bitCount = 0;
			}     
			break;     
                        
		case REVERSE:
			if(deltaTime - RC6_JITTER < RC6_SHORTPULSE && RC6_SHORTPULSE < deltaTime + RC6_JITTER)                         
			{
				if(border)
					state = ERROR;
				else
				{
					border = 1;
					start = 0;
				}      
			}
			else if(deltaTime - RC6_JITTER < RC6_LONGPULSE && RC6_LONGPULSE < deltaTime + RC6_JITTER)                         
			{
				if(!border)
					state = ERROR;
				else      
					state = DECODE;
			}
			else if(deltaTime - RC6_JITTER < (RC6_LONGPULSE + RC6_SHORTPULSE) 
                                                && (RC6_LONGPULSE + RC6_SHORTPULSE) < deltaTime + RC6_JITTER)                         
			{
				if(start)
				{
					start = 0;
					bit = !bit;
					state = DECODE;
				}
				else
					state = ERROR;
			}
			else
				state = ERROR;
			if(state == DECODE)
			{
				if((bit & 1) ^ check)
					repeating = 0;
				else 
					repeating = 1;
				check = bit & 1;       
				start = 1;
				border = 0;
			}
			break;
                        
		case DECODE:
			if (deltaTime - RC6_JITTER < RC6_SHORTPULSE  &&  RC6_SHORTPULSE < deltaTime + RC6_JITTER)
			{
				if(start)
					state = ERROR;
				else if(border)
				{
					border = 0;

⌨️ 快捷键说明

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