phantom_api.c
来自「QPSK Tuner details, for conexant chipset」· C语言 代码 · 共 1,923 行 · 第 1/5 页
C
1,923 行
PHANTOM_GetBTL(PHANTOM_NIM *p_nim, /* pointer to nim */
long *p_btl) /* BTL register value returned to caller */
{
unsigned long reg_value;
/* validate nim */
PHANTOM_DBG_VALIDATE_NIM(p_nim);
if (p_btl == 0)
{
PHANTOM_DBG_SET_ERROR(PHANTOM_BADPTR);
return (False);
}
*p_btl = 0;
if (PHANTOM_RegisterRead(p_nim, PHANTOM_P0_A1_SYMBRATE_OFFSET, ®_value, PHANTOM_USE_DEMOD_HANDLE) == False)
{
return (False);
}
*p_btl = (long)PHANTOM_DRIVER_ConvertToTwos(reg_value, 16);
return (True);
} /* PHANTOM_GetBTL() */
/*******************************************************************************************************
* PHANTOM_SetLNBDC()
* sets voltage to LNb to either high (~18v) or low (~13v)
*******************************************************************************************************/
BOOL
PHANTOM_SetLNBDC(PHANTOM_NIM *p_nim, /* pointer to nim */
PHANTOM_LNBDC_LEVEL lnbpol) /* LNB_HIGH or LNB_LOW */
{
unsigned char value;
/* validate nim */
PHANTOM_DBG_VALIDATE_NIM(p_nim);
switch (lnbpol)
{
case PHANTOM_LNBDC_HIGH:
case PHANTOM_LNBDC_LOW:
value = (unsigned char)(lnbpol == PHANTOM_LNBDC_HIGH ? 0x01UL : 0x00UL);
/* LLF to set the LNB DC Level control bit */
if (PHANTOM_LLF_LNBDCLevel (p_nim, value) == False)
{
return (False);
}
return (True);
default: break;
} /* switch(... */
PHANTOM_DBG_SET_ERROR(PHANTOM_BAD_PARM);
return(False);
} /* PHANTOM_SetLNBDC() */
/*******************************************************************************************************
* PHANTOM_SetLNBTone()
* function to turn-on or off LNB tone
*******************************************************************************************************/
BOOL
PHANTOM_SetLNBTone(PHANTOM_NIM *p_nim, /* pointer to nim */
PHANTOM_LNBTONE lnb_tone)/* PHANTOM_LNBTONE_ON or PHANTOM_LNBTONE_OFF */
{
/* validate nim */
PHANTOM_DBG_VALIDATE_NIM(p_nim);
switch(lnb_tone)
{
case PHANTOM_LNBTONE_ON:
case PHANTOM_LNBTONE_OFF:
if (PHANTOM_LLF_LNBPCBConfig(p_nim,
(unsigned char)PHANTOM_DEFAULT_LNB_DC_POLARITY,
(unsigned char)PHANTOM_DEFAULT_LNB_OPEN_DRAIN,
(unsigned char)lnb_tone) == False)
{
return(False);
}
break;
default:
PHANTOM_DBG_SET_ERROR(PHANTOM_BAD_PARM);
return(False);
}
return(True);
} /* PHANTOM_SetLNBTone() */
/*******************************************************************************************************
* PHANTOM_GetLNBOffset()
* function to return acq. offset
*******************************************************************************************************/
BOOL
PHANTOM_GetLNBOffset(PHANTOM_NIM *p_nim, /* pointer to nim */
long *p_lnboffset) /* returned acq. offset value */
{
long ctl;
signed long frequency_offset;
/* validate nim */
PHANTOM_DBG_VALIDATE_NIM(p_nim);
if (PHANTOM_GetCTL(p_nim, &ctl) == False)
{
return (False);
}
if (PHANTOM_GetFrequencyOffset(p_nim, &frequency_offset) == False)
{
return (False);
}
*p_lnboffset = ctl - frequency_offset;
return (True);
} /* PHANTOM_GetLNBOffset() */
/*******************************************************************************************************
* PHANTOM_GetTunerPLLFrequency()
* function to retrieve the tuner PLL freq. during lock/acq
*******************************************************************************************************/
BOOL
PHANTOM_GetTunerPLLFrequency(PHANTOM_NIM *p_nim, /* pointer to nim */
unsigned long *p_pll_frequency) /* pointer to storage for return value */
{
/* test for valid nim */
PHANTOM_DBG_VALIDATE_NIM(p_nim);
if (p_pll_frequency == 0)
{
PHANTOM_DBG_SET_ERROR(PHANTOM_BAD_PARM);
return (False);
}
if (PHANTOM_RegisterRead(p_nim, PHANTOM_P0_97_TUNER_FREQ_KHZ, p_pll_frequency, PHANTOM_USE_DEMOD_HANDLE) == False)
{
return (False);
}
return(True);
} /* PHANTOM_GetTunerPLLFrequency() */
/*******************************************************************************************************
* PHANTOM_GetFrequencyOffset()
* function to return the frequency offset (requested - pll freq.). Must be called after tuner is tuned.
*******************************************************************************************************/
BOOL
PHANTOM_GetFrequencyOffset(PHANTOM_NIM *p_nim,
signed long *p_frequency_offset)
{
unsigned long tuner_pll_frequency = 0;
/* validate nim */
PHANTOM_DBG_VALIDATE_NIM(p_nim);
if (p_frequency_offset == 0)
{
PHANTOM_DBG_SET_ERROR(PHANTOM_BADPTR);
return (False);
}
if (PHANTOM_GetTunerPLLFrequency(p_nim, &tuner_pll_frequency) == False)
{
return (False);
}
*p_frequency_offset = (signed long)(tuner_pll_frequency - p_nim->freq_ideal);
return(True);
}
/*******************************************************************************************************
* PHANTOM_GetGPIOIn()
*
* Description:
* This function will get the specified GPIOs input value.
*
* Return Value:
* TRUE - operation successful; FALSE - otherwise
*
* I/O Parameters Descriptions
* IN PHANTOM_NIM* p_nim Pointer to PHANTOM_NIM structure allocated by application
* IN unsigned char* p_GPI GPO4,3,2,1,0. Default 0.
* IN unsigned char GPI_mask If bit i=0 don't get the input data of the corresponding line.
* Get the data at the position according to GPI_mask, otherwise.
*******************************************************************************************************/
BOOL
PHANTOM_GetGPIOIn (PHANTOM_NIM *p_nim,
unsigned char *p_GPI,
unsigned char GPI_mask)
{
unsigned long reg_value;
*p_GPI = 0;
if (PHANTOM_RegisterRead(p_nim, PHANTOM_SC_FD_GPIO_INPUTS, ®_value, PHANTOM_USE_DEMOD_HANDLE) == False)
{
return(False);
}
*p_GPI = (unsigned char)(reg_value & GPI_mask);
return (True);
}
/*******************************************************************************************************
* PHANTOM_SetGPIOMode()
*
* Description:
* This function will set the GPIO mode.
*
* Return Value:
* TRUE - operation successful; FALSE - otherwise
*
* I/O Parameters Descriptions
* IN PHANTOM_NIM* p_nim Pointer to PHANTOM_NIM structure allocated by application
* IN unsigned char mode_sel mode_sel[n] = PHANTOM_GPIO_MODE_TTL or PHANTOM_GPIO_MODE_OD.
*
*******************************************************************************************************/
BOOL
PHANTOM_SetGPIOMode (PHANTOM_NIM *p_nim, unsigned char mode_sel)
{
PHANTOM_LLF llf;
llf.op_code = PHANTOM_OPCODE_GPIO_MODE;
llf.data[0] = mode_sel;
llf.send_data_length = 1; /* Number of LLF arguments */
llf.received_data_length = 0; /* Number of return arguments */
if (PHANTOM_ExecuteLLF(p_nim, &llf) == False) /* Send it to FIFO */
{
PHANTOM_DBG_SET_ERROR(PHANTOM_LLF_GPIO_MODE_ERR);
return(False);
}
return (True);
}
/*******************************************************************************************************
* PHANTOM_GetLNBTone()
* function to read BC register
* The return value is 0 or 1.
*******************************************************************************************************/
BOOL
PHANTOM_GetLNBTone(PHANTOM_NIM *p_nim,/* pointer to nim */
long *p_lnb_tone)/* returned ctl value to caller */
{
unsigned long reg_value;
/* validate nim */
PHANTOM_DBG_VALIDATE_NIM(p_nim);
if (p_lnb_tone == 0)
{
PHANTOM_DBG_SET_ERROR(PHANTOM_BADPTR);
return (False);
}
if (PHANTOM_RegisterRead(p_nim, PHANTOM_P0_BC_LNB_TONE, ®_value, PHANTOM_USE_DEMOD_HANDLE) == False)
{
return (False);
}
*p_lnb_tone = reg_value ;
return (True);
}
#if PHANTOM_INCLUDE_DISEQC2
/*******************************************************************************************************
* PHANTOM_DiseqcInitialize
* Function to initialize diseqc
* Parameters:
* I/O Parameters Descriptions
* --------------------------------------------------------------------------------
* IN p_nim Pointer to PHANTOM_NIM structure allocated by application.
* IN reply_expiration_window Reply expiration window.
* IN lnb_tone_amplitude Range 0 to 63.
* IN lnb_tone_frequency Frequency in kHz.
* IN lnb_tone_detection_thresh Threshold that determines the existence of 22kHz tone.
* IN lnb_tone_burst_enable Determines if tone burst will be sent or not.
* IN lnb_mode Tone, Envelope, static 0 static 1.
*
*******************************************************************************************************/
BOOL
PHANTOM_DiseqcInitialize(PHANTOM_NIM *p_nim,
PHANTOM_LNB_RX_EXP_WINDOW reply_expiration_window,
unsigned char lnb_tone_amplitude,
unsigned char lnb_tone_frequency,
unsigned char lnb_tone_detection_thresh,
PHANTOM_LNB_TONEBURST_EN_SET lnb_tone_burst_enable,
PHANTOM_LNBMODE_SET lnb_mode)
{
/* test for valid nim */
PHANTOM_DBG_VALIDATE_NIM(p_nim);
/* Enable the DiSEqC 1-bit ADC */
if (PHANTOM_RegisterWrite(p_nim, PHANTOM_SC_E0_DISEQC_ADC_ENABLE, 0x01UL, PHANTOM_USE_DEMOD_HANDLE) == False)
{
return(False);
}
if (p_nim->tuner_ref_clkout_div == PHANTOM_TUNER_REF_CLKOUT_DIV2) /* tuner is dividing the demod ref clk */
{
lnb_tone_frequency = (unsigned char)(lnb_tone_frequency * 2);
}
if (PHANTOM_LLF_LNBConfig(p_nim,
(unsigned char)reply_expiration_window,
lnb_tone_amplitude,
lnb_tone_frequency,
(unsigned char)lnb_tone_detection_thresh,
(unsigned char)lnb_tone_burst_enable,
(unsigned char)lnb_mode) == False)
{
return(False);
}
return (True);
}
/*******************************************************************************************************
* PHANTOM_DiseqcReceiveMessage
* Function to receive diseqc message.
* Parameters:
* I/O Parameters Descriptions
* --------------------------------------------------------------------------------
* IN p_nim Pointer to PHANTOM_NIM structure allocated by application.
* IN p_buffer Pointer to allocated storage where Rx'd Diseqc message will be stored.
* IN buffer_len Length in bytes of buffer.
* IN p_received_len Returned number of bytes read from Page0.
* IN p_parity_errors Parity errors: 0 indicates no errors; binary 1 indicates an error.
* IN p_reply_errors 1 in bit i indicates error in byte i.
*
*******************************************************************************************************/
BOOL
PHANTOM_DiseqcReceiveMessage(PHANTOM_NIM *p_nim,
unsigned char *p_buffer,
unsigned char buffer_len,
unsigned char *p_received_len,
unsigned char *p_parity_errors,
unsigned char *p_reply_errors)
{
unsigned long reg_value;
unsigned long count;
unsigned char byte_count;
/* Test for valid nim */
PHANTOM_DBG_VALIDATE_NIM(p_nim);
if (p_buffer == 0 || p_received_len == 0 || p_parity_errors == 0 || p_reply_errors == 0)
{
PHANTOM_DBG_SET_ERROR(PHANTOM_BAD_PARM);
return(False);
}
/* start pulling bytes from the demod */
count = 0;
*p_received_len = 0;
do
{ /* check for an existing rx message */
if (PHANTOM_RegisterRead(p_nim, PHANTOM_P0_BC_LNB_RX_READY, ®_value, PHANTOM_USE_DEMOD_HANDLE) == False)
{
return(False);
}
if (reg_value == 0x01UL)
{
break; /* break out of while loop */
}
count++;
} while(count <= PHANTOM_MAX_LNB_INTR_POLL);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?