/****************************************************************************** *_Copyright (c) 2009 Digital Stream Technology Inc. All Rights Reserved. * * Module: dstdduirt.c * * Description * * @author * @version $Revision: 1.1 $ * ******************************************************************************/ #include #include #include #include #include #include #include #include "dsthalcommon.h" #include "dsthallocal.h" #include "dstdduirt.h" #ifdef DMALLOC #include #endif /****************************************************************************** * Global variable declaration ******************************************************************************/ /****************************************************************************** * Imported variable declaration ******************************************************************************/ /****************************************************************************** * Imported function declaration ******************************************************************************/ /****************************************************************************** * Local definitions ******************************************************************************/ /****************************************************************************** * Local typedefs ******************************************************************************/ /****************************************************************************** * Local variables declaration ******************************************************************************/ static int g_IrFD = -1; static int g_KeyFD = -1; /****************************************************************************** * Local function prototypes ******************************************************************************/ static int Init_IRThread(void); static int Init_KeyPadThread(void); static void Terminate_IRThread(void); static void Terminate_KeyThread(void); static int ir_debug = 0; static int key_debug = 0; #if 0 ___Common_Functions___() #endif DHL_RESULT DD_IR_Init(DHL_IR_FORMAT IrFormat) { DHL_RESULT dhlResult = DHL_OK; if ( (IrFormat < DHL_IR_START) || (IrFormat > DHL_IR_END) ) { printf("|%s| This IR format is not supported yet.\n", __FUNCTION__); dhlResult = DHL_FAIL_NO_HARDWARE_SUPPORT; return dhlResult; } // // Open IR device. // // // Init and starts IR thread. // if (Init_IRThread() < 0 ) { printf("%s| ERROR, LINE=%d\n", __FUNCTION__, __LINE__); dhlResult = DHL_FAIL_CORE_DRIVER; } return dhlResult; } DHL_RESULT DD_IR_Close(void) { DHL_RESULT dhlResult = DHL_OK; Terminate_IRThread(); if ( g_IrFD != -1 ) close(g_IrFD); g_IrFD = -1; return dhlResult; } DHL_RESULT DD_IR_SetFormat(DHL_IR_FORMAT IrFormat) { DHL_RESULT dhlResult = DHL_OK; if ( (IrFormat < DHL_IR_START) || (IrFormat > DHL_IR_END) ) { printf("|%s| This IR format is not supported yet.\n", __FUNCTION__); dhlResult = DHL_FAIL_NO_HARDWARE_SUPPORT; return dhlResult; } return dhlResult; } DHL_RESULT DD_IR_SetCustomCode(DS_U16 CustomCode) { DHL_RESULT dhlResult = DHL_OK; return dhlResult; } static int g_IR_ScanTime = IR_REPEAT_TIMEOUT * 10; void DD_IR_SetScanTime(DS_U16 ScanTime) { g_IR_ScanTime = ScanTime; } #if 0 ___IR_Thread___() #endif ///////////////////////////////////////////////////////////////////////////////////////// // // NEC - HDiT ¸®¸ðÄÁÀ¸·Î Å×½ºÆ® °á°ú // ÀÀ´ä¼Óµµ: (Button 1ȸ ÀÔ·Â ÈÄ, DN --> UP Event ¶ß´Â ¼Óµµ) 120 msec // static int g_IrThreadRun = 0; static OS_TASK_ID irId = (OS_TASK_ID)0; //static DS_U32 IRTimeout = 0; void cbIrFunction(int bKeypad, DS_U32 Code, int bPressed) { extern IRCbFunc_t cbIRFunc; DS_U32 curTick = OS_GetTickCount(); if ( ir_debug ) printf("%d.%02d [%s-0x%x-%s]\n", (int)(curTick / 100), (int)(curTick % 100), bKeypad!=DHL_IR_REMOCON ? "KEYPAD" : "REMOCON", (unsigned int)Code, bPressed ? "DN" : "UP"); if ( cbIRFunc ) cbIRFunc( bKeypad, Code, bPressed ); } static void tIR_Thread(DS_U32 arg) { unsigned long ch[4] = {0,0,0,0}; struct pollfd pfd; while (1) { OS_Delay(1); if (g_IrThreadRun == 0) continue; pfd.fd = g_IrFD; pfd.events = POLLIN; pfd.revents = 0; if (poll(&pfd, 1, 0) <= 0) continue; if (read(g_IrFD, ch, 4) <= 0) continue; cbIrFunction( DHL_IR_REMOCON, ch[0], 1 ); } } static int Init_IRThread(void) { if ( g_IrThreadRun == 1 ) { printf("|%s| WARNING: IR thread is already initialized. (IR Thread ID: 0x%08lX)\n", __FUNCTION__, (DS_U32)irId); return 0; } if ( irId == (OS_TASK_ID)0 ) { irId = OS_SpawnTask( tIR_Thread, "tIR_Thread", IR_THREAD_PRIORITY, IR_THREAD_STACKSIZE, 0 ); if ( irId == (OS_TASK_ID)0 ) { printf("|%s| ERROR: Cannot create thread for IR.\n", __FUNCTION__); return -1; } } g_IrThreadRun = 1; return 0; } static void Terminate_IRThread(void) { g_IrThreadRun = 0; } void set_ir_debug(int d) { ir_debug = d; printf("IR Debug: %s (%d)\n", d ? "On" : "Off", d); } #if 0 ___Common_Functions_For_KeyPad___() #endif ///////////////////////////////////////////////////////////////////////////////////////// // // // // static int g_KeyThreadRun = 0; static OS_TASK_ID KeyId = (OS_TASK_ID)0; //static DS_U32 KeyPadTimeout = 0; static int g_KeyPad_ScanTime = 100; DHL_RESULT DD_KeyPad_Init(void) { DHL_RESULT dhlResult = DHL_OK; // // Init and starts IR thread. // if (Init_KeyPadThread() < 0 ) { printf("%s| ERROR, LINE=%d\n", __FUNCTION__, __LINE__); dhlResult = DHL_FAIL_CORE_DRIVER; } return dhlResult; } DHL_RESULT DD_KeyPad_Close(void) { DHL_RESULT dhlResult = DHL_OK; Terminate_KeyThread(); if ( g_KeyFD != -1 ) close(g_IrFD); g_KeyFD = -1; return dhlResult; } void DD_KeyPad_SetScanTime(DS_U16 ScanTime) { g_KeyPad_ScanTime = ScanTime; } static void tKeyPad_Thread(DS_U32 arg) { while ( 1 ) { OS_mDelay(g_KeyPad_ScanTime); } } static int Init_KeyPadThread(void) { if ( g_KeyThreadRun == 1 ) { printf("|%s| WARNING: IR thread is already initialized. (IR Thread ID: 0x%08lX)\n", __FUNCTION__, (DS_U32)irId); return 0; } if ( KeyId == (OS_TASK_ID)0 ) { irId = OS_SpawnTask( tKeyPad_Thread, "tKeyPad_Thread", IR_THREAD_PRIORITY, IR_THREAD_STACKSIZE, 0 ); if ( irId == (OS_TASK_ID)0 ) { printf("|%s| ERROR: Cannot create thread for IR.\n", __FUNCTION__); return -1; } } g_IrThreadRun = 1; return 0; } static void Terminate_KeyThread(void) { g_IrThreadRun = 0; } void set_key_debug(int d) { key_debug = d; printf("KEY Debug: %s (%d)\n", d ? "On" : "Off", d); }