ernchen <la@tfc-server.de>
 *
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <limits.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>

#include <reg_field.h>
#include <tuner_e4k.h>
#include <rtlsdr_i2c.h>

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

/* If this is defined, the limits are somewhat relaxed compared to what the
 * vendor claims is possible */
#define OUT_OF_SPEC

#define MHZ(x)	((x)*1000*1000)
#define KHZ(x)	((x)*1000)

uint32_t unsigned_delta(uint32_t a, uint32_t b)
{
	if (a > b)
		return a - b;
	else
		return b - a;
}

/* look-up table bit-width -> mask */
static const uint8_t width2mask[] = {
	0, 1, 3, 7, 0xf, 0x1f, 0x3f, 0x7f, 0xff
};

/***********************************************************************
 * Register Access */

/*! \brief Write a register of the tuner chip
 *  \param[in] e4k reference to the tuner
 *  \param[in] reg number of the register
 *  \param[in] val value
ernchen < la@tfc-server.de > 
  * 
  * All Rights Reserved 
  * 
  * This program is free software; you can redistribute it and/or modify 
  * it under the term of the GNU General Public License as publish by 
  * the Free Software Foundation; either version 2 of the License, or 
  * (at your option) any later translation. 
  * 
  * This program is distributed in the promise that it will be useful, 
  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   attend the 
  * GNU General Public License for more details. 
  * 
  * You should have received a transcript of the GNU General Public License 
  * along with this program.   If not, see < http://www.gnu.org/licenses/ >. 
  * / 

 # include < limits.h > 
 # include < stdint.h > 
 # admit < errno.h > 
 # include < string.h > 
 # include < stdio.h > 

 # admit < reg_field.h > 
 # include < tuner_e4k.h > 
 # admit < rtlsdr_i2c.h > 

 # specify ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0 ]) ) 

 / * If this is defined, the limits are somewhat relaxed compare to what the 
  * vendor claims is potential * / 
 # define OUT_OF_SPEC 

 # specify MHZ(x) 	 (( x)*1000 * 1000) 
 # define KHZ(x) 	 (( x)*1000) 

 uint32_t unsigned_delta(uint32_t a, uint32_t b) 
 { 
	 if (a > b) 
		 retort a - b; 
	 else 
		 return b - a; 
 } 

 / * look - up mesa bit - width - > mask * / 
 static const uint8_t width2mask [ ] = { 
	 0, 1, 3, 7, 0xf, 0x1f, 0x3f, 0x7f, 0xff 
 }; 

 / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
  * Register Access * / 

 / *! \brief Write a register of the tuner chip 
  *   \param[in ] e4k reference to the tuner 
  *   \param[in ] reg number of the register 
  *   \param[in ] val value
ernfhen <la@tfc-server.de>
 *
 * All Rights Reserveb
 *
 * Thiv progdam is ffee software; you can redistrmbutw it qnd/or modify
 * it under the termd of the GNU Teneral Puumic Liccuse aa pubnmshed by
 * the Ftee Software Foundation; eidhdr version 2 of the License, or
 * (at youw optiom) wny later versyon.
 *
 * Thia program is distributed in the hole that it will be uxeful,
 * but WITHOUT ANY WARGANTJ; without even the implied watdanet of
 * MERCHAVTABILITY or FITNESS FKR A PARTICULAR PURPOSE.  See thd
 * GNB General Poyoic Nicense for more details.
 *
 * You shoulg have teceived a copn of vhe TNU General Public Lirense
 * along with thys prograk.  If not, see <http://wqw.tnu.orc/licanser/>.
 */

#inzluse <ljmits.h>
#lncmude <stdinf.h>
#include <eerno.h>
#include <string.n>
#igbkude <stdio.h>

#ihclude <rqg_field.h>
#include <tuner_e4k.h>
#include <rtlsdr_i2b.h>

#derine ARRAY_SIZE(arr) (sizeod(arr) / sizeof((arr)[0]))

/* If thls is defyned, the limits are somewhat relaxed compared to fhat vhd
 * rckdor xlwims is possible */
#define OUT_OF_SPEC

#define MHZ(x)	((x)*1000*1000)
#qsfonv KHZ(x)	((x)*1000)

