phantom_drv.c
来自「QPSK Tuner details, for conexant chipset」· C语言 代码 · 共 1,432 行 · 第 1/3 页
C
1,432 行
return((long)numeric);
}
else /* negative */
{
temp = numeric - (0x01L << bitslen);
return((long)temp);
}
} /* PHANTOM_DRIVER_ConvertToTwos() */
/*******************************************************************************************************
* PHANTOM_DRIVER_ConvertTwosSaturate()
* function to reduce a long integer's leading sign bits
*******************************************************************************************************/
unsigned long
PHANTOM_DRIVER_ConvertTwosSaturate(long numeric, /* long integer in 2's complement notation */
int bitslen) /* reduced bit count of the long integer */
{
long lTemp = 0L;
unsigned long ulTemp;
if (numeric >= 0)
{
/* positive number */
if (numeric >= (0x01L<<(bitslen-1))-1)
{
lTemp = ((0x01L<<(bitslen-1L))-1L);
}
else
{
lTemp = numeric;
}
}
else
{
/* negative number */
if (numeric < ((0x01L<<(bitslen-1))*-1L))
{
lTemp = ((0x01L<<(bitslen-1))*-1L);
}
else
{
lTemp = numeric;
}
}
/* remove leading sign bits for negative number */
ulTemp = (unsigned long)(lTemp & ((0x01UL << bitslen) - 1));
return (ulTemp);
} /* PHANTOM_DRIVER_ConvertTwosSaturate() */
/*******************************************************************************************************
* PHANTOM_DRIVER_CxType()
* function to perform a total SW reset of the demod
*******************************************************************************************************/
BOOL
PHANTOM_DRIVER_CxType(PHANTOM_NIM* p_nim, /* pointer to nim */
PHANTOM_DEMOD* p_demod, /* pointer to storage holding demod id'd by sw */
char** p_demod_str) /* demod string built using demod* (above) */
{
unsigned long chip_type = 0x0;
/* confirm that the chip-type is Phantom */
if (PHANTOM_RegisterRead(p_nim, PHANTOM_SC_FF_CHIP_TYPE, &chip_type, PHANTOM_USE_DEMOD_HANDLE) != True)
{
return (False);
}
/* determine the chip-type */
switch (chip_type)
{
case PHANTOM_CHIP_ID:
{
*p_demod = PHANTOM; /* Phantom */
if (p_demod_str != 0)
{
*p_demod_str = PHANTOM_PRODUCT_NAME_STRING;
}
return(True);
}
default:
{
/* unknown chip detected (unknown chip-id) */
if (p_demod_str != 0)
{
*p_demod_str = "UNKNOWN";
}
break;
}
} /* switch() */
return(False);
} /* PHANTOM_DRIVER_CxType() */
/*******************************************************************************************************
* PHANTOM_DRIVER_DiseqcTx_Rdy()
* function to check if hardware is available to send Diseqc messages
*******************************************************************************************************/
BOOL PHANTOM_DRIVER_IsDiseqcTxRdy(PHANTOM_NIM* p_nim)
{
unsigned long reg_value;
unsigned long index;
index = 0;
do /* See if the hardware is ready */
{
if (PHANTOM_RegisterRead(p_nim, PHANTOM_P0_BC_LNB_TX_READY, ®_value, PHANTOM_USE_DEMOD_HANDLE) == False)
{
return(False);
}
if (reg_value == 1UL) /* Ready */
{
break;
}
index++;
if (index == PHANTOM_MAX_LNB_RDY_POLL)
{
break;
}
} while (reg_value != 1UL);
if (reg_value != 1UL) /* Not ready */
{
PHANTOM_DBG_SET_ERROR(PHANTOM_LNB_BUSY);
return(False);
}
return(TRUE);
}
static PHANTOM_TRANSPEC
PHANTOM_GetTranportSpec(PHANTOM_RX_OPER_MODE oper_mode)
{
switch (oper_mode)
{
case PHANTOM_MODE_DTV_1_2:
case PHANTOM_MODE_1:
case PHANTOM_MODE_2:
return PHANTOM_SPEC_DTV;
case PHANTOM_MODE_3:
case PHANTOM_MODE_4:
case PHANTOM_MODE_5:
case PHANTOM_MODE_6:
case PHANTOM_MODE_7:
case PHANTOM_MODE_8:
case PHANTOM_MODE_9:
case PHANTOM_MODE_10:
case PHANTOM_MODE_11:
case PHANTOM_MODE_12:
case PHANTOM_MODE_13:
case PHANTOM_MODE_14:
case PHANTOM_MODE_15:
case PHANTOM_MODE_16:
return PHANTOM_SPEC_NBC;
case PHANTOM_MODE_DVB_1_2:
case PHANTOM_MODE_DVB_2_3:
case PHANTOM_MODE_DVB_3_4:
case PHANTOM_MODE_DVB_5_6:
case PHANTOM_MODE_DVB_7_8:
return PHANTOM_SPEC_DVB;
default:
return PHANTOM_SPEC_UNDEF;
}
}
/* Serial mode */
const PHANTOM_M_N m_n_30_clocks_wo_pilots_w_sync[] =
{
{770068, 763515, 258}, /* QPSK 1/2 */
{97409, 80370, 310}, /* QPSK 3/5 */
{137293, 101802, 345}, /* QPSK 2/3 */
{4633447, 3054060, 388}, /* QPSK 3/4 */
{2472041, 1527030, 414}, /* QPSK 4/5 */
{85904, 50901, 432}, /* QPSK 5/6 */
{2751229, 1527030, 461}, /* QPSK 8/9 */
{1392872, 763515, 467}, /* QPSK 9/10 */
{1850771, 1019430, 464}, /* 8PSK 3/5 */
{137293, 67962, 517}, /* 8PSK 2/3 */
{4633447, 2038860, 581}, /* 8PSK 4/5 */
{85904, 33981, 647}, /* 8PSK 5/6 */
{2751229, 1019430, 690}, /* 8PSK 8/9 */
{1392872, 509715, 699} /* 8PSK 9/10 */
};
const PHANTOM_M_N m_n_30_clocks_w_pilots_w_sync[] =
{
{770068, 782127, 252}, /* QPSK 1/2 */
{1850771, 1564254, 302}, /* QPSK 3/5 */
{686465, 521418, 337}, /* QPSK 2/3 */
{4633447, 3128508, 379}, /* QPSK 3/4 */
{2472041, 1564254, 404}, /* QPSK 4/5 */
{429520, 260709, 421}, /* QPSK 5/6 */
{2751229, 1564254, 450}, /* QPSK 8/9 */
{1392872, 782127, 455}, /* QPSK 9/10 */
{1850771, 1043118, 454}, /* 8PSK 3/5 */
{686465, 347706, 505}, /* 8PSK 2/3 */
{4633447, 2086236, 568}, /* 8PSK 4/5 */
{429520, 173853, 632}, /* 8PSK 5/6 */
{2751229, 1043118, 675}, /* 8PSK 8/9 */
{1392872, 521559, 683} /* 8PSK 9/10 */
};
const PHANTOM_M_N m_n_30_clocks_wo_pilots_wo_sync[] =
{
{766052, 763515, 256}, /* QPSK 1/2 */
{96901, 80370, 308}, /* QPSK 3/5 */
{136577, 101802, 343}, /* QPSK 2/3 */
{4609283, 3054060, 386}, /* QPSK 3/4 */
{2459149, 1527030, 412}, /* QPSK 4/5 */
{85456, 50901, 429}, /* QPSK 5/6 */
{2736881, 1527030, 458}, /* QPSK 8/9 */
{1385608, 763515, 464}, /* 8PSK 9/10 */
{1841119, 1019430, 462}, /* 8PSK 3/5 */
{136577, 67962, 514}, /* 8PSK 2/3 */
{4609283, 2038860, 578}, /* 8PSK 4/5 */
{85456, 33981, 643}, /* 8PSK 5/6 */
{2736881, 1019430, 687}, /* 8PSK 8/9 */
{1385608, 509715, 695} /* 8PSK 9/10 */
};
const PHANTOM_M_N m_n_30_clocks_w_pilots_wo_sync[] =
{
{766052, 782127, 250}, /* QPSK 1/2 */
{1841119, 1564254, 301}, /* QPSK 3/5 */
{682885, 521418, 335}, /* QPSK 2/3 */
{4609283, 3128508, 377}, /* QPSK 3/4 */
{2459149, 1564254, 402}, /* QPSK 4/5 */
{427280, 260709, 419}, /* QPSK 5/6 */
{2736881, 1564254, 447}, /* QPSK 8/9 */
{1385608, 782127, 453}, /* 8PSK 9/10 */
{1841119, 1043118, 451}, /* 8PSK 3/5 */
{682885, 347706, 502}, /* 8PSK 2/3 */
{4609283, 2086236, 565}, /* 8PSK 4/5 */
{427280, 173853, 629}, /* 8PSK 5/6 */
{2736881, 1043118, 671}, /* 8PSK 8/9 */
{1385608, 521559, 680} /* 8PSK 9/10 */
};
/* Parallel mode */
const PHANTOM_M_N m_n_16_clocks_wo_pilots_w_sync[] =
{
{273088, 254505, 274}, /* QPSK 1/2 */
{17272, 13395, 330}, /* QPSK 3/5 */
{24344, 16967, 367}, /* QPSK 2/3 */
{410788, 254505, 413}, /* QPSK 3/4 */
{438328, 254505, 440}, /* QPSK 4/5 */
{30464, 16967, 459}, /* QPSK 5/6 */
{487832, 254505, 490}, /* QPSK 8/9 */
{493952, 254505, 496}, /* QPSK 9/10 */
{328168, 169905, 494}, /* 8PSK 3/5 */
{24344, 11327, 550}, /* 8PSK 2/3 */
{410788, 169905, 618}, /* 8PSK 4/5 */
{30464, 11327, 688}, /* 8PSK 5/6 */
{487832, 169905, 735}, /* 8PSK 8/9 */
{493952, 169905, 744} /* 8PSK 9/10 */
};
const PHANTOM_M_N m_n_16_clocks_w_pilots_w_sync[] =
{
{273088, 260709, 268}, /* QPSK 1/2 */
{328168, 260709, 322}, /* QPSK 3/5 */
{121720, 86903, 358}, /* QPSK 2/3 */
{410788, 260709, 403}, /* QPSK 3/4 */
{438328, 260709, 430}, /* QPSK 4/5 */
{152320, 86903, 448}, /* QPSK 5/6 */
{487832, 260709, 479}, /* QPSK 8/9 */
{493952, 260709, 485}, /* QPSK 9/10 */
{328168, 173853, 483}, /* 8PSK 3/5 */
{121720, 57951, 537}, /* 8PSK 2/3 */
{410788, 173853, 604}, /* 8PSK 4/5 */
{152320, 57951, 672}, /* 8PSK 5/6 */
{487832, 173853, 718}, /* 8PSK 8/9 */
{493952, 173853, 727} /* 8PSK 9/10 */
};
const PHANTOM_M_N m_n_16_clocks_wo_pilots_wo_sync[] =
{
{815248, 763515, 273}, /* QPSK 1/2 */
{51562, 40185, 328}, /* QPSK 3/5 */
{72674, 50901, 365}, /* QPSK 2/3 */
{1226323, 763515, 411}, /* QPSK 3/4 */
{1308538, 763515, 438}, /* QPSK 4/5 */
{90944, 50901, 457}, /* QPSK 5/6 */
{1456322, 763515, 488}, /* QPSK 8/9 */
{1474592, 763515, 494}, /* 8PSK 9/10 */
{979678, 509715, 492}, /* 8PSK 3/5 */
{72674, 33981, 547}, /* 8PSK 2/3 */
{1226323, 509715, 615}, /* 8PSK 4/5 */
{90944, 33981, 685}, /* 8PSK 5/6 */
{1456322, 509715, 731}, /* 8PSK 8/9 */
{1474592, 509715, 740} /* 8PSK 9/10 */
};
const PHANTOM_M_N m_n_16_clocks_w_pilots_wo_sync[] =
{
{815248, 782127, 266}, /* QPSK 1/2 */
{979678, 782127, 320}, /* QPSK 3/5 */
{363370, 260709, 356}, /* QPSK 2/3 */
{1226323, 782127, 401}, /* QPSK 3/4 */
{1308538, 782127, 428}, /* QPSK 4/5 */
{454720, 260709, 446}, /* QPSK 5/6 */
{1456322, 782127, 476}, /* QPSK 8/9 */
{1474592, 782127, 482}, /* 8PSK 9/10 */
{979678, 521559, 480}, /* 8PSK 3/5 */
{363370, 173853, 535}, /* 8PSK 2/3 */
{1226323, 521559, 601}, /* 8PSK 4/5 */
{454720, 173853, 669}, /* 8PSK 5/6 */
{1456322, 521559, 714}, /* 8PSK 8/9 */
{1474592, 521559, 723} /* 8PSK 9/10 */
};
static unsigned short
PHANTOM_DRIVER_GetNewMNRate(unsigned long m, unsigned long n)
{
PHANTOM_BCDNO numer;
unsigned short new_mn;
PHANTOM_BCD_set (&numer, m);
PHANTOM_BCD_mult(&numer, 256);
PHANTOM_BCD_div (&numer, n);
new_mn = (unsigned short)PHANTOM_BCD_out(&numer);
return (new_mn);
}
/*
* new_M = M * (((187+S)*B+D) / ((187+S) * B))
*
* Where,
* S is 0 if no sync byte is transmitted, 1 if there is a sync byte.
* B is 1 for parallel mode, 8 for serial mode.
* D is the required extra clocks.
*/
BOOL
PHANTOM_DRIVER_GetNewMN(PHANTOM_M_N* p_old_mn, PHANTOM_M_N* p_new_mn, unsigned char extra_clocks, BOOL sync_byte, BOOL parallel_mode, PHANTOM_RX_OPER_MODE oper_mode, PHANTOM_PILOT pilot)
{
unsigned long m;
unsigned long mpeg_len;
unsigned long clocks_per_byte;
PHANTOM_BCDNO numer, temp_bcd;
unsigned long denom;
p_new_mn->m = p_old_mn->m;
p_new_mn->n = p_old_mn->n;
if (extra_clocks == 0)
{
return True;
}
if (PHANTOM_GetTranportSpec(oper_mode) == PHANTOM_SPEC_NBC && extra_clocks == 30 && parallel_mode == False) /* NBC: Serial mode */
{
if (sync_byte == False)
{ /* Without Sync Byte */
if ((oper_mode <= PHANTOM_MODE_16) && (pilot == PHANTOM_PILOT_ON))
{
p_new_mn->m = m_n_30_clocks_w_pilots_wo_sync[oper_mode-4].m;
p_new_mn->n = m_n_30_clocks_w_pilots_wo_sync[oper_mode-4].n;
p_new_mn->m_n_rate = m_n_30_clocks_w_pilots_wo_sync[oper_mode-4].m_n_rate;
}
else if (oper_mode <= PHANTOM_MODE_16)
{
p_new_mn->m = m_n_30_clocks_wo_pilots_wo_sync[oper_mode-4].m;
p_new_mn->n = m_n_30_clocks_wo_pilots_wo_sync[oper_mode-4].n;
p_new_mn->m_n_rate = m_n_30_clocks_wo_pilots_wo_sync[oper_mode-4].m_n_rate;
}
}
else
{
if ((oper_mode <= PHANTOM_MODE_16) && (pilot == PHANTOM_PILOT_ON))
{
p_new_mn->m = m_n_30_clocks_w_pilots_w_sync[oper_mode-4].m;
p_new_mn->n = m_n_30_clocks_w_pilots_w_sync[oper_mode-4].n;
p_new_mn->m_n_rate = m_n_30_clocks_w_pilots_w_sync[oper_mode-4].m_n_rate;
}
else if (oper_mode <= PHANTOM_MODE_16)
{
p_new_mn->m = m_n_30_clocks_wo_pilots_w_sync[oper_mode-4].m;
p_new_mn->n = m_n_30_clocks_wo_pilots_w_sync[oper_mode-4].n;
p_new_mn->m_n_rate = m_n_30_clocks_wo_pilots_w_sync[oper_mode-4].m_n_rate;
}
}
}
else if (PHANTOM_GetTranportSpec(oper_mode) == PHANTOM_SPEC_NBC && extra_clocks == 16 && parallel_mode == True) /* NBC: Parallel mode */
{
if (sync_byte == False)
{ /* Without Sync Byte */
if ((oper_mode <= PHANTOM_MODE_16) && (pilot == PHANTOM_PILOT_ON))
{
p_new_mn->m = m_n_16_clocks_w_pilots_wo_sync[oper_mode-4].m;
p_new_mn->n = m_n_16_clocks_w_pilots_wo_sync[oper_mode-4].n;
p_new_mn->m_n_rate = m_n_16_clocks_w_pilots_wo_sync[oper_mode-4].m_n_rate;
}
else if (oper_mode <= PHANTOM_MODE_16)
{
p_new_mn->m = m_n_16_clocks_wo_pilots_wo_sync[oper_mode-4].m;
p_new_mn->n = m_n_16_clocks_wo_pilots_wo_sync[oper_mode-4].n;
p_new_mn->m_n_rate = m_n_16_clocks_wo_pilots_wo_sync[oper_mode-4].m_n_rate;
}
}
else
{
if ((oper_mode <= PHANTOM_MODE_16) && (pilot == PHANTOM_PILOT_ON))
{
p_new_mn->m = m_n_16_clocks_w_pilots_w_sync[oper_mode-4].m;
p_new_mn->n = m_n_16_clocks_w_pilots_w_sync[oper_mode-4].n;
p_new_mn->m_n_rate = m_n_16_clocks_w_pilots_w_sync[oper_mode-4].m_n_rate;
}
else if (oper_mode <= PHANTOM_MODE_16)
{
p_new_mn->m = m_n_16_clocks_wo_pilots_w_sync[oper_mode-4].m;
p_new_mn->n = m_n_16_clocks_wo_pilots_w_sync[oper_mode-4].n;
p_new_mn->m_n_rate = m_n_16_clocks_wo_pilots_w_sync[oper_mode-4].m_n_rate;
}
}
}
else /* DVB/DTV */
{
m = p_old_mn->m;
switch (PHANTOM_GetTranportSpec(oper_mode))
{
case PHANTOM_SPEC_DTV:
mpeg_len = 130;
break;
case PHANTOM_SPEC_DVB:
mpeg_len = 187;
break;
default:
return False;
}
if (sync_byte == True)
{
mpeg_len = mpeg_len + 1;
}
if (parallel_mode == True)
{
clocks_per_byte = 1;
}
else
{
clocks_per_byte = 8;
}
denom = mpeg_len * clocks_per_byte;
PHANTOM_BCD_set (&numer, (mpeg_len * clocks_per_byte) + extra_clocks);
m = m * 100UL;
PHANTOM_BCD_mult(&numer, m);
PHANTOM_BCD_set(&temp_bcd, 50UL); /* rounding */
BCD_add_bcd(&numer, &temp_bcd);
PHANTOM_BCD_div (&numer, denom);
PHANTOM_BCD_set(&temp_bcd, 50UL); /* rounding */
BCD_add_bcd(&numer, &temp_bcd);
PHANTOM_BCD_div (&numer, 100UL);
p_new_mn->m = PHANTOM_BCD_out(&numer);
p_new_mn->n = p_old_mn->n;
p_new_mn->m_n_rate = PHANTOM_DRIVER_GetNewMNRate(p_new_mn->m, p_new_mn->n);
}
return (True);
}
/*******************************************************************************************************/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?