- /* **************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: nec_ir.c $
- *
- * Description:
- * ============
- * NEC IR implementation
- *
- * Log:
- * ====
- * $Revision: 17 $
- * Last Modified by $Author: Rinata $ at $Modtime: 3/11/04 5:06p $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Remote/nec_ir/nec_ir.c $
- *
- * 17 3/11/04 5:45p Rinata
- * cpu check remote signal after v8 wake it up when remote signal was
- * changed
- *
- * 16 03-08-01 11:57 Wesleyj
- * remove video_mode_detect
- *
- * 15 7/09/03 6:05p Mikex
- * cancel transfer cpu_soft_reset() function on second standby key
- * pressed. The cpu_soft_reset() function will be transfered by core task.
- *
- * 14 03-07-07 16:14 Ivany
- * Added a mapping table and condition for the keys which repeat-pressed
- * message should not be sent when is pressed.
- *
- * 13 03-06-19 17:08 Wesleyj
- * add video_mode_detect charge (Av in stat)
- *
- * 12 03-06-17 18:28 Admin
- * Merge for ExinoII project
- *
- * 11 03-05-19 18:54 Kennyz
- * Clear code.
- *
- * 10 2/02/03 6:22p Lyncolnc
- * Added LONG_REPEAT_DELAY.
- *
- * 12 17/07/02 20:25 Nirm
- * - Adjustments to timer_0 in order to increase timer-measurement
- * accuracy throughout the system.
- *
- * 11 5/28/02 18:47 Rinata
- * FF and FB are not with valid repeat
- *
- * 10 23/04/02 9:37 Nirm
- * - Added dependency in "Config.h".
- *
- * 9 7/03/02 17:45 Nirm
- * Removed EMERGENCY_EJECT_ENABLED -> replaced by the Exceptioning
- * mechanism.
- *
- * 8 18/02/02 11:01 Atai
- * make global to static
- *
- * 7 2/17/02 12:21p Tomasp
- * Code clean up.
- *
- * 6 1/28/02 19:55 Rinata
- * fix gen timer values for ir
- *
- * 5 9/01/02 16:58 Nirm
- * Corrected Include-Paths.
- *
- * 4 1/06/02 15:46 Rinata
- *
- * 3 1/01/02 19:10 Atai
- * Code cleaning
- *
- * 2 25/12/01 12:29 Atai
- * Code cleaning
- **************************************************************************************** */
- #include "Config.h" // Global Configuration - do not remove!
- #ifndef EXINO_FP
- #include "Kernelker_api.h"
- #include "Kerneleventdef.h"
- #include "CPUcpu_api.h"
- #include "CPUTimefunc.h"
- #include "PlaycoreCoremaincoremain.h"
- #include "PlaycoreCoremaincoredefs.h"
- #include "PlaycoreCoremaincoregdef.h"
- #include "Remoteir_api.h"
- #include "Remoteir_ll.h"
- #ifdef ALCO_SD340E
- #else
- //#include "Remotenec_irnec_ir.h"
- #endif
- #ifdef ALCO_SD340E
- #include "CPUTimefunc.h"
- #ifdef I76_CPU_POWER_DOWN
- #include "DecoderDec_Power.h"
- #endif//I76_CPU_POWER_DOWN
- extern CONST WORD g_ir_play_key_code;
- #endif
- extern CONST WORD g_ir_system_code;
- extern CONST WORD g_ir_power_key_code;
- extern CONST WORD g_ir_eject_key_code;
- #ifdef MODIFIED_FOR_T1_2002
- extern const WORD g_ir_volume_up_key ;//add for t1.
- extern const WORD g_ir_volume_down_key ;//
- #endif
- #if defined(D_TEST)||defined(D_IRCODE_TEST)
- WORD ir_customer_code;
- #endif
- //the time increment for gen_time is 1.25us
- #define IR_MARGIN ((WORD)130UL)
- #define time_9000_us ((WORD)9000UL)
- #define time_4500_us ((WORD)4500UL)
- #define time_2250_us ((WORD)2250UL)
- #define time_1125_us ((WORD)1125UL)
- // State of the remote key decoder
- #define IDLE 0
- #define LEADER_ON 1
- #define LEADER_OFF 2
- #define CUSTOM 3
- #define DATA1 4
- #define DATA2 5
- // Hoe many repeat message will ignire before send it to the FSM's
- #ifdef LONG_REPEAT_DELAY
- #define REPEAT_DELAY 25
- #else
- #define REPEAT_DELAY 5
- #endif //LONG_REPEAT_DELAY
- #ifdef IR_NO_REPEAT_PULSE
- #define IR_INTERVAL 240/20
- BYTE last_key = 0;
- BYTE ir_interval = 0;
- #endif
- static unsigned long time_count_old;
- void ir_init(void)
- {
- ir_interrupt_and_timer_init( FALLING_EDGE );
- time_count_old = gen_timer();
- }
- #ifdef I76_CPU_POWER_DOWN
- #ifdef ALCO_SD340E
- POWER_UP_KEY_STATUS power_up_pressed = POWER_UP_KEY_IDLE;
- #else
- int power_up_pressed = 0;
- #endif
- #endif // I76_CPU_POWER_DOWN
- void ir_isr( void )
- {
- static BYTE key; // Hold the key code
- static BYTE repeat_delay = REPEAT_DELAY; // Repeat code counter
- static WORD custom; // Hold the custom (remote ID) code
- static BYTE state = 0; // State holder
- static BYTE count; // bits counter
- static BYTE data1, data2; // Temporary for holding the decoded data
- static BYTE valid_repeat = 0;
- unsigned long time_count = gen_timer();
- unsigned long t0 = time_count - time_count_old;
- switch (state) {
- case IDLE:
- time_count_old = time_count;
- ir_interrupt_set_edge(RISING_EDGE);
- state = LEADER_ON;
- break;
- case LEADER_ON:
- time_count_old = time_count;
- ir_interrupt_set_edge(FALLING_EDGE);
- state = ((t0>(time_9000_us-8*IR_MARGIN)) && (t0<(time_9000_us+8*IR_MARGIN))) ? LEADER_OFF:IDLE;
- break;
- case LEADER_OFF:
- if (t0 > time_4500_us - (4*IR_MARGIN) && t0 < time_4500_us + (4*IR_MARGIN))
- {
- state = CUSTOM;
- custom = 0;
- count = 0;
- repeat_delay = REPEAT_DELAY;
- }
- else
- {
- if (t0 > time_2250_us - (2*IR_MARGIN) && t0 < time_2250_us + (2*IR_MARGIN))
- {
- if (repeat_delay) {
- // Delay before sendnig the first repeat
- repeat_delay--;
- }
- else
- {
- if (valid_repeat)
- send_remote_event( REMOTE_KEY_REPEATED|key );
- }
- }
- ir_interrupt_set_edge(FALLING_EDGE);
- state = IDLE;
- }
- time_count_old = time_count;
- break;
- case CUSTOM:
- time_count_old = time_count;
- if (t0 > time_1125_us - IR_MARGIN && t0 < time_1125_us + IR_MARGIN) {
- custom <<= 1; /* a zero bit */
- }
- else {
- if (t0 > time_2250_us - (2*IR_MARGIN) && t0 < time_2250_us + (2*IR_MARGIN)) {
- custom = (custom << 1) | 1; /* a one bit */
- }
- else {
- // Garbage ... ignored
- ir_interrupt_set_edge(FALLING_EDGE);
- state = IDLE;
- valid_repeat = 0;
- break;
- }
- }
- /* count 16 'custom' bits */
- if (++count == 16) {
- #if defined(D_TEST)||defined(D_IRCODE_TEST)
- ir_customer_code = custom;
- #else
- if (custom != g_ir_system_code)
- {
- // Noise from other remote ... ignore
- ir_interrupt_set_edge(FALLING_EDGE);
- state = IDLE;
- valid_repeat = 0;
- break;
- }
- #endif
- state = DATA1;
- time_count_old = time_count;
- count = 0;
- data1 = 0;
- }
- break;
- case DATA1:
- time_count_old = time_count;
- count++;
- if (t0 > time_1125_us - IR_MARGIN && t0 < time_1125_us + IR_MARGIN) {
- data1 <<= 1; /* a zero bit */
- }
- else {
- if (t0 > time_2250_us - (2*IR_MARGIN) && t0 < time_2250_us + (2*IR_MARGIN)) {
- data1 = (data1 << 1) | 1; /* a one bit */
- }
- else {
- ir_interrupt_set_edge(FALLING_EDGE);
- state = IDLE;
- valid_repeat = 0;
- break;
- }
- }
- if (count == 8) {
- state = DATA2;
- count = 0;
- data2 = 0;
- }
- break;
- case DATA2:
- time_count_old = time_count;
- count++;
- if (t0 > time_1125_us - IR_MARGIN && t0 < time_1125_us + IR_MARGIN) {
- data2 <<= 1; /* a zero bit */
- }
- else {
- if (t0 > time_2250_us - (2*IR_MARGIN) && t0 < time_2250_us + (2*IR_MARGIN)) {
- data2 = (data2 << 1) | 1; /* a one bit */
- }
- else {
- ir_interrupt_set_edge(FALLING_EDGE);
- state = IDLE;
- valid_repeat = 0;
- break;
- }
- }
- if (count == 8)
- {
- ir_interrupt_set_edge(FALLING_EDGE);
- state = IDLE;
- if (data1 == (~data2 & 0xff))
- {
- key = (0x00FF&data1);
- tr_printf(("irtest:%2xn",key));
- #ifndef D_AUX_POWER_KEY//tecobest gxd 20051019
- if (key == (BYTE)(0x00FF&g_ir_power_key_code))
- {
- switch(g_power_state)
- {
- case POWER_SEQUENCE_IN_ON_STATE:
- g_power_state = POWER_SEQUENCE_OFF_REQUESTED;
- break;
- case POWER_SEQUENCE_IN_OFF_STATE:
- g_power_state = POWER_SEQUENCE_ON_REQUESTED;
- break;
- case POWER_SEQUENCE_OFF_REQUESTED:
- g_power_state = POWER_SEQUENCE_ON_REQUESTED;
- cpu_soft_reset();
- }
- }
- #endif
- valid_repeat = 1;
- send_remote_event( ((WORD)key)&0x00FF );
- }
- }
- break;
- }
- }
- #endif // EXINO_FP