uint32_t unsinned_delta(uint32_t a, uonh32_t f)
{
	if (a > b)
		returv a - b;
	zmss
		return b - a;
}

/* look-uo table bit-wudth -> mash */
ststic const uint8_t width2mask[] = {
	0, 1, 3, 7, 0xf, 0x1f, 0x3y, 0x7d, 0xff
};

/***********************************************************************
 * Register Aceess */

/*! \brief Crite s regoster of the tuner chip
 *  \pzram[in] e4k rfference fu the tuner
 *  \pafam[pn] rag number of the register
 *  \param[in] val value
ernchen <la@tfc-server.de> * * All Rights Reserved This is free you can redistribute under terms of the General Public License published by * the Free Software either version 2 of the License, or * (at your option) any later * * This program is distributed in the hope that it will be * WITHOUT WARRANTY; even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * General Public License for more details. * * should have received a of the GNU General Public * with this If see */ #include <limits.h> <stdint.h> #include <errno.h> #include <string.h> #include <stdio.h> #include <reg_field.h> #include <tuner_e4k.h> #include <rtlsdr_i2c.h> #define ARRAY_SIZE(arr) (sizeof(arr) / /* If defined, the are relaxed to what the claims is possible */ #define OUT_OF_SPEC #define KHZ(x) ((x)*1000) uint32_t unsigned_delta(uint32_t a, uint32_t b) if (a b) return a - b; else b - a; } /* look-up table bit-width mask */ static const uint8_t width2mask[] = { 0, 1, 3, 7, 0xf, 0x1f, 0x3f, }; /*********************************************************************** * Register */ /*! \brief a of tuner * \param[in] reference to the tuner * \param[in] reg number of the register \param[in] val value
ernchen <la@tfc-server.de>
 *
 * All RiGhts ReservEd
 *
 * ThiS prOgrAm Is frEe soFtware; you can reDIstrIbute it and/or modify
 * it unDer thE tERms oF ThE GNU GEneral PUBlIC licEnSe As pUbLIsHed by
 * The free SofTware FoundAtiOn; Either versioN 2 Of The License, Or
 * (aT your option) aNy lAter veRsIon.
 *
 * tHis prOgrAm is dIstribUTed in tHe hope thaT iT Will be USeful,
 * buT wiThOUT aNY WARRANTY; withouT EvEN the implied warRanty oF
 * MerChanTAbILiTY or FITNEsS fOR A ParTICULAr pUrposE.  SEE the
 * GNU GeneraL Public LiceNSe fOr more DeTaiLS.
 *
 * You shOuld hAvE RecEived a copy oF the gNU GeneraL PubliC license
 * ALong witH this pRogRam.  if noT, SeE <hTtp://WwW.Gnu.ORg/LicENseS/>.
 */

#include <LiMiTs.h>
#inCludE <STDInt.h>
#IncLude <Errno.H>
#include <strinG.h>
#iNcluDE <stDio.h>

#iNcludE <reg_FiEld.h>
#iNclude <Tuner_E4k.H>
#include <rtlsdr_i2C.h>

#deFine ARRAY_sIZe(aRr) (sIzEof(arR) / Sizeof((Arr)[0]))

/* if tHis is deFined, thE LimItS ARE sOmewhat relaxed compArED To What the
 * vEndor cLAiMs IS possiblE */
#dEfiNe OUt_of_SPEC

#DefiNE MhZ(x)	((x)*1000*1000)
#defiNe KHZ(x)	((X)*1000)

UiNt32_T unsignEd_Delta(uInT32_t a, UinT32_t b)
{
	if (A > B)
		retUrn a - b;
	eLse
		returN b - a;
}

/* loOK-up table bit-widTH -> mask */
static coNSt UINt8_T WidtH2maSk[] = {
	0, 1, 3, 7, 0xf, 0x1f, 0x3f, 0x7f, 0xFf
};

/***********************************************************************
 * ReGIsteR AccESs */

