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

📄 ir_api.c

📁 SAMSUNG 5009的源代码
💻 C
字号:
/******************************************************************************
 * File name  : IR_api.c                                                      *
 * Start date :                                                               *
 * By         : S.C.Kwon                                                      *
 * Contact    :                                                               *
 * Description: Remocon Receive Low Level API                                  *
 * $Log:$                                                                     *
 ******************************************************************************
 */  

/******************************************************************************
 *   INCLUDES                                                                 *
 ******************************************************************************/
#include "Basic_typedefs.h"
#include "CUSTOM/Custom_option.h"
#include "OS/OS_abstract.h"
#include "API/SH_types.h"
#include "API/SH_api.h"
#include "API/SH_reg.h"

#include "CUSTOM/Ir_api.h"

/******************************************************************************
 *   Global variable                                                         
 *****************************************************************************/
volatile BYTE4	gIr_dev_type = IR_CLOCK_DEV_8192; /* for 117MHz */
SysHisr_t		gIrKeyHisr;

#define			TIME_PRE		SH_HCLK/2000000

extern FP_IFCALLBACK AttachedKeySendCallback;

enum { 
	IR_IDLE, 
	IR_LEADER, 
	IR_BITS, 
	IR_REPEAT1, 
	IR_REPEAT2 ,
	IR_DOUBLE1,
	IR_DOUBLE2
};


#define IR_REPEAT_COUNT					3


static unsigned short 			gIR_Key;
static int 					gIR_Bit_Count;
static unsigned long 			gIR_Custom_Buffer;	
static unsigned int				gIR_State;
static unsigned int 			gIR_Repeat_Count;

static unsigned short 			gIR_HISR_Msg;	/* Copy of 	gIR_Data_Buffer */

/******************************************************************************
 * Function name  : Timer_Set 
 * Arguments      :
 * Return         :
 * By             :
 * Description    :
 ******************************************************************************/
VOID Timer_Set(Timer_Select_t timer_select, UINT time_usec)
{
	UINT	timer_con, timer_data;
	if(time_usec > (0xffff<<5))	return;					//TimerErrType_t=FALSE;	

	else if(time_usec > (0xffff<<3)){
			timer_con  = (1<<16) | (1<<12) | (3<<8);	// PCLK/64
			timer_data = (time_usec >> 5);
			}

	else if(time_usec > (0xffff<<1)){
			timer_con = (1<<16) | (1<<12) | (2<<8);		// PCLK/16
			timer_data = (time_usec >> 3);
			}

	else if(time_usec > (0xffff<<0)){
			timer_con = (1<<16) | (1<<12) | (1<<8);		// PCLK/4
			timer_data = (time_usec >> 1);
			}

	else	{
			timer_con = (1<<16) | (1<<12) | (0<<8);		// PCLK/2 (Default)
			timer_data = (time_usec >> 0);
			}
	
	
	switch(timer_select) {
		
		case TimerA:
				rTAREF = (UINT)(TIME_PRE-1);
				rTACON = timer_con;							// Interval mode
				rTADATA1 = (timer_data-1);					// 
				rTACMD = 3;									// Timer start
				break;
		
		case TimerB:
				rTBREF = (UINT)(TIME_PRE-1);
				rTBCON = timer_con;							// Interval mode
				rTBDATA1 = (timer_data-1);					// 
				rTBCMD = 3;									// Timer start
				break;

		case TimerC:
				rTCREF = (UINT)(TIME_PRE-1);
				rTCCON = timer_con;							// Interval mode
				rTCDATA1 = (timer_data-1);					// 
				rTCCMD = 3;									// Timer start
				break;
		
		case TimerD:
				rTDREF = (UINT)(TIME_PRE-1);
				rTDCON = timer_con;							// Interval mode
				rTDDATA1 = (timer_data-1);					// 
				rTDCMD = 3;									// Timer start
				break;
		default:														break;
		
		}

}

/******************************************************************************
 * Function name  : IR_Variable_Init 
 * Arguments      :
 * Return         :
 * By             :
 * Description    :
 ******************************************************************************/
VOID IR_Variable_Init(VOID)
{
	gIR_Key=0x0000;
	gIR_Bit_Count=0;
	gIR_Custom_Buffer=0x00;	
	gIR_State=IR_IDLE;
	gIR_Repeat_Count=0;
}

