📄 hamaro_drv.c
字号:
/* hamaro_drv.c */
/*+++ *******************************************************************\
*
* Copyright and Disclaimer:
*
* ---------------------------------------------------------------
* ALL SOFTWARE, APPLICATIONS, DOCUMENTATION, OR MATERIALS
* FURNISHED HEREIN IS PROVIDED *AS IS*. CONEXANT DOES NOT MAKE
* ANY WARRANTIES, EITHER EXPRESS OR IMPLIED, AND HEREBY EXPRESSLY
* DISCLAIMS ANY AND ALL SUCH WARRANTIES TO THE EXTENT PERMITTED
* BY LAW, INCLUDING, SPECIFICALLY, ANY IMPLIED WARRANTY ARISING
* BY STATUTE OR OTHERWISE IN LAW OR FROM A COURSE OF DEALING OR
* USAGE OF TRADE. CONEXANT DOES NOT MAKE ANY WARRANTIES, EITHER
* EXPRESS OR IMPLIED, AND HEREBY EXPRESSLY DISCLAIMS ANY AND ALL
* SUCH WARRANTIES WITH RESPECT TO ALL SOFTWARE, APPLICATIONS,
* DOCUMENTATION, AND MATERIALS INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY, OR OF MERCHANTABLE QUALITY, OR OF FITNESS
* FOR ANY PURPOSE, PARTICULAR, SPECIFIC OR OTHERWISE, OR OF
* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OF OTHERS,
* RELATING TO THE SOFTWARE, APPLICATIONS, OPERATION,
* DOCUMENTATION, DATA OR RESULTS GENERATED BY THE OPERATION OR
* USE THEREOF, AND MATERIALS PROVIDED HEREIN. THE ENTIRE RISK AS
* TO THE SUBSTANCE, QUALITY AND PERFORMANCE OF SOFTWARE,
* APPLICATIONS, AND DOCUMENTATION DESCRIBING SUCH SOFTWARE
* REMAINS WITH THE BUYER.
*
* REGARDLESS OF WHETHER ANY REMEDY SET FORTH HEREIN FAILS OF ITS
* ESSENTIAL PURPOSE OR OTHERWISE, CONEXANT SHALL NOT BE LIABLE
* FOR ANY EXEMPLARY, SPECIAL, PUNITIVE, SPECULATIVE, INDIRECT,
* CONSEQUENTIAL OR INCIDENTAL DAMAGES OF ANY KIND (INCLUDING
* WITHOUT LIMITATION LOST PROFITS, LOSS OF INCOME, LOSS OF
* GOODWILL, OR OTHER TANGIBLE OR INTANGIBLE BUSINESS LOSS)
* ARISING OUT OF OR IN CONNECTION WITH, DIRECTLY OR INDIRECTLY,
* SOFTWARE, APPLICATIONS, DOCUMENTATION, OR ANY SERVICES OR
* MATERIALS PROVIDED HEREUNDER, OR USE OR INABILITY TO USE THE
* SOFTWARE, EVEN IF CONEXANT HAS BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGES.
*
* Copyright (c) 2001 Conexant Systems, Inc.
* All Rights Reserved.
* ---------------------------------------------------------------
*
* Module Revision Id:
*
* $Header: hamaro_drv.c, 15, 2006-10-20 2:12:16, Xiao Dong Zhang$
*
* Abstract:
*
* Contains internal Hamaro Driver software that is called by the API and
* other software layers.
*
\******************************************************************* ---*/
#include <time.h> /* ANSI Standard */
#include <string.h> /* ANSI Standard */
#include <stdlib.h> /* ANSI Standard (used for labs() )*/
#define HAMAROEXT /* forces globals to be static to this function */
#include "hamaro.h" /* Hamaro include files, ordered */
#include "hamaro_regs.h" /* Hamaro Internal */
/*******************************************************************************************************/
/* static arrays visible to this file only */
/*******************************************************************************************************/
static int dvb_cr_equate[] = {1,2,3,4,5,6,7,0};
static HAMARO_CODERATE dvb_cr_list[] = {HAMARO_CODERATE_1DIV2,HAMARO_CODERATE_2DIV3,HAMARO_CODERATE_3DIV4,
HAMARO_CODERATE_4DIV5,HAMARO_CODERATE_5DIV6,HAMARO_CODERATE_6DIV7,
HAMARO_CODERATE_7DIV8,HAMARO_CODERATE_NONE};
#if HAMARO_INCLUDE_DEBUG
/*******************************************************************************************************/
/* DRIVER_SetError() */
/*******************************************************************************************************/
void HAMARO_DRIVER_SetError( /* function to record error number into nim */
HAMARO_NIM *nim, /* nim pointer */
HAMAROERRNO err, /* API error number */
char *filename, /* filename (or useful info) (or NULL) where error occurred */
int lineno) /* line number where error occurred */
{
/* usage: It is important to place this error-recording function at or near */
/* point of error, in order to track and find program and line of error */
/* see: Macro -> HAMARO_DRIVER_SET_ERROR */
/* validate nim, if invalid nim, nothing to do, so bail */
if (nim == NULL) return;
/* if (HAMARO_DRIVER_ValidNim(nim) == False) return; No need to validate */
/* record only the first error, not the last one encountered */
if (nim->__errno == HAMARO_NOERR)
{
nim->__errno = err;
nim->errfname = filename;
nim->errline = lineno;
}
return;
} /* HAMARO_DRIVER_Seterror() */
/*******************************************************************************************************/
/* HAMARO_DRIVER_GetError() */
/*******************************************************************************************************/
char *HAMARO_DRIVER_GetError( /* function to retrieve string info concerning error no in nim */
HAMAROERRNO err) /* error number */
{
int i;
static HAMARO_NIM_ERROR nimerr[] = /* static list of errors (add to list as needed) */
{
{HAMARO_NOERR, "(No error)"}, /* No error encountered */
{HAMARO_BADPTR, "Bad pointer"}, /* bad pointer passed to API function */
{HAMARO_INVALID_NIM, "Bad HAMARO_NIM pointer"}, /* bad nim pointer passed to API */
{HAMARO_NIM_OPENED, "HAMARO_NIM already opened"}, /* bad nim pointer passed to API */
{HAMARO_SBIO_NULL, "User SBIO functs are NULL"}, /* user-supplied SBRead or SBWrite funct is NULL */
{HAMARO_TIMER_NULL, "Invalid Timer() function"}, /* timer specified at init is not valid */
{HAMARO_NIM_NULL, "HAMARO_NIM ptr is NULL"}, /* nim pointer passed is null */
{HAMARO_IO_READERR, "I/O Err: read"}, /* error encountered at read demod */
{HAMARO_IO_WRITERR, "I/O Err: write"}, /* error encountered at write demod */
{HAMARO_INVALID_TUNER,"tuner type is not valid"}, /* tuner-type invalid or not supported */
{HAMARO_TUNER_PARMS, "tunerparms pointer is NULL"},/* tuner-parms pointer is NULL */
{HAMARO_CONST_IQBUF, "NULL at ConstGetPoints()"}, /* NULL pointer pased at HAMARO_ConstGetPoints() */
{HAMARO_CONST_IQLOW, "Too few ConstGetPoints()"}, /* too few constellation pts, reduce count or try later */
{HAMARO_BAD_PARM, "API: Bad parm passed"}, /* bad parameter passed by caller -- see fil/line to determine error */
{HAMARO_SETILLEGAL, "Warn: API illegal setting"}, /* requested setting is illegal and ignored */
{HAMARO_BAD_RTNVAL, "API: Bad return value"}, /* hardware returned a n invalid result */
{HAMARO_PARM_RANGE, "API: Parm bounds error"}, /* parm passed was out of valid range */
{HAMARO_LOCKIND_ERR, "API: Error reading lockind"},/* unable to read a lockind register */
{HAMARO_REG_MATCH_IDX, "Register index corrupt"}, /* Register array built in hamaro_reg.h is corrupt */
{HAMARO_REG_MATCH_TRX, "Register translate error"}, /* unable to translate from raw to enum */
{HAMARO_REG_MATCH_DTRX, "Register detranslate error"},/* unable to translate from raw to enum */
{HAMARO_REG_VERFY_IDX, "Reg.Map: Idx != rec no"}, /* register map index does not match linear position */
{HAMARO_REG_VERFY_ADDR, "Reg.Map: Addr range err"}, /* reg.map addr variable out of range */
{HAMARO_REG_VERFY_REGRW, "Reg.Map: regrw field err"}, /* reg.map regrw field contains invalid data */
{HAMARO_REG_VERFY_REGFLT,"Reg.Map: bad filter val"}, /* reg.map regfilter field contains invalid data */
{HAMARO_REG_VERFY_REGDTP,"Reg.Map: bad data type"}, /* reg.map regdaattype field contains invalid data */
{HAMARO_REG_VERFY_DFLT, "Reg.Map: Default bound err"},/* reg.map default value is out of bounds */
{HAMARO_REG_VERFY_BCNT, "Reg.Map: Bit cnt/len err"}, /* reg.map bit count/length are questionable */
{HAMARO_REG_VERFY_DTLEN, "Reg.Map: data type/len err"},/* reg.map regdattype inconsistent with length */
{HAMARO_REG_HDWR_REWTERR,"Read/Mask/Wt err at write"}, /* I/O err at SBWrite() at read/write/mask */
{HAMARO_REG_HDWR_REGRDO, "Write attempt to r/o reg"}, /* I/O error: write attempt to RO register */
{HAMARO_REG_HDWR_REGWTO, "Read attempt to w/o reg"}, /* I/O error: read attempt to WO register */
{HAMARO_RANGE, "Warn:Write Bounds Error"}, /* Register written with bounds error data */
{HAMARO_INIT_XTAL, "Init: xtal bounds error"}, /* crystal freq is out-of-bounds */
{HAMARO_INIT_VCO, "Init: vcoinit neither T/F"}, /* vcoinit is neither True nor False */
{HAMARO_INIT_MPEG, "Init: Default MPEG is NULL"},/* Mpeg (default settings) struct is NULL */
{HAMARO_INIT_TUNER, "Init: HAMAROTuner parm bad"}, /* tuner parm passed is invalid */
{HAMARO_DEMOD_ERR, "Demod has invalid setting"}, /* demod register read has invalid setting */
{HAMARO_VITSETTING, "Demod viterbi setting null"},/* demod viterbi search list is set to zero */
{HAMARO_ERRBYTE, "Demod not set for BYTEerr"}, /* demod is not set to return BYTE error counts */
{HAMARO_NOTSUPPORT, "Feature not supported"}, /* asked-for feature not supported by driver */
{HAMARO_INVALID_VCONO, "HAMAROTuner: Invalid vco no"}, /* invalid vco number selected in driver */
{HAMARO_BAD_BP, "HAMAROTuner: Invalid BP pct"}, /* invalid breakpoint% */
{HAMARO_BAD_CXCTL, "HAMAROTuner: Invalid ctl bits"}, /* invalid setting for tuner control bits (b20,19) */
{HAMARO_BAD_CXDATA, "HAMAROTuner: data range error"}, /* data to be sent to tuner fails range check */
{HAMARO_BAD_CXMETH, "HAMAROTuner: io method setting"}, /* tuner i/o method is invalid see TUNER_io_method setting */
{HAMARO_TUNERERR, "HAMAROTuner: default setting err"},/* unable to set tuner to default i/o settings */
{HAMARO_TUNERIO, "HAMAROTuner: unable perform I/O"}, /* unable to write data to tuner */
{HAMARO_BAD_DIV, "API: Averted div by zero"}, /* trapped a div by zero err, results are undef */
{HAMARO_BAD_TUNERPARMS, "HAMAROTuner: Bad Parms passed"}, /* tunerparms passed by caller contains invalid settings */
{HAMARO_TUNEREDGE, "HAMAROTuner: Can't find VCO edge"},/* unable to find a tuner edge */
{HAMARO_VITSET, "Viterbi coderate settings"}, /* viterbi code rate settings are wrong/bad */
{HAMARO_IQ_IO, "Demod: Err reading IQ pair"},/* demod: unable to read I, Q paired data */
{HAMARO_CXTYPE, "Demod: Unable to ID demod"}, /* unable to determine demod type (CxType) */
{HAMARO_BADCXDATABND,"HAMAROTuner: band range error"}, /* band data sent to tuner fails data range test */
{HAMARO_BADCXDATAVGA,"HAMAROTuner: VGA range error"}, /* vga data sent to tuner fails data range test */
{HAMARO_BADCXDATAVCA,"HAMAROTuner: VCA range error"}, /* vca data sent to tuner fails data range test */
{HAMARO_BADCXDATAPLL,"HAMAROTuner: data range error"}, /* pll data sent to tuner fails data range test */
{HAMARO_TUNERREF, "HAMAROTuner: Invalif Ref Divider"},/* invalid refernce divider passed as parm to funct */
{HAMARO_TUNERVCO, "No valid VCO exists for the selected frequency: VCO edge detection required."},
/* ^^ No valid VCO exists for the selected frequency (detect VCO edges) */
{HAMARO_LNB_MSGLEN, "LNB message too short"}, /* unable to send a short LNB message */
{HAMARO_LNB_STALLED, "LNB message stalled"}, /* unable to send LNB message in time allocated */
{HAMARO_LNB_BUSY, "LNB message BUSY"}, /* LNB message busy flag is not set (should be set -> 0x01 indicates NOT busy) */
{HAMARO_DEMOD_REVB_SINGLE,"Invalid use of RevB SW"},/* (invalid use of Rev B SW) */
{HAMARO_DISEQC_RXLEN,"Diseqc: Rx buffer too short"},/* passed-in rx buffer len was <= 0 */
{HAMARO_DISEQC_VERSION,"Diseqc: No Rx HW on demod"},/* demod does not contain this capability */
{HAMARO_DISEQC_TIMEOUT,"Diseqc: Rx Timeout"}, /* demod took to long to rx diseqc message */
{HAMARO_PDMFOUT, "Error setting pdmfout reg"},/* error setting pdmfout register */
/* end-of-list of errors -- must be last record */
{HAMARO_IQ_NULL, "HAMARO_IQPAK pointer is NULL"}, /* HAMARO_IQPAK constellation pointer is NULL */
{HAMARO_SCE_DEADLOCK,"SCE Deadlock"}, /* Symbol Clock Estimator deadlock */
{HAMARO_DEMOD_UNSUPPORTED,"Demod: Not supported by driver"}, /* demod is not supported by the driver */
{HAMARO_EOERR, "(end of err list)"} /* timer specified at init is not valid */
};
/* find the error string, report it back to collar */
for (i = 1 ; nimerr[i].__errno != HAMARO_EOERR ; i++)
{
if (nimerr[i].__errno == err)
{
return(nimerr[i].errstr);
}
}
return(nimerr[0].errstr);
} /* HAMARO_DRIVER_GetError() */
#endif /* HAMARO_INCLUDE_DEBUG */
/*******************************************************************************************************/
/* HAMARO_DRIVER_preinit() */
/*******************************************************************************************************/
void HAMARO_DRIVER_preinit() /* function to pre-init tuner/demod strings (data must be available */
{ /* prior to successful InitEnv() for GUI access) */
static int driver_inited = False;
static unsigned int ts_list[] = /* tuners-supported list */
{
#if HAMARO_INCLUDE_ROSIE
(unsigned int)HAMARO_CX24108, /* tuner enum (rosie) */
#endif
#if HAMARO_INCLUDE_VIPER
(unsigned int)HAMARO_CX24128, /* tuner enum (viper) */
#endif
#if HAMARO_INCLUDE_RATTLER
(unsigned int)HAMARO_CX24113, /* tuner enum (Rattler) */
#endif
0}; /* zero marks end-of-list */
static char *ts_names[HAMARO_MAX_TUNERSUPPORT] =
{
#if HAMARO_INCLUDE_ROSIE
HAMARO_ROSIE_TYPE_STRING, /* rosie */
#endif
#if HAMARO_INCLUDE_VIPER
HAMARO_VIPER_TYPE_STRING, /* Viper */
#endif
#if HAMARO_INCLUDE_RATTLER
HAMARO_RATTLER_TYPE_STRING, /* Rattler */
#endif
NULL}; /* NULL marks end-of-list */
if (driver_inited == False)
{
hamaro_tuners_supported = ts_list; /* list of supported tuners */
_hamaro_tuners_supported = &ts_names[0];
}
driver_inited = True;
return;
} /* HAMARO_DRIVER_preinit() */
/*******************************************************************************************************/
/* HAMARO_DRIVER_ValidateNim() */
/*******************************************************************************************************/
BOOL HAMARO_DRIVER_ValidateNim( /* function to test nim for NULL and inclusion in HAMARO_NIM_LIST */
HAMARO_NIM *nim) /* pointer to nim */
{
HAMARO_DRIVER_preinit();
/* test for NULL nim */
if (nim == NULL)
{
/* invalid nim or already allocated */
HAMARO_DRIVER_SET_ERROR(nim,HAMARO_NIM_NULL);
}
else
{
/* nim was not NULL, so test other validity properties */
return(HAMARO_DRIVER_ValidNim(nim));
}
return(False);
} /* HAMARO_DRIVER_ValidNim() */
/*******************************************************************************************************/
/* HAMARO_DRIVER_ValidateNimIq() */
/*******************************************************************************************************/
BOOL HAMARO_DRIVER_ValidateNimIq( /* function to validate nim IQ pointer */
HAMARO_NIM *nim) /* pointer to nim */
{
if (nim->iqpak == NULL)
{
/* invalid nim or already allocated */
HAMARO_DRIVER_SET_ERROR(nim,HAMARO_IQ_NULL);
return(False);
}
return(True);
} /* HAMARO_DRIVER_ValidateNimIq() */
/*******************************************************************************************************/
/* HAMARO_DRIVER_ValidNim() */
/*******************************************************************************************************/
BOOL HAMARO_DRIVER_ValidNim( /* function to validate a nim pointer */
HAMARO_NIM *nim) /* pointer to nim */
{
int i;
HAMARO_DRIVER_preinit();
/* test nims saved via init env for validity */
for (i = 0 ; i < HAMARO_MAX_NIMS ; i++)
{
if (hamaro_nim_list.nim[i] == nim) return(True);
}
return(False);
} /* HAMARO_DRIVER_ValidNim() */
/*******************************************************************************************************/
/* _HAMARO_DRIVER_wait() */
/*******************************************************************************************************/
BOOL _HAMARO_DRIVER_wait( /* function to wait a specified number of ms */
HAMARO_NIM *nim, /* pointer to nim */
int mscount) /* ms to wait */
{
clock_t current_tick, stop_tick;
if ((nim == NULL) || (mscount < 0))
{
return (False);
}
/* determine the stop tick */
if ((stop_tick = clock()) == (clock_t)-1)
{
return (False);
}
stop_tick += (CLOCKS_PER_SEC / 1000) * mscount;
/* countinue testing time until ms count is achieved */
while ((current_tick = clock()) != (clock_t)-1)
{
if (current_tick > stop_tick)
{
return (True);
}
}
return (False);
} /* _HAMARO_DRIVER_wait() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -