demod.c
来自「QPSK Tuner details, for conexant chipset」· C语言 代码 · 共 1,683 行 · 第 1/5 页
C
1,683 行
DEMOD_STATUS cnxt_demod_get_unit_type(u_int32 unit, DEMOD_NIM_TYPE *unit_type)
{
u_int32 module;
if (!demod_initialized)
{
return DEMOD_UNINITIALIZED;
}
if (unit >= total_number_units)
{
return DEMOD_BAD_UNIT;
}
if (!unit_type)
{
return DEMOD_BAD_PARAMETER;
}
module = unit_xlat_table[unit];
unit -= module_base_unit[module];
return function_table[module].unit_type(unit, unit_type);
}
/*****************************************************************************/
/* FUNCTION: cnxt_demod_get_unit_num */
/* */
/* PARAMETERS: handle - the handle for which the connect operation is */
/* requested. */
/* unitnum - pointer to the u_int32 which will be written with */
/* the unit number corresponding to the supplied handle */
/* */
/* DESCRIPTION: This function allows the caller to determine the unit */
/* number associated with the supplied handle. */
/* */
/* RETURNS: DEMOD_UNINITIALIZED - the system has not been initialized. */
/* DEMOD_SUCCESS - unit number retrieved successfully */
/* DEMOD_BAD_PARAMETER - NULL pointer passed */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
DEMOD_STATUS cnxt_demod_get_unit_num(u_int32 handle, u_int32 *unitnum)
{
if (!demod_initialized)
{
return DEMOD_UNINITIALIZED;
}
if ((handle & HANDLE_MAGIC_MASK) != HANDLE_MAGIC)
{
return DEMOD_BAD_HANDLE;
}
if (!unitnum)
{
return DEMOD_BAD_PARAMETER;
}
*unitnum = module_base_unit[(handle >> 8) & 0xFF] + (handle & 0xff);
return DEMOD_SUCCESS;
}
/*****************************************************************************/
/* FUNCTION: cnxt_demod_open */
/* */
/* PARAMETERS: unit - the unit number for which the open operation is */
/* requested. */
/* controlled - flag to indicate whether the client requests */
/* control capability for the interface (ability to order */
/* ioctl, connect, disconnect, or scan operations). */
/* handle - pointer to a variable to be set with the value of */
/* a handle to be used for subsequent operations. */
/* */
/* DESCRIPTION: This function links together a client application and a */
/* unit in the system by assigning a handle for the client to */
/* use in subsequent calls. */
/* */
/* RETURNS: DEMOD_UNINITIALIZED - the system has not been initialized. */
/* DEMOD_BAD_UNIT - the unit number is not valid. */
/* DEMOD_CONTROLLED - control access is requested to a device */
/* that is already controlled by another client. */
/* DEMOD_OPEN_COUNT - the system is already handling the */
/* maximum number of clients for the unit. */
/* DEMOD_SUCCESS - the function completed successfully. */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
DEMOD_STATUS cnxt_demod_open(u_int32 unit, bool controlled, u_int32 *handle)
{
u_int32 ii, flat_unit, module;
if (!demod_initialized)
{
return DEMOD_UNINITIALIZED;
}
if (unit >= total_number_units)
{
return DEMOD_BAD_UNIT;
}
if (controlled && is_controlled[unit])
{
return DEMOD_CONTROLLED;
}
if (!handle)
{
return DEMOD_BAD_PARAMETER;
}
/* find a handle to give back for this unit */
*handle = 0;
for (ii = 0; ii < MAX_CALLBACKS; ++ii)
{
if (open_flag[unit][ii] == 0)
{
open_flag[unit][ii] = 1;
*handle = HANDLE_MAGIC + (ii << 16);
break;
}
}
if (*handle == 0)
{
return DEMOD_OPEN_COUNT;
}
flat_unit = unit;
module = unit_xlat_table[unit];
unit -= module_base_unit[module];
is_controlled[flat_unit] |= controlled;
*handle |= (module << 8) | unit;
if (controlled)
{
*handle |= 0x80000000;
}
return DEMOD_SUCCESS;
}
/*****************************************************************************/
/* FUNCTION: cnxt_demod_close */
/* */
/* PARAMETERS: handle - the handle to be closed. */
/* */
/* DESCRIPTION: This function terminates operation of a unit by a client. */
/* Once calling cnxt_demod_close, a client must not use the */
/* handle value to access the system again or the access may */
/* cause undefined operation. */
/* */
/* RETURNS: DEMOD_UNINITIALIZED - the system has not been initialized. */
/* DEMOD_SUCCESS - the function completed successfully. */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
DEMOD_STATUS cnxt_demod_close(u_int32 handle)
{
u_int32 module, unit, flat_unit, controlled, slot;
if (!demod_initialized)
{
return DEMOD_UNINITIALIZED;
}
if ((handle & HANDLE_MAGIC_MASK) != HANDLE_MAGIC)
{
return DEMOD_BAD_HANDLE;
}
module = (handle >> 8) & 0xff;
unit = handle & 0xff;
flat_unit = unit + module_base_unit[module];
controlled = (handle & 0x80000000) != 0;
is_controlled[flat_unit] &= (controlled == 0);
slot = (handle >> 16) & 0x3f;
if (slot >= MAX_CALLBACKS)
{
return DEMOD_BAD_UNIT;
}
open_flag[flat_unit][slot] = 0;
#if 0
for (ii = 0; ii < MAX_CALLBACKS; ++ii)
{
if (open_flag[unit][ii] == handle)
{
open_flag[unit][ii] = 0;
break;
}
}
#endif
return DEMOD_SUCCESS;
}
/*****************************************************************************/
/* FUNCTION: cnxt_demod_ioctl */
/* */
/* PARAMETERS: handle - the handle for which the ioctl operation is */
/* requested. */
/* type - the type of ioctl operation requested. */
/* data - pointer to the DEMOD_IOCTL_TYPE structure that */
/* contains data for the operation or will be filled out */
/* with data by the operation. */
/* */
/* DESCRIPTION: This function implements various module-specific control or */
/* status functions. */
/* */
/* RETURNS: DEMOD_UNINITIALIZED - the system has not been initialized. */
/* DEMOD_NOT_CONTROLLED - the handle for which the operation */
/* is requested does not have control of the device. */
/* The return value from the called module function. */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
DEMOD_STATUS cnxt_demod_ioctl(u_int32 handle, DEMOD_IOCTL_TYPE type, void *data)
{
u_int32 module, unit;
if (!demod_initialized)
{
return DEMOD_UNINITIALIZED;
}
if ((handle & HANDLE_MAGIC_MASK) != HANDLE_MAGIC)
{
return DEMOD_BAD_HANDLE;
}
module = (handle >> 8) & 0xff;
unit = handle & 0xff;
if (!(handle & 0x80000000))
{
return DEMOD_NOT_CONTROLLED;
}
return function_table[module].ioctl(unit, type, data);
}
/*****************************************************************************/
/* FUNCTION: cnxt_demod_connect */
/* */
/* PARAMETERS: handle - the handle for which the connect operation is */
/* requested. */
/* tuning - pointer to the TUNING_SPEC structure containing */
/* parameters for the requested connection. */
/* */
/* DESCRIPTION: This function connects to a stream by calling the module */
/* driver to perform the actual connection. */
/* */
/* RETURNS: DEMOD_UNINITIALIZED - the system has not been initialized. */
/* DEMOD_NOT_CONTROLLED - the handle for which the operation */
/* is requested does not have control of the device. */
/* The return value from the called module function. */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
DEMOD_STATUS cnxt_demod_connect(u_int32 handle, TUNING_SPEC *tuning)
{
u_int32 module, unit, dummy;
if (!demod_initialized)
{
return DEMOD_UNINITIALIZED;
}
if ((handle & HANDLE_MAGIC_MASK) != HANDLE_MAGIC)
{
return DEMOD_BAD_HANDLE;
}
if (!tuning)
{
return DEMOD_BAD_PARAMETER;
}
module = (handle >> 8) & 0xff;
unit = handle & 0xff;
if (!(handle & 0x80000000))
{
return DEMOD_NOT_CONTROLLED;
}
if (function_table[module].scan_next)
{
/* manipulate the state machine */
if ((unit_state_machine_info[GLOBAL_UNIT_NUMBER].state == CONNECTED) ||
(unit_state_machine_info[GLOBAL_UNIT_NUMBER].state == DISCONNECTED) ||
(unit_state_machine_info[GLOBAL_UNIT_NUMBER].state == LOCK_WANTED))
{
unit_state_machine_info[GLOBAL_UNIT_NUMBER].scanning = FALSE;
/* Check if we are already connected to this multiplex */
if (tuning_spec_equal(*tuning,
unit_state_machine_info[GLOBAL_UNIT_NUMBER].requested_tuning_spec) &&
(unit_state_machine_info[GLOBAL_UNIT_NUMBER].state == CONNECTED))
{
/* Call callback function */
call_back(GLOBAL_UNIT_NUMBER,
DEMOD_CONNECT_STATUS,
DEMOD_CONNECTED,
&unit_state_machine_info[GLOBAL_UNIT_NUMBER].tuning_spec);
trace_new((TRACE_LEVEL_3 | TRACE_DMD),
"Callback, acquire succeed\n");
return DEMOD_SUCCESS;
}
else
{
/* set the TUNING_SPEC */
unit_state_machine_info[GLOBAL_UNIT_NUMBER].tuning_spec = *tuning;
/* keep a record of the tuning spec */
unit_state_machine_info[GLOBAL_UNIT_NUMBER].requested_tuning_spec = *tuning;
/* change the state */
if (change_demod_state(unit, module, CALL_CONNECT) == RC_OK)
{
return DEMOD_SUCCESS;
}
else
{
return DEMOD_IS_BUSY;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?