appblast.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:33k
- /* =======================
- * IMPROVEMENTS THOUGHT OF
- * =======================
- *
- * =====================
- * MODIFICATION HISTORY:
- * =====================
- *
- * Date Initials Modification
- * ---- -------- ------------
- * 18.03.2002 TM CREATED
- * 03.02.03 TM Adapt to new STBLAST
- * 03.08.03 TM Adapt to 5517 mboard
- */
- /* Includes --------------------------------------------------------------- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "stlite.h" /* System */
- #include "stdevice.h"
- #include "stddefs.h"
- #include "stcommon.h"
- #include "stsys.h"
- #include "stblast.h" /* STAPI */
- #include "stboot.h" /* Dependencies */
- #include "sttbx.h"
- #include "stevt.h"
- #include "usif.h"
- #include "sing_data.h"
- #include "appblast.h"
- #include "blast.h"
- #include "rckeymap.h"
- #include "osp.h"
- #if 0 /* BLOCK COMMENTED OUT by Louie on 9/23/2004 */
- #undef USE_RC5_REMOTE
- #endif /* BLOCK COMMENT */
- #pragma ST_device (device_access8_t)
- typedef volatile U8 device_access8_t;
- #ifdef INTEGRATE_FRONT_PANEL_KEYBOARD
- #define PIO_OUT 0
- #define PIO_OUT_SET (1 * 4)
- #define PIO_OUT_CLR (2 * 4)
- #define PIO_IN (4 * 4)
- #define PIO_C0 (8 * 4)
- #define PIO_C0_SET (9 * 4)
- #define PIO_C0_CLR (10 * 4)
- #define PIO_C1 (12 * 4)
- #define PIO_C1_SET (13 * 4)
- #define PIO_C1_CLR (14 * 4)
- #define PIO_C2 (16 * 4)
- #define PIO_C2_SET (17 * 4)
- #define PIO_C2_CLR (18 * 4)
-
- #define KEYBOARD_SENSE_PIO_ADDRESS PIO_3_BASE_ADDRESS
- #define KEYBOARD_SCAN1_PIO_ADDRESS PIO_4_BASE_ADDRESS
- #define KEYBOARD_SCAN1_BIT PIO_BIT_0 /* PIO2.0 */
- #define KEYBOARD_SENSE_MASK 0xF0 /*0x0F*/ /*four key bits */
- #define NO_OF_FRONT_PANEL_KEY_SENSE_BITS 4
- device_access8_t * Keyboard_sense_p = (device_access8_t *) KEYBOARD_SENSE_PIO_ADDRESS;
- /*
- * VICKY - 08.10.98
- * modified the bounce time from 100msec to 1sec
- */
- #define KEYBOARD_BOUNCE_SETTLE_TIME ( ST_GetClocksPerSecond()/ 10 ) /* 100 mSec */
- #define KEYBOARD_SCAN_LINE_SETTLE_TIME ( ST_GetClocksPerSecond() / 1000 ) /* 1 mSec */
- #define READ_KEY_BITS
- ( (* ( Keyboard_sense_p + PIO_IN ) /*>>1*/) & KEYBOARD_SENSE_MASK )
- #endif /*INTEGRATE_FRONT_PANEL_KEYBOARD*/
- #define SWITCH1_MASK 0x10 /* POWER_STANDBY */
- #define SWITCH2_MASK 0x01 /* VOL_DOWN_CUM_LEFT_ARROW_KEY */
- #define SWITCH3_MASK 0x20 /* VOL_UP_CUM_RIGHT_ARROW_KEY */
- #define SWITCH4_MASK 0x02 /* PROG_NEXT_CUM_UP_ARROW_KEY */
- #define SWITCH5_MASK 0x40 /* PROG_NEXT_CUM_DOWN_ARROW_KEY */
- #define SWITCH6_MASK 0x04 /* MENU_KEY */
- #define SWITCH7_MASK 0x80 /* SELECT_KEY */
- #define SYMBOL_BUFFER_SIZE 200
- #define REMOTE_KEY_BUFFER_SIZE 20
- #define SOFTWARE_UPDATE_ID "1.0"
- /*static message_queue_t *pstUsifMsgQueue;*/
- static task_t *pKeyboardRCTask;
- static task_t *pBlastReadTask;
- static STBLAST_ProtocolParams_t RcProtocolReceive;
- //static STBLAST_ProtocolParams_t RcProtocolTransmit;
- static U8 aucRemoteKeyBuffer [ REMOTE_KEY_BUFFER_SIZE ];
- semaphore_t *psemRemoteKeySensedSignal;
- #ifdef TM_BLAST /*TMTM*/
- extern semaphore_t BlasterSemaphoreRead;
- extern semaphore_t BlasterSemaphoreWrite;
- #else
- extern semaphore_t BlasterSemaphore;
- #endif
- #if defined (CHENG_ENABLE_STILL_LAYER)||defined (CHENG_ENABLE_STILL_VIEWPORT)
- extern BOOL DEMO_OPEN;
- #endif
- extern void SRDBE_PrintXpdrDatabase(void);
- extern void SRDBE_PrintProgDatabase(void);
- extern void NVM_RWTest(void);
- /*****************************************************************************
- CODE
- *****************************************************************************/
- //TMTM
- #ifdef TMGFX_TEST
- extern int Red_Test( void );
- extern int Green_Test( void );
- extern int Blue_Test( void );
- extern int Yellow_Test( void );
- extern int GFX_Cls( void );
- void Keycallback(U8 key)
- {
- STTBX_Print(("999key value received: %dn", key));
- switch(key)
- {
- case rc_kKeyRed:
- Red_Test();
- break;
- case rc_kKeyGreen:
- Green_Test();
- break;
- case rc_kKeyBlue:
- Blue_Test();
- break;
- case rc_kKeyYellow:
- Yellow_Test();
- break;
- case rc_kKeyExit:
- GFX_Cls();
- break;
- }
- //if (key != rc_kKeyInvalid)
- //SRCMD_UserInputCallBack(key);
- }
- #endif
- /*****************************************************************************
- PROTOCOL
- *****************************************************************************/
- /*****************************************************************************
- BLAST_ReceiveProtocol()
- Description: This function allows to choose the correct reception protocol.
- *****************************************************************************/
- STBLAST_ProtocolParams_t BLAST_ReceiveProtocol(int Name)
- {
- STBLAST_ProtocolParams_t RcProtocol;
- /*-- Remote Control Name --*/
- switch(Name)
- {
- case 0 :
- /*----------------- Sony Remote Control ------------------*/
- RcProtocol.UserDefined.Coding = STBLAST_CODING_PULSE;
- RcProtocol.UserDefined.SubCarrierFreq = 40000;
- RcProtocol.UserDefined.NumberStartSymbols = 1;
- RcProtocol.UserDefined.NumberStopSymbols = 0;
- RcProtocol.UserDefined.HighDataSymbol.MarkPeriod = 600;
- RcProtocol.UserDefined.HighDataSymbol.SymbolPeriod = 1200;
- RcProtocol.UserDefined.LowDataSymbol.MarkPeriod = 1200;
- RcProtocol.UserDefined.LowDataSymbol.SymbolPeriod = 1800;
- RcProtocol.UserDefined.NumberPayloadBits = 12;
- RcProtocol.UserDefined.StartSymbols[0].MarkPeriod = 2400;
- RcProtocol.UserDefined.StartSymbols[0].SymbolPeriod = 3000;
- break;
- case 1 :
- /*----------------- ST Remote Control --------------------*/
- RcProtocol.UserDefined.Coding = STBLAST_CODING_SPACE;
- RcProtocol.UserDefined.SubCarrierFreq = 5000;
- RcProtocol.UserDefined.NumberStartSymbols = 0;
- RcProtocol.UserDefined.NumberStopSymbols = 0;
- RcProtocol.UserDefined.HighDataSymbol.MarkPeriod = 250;
- RcProtocol.UserDefined.HighDataSymbol.SymbolPeriod = 7600;
- RcProtocol.UserDefined.LowDataSymbol.MarkPeriod = 250;
- RcProtocol.UserDefined.LowDataSymbol.SymbolPeriod = 5100;
- RcProtocol.UserDefined.NumberPayloadBits = 12;
- break;
- case 2 :
- /*--------- Force Remote Control ------------*/
- RcProtocol.UserDefined.Coding = STBLAST_CODING_SPACE;
- RcProtocol.UserDefined.SubCarrierFreq = 38000;
- RcProtocol.UserDefined.NumberStartSymbols = 10;
- RcProtocol.UserDefined.NumberStopSymbols = 0;
- RcProtocol.UserDefined.HighDataSymbol.MarkPeriod = 500;
- RcProtocol.UserDefined.HighDataSymbol.SymbolPeriod = 2000;
- RcProtocol.UserDefined.LowDataSymbol.MarkPeriod = 500;
- RcProtocol.UserDefined.LowDataSymbol.SymbolPeriod = 1000;
- RcProtocol.UserDefined.NumberPayloadBits = 8;
- /* Start symbol */
- RcProtocol.UserDefined.StartSymbols[0].MarkPeriod = 8000;
- RcProtocol.UserDefined.StartSymbols[0].SymbolPeriod = 12000;
- /* Address symbols */
- RcProtocol.UserDefined.StartSymbols[1].MarkPeriod = 500; /* 0*/
- RcProtocol.UserDefined.StartSymbols[1].SymbolPeriod = 1000;
- RcProtocol.UserDefined.StartSymbols[2].MarkPeriod = 500; /* 0*/
- RcProtocol.UserDefined.StartSymbols[2].SymbolPeriod = 1000;
- RcProtocol.UserDefined.StartSymbols[3].MarkPeriod = 500; /* 0*/
- RcProtocol.UserDefined.StartSymbols[3].SymbolPeriod = 1000;
- RcProtocol.UserDefined.StartSymbols[4].MarkPeriod = 500; /* 1*/
- RcProtocol.UserDefined.StartSymbols[4].SymbolPeriod = 2000;
- RcProtocol.UserDefined.StartSymbols[5].MarkPeriod = 500; /* 0*/
- RcProtocol.UserDefined.StartSymbols[5].SymbolPeriod = 1000;
- RcProtocol.UserDefined.StartSymbols[6].MarkPeriod = 500; /* 0*/
- RcProtocol.UserDefined.StartSymbols[6].SymbolPeriod = 1000;
- RcProtocol.UserDefined.StartSymbols[7].MarkPeriod = 500; /* 0*/
- RcProtocol.UserDefined.StartSymbols[7].SymbolPeriod = 1000;
- RcProtocol.UserDefined.StartSymbols[8].MarkPeriod = 500; /* 0*/
- RcProtocol.UserDefined.StartSymbols[8].SymbolPeriod = 1000;
- /* Padding symbol */
- RcProtocol.UserDefined.StartSymbols[9].MarkPeriod = 500;
- RcProtocol.UserDefined.StartSymbols[9].SymbolPeriod = 4500;
- break;
- case 3 :
- /*--------- Complete for other Remote Control ------------*/
- RcProtocol.UserDefined.Coding = 0;
- RcProtocol.UserDefined.SubCarrierFreq = 0;
- RcProtocol.UserDefined.NumberStartSymbols = 1;
- RcProtocol.UserDefined.NumberStopSymbols = 1;
- RcProtocol.UserDefined.HighDataSymbol.MarkPeriod = 0;
- RcProtocol.UserDefined.HighDataSymbol.SymbolPeriod = 0;
- RcProtocol.UserDefined.LowDataSymbol.MarkPeriod = 0;
- RcProtocol.UserDefined.LowDataSymbol.SymbolPeriod = 0;
- RcProtocol.UserDefined.NumberPayloadBits = 0;
- RcProtocol.UserDefined.Delay = 0;
- RcProtocol.UserDefined.StartSymbols[0].MarkPeriod = 0;
- RcProtocol.UserDefined.StartSymbols[0].SymbolPeriod = 0;
- RcProtocol.UserDefined.StopSymbols[0].MarkPeriod = 0;
- RcProtocol.UserDefined.StopSymbols[0].SymbolPeriod = 0;
- break;
- }
- return RcProtocol;
- }
- static rc_navKeyStroke_t eCurKeyCode = rc_KeyInvalid;
- rc_navKeyStroke_t KB_IR_GetCurKeyCode(void)
- {
- return eCurKeyCode;
- }
- static BOOL bKeyLock = FALSE;
- BOOL KB_IR_GetKeyLock(void)
- {
- return bKeyLock;
- }
- void KB_IR_SetKeyLock(BOOL bLock)
- {
- bKeyLock = bLock;
- }
- /*****************************************************************************
- BLASTER_LoopRead()
- Description: This function read in RC code and decode it.
- *****************************************************************************/
- void BLASTER_LoopRead(void *ParamP_p)
- {
- ST_ErrorCode_t ErrCode;
- int iNewRemoteKeyVal, iRepeatKeyCount, iRemoteKeyBufferWriteOffset = 0;
- int iKey2bStored;
- #ifdef USE_RC5_REMOTE /* BLOCK COMMENTED OUT by Louie on 11/1/2004 */
- int iCurrentKey, iPrevKey; /*iCurrentKey and iPrevKey added by ilyas 08092004*/
- #else
- STBLAST_Symbol_t SymbolBuffer[SYMBOL_BUFFER_SIZE];
- U32 SymbolsRead;
- int i;
- #endif /* USE_RC5_REMOTE */
- BOOL bCurToggleStatus, bPrevToggleStatus, NotRepeatedKey;
- #ifdef USE_RC5_REMOTE
- #define REMOTE_KEY_TOGGLE_BIT_MASK 0x800
- #define REMOTE_KEY_ADDR_MASK 0x7C0 /* based on 14 bit RC-5 code added by ilyas */
- #define REMOTE_KEY_DATA_MASK 0x3F /* based on 14 bit RC-5 code added by ilyas */
- #define REMOTE_KEY_EXTENDED_MASK 0x1000 /* based on 14 bit RC-5 code added by ilyas */
- #define REMOTE_KEY_EXTENDED_APPEND_BIT 0x40/* based on 14 bit RC-5 code added by ilyas */
- #define CUSTOMER_CODE 0x2C0 /*for this Remote the customer code is 0x80*/
- #else
- #define REMOTE_KEY_ADDR_MASK 0x1C0 /* based on he 11 bit value */
- #define REMOTE_KEY_DATA_MASK 0x3F /* based on the 11 bit value */
- #define REMOTE_KEY_TOGGLE_BIT_MASK 0x200 /* based on the 11 bit value */
- #define REMOTE_SLAVE_ADDRESS 0x140 /* slave address is 5 */
- #define REMOTE_KEY_BUFFER_SIZE 20
- #define REMOTE_KEY_LOGIC_0 0xFE
- #define REMOTE_KEY_LOGIC_1 0x01
- #define REMOTE_KEY_REPEATED 0x80
- #endif /*USE_RC5_REMOTE*/
- #ifdef USE_RC5_REMOTE
- U32 NumberRead; /*No. of frames*/
- U32 CodeReceived;
- #endif /*USE_RC5_REMOTE*/
- iRepeatKeyCount = 20; //Lynn org=5
- bPrevToggleStatus = FALSE;
- while(1)
- {
- #ifdef USE_RC5_REMOTE
- ErrCode = STBLAST_Receive(BlasterHandle[BLASTER_RECEIVER], &CodeReceived, 1, &NumberRead, 200);
- #else
- SymbolsRead = 0;
- ErrCode = STBLAST_ReadRaw(BlasterHandle[BLASTER_RECEIVER],SymbolBuffer,SYMBOL_BUFFER_SIZE,&SymbolsRead,15000,100);
- #endif /*USE_RC5_REMOTE*/
- if (ErrCode == ST_NO_ERROR)
- {
- /* Await result completion */
- BLASTDEBUG(STTBX_Print(("Awaiting symbols...")));
- /* Now wait for the semaphore from the event, either fail or succeed */
- #ifdef TM_BLAST /*TMTM*/
- semaphore_wait(&BlasterSemaphoreRead);
- #else
- semaphore_wait(&BlasterSemaphore);
- #endif
- /* Check error-code */
- BLASTDEBUG(STTBX_Print(("STBLAST_ReadRaw()", LastError)));
- BLASTDEBUG(STTBX_Print(("Received %i symbols: ", SymbolsRead)));
- iNewRemoteKeyVal = 0;
- NotRepeatedKey = TRUE;
- #ifdef USE_RC5_REMOTE
- if(NumberRead != 1)
- continue;
-
- /*read in the code received according to rc5 protocol - ilyas*/
- if((CodeReceived & REMOTE_KEY_ADDR_MASK) == CUSTOMER_CODE)
- {
- if(CodeReceived & REMOTE_KEY_EXTENDED_MASK)
- iKey2bStored = CodeReceived & REMOTE_KEY_DATA_MASK;
- else
- iKey2bStored = (CodeReceived & REMOTE_KEY_DATA_MASK)| REMOTE_KEY_EXTENDED_APPEND_BIT;
-
- iCurrentKey = iKey2bStored;
- }
- else
- { /*not the current customer code reject it*/
- continue;
- }
-
- /* check if key is repeated by checking the toggle flag */
- if(CodeReceived & REMOTE_KEY_TOGGLE_BIT_MASK)
- bCurToggleStatus = TRUE;
- else
- bCurToggleStatus = FALSE;
- if((bCurToggleStatus == bPrevToggleStatus )&& (iCurrentKey == iPrevKey))
- {
- if ( ++iRepeatKeyCount <= 20 ) /*Lynn org=5 */
- {
- NotRepeatedKey = FALSE;
- continue;
- }
- else
- {
- NotRepeatedKey = TRUE;
- iKey2bStored |= REMOTE_KEY_REPEATED;
- }
- }
- else
- {
- bPrevToggleStatus = bCurToggleStatus;
- iPrevKey = iCurrentKey;
- iRepeatKeyCount = 0;
- }
- /*
- * save the key value and signal the Keyboard process task
- * to process this new key
- */
- if ( iRemoteKeyBufferWriteOffset >= REMOTE_KEY_BUFFER_SIZE )
- iRemoteKeyBufferWriteOffset = 0;
- aucRemoteKeyBuffer [ iRemoteKeyBufferWriteOffset ] = ( U8 ) iKey2bStored;
- ++iRemoteKeyBufferWriteOffset;
- BLASTDEBUG(STTBX_Print(("The whole keyCode is %xn",iNewRemoteKeyVal)));
- semaphore_signal ( psemRemoteKeySensedSignal );
- #else
- if (SymbolsRead /*== 19*/ > 0)
- {
-
- #ifdef USE_FORCERC
- for (i=10; i<(SymbolsRead-1); i++) /*Check only for bits 10 to 19*/
- {
- BLASTDEBUG(STTBX_Print(("{Sym, Mark}={ %d, %d }",
- SymbolBuffer[i].SymbolPeriod,
- SymbolBuffer[i].MarkPeriod)));
-
- if ((SymbolBuffer[i].SymbolPeriod<700)||(SymbolBuffer[i].SymbolPeriod>2300))
- {
- BLASTDEBUG(STTBX_Print(("There is ErrCode in symbol number %dn",i)));
- }
- else
- {
- iNewRemoteKeyVal <<= 1;
- if ((SymbolBuffer[i].SymbolPeriod>1500)&&(SymbolBuffer[i].SymbolPeriod<2300))
- {
- iNewRemoteKeyVal |= REMOTE_KEY_LOGIC_1;
- BLASTDEBUG(STTBX_Print(("1 ")));
- }
- else
- {
- /*iNewRemoteKeyVal &= 0xFE;*/
- BLASTDEBUG(STTBX_Print(("0 ")));
- }
- }
- }
- #else
- #ifdef USE_STDEMORC
- for (i=0; i<(SymbolsRead-1); i++) /*Check only for bits 0 to 9*/
- {
- BLASTDEBUG(STTBX_Print(("{Sym, Mark}={ %d,%d }",
- SymbolBuffer[i].SymbolPeriod,
- SymbolBuffer[i].MarkPeriod)));
-
- if ((SymbolBuffer[i].SymbolPeriod<4000)||(SymbolBuffer[i].SymbolPeriod>10000))
- {
- BLASTDEBUG(STTBX_Print(("There is ErrCode in symbol number %dn",i)));
- }
- else
- {
- iNewRemoteKeyVal <<= 1;
- if ((SymbolBuffer[i].SymbolPeriod>7000)&&(SymbolBuffer[i].SymbolPeriod<10000))
- {
- iNewRemoteKeyVal |= REMOTE_KEY_LOGIC_1;
- BLASTDEBUG(STTBX_Print(("1 ")));
- }
- else
- {
- /*iNewRemoteKeyVal &= 0xFE;*/
- BLASTDEBUG(STTBX_Print(("0 ")));
- }
- }
- }
- #endif /*USE_STDEMORC*/
- #endif /*USE_FORCERC*/
-
- #ifdef USE_STDEMORC
- if ( ( iNewRemoteKeyVal & REMOTE_KEY_ADDR_MASK ) == REMOTE_SLAVE_ADDRESS )
- #endif /*USE_STDEMORC*/
- {
- /*
- * if address read is ok, save the key read into the remote
- * keyboard buffer
- */
- #ifdef USE_STDEMORC
- iKey2bStored = iNewRemoteKeyVal & REMOTE_KEY_DATA_MASK;
- BLASTDEBUG(STTBX_Print(("The whole keyCode is %xn",iKey2bStored)));
- if ( iNewRemoteKeyVal & REMOTE_KEY_TOGGLE_BIT_MASK )
- bCurToggleStatus = TRUE;
- else
- bCurToggleStatus = FALSE;
-
- if ( bCurToggleStatus == bPrevToggleStatus )
- {
- if ( ++iRepeatKeyCount <= 20 ) /*Lynn org=5 */
- NotRepeatedKey = FALSE;
- else
- {
- NotRepeatedKey = TRUE;
- iKey2bStored |= REMOTE_KEY_REPEATED;
- }
- }
- #else
- iKey2bStored = iNewRemoteKeyVal; /*& REMOTE_KEY_DATA_MASK; TM Force*/
- BLASTDEBUG(STTBX_Print(("The whole keyCode is %xn",iKey2bStored)));
- if ( ++iRepeatKeyCount <= 20 ) /*Lynn org=5 */
- NotRepeatedKey = FALSE;
- else
- NotRepeatedKey = TRUE;
- #endif /*USE_STDEMORC*/
- if (NotRepeatedKey)
- {
- bPrevToggleStatus = bCurToggleStatus;
- iRepeatKeyCount = 0;
- /*
- * Adjust WRITE offset
- */
- if ( iRemoteKeyBufferWriteOffset >= REMOTE_KEY_BUFFER_SIZE )
- iRemoteKeyBufferWriteOffset = 0;
- /*
- * save the key value and signal the Keyboard process task
- * to process this new key
- */
- aucRemoteKeyBuffer [ iRemoteKeyBufferWriteOffset ] = ( U8 ) iKey2bStored;
- ++iRemoteKeyBufferWriteOffset;
- BLASTDEBUG(STTBX_Print(("The whole keyCode is %xn",iNewRemoteKeyVal)));
- semaphore_signal ( psemRemoteKeySensedSignal );
- }
- }
- }
- #endif /* USE_RC5_REMOTE */
- }
- else
- {
- BLASTDEBUG(STTBX_Print(("Error result: %s, ", /*BLAST_ErrorString*/(ErrCode))));
- }
- }
- }
- /*****************************************************************************
- BlastEvtHandler()
- Description: This function allows to wake up the read and write event
- ****************************************************************************/
- #ifdef TM_BLAST
- static void BlastEvtHandler(STEVT_CallReason_t Reason,
- STEVT_EventConstant_t Event,
- const void *EventData)
- {
- switch (Event)
- {
- case STBLAST_READ_DONE_EVT:
- semaphore_signal(&BlasterSemaphoreRead);
- break;
- case STBLAST_WRITE_DONE_EVT:
- semaphore_signal(&BlasterSemaphoreWrite);
- break;
- default:
- break;
- }
- }
- #endif
- /*-------------------------------------------------------------------------------------------- */
- /*
- * CODE : keyboard_process
- * TYPE : process, low_priority (KEYBOARD_PROCESS_PRIORITY)
- * PROTOTYPE :
- * static void keyboard_process ( void );
- * STACK : KEYBOARD_PROCESS_WORKSPACE
- * INPUT : nothing
- * OUTPUT : nothing
- *
- * GLOBAL VARIABLES USED :
- * a. psemRemoteKeySensedSignal Semaphore ( R )
- * b. aucRemoteKeyBuffer array of char ( W )
- * c. iRemoteKeyReadOffset int ( R/W )
- * d. usif_msg_poolid mboxid_t ( R )
- * e. usif_mboxid mboxid_t ( R )
- *
- * DEVICES ACCESSED : On-Board key matrix.
- * FUNCTIONS CALLED : nothing
- * CALLERS :
- * a. keyboard_init - resident call .
- *
- * PURPOSE:
- * To handle the keymatrix scanning and processing the remote key
- * sensed.
- *
- * ALGORITHM:
- * This task wakes up every 100 mSec and scans both the rows of KEYMATRIX
- * If it finds any of the keys pressed then converts it into the exact
- * scan code and passes to the user interface routine for the further
- * action. This task also responsible to convert the remote key sensed
- * into proper keyscan code.
- */
- static void KeyboardRC_Process ( void *pvParam )
- {
- int iBufferBacklog;
- U8 iRemoteKeyBufferReadOffset = 0;
- U8 ucKeyRead, ucPrevKeyRead;
- BOOL bFirstRemoteKey;
- rc_navKeyStroke_t uiKeycode = 0;
- KB_OSPMsgNode ospMsg;
- #ifdef INTEGRATE_FRONT_PANEL_KEYBOARD
- int iKeyReadForScan0;
- int iKeyReadForScan1;
- clock_t timeout;
- device_access8_t * Keyboard_scan_p = (device_access8_t *) KEYBOARD_SCAN1_PIO_ADDRESS;
- #endif
- /* #define DUMMY_CODE */
- #ifdef DUMMY_CODE
- BOOL bPrintDummy = FALSE;
- #endif
- bFirstRemoteKey = TRUE;
-
- /*
- * make sure the key_scan line by default is ONE
- */
- #ifdef INTEGRATE_FRONT_PANEL_KEYBOARD
- *( Keyboard_scan_p + PIO_OUT_SET ) = KEYBOARD_SCAN1_BIT;
- #endif
- while ( TRUE )
- {
- /*
- * wakeup after 100 mSec
- */
- task_delay (ST_GetClocksPerSecondLow() / 10);
- /*
- * test whether any remote control key is available in the buffer
- * if it is so, convert the key value into the proper key code
- */
- iBufferBacklog = psemRemoteKeySensedSignal -> semaphore_count;
- if ( iBufferBacklog )
- {
- /*
- * verify whether the buffer has overflown already, since the
- * adding of new key into the keyboard circular buffer is by the
- * Remote ISR
- */
- if ( iBufferBacklog > REMOTE_KEY_BUFFER_SIZE )
- {
- /*
- * skip off all the keys available in the buffer.
- */
- KBDEBUG(STTBX_Print(( "Remote key response backlog -> %dn", iBufferBacklog )));
- while ( iBufferBacklog )
- {
- ++iRemoteKeyBufferReadOffset;
- /*
- * hey watchout it is time consuming
- */
- if ( iRemoteKeyBufferReadOffset >= REMOTE_KEY_BUFFER_SIZE )
- iRemoteKeyBufferReadOffset = 0;
- semaphore_wait ( psemRemoteKeySensedSignal );
- --iBufferBacklog;
- }
- /*
- * instead of testing the iRemoteKeyBufferReadOffset at every
- * iteration in the above said loop the following would be very
- * efficient. But somehow I'm not confident ...
- */
- /*
- iRemoteKeyBufferReadOffset = iRemoteKeyBufferReadOffset % REMOTE_KEY_BUFFER_SIZE;
- */
- }
- else
- {
- ucPrevKeyRead = ucKeyRead;
- ucKeyRead = aucRemoteKeyBuffer [ iRemoteKeyBufferReadOffset ];
- /*
- * START = added by VICKY on 12.12.96
- */
- if ( bFirstRemoteKey == TRUE )
- {
- ucPrevKeyRead = ucKeyRead; /*& ~REMOTE_KEY_REPEATED; TMTM Force*/
- bFirstRemoteKey = FALSE;
- }
- /*
- * END = on 12.12.96
- */
- KBDEBUG(STTBX_Print(( "Remote key sensed [%X]n", ucKeyRead )));
-
- #ifdef USE_STDEMORC /*TMTM not Force*/
- if ( ( ucKeyRead & REMOTE_KEY_REPEATED ) &&
- ( ucKeyRead & ~REMOTE_KEY_REPEATED ) != ucPrevKeyRead )
- {
- /*
- * if wrong key is sensed, due to the bit error during
- * framing the key value, then skip that key
- */
- ucKeyRead &= ~REMOTE_KEY_REPEATED;
- KBDEBUG(STTBX_Print(( "Wrong Remote key C[%X] P[%X]n", ucKeyRead, ucPrevKeyRead )));
- }
- else
- {
- ucKeyRead = aucRemoteKeyBuffer [ iRemoteKeyBufferReadOffset ] & ~REMOTE_KEY_REPEATED;
- #else
- {
- ucKeyRead = aucRemoteKeyBuffer [ iRemoteKeyBufferReadOffset ]; /* & ~REMOTE_KEY_REPEATED; TMTM Force*/
- #endif
- //STTBX_Print(( "n[Han]:ucKeyRead[0x%x]", ucKeyRead ));
- /*
- * convert the numeric keys into ascending order
- */
- switch ( ucKeyRead )
- {
- case KB_BUT_KEY_0:
- uiKeycode = rc_KeyNum0;
- break;
- case KB_BUT_KEY_1:
- uiKeycode = rc_KeyNum1;
- break;
- case KB_BUT_KEY_2:
- uiKeycode = rc_KeyNum2;
- break;
- case KB_BUT_KEY_3:
- uiKeycode = rc_KeyNum3;
- break;
- case KB_BUT_KEY_4:
- uiKeycode = rc_KeyNum4;
- break;
- case KB_BUT_KEY_5:
- uiKeycode = rc_KeyNum5;
- break;
- case KB_BUT_KEY_6:
- uiKeycode = rc_KeyNum6;
- break;
- case KB_BUT_KEY_7:
- uiKeycode = rc_KeyNum7;
- break;
- case KB_BUT_KEY_8:
- uiKeycode = rc_KeyNum8;
- break;
- case KB_BUT_KEY_9:
- uiKeycode = rc_KeyNum9;
- break;
- case KB_BUT_KEY_POWER:
- uiKeycode = rc_KeyPower;
- break;
- case KB_BUT_KEY_MUTE:
- uiKeycode = rc_KeyMute;
- break;
- case KB_BUT_KEY_TRACK:
- uiKeycode = rc_KeyTrack;
- break;
- case KB_BUT_KEY_VOLPLUS:
- uiKeycode = rc_KeyVolPlus;
- break;
- case KB_BUT_KEY_VOLMINUS:
- uiKeycode = rc_KeyVolMinus;
- break;
- case KB_BUT_KEY_RETURN:
- uiKeycode = rc_KeyReturn;
- break;
- case KB_BUT_KEY_SCREEN:
- uiKeycode = rc_KeyScreen;
- break;
- case KB_BUT_KEY_SWITCH:
- uiKeycode = rc_KeySwitch;
- break;
- case KB_BUT_KEY_PAGEUP:
- uiKeycode = rc_KeyPageUp;
- break;
- case KB_BUT_KEY_PAGEDOWN:
- uiKeycode = rc_KeyPageDown;
- break;
- case KB_BUT_KEY_GUIDE:
- uiKeycode = rc_KeyGuide;
- break;
- case KB_BUT_KEY_UP:
- uiKeycode = rc_KeyUp;
- break;
- case KB_BUT_KEY_DOWN:
- uiKeycode = rc_KeyDown;
- break;
- case KB_BUT_KEY_LEFT:
- uiKeycode = rc_KeyLeft;
- break;
- case KB_BUT_KEY_RIGHT:
- uiKeycode = rc_KeyRight;
- break;
- case KB_BUT_KEY_OK:
- uiKeycode = rc_KeyOK;
- break;
- case KB_BUT_KEY_MENU:
- uiKeycode = rc_KeyMenu;
- break;
- case KB_BUT_KEY_EXIT:
- uiKeycode = rc_KeyExit;
- break;
- case KB_BUT_KEY_RED:
- uiKeycode = rc_KeyRed;
- break;
- case KB_BUT_KEY_GREEN:
- uiKeycode = rc_KeyGreen;
- break;
- case KB_BUT_KEY_YELLOW:
- uiKeycode = rc_KeyYellow;
- break;
- case KB_BUT_KEY_BLUE:
- uiKeycode = rc_KeyBlue;
- break;
- case KB_BUT_KEY_FAV:
- uiKeycode = rc_KeyFav;
- break;
- case KB_BUT_KEY_LANGUAGE:
- uiKeycode = rc_KeyLan;
- break;
- case KB_BUT_KEY_COLLECTION:
- uiKeycode = rc_KeyColleciton;
- break;
- case KB_BUT_KEY_SET:
- uiKeycode = rc_KeySet;
- break;
- case KB_BUT_KEY_VIDEO:
- uiKeycode = rc_KeyVideo;
- break;
- case KB_BUT_KEY_AUDIO:
- uiKeycode = rc_KeyAudio;
- break;
- case KB_BUT_KEY_NVOD:
- uiKeycode = rc_KeyNVOD;
- break;
- case KB_BUT_KEY_INFOR:
- uiKeycode = rc_KeyInfor;
- break;
- case KB_BUT_KEY_MAIL:
- uiKeycode = rc_KeyMail;
- break;
- case KB_BUT_KEY_GAME:
- uiKeycode = rc_KeyGame;
- break;
- case KB_BUT_KEY_STOCK:
- uiKeycode = rc_KeyStock;
- break;
- case KB_BUT_KEY_ORDER:
- uiKeycode = rc_KeyOrder;
- break;
- case KB_BUT_KEY_F1:
- uiKeycode = rc_KeyF1;
- break;
- case KB_BUT_KEY_F2:
- uiKeycode = rc_KeyF2;
- break;
- case KB_BUT_KEY_F3:
- uiKeycode = rc_KeyF3;
- break;
- case KB_BUT_KEY_F4:
- uiKeycode = rc_KeyF4;
- break;
-
- default:
- uiKeycode = rc_KeyInvalid;
- break;
- }
- if (uiKeycode != rc_KeyInvalid)
- {
- eCurKeyCode = uiKeycode;
- ospMsg.Word1=MOD_KEY;
- ospMsg.Word3=uiKeycode;
- //KB_MENUTranslateMsg(&ospMsg);
- kb_machblue_key(uiKeycode);
- }
- }
- ++iRemoteKeyBufferReadOffset;
- if ( iRemoteKeyBufferReadOffset >= REMOTE_KEY_BUFFER_SIZE )
- iRemoteKeyBufferReadOffset = 0;
- semaphore_wait ( psemRemoteKeySensedSignal );
- }
- }
-
- #ifdef INTEGRATE_FRONT_PANEL_KEYBOARD
- /*
- * scan key matrix for SCAN_LINE0 which is always '0'
- */
- /* KBDEBUG(STTBX_Print((severity_info, "READ_KEY_BITS = 0X%02X n",READ_KEY_BITS))); */
- iKeyReadForScan0 = ( ( READ_KEY_BITS ) & KEYBOARD_SENSE_MASK ) ^ KEYBOARD_SENSE_MASK;
-
- if ( iKeyReadForScan0 )
- {
- /*
- * some keys pressed on SENSE_0
- */
- task_delay ( KEYBOARD_BOUNCE_SETTLE_TIME );
- iKeyReadForScan1 = iKeyReadForScan0;
- }
- else
- {
- /*
- * scan key matrix for SCAN_LINE1, which is always '1', by bringing
- * it to logic 0 and sense the keys
- */
- * ( Keyboard_scan_p + PIO_OUT_CLR ) = KEYBOARD_SCAN1_BIT;
- task_delay ( KEYBOARD_SCAN_LINE_SETTLE_TIME );
- iKeyReadForScan1 = ( ( READ_KEY_BITS ) & KEYBOARD_SENSE_MASK ) ^ KEYBOARD_SENSE_MASK;
- * ( Keyboard_scan_p + PIO_OUT_SET ) = KEYBOARD_SCAN1_BIT;
- iKeyReadForScan1 = iKeyReadForScan1 << NO_OF_FRONT_PANEL_KEY_SENSE_BITS;
-
- if ( iKeyReadForScan1 )
- {
- /*
- * some keys pressed on SENSE_0
- */
- task_delay ( KEYBOARD_BOUNCE_SETTLE_TIME );
- }
- }
- /*
- * if any of those key is pressed then convert them into exact
- * scan code
- */
- if ( iKeyReadForScan1 )
- {
- /*
- * if LEFT(SW1) and RIGHT(SW2) arrow keys are pressed together
- * then it means MENU_CUM_EXIT_KEY
- */
- ucKeyRead = 0;
- {
- if ( iKeyReadForScan1 & SWITCH2_MASK )
- ucKeyRead = VOL_DOWN_CUM_LEFT_ARROW_KEY;
- if ( iKeyReadForScan1 & SWITCH4_MASK )
- ucKeyRead = PROG_PREV_CUM_DOWN_ARROW_KEY; /*PROG_PREV_CUM_UP_ARROW_KEY;*/
- if ( iKeyReadForScan1 & SWITCH6_MASK )
- ucKeyRead = MENU_CUM_EXIT_KEY;
- if ( iKeyReadForScan1 & SWITCH3_MASK )
- ucKeyRead = VOL_UP_CUM_RIGHT_ARROW_KEY;
- if ( iKeyReadForScan1 & SWITCH5_MASK )
- ucKeyRead = PROG_NEXT_CUM_UP_ARROW_KEY; /*PROG_NEXT_CUM_DOWN_ARROW_KEY;*/
- if ( iKeyReadForScan1 & SWITCH1_MASK )
- ucKeyRead = POWER_KEY;
- if ( iKeyReadForScan1 & SWITCH7_MASK )
- ucKeyRead = SELECT_KEY;
- }
- if ( ucKeyRead )
- {
- /* if any key is sensed send it to USIF */
- timeout = WAIT_FOR_1_SEC;
-
- }
- }
- #endif
- }
- }
- /*
- * CODE : keyboard_init
- * TYPE : subroutine
- * PROTOTYPE :
- * BOOL keyboard_init ( void );
- *
- * STACK : callers stack
- * INPUT : nothing
- * OUTPUT :
- * a. initialisation_status BOOL
- * If the module is successfuly initialised then it will be FALSE else
- * TRUE
- *
- * GLOBAL VARIABLES USED :
- * a. usif_mbx symbol type mailbox ( R )
- * b. usif_pool symbol type mailbox ( R )
- * c. usif_msg_poolid mboxid_t ( W )
- * d. usif_mboxid mboxid_t ( W )
- *
- * DEVICES ACCESSED : nothing
- * FUNCTIONS CALLED :
- * CALLERS :
- * a. main ....MAINSOURCEMAIN.C
- *
- * PURPOSE :
- * Initialise the keyboard module
- */
- /*{{{ DVBKeyboardInit ()*/
- BOOL RcKeyboardProcessSetup ( void )
- {
- int RC_Name;
- BOOL bError = FALSE;
-
- #ifdef INTEGRATE_FRONT_PANEL_KEYBOARD
- device_access8_t * PIO_SCAN_p = (device_access8_t *) KEYBOARD_SCAN1_PIO_ADDRESS ;
- #endif
- BLASTER_Setup();
-
- BLASTDEBUG(STTBX_Print(( "KEYBOARD Driver version [%s]n", SOFTWARE_UPDATE_ID )));
- #ifdef INTEGRATE_FRONT_PANEL_KEYBOARD
- /* Configure ScanPIO as Output Pushpull */
- * ( PIO_SCAN_p + PIO_C0_CLR ) = KEYBOARD_SCAN1_BIT;
- * ( PIO_SCAN_p + PIO_C1_SET ) = KEYBOARD_SCAN1_BIT;
- * ( PIO_SCAN_p + PIO_C2_CLR ) = KEYBOARD_SCAN1_BIT;
- #endif
- psemRemoteKeySensedSignal = semaphore_create_fifo ( 0 );
- //semaphore_init_fifo(&psemRemoteKeySensedSignal, 0);
-
- /*------ Setup Keyboard & RC management Process ------*/
- if ( ( pKeyboardRCTask=task_create( KeyboardRC_Process,NULL,2048,5,"KeyboardTask",0 ) ) == NULL )
- {
- BLASTDEBUG(STTBX_Print(( "Failed to start keyboard processn" )));
- bError = FALSE;
- }
- #ifndef INTEGRATE_FRONT_PANEL_KEYBOARD
- BLASTDEBUG(STTBX_Print(( "Front Panel Key sense not includednn" )));
- #endif
- task_delay(1000);
- /*------ Setup Blaster Receiver task ------*/
- #ifdef USE_STDEMORC
- RC_Name = 1;
- #elif defined (USE_FORCERC)
- RC_Name = 2;
- #endif
- #ifdef USE_RC5_REMOTE
- {
- memset(&RcProtocolReceive, 0, sizeof(STBLAST_ProtocolParams_t));
- STBLAST_SetProtocol(BlasterHandle[BLASTER_RECEIVER], STBLAST_PROTOCOL_RC5, &RcProtocolReceive);
- }
- #else
- RcProtocolReceive = BLAST_ReceiveProtocol(RC_Name);
- {
- STBLAST_Protocol_t Protocol;
- Protocol = STBLAST_PROTOCOL_USER_DEFINED;
- STBLAST_SetProtocol(BlasterHandle[BLASTER_RECEIVER], Protocol, &RcProtocolReceive);
- }
- #endif
- BLASTDEBUG(STTBX_Print(("Create BLASTER taskn")));
- if ( ( pBlastReadTask=task_create( BLASTER_LoopRead,0L,2048,5,"BLASTER Read task",0 ) ) == NULL )
- {
- BLASTDEBUG(STTBX_Print(("Unable to Create BLASTER Read taskn")));
- bError = TRUE;
- }
- else
- {
- BLASTDEBUG(STTBX_Print(("Running BLASTER Read task...n")));
- }
-
- return bError;
- }
- /*eof*/