rc6_ir.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:18k
源码类别:

DVD

开发平台:

Others

  1. #include "Config.h" // Global Configuration - do not remove!
  2. #include "Kernelker_api.h"
  3. #include "Kerneleventdef.h"
  4. #include "CPUcpu_api.h"
  5. #include "CPUTimefunc.h"
  6. #include "PlaycoreCoremaincoremain.h"
  7. #include "PlaycoreCoremaincoredefs.h"
  8. #include "PlaycoreCoremaincoregdef.h"
  9. #include "Remoteir_api.h"
  10. #include "Remoteir_ll.h"
  11. #include "Remoterc6_irrc6_ir.h"
  12. extern CONST WORD g_ir_system_code;
  13. extern CONST WORD g_ir_power_key_code;
  14. extern CONST WORD g_ir_eject_key_code;
  15. #define RC6_GROUPSIZE         8 // bits
  16. #define RC6_CODESIZE 8 // bits
  17. #define RC6_SHORTPULSE 444UL
  18. #define RC6_JITTER     200UL
  19. #define RC6_LONGPULSE  888UL
  20. #define RC6_HEADPULSE (6*RC6_SHORTPULSE)
  21. // State of the remote key decoder
  22. #define ERROR    0
  23. #define IDLE      1
  24. #define HEADER1      2
  25. #define HEADER2      3
  26. #define HEADER3      4
  27. #define MODE         5
  28. #define REVERSE      6
  29. #define DECODE    7
  30. #define RESYNC    8
  31. #define REPEAT_DELAY 5    // pre-delay before repeating.
  32. #define REPEAT_STEP 2     // delay between repeated events.
  33. #define STOPKEY_DELAY  0x10   //for the Philips project
  34. #define IRKC_NULL       0xFF   //for the philips project
  35. #define Philips_DVD    0x04
  36. #define PHILIPS        1
  37. void ir_init(void)
  38. {
  39. ir_interrupt_and_timer_init( FALLING_EDGE );
  40. }
  41. void ir_isr( void )
  42. {
  43.         static BYTE interruptTypeFlag = 0;
  44.         static BYTE state = IDLE;
  45.         static BYTE bitCount;
  46.         //static BYTE decode;
  47.         static BYTE group;
  48.         static BYTE code;
  49.         static BYTE oldcode;
  50.         static BYTE bit = 0;
  51.         static BYTE check = 0;
  52.         static BYTE repeating = 0;
  53.         static BYTE repeatDelay = REPEAT_DELAY; // Repeat code counter
  54.         static BYTE repeatStep=0;
  55.         static DWORD timeCountOld;
  56.   
  57.         /* henry start */
  58.         static BYTE    model;                /* mode value */
  59.         static BYTE    border;              /*indicator of a border of long cycle*/
  60.         static BYTE    start;               /* indicator of starting next segment */
  61.         /* henry end */
  62.         
  63.         DWORD timeCount;
  64.         DWORD deltaTime;
  65.         BYTE validRepeat = 0;
  66.         BYTE key = 0;   // Hold the key code
  67.         /* for the Philips project */
  68.         static BYTE lastkey;
  69.         static BYTE stopkey_repeatDelay;
  70.         timeCount =gen_timer();
  71.         deltaTime = timeCount - timeCountOld;
  72.         timeCountOld = timeCount;
  73.         if (!interruptTypeFlag)
  74.         {
  75.                 ir_interrupt_set_edge( RISING_EDGE );
  76.                 interruptTypeFlag = 1;
  77.         }
  78.         else
  79.         {
  80.                 ir_interrupt_set_edge( FALLING_EDGE );
  81.                 interruptTypeFlag = 0;
  82.         }
  83.         switch (state) {
  84.                 case ERROR:
  85.                  // to be filled later when it is needed.
  86.                         state = IDLE;
  87.                 case IDLE:
  88.                         bitCount = 0;
  89.                         model = 0;
  90.                         group = 0;
  91.                         code = 0;
  92.                         border = 0;
  93.                         start = 0;
  94.                         bit = 1;
  95.                         
  96.                         
  97.                         if(interruptTypeFlag == 1)
  98.                                 state = HEADER1;
  99.                         else
  100.                                 state = ERROR;
  101.                         break;
  102.                 case HEADER1:
  103.                         if(deltaTime - RC6_JITTER < RC6_HEADPULSE && RC6_HEADPULSE < deltaTime + RC6_JITTER)
  104.                                 state = HEADER2;
  105.                 else
  106.                                 state = ERROR;
  107.                         break;
  108.         
  109.                 case HEADER2:
  110.                         if(deltaTime - RC6_JITTER < RC6_LONGPULSE && RC6_LONGPULSE < deltaTime + RC6_JITTER)
  111.                                 state = HEADER3;
  112.                         else
  113.                                 state = ERROR;
  114.                         break;
  115.         
  116.                 case HEADER3:
  117.                         if(deltaTime - RC6_JITTER < RC6_SHORTPULSE && RC6_SHORTPULSE < deltaTime + RC6_JITTER)                                                
  118.                                 state = MODE;
  119.                         else
  120.                                 state = ERROR;
  121.                         break;
  122.                         
  123.                 case MODE:
  124.                         if(deltaTime - RC6_JITTER < RC6_LONGPULSE && RC6_LONGPULSE < deltaTime + RC6_JITTER)
  125.                         {                         
  126.                                 if(border)
  127.                                 {
  128.                                       state = ERROR;
  129.                                       border = 0;
  130.                                       break;
  131.                                 }
  132.                                 bit = !bit;
  133.                                 bitCount++;
  134.                                 model <<= 1;
  135.                                 model |= bit & 1;
  136.                         }        
  137.                         else if(deltaTime - RC6_JITTER < RC6_SHORTPULSE && RC6_SHORTPULSE < deltaTime + RC6_JITTER)
  138.                         {
  139.                                 if(border)
  140.                                 {
  141.                                       border = 0;
  142.                                       bitCount++;
  143.                                       model <<= 1;
  144.                                       model |= bit & 1;
  145.                                 }
  146.                                 else
  147.                                       border = 1;
  148.                         }
  149.                         else 
  150.                         {
  151.                                 state = ERROR;
  152.                                 break;
  153.                         }        
  154.                         if(bitCount == 3)
  155.                         {
  156.                              state = REVERSE;
  157.                              start = 1;
  158.                              bitCount = 0;
  159.                         }     
  160.                         break;     
  161.                         
  162.                 case REVERSE:
  163.                         if(deltaTime - RC6_JITTER < RC6_SHORTPULSE && RC6_SHORTPULSE < deltaTime + RC6_JITTER)                         
  164.                         {
  165.                                 if(border)
  166.                                       state = ERROR;
  167.                                 else
  168.                                 {
  169.                                       border = 1;
  170.                                       start = 0;
  171.                                 }      
  172.                         }
  173.                         else if(deltaTime - RC6_JITTER < RC6_LONGPULSE && RC6_LONGPULSE < deltaTime + RC6_JITTER)                         
  174.                         {
  175.                                 if(!border)
  176.                                       state = ERROR;
  177.                                 else      
  178.                                       state = DECODE;
  179.                         
  180.                         }
  181.                         else if(deltaTime - RC6_JITTER < (RC6_LONGPULSE + RC6_SHORTPULSE) 
  182.                                                 && (RC6_LONGPULSE + RC6_SHORTPULSE) < deltaTime + RC6_JITTER)                         
  183.                         {
  184.                                 if(start)
  185.                                 {
  186.                                       start = 0;
  187.                                       bit = !bit;
  188.                                       state = DECODE;
  189.                                 }
  190.                                 else
  191.                                       state = ERROR;
  192.                         }
  193.                         else
  194.                                 state = ERROR;
  195.                         if(state == DECODE)
  196.                         {
  197.                                 if((bit & 1) ^ check)
  198.                                        repeating = 0;
  199.                                 else 
  200.                                        repeating = 1;
  201.                                 check = bit & 1;       
  202.                                 start = 1;
  203.                                 border = 0;
  204.                         }
  205.                         break;
  206.                         
  207.                 case DECODE:
  208.                         if (deltaTime - RC6_JITTER < RC6_SHORTPULSE  &&  RC6_SHORTPULSE < deltaTime + RC6_JITTER)
  209.                         {
  210.                                 if(start)
  211.                                      state = ERROR;
  212.                                 else if(border)
  213.                                 {
  214.                                      border = 0;
  215.                                      bitCount++;
  216.                                 }     
  217.                                 else
  218.                                      border = 1;
  219.                        }
  220.                        else if (deltaTime - RC6_JITTER < RC6_LONGPULSE  &&  RC6_LONGPULSE < deltaTime + RC6_JITTER)
  221.                        {
  222.                                 if(start)
  223.                                 {
  224.                                      start = 0;
  225.                                      border = 1;
  226.                                 }     
  227.                                 else if(border)     
  228.                                      state = ERROR;
  229.                                 else
  230.                                 {
  231.                                      bit = !bit;
  232.                                      bitCount++;
  233.                                 }                                            
  234.                        } 
  235.                        else if (deltaTime - RC6_JITTER < (RC6_LONGPULSE + RC6_SHORTPULSE) 
  236.                                             && (RC6_LONGPULSE + RC6_SHORTPULSE) < deltaTime + RC6_JITTER)
  237.                        {
  238.                                 if(start)
  239.                                 {
  240.                                       start = 0;
  241.                                       border = 0;
  242.                                       bit = !bit;
  243.                                       bitCount++;
  244.                                 }
  245.                                 else
  246.                                       state = ERROR;
  247.                        }
  248.                        else
  249.                                 state = ERROR;
  250.                        if(state == DECODE)
  251.                        {
  252.                                 if(bitCount <= RC6_GROUPSIZE)
  253.                                 {
  254.                                       group |= (bit & 1)<<(RC6_GROUPSIZE - bitCount);
  255.                                 }
  256.                                 else
  257.                                 {
  258.                                       code |= (bit & 1)<<(RC6_CODESIZE + RC6_GROUPSIZE - bitCount);
  259.                                 }
  260.                                 if(bitCount == RC6_GROUPSIZE + RC6_CODESIZE)
  261.                                 {
  262.                                       if (group == g_ir_system_code)
  263.                                       {
  264.                                              /* add code for judging if the key is pressed repeatly more truly */
  265.                                              if((oldcode != code) && (repeating == 1))
  266.                                                    repeating = 0;
  267.                                              oldcode = code;
  268.                                              /* add code end */
  269.                                                          
  270.                                              key = (BYTE)(0x00FF&code);
  271.                                              switch(key)
  272.                                              {  
  273.                                                    case IRKC_DOWN:
  274.                                                    case IRKC_UP:
  275.                                                    case IRKC_RIGHT:
  276.                                                    case IRKC_LEFT:
  277.                                                          validRepeat=1;
  278.                                                          break;
  279. #ifdef USE_SKIPF_KEY_FOR_STEPF_KEY_IN_PAUSE_MODE
  280. #ifdef D_VESTEL_REMOTE
  281.                                                    case IRKC_SKIPF: //BT021003: Add STEPF key repeating
  282.                                                          if ( (gcs.pstate == PST_PAUSE) && (IS_COP_ENABLE(COP_STEP)) )
  283.                                                          {
  284.                                                               validRepeat=1;
  285.                                                               break;
  286.                                                          }
  287. #endif //D_VESTEL_REMOTE
  288. #endif //USE_SKIPF_KEY_FOR_STEPF_KEY_IN_PAUSE_MODE
  289.                                                    default:
  290.                                                               validRepeat=0;
  291.                                              }
  292.                                              if (repeating)
  293.                                              {
  294.                                                    /* design for philips project:repeating to push stop key instead of pushing open key */
  295.                                                    #ifdef   PHILIPS
  296.                                                    if(key == IRKC_STOP)
  297.                                                    {
  298.                                                            if(stopkey_repeatDelay)
  299.                                                                  stopkey_repeatDelay--;
  300.                                                            else
  301.                                                            {
  302.                                                                  key = IRKC_EJECT;
  303.                                                                  if(lastkey != key)
  304.                                                                  {
  305.                                                                       lastkey = key;
  306.                                                                       send_remote_event((WORD)key&0x00FF);
  307.                                                                  }     
  308.                                                            }
  309.                                                    }
  310.                                                    else
  311.                                                    #endif //End ifdef PHILIPS
  312.                                                    
  313.                                                    if(repeatDelay)
  314.                                                    {
  315.                                                       repeatDelay--;
  316.                                                    }
  317.                                                    else if (validRepeat)
  318.                                                    {
  319.                                                           if (!(repeatStep++ % REPEAT_STEP))
  320.                                                           send_remote_event(((WORD)key)&0x00FF );
  321.                                                    }
  322.                                              }
  323.                                              else
  324.                                              {
  325.                                                    #ifdef PHILIPS
  326.                                                    if(key == IRKC_STOP)
  327.                                                    {
  328.                                                           stopkey_repeatDelay = STOPKEY_DELAY;
  329.                                                           lastkey = IRKC_NULL;
  330.                                                    }       
  331.                                                    #endif //End ifdef PHILIPS
  332.                                                    repeatDelay = REPEAT_DELAY;
  333.                                                    send_remote_event(((WORD)key)&0x00FF);
  334.                                              }
  335.                                              if (bit & 1)
  336.                                              { // LOW to HIGH transition of clock
  337.                                                    state = IDLE; // If_last bit is 1 then this is the last clock edge of stream
  338.                                                    ir_interrupt_set_edge( RISING_EDGE );
  339.                                                    interruptTypeFlag = 1;
  340.                                              }
  341.                                              else // HIGH to LOW transition of clock
  342.                                                    state = RESYNC; // If_last bit is 0 then we need to wait for one more clock edge
  343.                                       }
  344.                                }
  345.                         }
  346.                         break;
  347.                 case RESYNC:
  348.                         if (deltaTime - RC6_JITTER < RC6_SHORTPULSE  &&  RC6_SHORTPULSE < deltaTime + RC6_JITTER)
  349.                         {
  350.                                 state = IDLE;
  351.                                 ir_interrupt_set_edge( RISING_EDGE );
  352.                                 interruptTypeFlag = 1;
  353.                         }
  354.                         else if (deltaTime - RC6_JITTER < RC6_LONGPULSE  &&  RC6_LONGPULSE < deltaTime + RC6_JITTER)
  355.                         {
  356.                                 state = IDLE;
  357.                                 ir_interrupt_set_edge( RISING_EDGE );
  358.                                 interruptTypeFlag = 1;
  359.                         }
  360.                         else
  361.                         {
  362.                                 state = ERROR;
  363.                         }
  364.                         break;
  365.                 default:
  366.                         state = ERROR;
  367.                         break;
  368.       }
  369. }
  370.