/******************************************************************************
 * Function name  : IR_Send_Msg 
 * Arguments      :
 * Return         :
 * By             :
 * Description    :
 ******************************************************************************/
VOID CheckIcon(unsigned char key);

VOID IR_Send_Msg(USHORT IR_Key, SINT Para)
{
	Para = 0;	/* for no warning */
	gIR_HISR_Msg = IR_Key;
	SysPrintf("\n@@@@IR_Send_Msg [%x] / %x@@@@@ ", IR_Key, gIR_State);
	SysActivateHisr( &gIrKeyHisr, 0);	/* Acrivate Hisr */
}

//0 mean normal key
//0xFF mean repeat key
//other means long key

const unsigned char IrSetArray[] = {
//0x00	
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0x10
0x00,0x00,0x00,0x00,  0x00,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0x20
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0x30
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0x40	
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0x50
0x00,0x00,0x00,0x00,  0x00,0x00,0xFF,0x00,		/* >>> @: 5008CHN-XXX. oms 050227 CONTINOUS KEY VOL+/- */
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0x60
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0x70
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0x80	
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0x90
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0xA0
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0xB0
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0xC0	
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0xD0
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0xE0
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
//0xF0
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,
};


/******************************************************************************
 * Function name  : IR_IsrInterrupt 
 * Arguments      :
 * Return         :
 * By             :
 * Description    :
 ******************************************************************************/
VOID IR_LisrInterrupt(VOID)
{
    static USHORT ir_status;
    static USHORT ir_data;

    ir_status = (USHORT)rIRCON;//IRcon register has 4 bytes altogether

    if(ir_status & 01<<Ir_cap_int) //if capture interrupt
    {

    		/* 2005/09/07 : Park,HeeSang - Start */
		while( !(rIRCON & 0x40) )	//while( rIRCON & 0x40 )
		/* 2005/09/07 : Park,HeeSang - End */
		{
			ir_data = rIRDAT;  //read data from the register IRDAT
			if((ir_data >= IR_READ_PULSE_MIN) && (ir_data <= IR_READ_PULSE_MAX))
			{
				gIR_State = IR_BITS;
				gIR_Custom_Buffer = 0;
				gIR_Bit_Count = 0;
			}
			else if((gIR_State == IR_BITS)&&
				(((ir_data >= IR_DATA_ZERO_MIN) && (ir_data <= IR_DATA_ZERO_MAX))||
				((ir_data >= IR_DATA_ONE_MIN) && (ir_data <= IR_DATA_ONE_MAX)))
				){
	//save data
				gIR_Custom_Buffer>>=1;
				if((ir_data >= IR_DATA_ONE_MIN) && (ir_data <= IR_DATA_ONE_MAX))
					gIR_Custom_Buffer|=0x80000000;
				gIR_Bit_Count++;

				if(gIR_Bit_Count>=32){
					//SysPrintf("\n gIR_Custom_Buffer = :0x%lx count = %d \n",gIR_Custom_Buffer,gIR_Bit_Count);

					gIR_Bit_Count = 0;
					if( (gIR_Custom_Buffer & 0x0000FFFF)      == IR_CUSTOM_CODE )
					{
						gIR_Key = (gIR_Custom_Buffer>>16)&0xff;
						
						IR_Send_Msg(gIR_Key, 0);		
						if(IrSetArray[gIR_Key]==0){
							gIR_State = IR_IDLE;
						}
						else{
							gIR_State = IR_REPEAT1;
							gIR_Repeat_Count = 0;
						}					
					} else {				
	//not allow repeat key
						gIR_State = IR_IDLE;
					}
				}
			}
	    		/* 2005/09/07 : Park,HeeSang - Start */
//			else if((gIR_State == IR_DOUBLE1)||(gIR_State == IR_REPEAT1)){
			else if( gIR_State == IR_REPEAT1 ){
			/* 2005/09/07 : Park,HeeSang - End */
				gIR_State++;
			}
			else if((gIR_State == IR_REPEAT2)&&
				(ir_data>=IR_DATA_REPEAT_MIN)&&
				(ir_data<=IR_DATA_REPEAT_MAX)
				)
			{
				if(gIR_Repeat_Count<IR_REPEAT_COUNT)
					gIR_Repeat_Count++;
				else{
					IR_Send_Msg(gIR_Key, 0);
				}
				gIR_State = IR_REPEAT1;
			}
    		/* 2005/09/07 : Park,HeeSang - Start */
			else{
				/* Recover the original source */
				gIR_State = IR_IDLE;
			}
		/* 2005/09/07 : Park,HeeSang - End */
		}
		
		IrInt_Clr(Ir_cap_int);                  /* Interrupt pending bit clear */
	}


	Intclr_Scr(IR_INT);                     /* Source pending bit clear    */
	Intclr_Pnd(IR_INT);                     /* Interrupt pending bit clear */
}