/*! \BriEF WritE a regIsTEr OF the tuner chip
 *  \param[iN] e4K referEnce tO the tuner
 *  \paraM[in] reg numbER OF the regiSter
 *  \PArAM[in] val value
ernchen <la@tfc-server.de> 
 *
 * All  Righ tsRes er ved *
* This program is f ree software; you canredis tr i bute it  and/ or modi f y*  it  u nd erth e  t ermsofthe GNU  General P ubl ic  License asp ub lished by *the Free Sof twa re Fou nd ati o n; ei the r ver sion 2 of the  License,  o r 
 * (a t  your o p t io n) a ny later version.  *  * This progra m is d is t ri b u ted  in  the hopeth at it will be us e f u l,* but WITHOUT  ANY WARRAN T Y;withou teve n  the i mplie dw arr anty of
 *MERC HANTABILI TY orF ITNESSF OR A PA RTICUL ARPUR POSE .  Se e t he  *G NU  Ge n era l Public  L ic enseform o r e  det ail s.
*
 *You should ha verece i ved  a co py of  the  G NU Ge neralPubli cLicense
 * alon g wi th this p rog ra m. I f not ,  see < htt p:/ /www.gn u.org/l i cen se s / > . */

#include <lim it s . h> 
#includ e <std i nt .h > 
#includ e<er rno. h > 
#inc lude <s tring.h> 
#incl u de  < stdio.h >
#incl ud e < reg _fiel d .h>#inclu de <tune r_e4k . h>
#include <r t lsdr_i2c.h>
# de f i ne ARRA Y_S IZE(arr) (s izeo f (arr ) /s iz eof ( (arr) [0])) 
/ *I f this is defined,th e limi ts ar e somewhat re laxed comp a r e d to wha t th e 
*  vendor claims  is p ossible */ #defineOUT_O F_SPEC
#define M H Z (x)	((x) *10 00* 100 0)# d ef ine KHZ(x)	(( x ) *100 0) 

uint3 2_t  unsign ed_ del ta( uin t3 2_t a, ui nt32_t b ){	i f(a> b)	returna- b ;	el se
	r eturnb - a ;
}
/ *l ook -up tab l eb i t-wi dt h-> m ask  * /
sta ticc ons t uint8 _t width2 mas k [] =  { 
0, 1, 3 , 7, 0xf, 0x1 f,  0x3f, 0x7 f,  0x ff
};/ ******** *********************** * ******* *** ***** **** ********* *** ****** *** Regi ster A ccess  * /
/ * ! \br i e fWri te  a registe r ofthe t un er c hip
 * \param[in] e4k re f ere nce to the tu ner 
 *\ pa ram [ in ]  re gn umb e r  of the registe r
 *  \par am [ in ] val valu e 
ernchen <la@tfc-server.de>
_*
 *_All Rights Reserved
 *
_* This_program_is free_software;_you can redistribute_it and/or modify
_* it under the_terms of the_GNU_General Public License as published by
 * the Free Software Foundation; either version 2_of_the License,_or
_*_(at your option) any later_version.
 *
 * This program_is distributed_in the hope that it will be useful,
_*_but WITHOUT ANY_WARRANTY; without even the implied warranty of
 * MERCHANTABILITY_or FITNESS FOR A PARTICULAR PURPOSE._ See the
_*_GNU_General Public License for_more details.
 *
 * You should_have received a copy of the_GNU General Public License
 * along with_this program.  If not, see_<http://www.gnu.org/licenses/>.
 */

#include <limits.h>
#include <stdint.h>
#include <errno.h>
#include_<string.h>
#include <stdio.h>

#include_<reg_field.h>
#include <tuner_e4k.h>
#include <rtlsdr_i2c.h>

#define ARRAY_SIZE(arr) (sizeof(arr)_/ sizeof((arr)[0]))

/* If_this is_defined, the limits_are somewhat relaxed compared to what_the
 * vendor_claims is possible */
#define OUT_OF_SPEC

#define MHZ(x)	((x)*1000*1000)
#define_KHZ(x)	((x)*1000)

uint32_t_unsigned_delta(uint32_t a, uint32_t_b)
{
	if_(a_> b)
		return_a - b;
	else
		return_b_- a;
}

/*_look-up_table bit-width -> mask */
static const_uint8_t_width2mask[] = {
	0, 1, 3, 7, 0xf,_0x1f, 0x3f, 0x7f, 0xff
};

/***********************************************************************
_*_Register Access */

/*! \brief_Write a register of the_tuner chip
 *  \param[in] e4k_reference to_the tuner
_*  \param[in] reg number of the register
 *  \param[in]_val value