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

📄 demod_dcf8722.c

📁 机顶盒解调芯片DCF8722驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
         uMessage = uRxMsg[3];
         switch (uMessage)
         {
            case NIM_MSG_INTERRUPT:
               #if (defined CABLE_INT_DISABLED)
               /* if use the POLLING method, there is no NIM_MSG_INTERRUPT message. */
               #else /* CABLE_INT_DISABLED is not defined, use the INTERRUPT method */
               debug_out (TL_INFO, "CABLE TASK: received NIM_MSG_INTERRUPT message\n");
               /* check the interrupt type */
               /* get the current lock status of the cable front end */
               dcf872x_get_lockstatus (uUnit, &bLockState);
               #endif /* CABLE_INT_DISABLED */
               break;
            
            case NIM_MSG_TIMEOUT:
               // debug_out (TL_INFO, "CABLE TASK: received NIM_MSG_TIMEOUT message\n");
               #if (defined CABLE_INT_DISABLED)
               /* get the current lock status of the cable front end */
               dcf872x_get_lockstatus (uUnit, &bLockState);
               // debug_out (TL_INFO, "CABLE TASK: current bLockState=0x%08X\n", bLockState);
               /* accroding to the current state, to do some processing. */
               switch (guNewLOCState[uUnit])
               {
                  case NIM_CONNECTING:
                  case NIM_FAILED:
                     if (TRUE == bLockState)
                     {
                        /* stop the connection timeout timer. */
                        rc = tick_stop (gNIMTimer);
                        debug_out (TL_INFO, "CABLE TASK: Locked\n");
                        /* update the state */
                        guOldLOCState[uUnit] = guNewLOCState[uUnit];
                        guNewLOCState[uUnit] = NIM_CONNECTED;
                        
                        #ifndef CABLE_LKDT_DISABLED
                        /* The new signal has been locked, turn on the lock indicator */
                        CABLE_LKDT_TURN_ON (CABLE_LKDT_GPIO_BANK, CABLE_LKDT_GPIO_BIT);
                        #endif
                        
                        /* call the callback function to indicate LOCKED. */
                        if (gpfnCallbacks[uUnit])
                        {
                           CallbackData.type      = DEMOD_CONNECT_STATUS;
                           CallbackData.parm.type = DEMOD_CONNECTED;
                           CallbackData.parm.tune = gLocalTuning[uUnit];
                           gpfnCallbacks[uUnit] (guLocalModule, uUnit, DEMOD_CONNECT_STATUS, &CallbackData);
                        }
                        /* clear and start all block counters. */
                        gTimeoutCnt = 0;
                        dcf872x_init_statics (uUnit);
                        /* we need start a timer to monitor the connection. */
                        rc = tick_set (gNIMTimer, (u_int32)(NIM_MONITOR_PERIOD), FALSE);
                        rc = tick_start (gNIMTimer);
                     }
                     else /* FALSE == bLockState */
                     {
                        gWaitingCnt++;
                        
                        if (guNewLOCState[uUnit] == NIM_CONNECTING)
                        {
						   /* NSD requires to send falaiure if signal can not be acquired in 200ms */
						#if NDS_CABLE_REQUIREMENT	
                           if (gWaitingCnt == 2)  /* 200 ms */
                           {
                              /* update the state */
                              guOldLOCState[uUnit] = guNewLOCState[uUnit];
                              guNewLOCState[uUnit] = NIM_FAILED;
                              /* if the front-end fails to acquire lock within N ms,
                               * call the callback function to indicate DEMOD_FAILED.
                               */
                              if (gpfnCallbacks[uUnit])
                              {
                                 CallbackData.type      = DEMOD_CONNECT_STATUS;
                                 CallbackData.parm.type = DEMOD_FAILED;
                                 CallbackData.parm.tune = gLocalTuning[uUnit];
                                 gpfnCallbacks[uUnit] (guLocalModule, uUnit, DEMOD_CONNECT_STATUS, &CallbackData);
                              }
                              debug_out (TL_INFO, "CABLE TASK: DEMOD_FAILED\n");
                           }
						#endif								
                        }
                        
                        if (gWaitingCnt == 6) /* 600 ms */
                        {
                           /* if the front end hasn't been SYNC for about M ms,
                            * we need try to connect the signal again.
                            */
                           gWaitingCnt = 0;   /* for the next M ms interval */
                           
                           /* if the auto-detect spectrum inversion is required,
                            * we also need change the spectrum inversion option before re-connection.
                            */
                           if (1 == gLocalTuning[uUnit].tune.nim_cable_tune.auto_spectrum)
                           {
                              switch (gLocalTuning[uUnit].tune.nim_cable_tune.spectrum)
                              {
                                 case SPECTRUM_NORMAL:
                                    gLocalTuning[uUnit].tune.nim_cable_tune.spectrum = SPECTRUM_INVERTED;
                                    break;
                                 case SPECTRUM_INVERTED:
                                    gLocalTuning[uUnit].tune.nim_cable_tune.spectrum = SPECTRUM_NORMAL;
                                    break;
                              }
                           }
                           
                           if (DRV_OK == dcf872x_connect(uUnit, (TUNING_SPEC *)(&gLocalTuning[uUnit]), TRUE))
                           {
                              gRetryCnt++;
                           }
                           
                           if (gRetryCnt == 3) /* 1800 ms */
                           {
                              /* if the front-end fails to acquire lock after 3 retries,
                               * call the callback function to indicate DEMOD_TIMEOUT.
                               */
                              if (gpfnCallbacks[uUnit])
                              {
                                 CallbackData.type      = DEMOD_CONNECT_STATUS;
                                 CallbackData.parm.type = DEMOD_TIMEOUT;
                                 CallbackData.parm.tune = gLocalTuning[uUnit];
                                 gpfnCallbacks[uUnit] (guLocalModule, uUnit, DEMOD_CONNECT_STATUS, &CallbackData);
                              }
                              gRetryCnt = 0;
                              debug_out (TL_INFO, "CABLE TASK: DEMOD_TIMEOUT\n");
                              
                              /* IF TIMEOUT IN AUTO-QAM DETECTION MODE, TRY 32-QAM MANUALLY */
                              if (gAutoQAMMode == 1)
                              {
                                 if (MOD_QAMAUTO == gLocalTuning[uUnit].tune.nim_cable_tune.modulation)
                                 {
                                    gLocalTuning[uUnit].tune.nim_cable_tune.modulation = MOD_QAM32;
                                 }
                                 else
                                 {
                                    gLocalTuning[uUnit].tune.nim_cable_tune.modulation = MOD_QAMAUTO;
                                 }
                              } /* endif (gAutoQAMMode) */
                           } /* endif (gRetryCnt) */
                        }
                     } /* endif bLockState */
                     break;
                  
                  case NIM_CONNECTED:
                     if (TRUE == bLockState)
                     {
                        if ( gTimeoutCnt == 0 )
                        {
                           /* monitor the performance of the front end. */
                           dcf872x_get_statics (uUnit);
                        }
                        
                        gTimeoutCnt ++;
                        
                        /* every (10 * NIM_MONITOR_PERIOD) ms */
                        if (gTimeoutCnt >= 10)
                        {
                           gTimeoutCnt = 0;
                        }
                     }
                     else
                     {
                        /* stop the monitor timer. */
                        rc = tick_stop (gNIMTimer);
                        debug_out (TL_INFO, "CABLE TASK: Lost signal\n");
                        /* update the state */
                        guOldLOCState[uUnit] = guNewLOCState[uUnit];
                        guNewLOCState[uUnit] = NIM_FAILED;
                        
                        #ifndef CABLE_LKDT_DISABLED
                        /* lost the signal lock, turn off the lock indicator */
                        CABLE_LKDT_TURN_OFF (CABLE_LKDT_GPIO_BANK, CABLE_LKDT_GPIO_BIT);
                        #endif
                        
                        /* call the callback function to indicate LOSE_LOCKED. */
                        if (gpfnCallbacks[uUnit])
                        {
                           CallbackData.type      = DEMOD_CONNECT_STATUS;
                           CallbackData.parm.type = DEMOD_DRIVER_LOST_SIGNAL;
                           CallbackData.parm.tune = gLocalTuning[uUnit];
                           gpfnCallbacks[uUnit] (guLocalModule, uUnit, DEMOD_CONNECT_STATUS, &CallbackData);
                        }
                        
                        /* IF LOST SIGNAL IN AUTO-QAM DETECTION MODE, ALWAYS RETRY WITH AUTO-QAM MODE. */
                        if (gAutoQAMMode == 1)
                        {
                           gLocalTuning[uUnit].tune.nim_cable_tune.modulation = MOD_QAMAUTO;
                        } /* endif (gAutoQAMMode) */
                        
                        /* try to connect the lost signal */
                        if (DRV_OK == dcf872x_connect(uUnit, (TUNING_SPEC *)(&gLocalTuning[uUnit]), TRUE))
                        {
                           /* clear the waiting counter and the retry counter */
                           gWaitingCnt = 0;
                           gRetryCnt   = 0;
                        }
                        /* start a timer to monitor the reconnection timeout */
                        rc = tick_set (gNIMTimer, (u_int32)(NIM_CONNECT_TIMEOUT), FALSE);
                        rc = tick_start (gNIMTimer);
                     }
                     break;
                  
                  default:
                     break;
               
               } /* endswitch guNewLOCState[uUnit] */
               #else /* CABLE_INT_DISABLED is not defined, use the INTERRUPT method */
               
               #endif /* CABLE_INT_DISABLED */
               break;
            
            case NIM_MSG_CONNECT:
               debug_out (TL_INFO, "CABLE TASK: received NIM_MSG_CONNECT message\n");
               /* update the state */
               guOldLOCState[uUnit] = guNewLOCState[uUnit];
               guNewLOCState[uUnit] = NIM_CONNECTING;
               #ifndef CABLE_LKDT_DISABLED
               /* the new signal is to be tuned, turn off the lock indicator */
               CABLE_LKDT_TURN_OFF (CABLE_LKDT_GPIO_BANK, CABLE_LKDT_GPIO_BIT);
               #endif
               /* connect to the required signal. */
               if (DRV_OK == dcf872x_connect(uUnit, (TUNING_SPEC *)(uRxMsg[1]), TRUE))
               {
                  /* clear the waiting counter and the retry counter */
                  gWaitingCnt = 0;
                  gRetryCnt   = 0;
               }
               /* start a timer to monitor the connection timeout. */
               rc = tick_set (gNIMTimer, (u_int32)(NIM_CONNECT_TIMEOUT), FALSE);
               rc = tick_start (gNIMTimer);
               /* release the semaphore to have the connection function return */
               //sem_put(gNIMSemaphore);
               break;
            
            case NIM_MSG_DISCONNECT:
               debug_out (TL_INFO, "CABLE TASK: received NIM_MSG_DISCONNECT message\n");
               /* do something to disconnect the current signal. */
               /* after disconnection, update the state. */
               guOldLOCState[uUnit] = guNewLOCState[uUnit];
               guNewLOCState[uUnit] = NIM_DISCONNECTED;
               #ifndef CABLE_LKDT_DISABLED
               /* disconnect with the signal, turn off the lock indicator */
               CABLE_LKDT_TURN_OFF (CABLE_LKDT_GPIO_BANK, CABLE_LKDT_GPIO_BIT);
               #endif
               /* call the callback function to indicate DISCONNECTED. */
               if (gpfnCallbacks[uUnit])
               {
                  CallbackData.type      = DEMOD_DISCONNECT_STATUS;
                  CallbackData.parm.type = DEMOD_DISCONNECTED;
                  gpfnCallbacks[uUnit] (guLocalModule, uUnit, DEMOD_DISCONNECT_STATUS, &CallbackData);
               }
               break;
            
            case NIM_MSG_SCAN:
               debug_out (TL_INFO, "CABLE TASK: received NIM_MSG_SCAN message\n");
               break;
            
            default:
               debug_out (TL_ERROR, "CABLE TASK: Unknown message 0x%x for unit %d\n", uMessage, uUnit);
               break;
         
         } /* endswitch (uMessage) */
      } /* end of processing messages */
      else
      {
         debug_out (TL_ERROR, "CABLE TASK: error code 0x%x when receiving message\n", iReturnCode);
      } /* end of receiving messages */
   } /* endwhile (1) */
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*               =========================================                   */
/*               =  FUNCTIONS OF CABLE FRONT-END DRIVER  =                   */
/*               =========================================                   */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#define CABLE_UNIT_TYPE_FUNC           cnxt_c_get_unit_type
#define CABLE_IOCTL_FUNC               cnxt_c_ioctl
#define CABLE_CONNECT_FUNC             cnxt_c_connect
#define CABLE_DISCONNECT_FUNC          cnxt_c_disconnect

⌨️ 快捷键说明

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