/******************************************************************************
 * Function name  : IR_Hisr 
 * Arguments      : 
 *		IN	
 * Return         : VOID
 * By             :	SunChul Kwon, modified by Taejin Kwon
 * Description    : 
 ******************************************************************************/
VOID IR_Hisr(VOID)
{
	(*AttachedKeySendCallback)( gIR_HISR_Msg, 0 );	
}

// disable Timer B in 5008. 2005.05.18. by CKLee.
#if (_USE_5008 || _USE_5010 || _USE_5005 || _USE_5009 || _USE_5015)
#else
/******************************************************************************
 * Function name  : IR_TimerLisr 
 * Arguments      : 
 *		IN	
 * Return         : VOID
 * By             :	SunChul Kwon, modified by Taejin Kwon
 * Description    : 
 ******************************************************************************/
VOID IR_TimerLisr( VOID )
{
	rTBCON = rTBCON;
	Intclr_Scr(INT_TIMERB);			// Source pending bit clear
	Intclr_Pnd(INT_TIMERB);	
}
#endif

/******************************************************************************
 * Function name  : IR_Init 
 * Arguments      : 
 *		IN		BYTE1	ir_dev_type
 *						#define 	IR_CLOCK_DEV_1024	1024
 * 						#define 	IR_CLOCK_DEV_2048	2048
 *						#define 	IR_CLOCK_DEV_4096	4096
 *						#define 	IR_CLOCK_DEV_8192	8192
 * Return         : VOID
 * By             :	SunChul Kwon, modified by Taejin Kwon
 * Description    : 
 ******************************************************************************/
VOID IR_Init( BYTE4 ir_dev_type )
{

	SysLisrEntryPtr_t temp_lisr; 
	rIRCON = 0x23B;					// FIFO full + Cap Interrupt Enable , PCLK/8192, falling edge interrupt

	IR_Variable_Init();

	rIRCON = rIRCON;	/* Reset Status */

	SysRegisterLisr(IR_INT, (SysLisrEntryPtr_t)IR_LisrInterrupt, temp_lisr,0);
	Enable_Int(IR_INT);
	SysCreateHisr( &gIrKeyHisr, "IR_HISR",(SysHisrEntryPtr_t)IR_Hisr,
				1, IR_HISR_SIZE, SYS_SYSTEM_POOL );	

// disable Timer B in 5008. 2005.05.18. by CKLee.
#if (_USE_5008 || _USE_5010 || _USE_5005 || _USE_5009 || _USE_5015)
#else
#if defined(_USE_IDLE_)
	/* Timer init for >>|, |<< */
	if( (rRSTSR & 0x7) == 0x2 )	/* S/W Reset */
	{	
		SysRegisterLisr(INT_TIMERB, (SysLisrEntryPtr_t)IR_TimerLisr, temp_lisr,0);	
		Enable_Int(INT_TIMERB);				// INT Enable (秦寸 MASK bit阑 clear)
		Timer_Set(TimerB, 500);	
	} else {
		//SysRegisterLisr(INT_TIMERB, (SysLisrEntryPtr_t)ADC_CheckTimerInIdle, temp_lisr, 0);
		Enable_Int(INT_TIMERB);				// INT Enable (秦寸 MASK bit阑 clear)
		Timer_Set(TimerB, 10000);	
	}
#else
	SysRegisterLisr(INT_TIMERB, (SysLisrEntryPtr_t)IR_TimerLisr, temp_lisr,0);	
	Enable_Int(INT_TIMERB);				// INT Enable (秦寸 MASK bit阑 clear)
	Timer_Set(TimerB, 500);	
#endif	
#endif

}

/* end of Ir_api.c */

⌨️ 快捷键说明

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