added Microtune 4702 support (from GNU Radio)

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1568 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.0
Stéphane Fillod, F8CFE 2003-10-20 20:34:02 +00:00
rodzic c7211b9642
commit 15a88a78dd
11 zmienionych plików z 451 dodań i 88 usunięć

Wyświetl plik

@ -18,13 +18,14 @@
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
MTSRCLIST = module_4937.c
MTSRCLIST = module_4937.c module_4702.c
GRIO_SOURCES = \
i2cio.cc \
i2cio_pp.cc \
i2c.cc \
microtune_4937.cc \
microtune_4702.cc \
microtune_eval_board.cc
lib_LTLIBRARIES = hamlib-microtune.la
@ -37,6 +38,7 @@ noinst_HEADERS = \
i2cio.h \
i2cio_pp.h \
microtune_4937.h \
microtune_4702.h \
microtune_eval_board.h \
microtune_eval_board_defs.h \
microtune.h

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Microtune backend - main file
* Copyright (c) 2003 by Stephane Fillod
*
* $Id: microtune.cc,v 1.2 2003-09-28 15:28:37 fillods Exp $
* $Id: microtune.cc,v 1.3 2003-10-20 20:34:02 fillods Exp $
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,11 +25,17 @@
#include "config.h"
#endif
#include <stdlib.h>
#include <hamlib/rig.h>
#include "register.h"
#include "microtune.h"
#include "microtune_eval_board.h"
#include <stdlib.h>
#include "microtune_4937.h"
#include "microtune_4702.h"
/*
* TODO: allow these to be modifiable through rig_set_conf
@ -40,11 +46,7 @@
for distance < 10kHz to the carrier
*/
#define M4937_I2C_ADDR (0xC2/2)
#define REF_DIVIDER 640
#define FAST_TUNING false
struct module_4937_priv_data {
struct microtune_priv_data {
microtune_eval_board *board;
freq_t actual_freq;
};
@ -53,13 +55,14 @@ struct module_4937_priv_data {
* TODO:
* - status iff PLL is locked
* - returns the output frequency of the tuner in Hz (->5.75e6) //3x7702.
* or 36.00e6
*/
int module_4937_init(RIG *rig)
int microtune_init(RIG *rig)
{
struct module_4937_priv_data *priv;
struct microtune_priv_data *priv;
priv = (struct module_4937_priv_data*)malloc(sizeof(struct module_4937_priv_data));
priv = (struct microtune_priv_data*)malloc(sizeof(struct microtune_priv_data));
if (!priv) {
/* whoops! memory shortage! */
return -RIG_ENOMEM;
@ -74,14 +77,14 @@ int module_4937_init(RIG *rig)
int module_4937_open(RIG *rig)
{
struct module_4937_priv_data *priv = (struct module_4937_priv_data *)rig->state.priv;
struct microtune_priv_data *priv = (struct microtune_priv_data *)rig->state.priv;
priv->board = new microtune_eval_board(&rig->state.rigport);
priv->board = new microtune_4937(&rig->state.rigport);
if (!priv->board) {
return -RIG_ENOMEM;
}
if (0 && !priv->board->board_present_p()) {
if (!priv->board->board_present_p()) {
rig_debug(RIG_DEBUG_WARN, "microtune: eval board is NOT present\n");
delete priv->board;
return -RIG_EPROTO;
@ -90,18 +93,36 @@ int module_4937_open(RIG *rig)
return RIG_OK;
}
int module_4937_close(RIG *rig)
int module_4702_open(RIG *rig)
{
struct module_4937_priv_data *priv = (struct module_4937_priv_data *)rig->state.priv;
struct microtune_priv_data *priv = (struct microtune_priv_data *)rig->state.priv;
priv->board = new microtune_4702(&rig->state.rigport);
if (!priv->board) {
return -RIG_ENOMEM;
}
if (!priv->board->board_present_p()) {
rig_debug(RIG_DEBUG_WARN, "microtune: eval board is NOT present\n");
delete priv->board;
return -RIG_EPROTO;
}
return RIG_OK;
}
int microtune_close(RIG *rig)
{
struct microtune_priv_data *priv = (struct microtune_priv_data *)rig->state.priv;
delete priv->board;
return RIG_OK;
}
int module_4937_cleanup(RIG *rig)
int microtune_cleanup(RIG *rig)
{
struct module_4937_priv_data *priv = (struct module_4937_priv_data *)rig->state.priv;
struct microtune_priv_data *priv = (struct microtune_priv_data *)rig->state.priv;
if (priv) {
free(priv);
@ -114,12 +135,12 @@ int module_4937_cleanup(RIG *rig)
/*
* It takes about 100 ms for the PLL to settle.
*/
int module_4937_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
int microtune_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
{
double actual_freq;
bool status;
struct module_4937_priv_data *priv = (struct module_4937_priv_data *)rig->state.priv;
struct microtune_priv_data *priv = (struct microtune_priv_data *)rig->state.priv;
status = priv->board->set_RF_freq((double)freq, &actual_freq);
@ -131,9 +152,9 @@ int module_4937_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
}
int module_4937_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
int microtune_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
{
struct module_4937_priv_data *priv = (struct module_4937_priv_data *)rig->state.priv;
struct microtune_priv_data *priv = (struct microtune_priv_data *)rig->state.priv;
*freq = priv->actual_freq;
@ -144,9 +165,9 @@ int module_4937_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
/*
* Assumes rig!=NULL, rig->state.priv!=NULL
*/
int module_4937_set_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t val)
int microtune_set_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t val)
{
struct module_4937_priv_data *priv = (struct module_4937_priv_data *)rig->state.priv;
struct microtune_priv_data *priv = (struct microtune_priv_data *)rig->state.priv;
switch(token) {
case TOK_AGCGAIN:
@ -158,3 +179,15 @@ int module_4937_set_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t val)
return RIG_OK;
}
DECLARE_INITRIG_BACKEND(microtune)
{
rig_debug(RIG_DEBUG_VERBOSE, "microtune: _init called\n");
rig_register(&module_4937_caps);
rig_register(&module_4702_caps);
return RIG_OK;
}

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Microtune backend - main header
* Copyright (c) 2001-2003 by Stephane Fillod
*
* $Id: microtune.h,v 1.3 2003-09-28 15:28:37 fillods Exp $
* $Id: microtune.h,v 1.4 2003-10-20 20:34:02 fillods Exp $
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -32,14 +32,18 @@ __BEGIN_DECLS
#define TOK_AGCGAIN TOKEN_BACKEND(1)
int module_4937_init(RIG *rig);
int module_4937_cleanup(RIG *rig);
int microtune_init(RIG *rig);
int microtune_cleanup(RIG *rig);
int module_4937_open(RIG *rig);
int module_4937_close(RIG *rig);
int module_4937_set_freq(RIG *rig, vfo_t vfo, freq_t freq);
int module_4937_get_freq(RIG *rig, vfo_t vfo, freq_t *freq);
int module_4937_set_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t val);
int module_4702_open(RIG *rig);
int microtune_close(RIG *rig);
int microtune_set_freq(RIG *rig, vfo_t vfo, freq_t freq);
int microtune_get_freq(RIG *rig, vfo_t vfo, freq_t *freq);
int microtune_set_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t val);
extern const struct rig_caps module_4937_caps;
extern const struct rig_caps module_4702_caps;
__END_DECLS

Wyświetl plik

@ -0,0 +1,177 @@
/* -*- c++-*- */
/*
* Copyright 2001,2003 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio 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, or (at your option)
* any later version.
*
* GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "microtune_4702.h"
#include <stdlib.h>
#include <stdio.h>
static const double first_IF = 36.00e6;
// The tuner internally has 3 bands: VHF Low, VHF High & UHF.
// These are the recommened boundaries
static const double VHF_High_takeover = 174e6;
static const double UHF_takeover = 470e6;
static int PLL_I2C_ADDR = 0x60;
static unsigned char
control_byte_1 (bool prescaler, int reference_divisor)
{
int c = 0x80;
//Note: Last two divider bits (bits 2 and 3 of this byte) determined later
if (prescaler)
c |= 0x10;
switch (reference_divisor){
case 2:
c |= 0x00; break;
case 4:
c |= 0x01; break;
case 8:
c |= 0x02; break;
case 16:
c |= 0x03; break;
case 32:
c |= 0x04; break;
case 64:
c |= 0x05; break;
case 128:
c |= 0x06; break;
case 256:
c |= 0x07; break;
case 24:
c |= 0x08; break;
case 5:
c |= 0x09; break;
case 10:
c |= 0x0A; break;
case 20:
c |= 0x0B; break;
case 40:
c |= 0x0C; break;
case 80:
c |= 0x0D; break;
case 160:
c |= 0x0E; break;
case 320:
c |= 0x0F; break;
default:
abort ();
}
return c;
}
static unsigned char
control_byte_2 (double target_freq)
{
int c;
if (target_freq < VHF_High_takeover) // VHF low
c = 0x8E;
else if (target_freq < UHF_takeover) // VHF high
{
c = 0x05;
if (target_freq < 390e6)
c |= 0x40;
else
c |= 0x80;
}
else
{ // UHF
c = 0x03;
if (target_freq < 750e6)
c |= 0x80;
else
c |= 0xC0;
}
return c;
}
/*!
* \brief select RF frequency to be tuned to output frequency.
* \p target_freq is the requested frequency in Hz, \p actual_freq
* is set to the actual frequency tuned. It takes about 100 ms
* for the PLL to settle.
*
* \returns true iff sucessful.
*/
bool
microtune_4702::set_RF_freq (double target_freq, double *p_actual_freq)
{
unsigned char buf[4];
double target_f_osc = target_freq + first_IF;
double f_ref = 4e6 / d_reference_divider;
//int divisor = (int) ((target_f_osc + (f_ref * 4)) / (f_ref * 8));
long int divisor = (long int) (target_f_osc / f_ref);
double actual_freq = (f_ref * divisor) - first_IF;
if (p_actual_freq != 0)
*p_actual_freq = actual_freq;
if ((divisor & ~0x1ffff) != 0) // >17 bit divisor
return false;
buf[0] = ((divisor & 0x07f00) >> 8) & 0xff; // DB1
buf[1] = divisor & 0xff; // DB2
buf[2] = control_byte_1 (prescaler, d_reference_divider);
buf[2] = (buf[2]|(((divisor & 0x18000) >> 10)) & 0xff);
buf[3] = control_byte_2 (target_freq);
printf ("%x\n", PLL_I2C_ADDR);
//#if 0
printf ("set_RF_freq: target: %g MHz actual: %g MHz %02x %02x %02x %02x\n",
target_freq/1e6, actual_freq/1e6, buf[0], buf[1], buf[2], buf[3]);
//#endif
return i2c_write (PLL_I2C_ADDR, buf, sizeof (buf));
}
bool
microtune_4702::read_info (unsigned char* buf)
{
return i2c_write (PLL_I2C_ADDR, buf, 2);
}
/*!
* \returns true iff PLL is locked
*/
bool
microtune_4702::pll_locked_p ()
{
// FIXME
return true;
}
/*!
* \returns the output frequency of the tuner in Hz.
*/
double
microtune_4702::get_output_freq ()
{
return 36.00e6;
}

Wyświetl plik

@ -0,0 +1,59 @@
/* -*- c++ -*- */
/*
* Copyright 2001,2003 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio 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, or (at your option)
* any later version.
*
* GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef _MICROTUNE_4702_H_
#define _MICROTUNE_4702_H_
#include <hamlib/rig.h>
#include "microtune_eval_board.h"
/*!
* \brief abstract class for controlling microtune 4702 tuner module
*/
class microtune_4702 : public microtune_eval_board {
public:
microtune_4702(port_t *port) : microtune_eval_board (port), d_reference_divider(320), prescaler(false) {}
~microtune_4702() {}
/*!
* \brief select RF frequency to be tuned to output frequency.
* \p freq is the requested frequency in Hz, \p actual_freq
* is set to the actual frequency tuned. It takes about 100 ms
* for the PLL to settle.
*
* \returns true iff sucessful.
*/
bool set_RF_freq (double freq, double *actual_freq);
bool read_info (unsigned char* buf);
double get_output_freq ();
bool pll_locked_p ();
private:
int d_reference_divider;
bool prescaler; /* if set, higher charge pump current:
faster tuning, worse phase noise
for distance < 10kHz to the carrier */
};
#endif /* _MICROTUNE_4702_H_ */

Wyświetl plik

@ -72,14 +72,6 @@ control_byte_2 (double target_freq, bool shutdown_tx_PGA)
return c;
}
microtune_4937::microtune_4937 ()
{
d_reference_divider = 640;
d_fast_tuning_p = false;
}
microtune_4937::~microtune_4937 (){}
/*!
* \brief select RF frequency to be tuned to output frequency.
* \p target_freq is the requested frequency in Hz, \p actual_freq
@ -121,17 +113,6 @@ microtune_4937::set_RF_freq (double target_freq, double *p_actual_freq)
return i2c_write (PLL_I2C_ADDR, buf, 4);
}
double
microtune_4937::set_RF_freq (double target_freq)
{
double actual_freq = 0.0;
if (set_RF_freq (target_freq, &actual_freq))
return actual_freq;
return 0.0;
}
/*!
* \returns true iff PLL is locked

Wyświetl plik

@ -23,14 +23,16 @@
#ifndef _MICROTUNE_4937_H_
#define _MICROTUNE_4937_H_
#include <hamlib/rig.h>
#include "microtune_eval_board.h"
/*!
* \brief abstract class for controlling microtune 4937 tuner module
*/
class microtune_4937 {
class microtune_4937 : public microtune_eval_board {
public:
microtune_4937 ();
virtual ~microtune_4937 ();
microtune_4937(port_t *port) : microtune_eval_board (port), d_reference_divider(640), d_fast_tuning_p(false) {}
~microtune_4937() {}
/*!
* \brief select RF frequency to be tuned to output frequency.
@ -42,9 +44,6 @@ public:
*/
bool set_RF_freq (double freq, double *actual_freq);
// returns actual freq or 0 if error (easier interface for SWIG)
double set_RF_freq (double freq);
/*!
* \returns true iff PLL is locked
*/
@ -56,12 +55,6 @@ public:
double get_output_freq ();
private:
//! \returns true iff successful
virtual bool i2c_write (int addr, const unsigned char *buf, int nbytes) = 0;
//! \returns number of bytes read or -1 if error
virtual int i2c_read (int addr, unsigned char *buf, int max_bytes) = 0;
int d_reference_divider;
bool d_fast_tuning_p; /* if set, higher charge pump current:
faster tuning, worse phase noise

Wyświetl plik

@ -31,22 +31,43 @@
#ifndef _MICROTUNE_EVAL_BOARD_H_
#define _MICROTUNE_EVAL_BOARD_H_
#include "microtune_4937.h"
#include "serial.h"
class i2cio;
class i2c;
/*!
* \brief concrete class for controlling microtune 4937 eval board attached to parallel port
* \brief concrete class for controlling a microtune eval board attached to parallel port
*/
class microtune_eval_board : public microtune_4937 {
class microtune_eval_board {
public:
microtune_eval_board (port_t *port);
~microtune_eval_board ();
virtual ~microtune_eval_board ();
//! is the eval board present?
bool board_present_p ();
virtual bool board_present_p ();
/*!
* \brief select RF frequency to be tuned to output frequency.
* \p freq is the requested frequency in Hz, \p actual_freq
* is set to the actual frequency tuned. It takes about 100 ms
* for the PLL to settle.
*
* \returns true iff sucessful.
*/
virtual bool set_RF_freq (double freq, double *actual_freq) = 0;
/*!
* \returns true iff PLL is locked
*/
virtual bool pll_locked_p () = 0;
/*!
* \returns the output frequency (IF center freq) of the tuner in Hz.
*/
virtual double get_output_freq () = 0;
/*!
* \brief set RF and IF AGC control voltages ([0, 5] volts)
@ -64,13 +85,14 @@ public:
void set_AGC (float value_0_1000);
private:
protected:
//! \returns true iff successful
virtual bool i2c_write (int addr, const unsigned char *buf, int nbytes);
//! \returns number of bytes read or -1 if error
virtual int i2c_read (int addr, unsigned char *buf, int max_bytes);
private:
void write_dac (int which, int value);
void write_both_dacs (int val0, int val1);

Wyświetl plik

@ -32,7 +32,7 @@
#define _MICROTUNE_EVAL_BOARD_DEFS_H_
/*
* The Microtune 4937DI5 cable modem tuner eval board is controlled
* The Microtune 4937DI5/4702DT5 cable modem tuner eval board is controlled
* by bit banging the PC parallel port. This file defines the relevant
* bits.
*

Wyświetl plik

@ -0,0 +1,102 @@
/*
* Hamlib microtune backend - 4702 file
* Copyright (c) 2003 by Stephane Fillod
*
* $Id: module_4702.c,v 1.1 2003-10-20 20:34:02 fillods Exp $
*
* This library 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, 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <hamlib/rig.h>
#include "microtune.h"
/*
* Microtune 4702 rig capabilities.
*/
#define M4702_FUNC RIG_FUNC_NONE
#define M4702_LEVEL RIG_LEVEL_NONE
#define M4702_PARM RIG_PARM_NONE
#define M4702_MODES (RIG_MODE_NONE) /* FIXME: IF */
#define M4702_VFO RIG_VFO_A
static const struct confparams module_4702_ext_parms[] = {
{ TOK_AGCGAIN, "agcgain", "AGC gain level", "RF and IF AGC levels",
NULL, RIG_CONF_NUMERIC, { .n = { 0, 1, .001 } }
},
{ RIG_CONF_END, NULL, }
};
const struct rig_caps module_4702_caps = {
.rig_model = RIG_MODEL_MICROTUNE_4702,
.model_name = "4702 DT5 tuner module",
.mfg_name = "Microtune",
.version = "0.2.1",
.copyright = "GPL",
.status = RIG_STATUS_UNTESTED,
.rig_type = RIG_TYPE_TUNER,
.targetable_vfo = 0,
.ptt_type = RIG_PTT_RIG,
.dcd_type = RIG_DCD_NONE,
.port_type = RIG_PORT_PARALLEL,
.has_get_func = M4702_FUNC,
.has_set_func = M4702_FUNC,
.has_get_level = M4702_LEVEL,
.has_set_level = RIG_LEVEL_SET(M4702_LEVEL),
.has_get_parm = M4702_PARM,
.has_set_parm = RIG_PARM_SET(M4702_PARM),
.chan_list = {
RIG_CHAN_END,
},
.scan_ops = RIG_SCAN_NONE,
.vfo_ops = RIG_OP_NONE,
.transceive = RIG_TRN_OFF,
.attenuator = { RIG_DBLST_END, },
.preamp = { RIG_DBLST_END, },
.rx_range_list2 = { {.start=MHz(50),.end=MHz(860),.modes=M4702_MODES,
.low_power=-1,.high_power=-1,M4702_VFO},
RIG_FRNG_END, },
.tx_range_list2 = { RIG_FRNG_END, },
/* minimum tuning step with a reference divider of 640? (see Advance data sheet) */
.tuning_steps = { {M4702_MODES,kHz(50)},
RIG_TS_END,
},
.extparms = module_4702_ext_parms,
.priv = NULL, /* priv */
.rig_init = microtune_init,
.rig_cleanup = microtune_cleanup,
.rig_open = module_4702_open,
.rig_close = microtune_close,
.set_freq = microtune_set_freq,
.get_freq = microtune_get_freq,
.set_ext_level = microtune_set_ext_level,
};

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib microtune backend - 4937 file
* Copyright (c) 2003 by Stephane Fillod
*
* $Id: module_4937.c,v 1.4 2003-10-01 19:31:59 fillods Exp $
* $Id: module_4937.c,v 1.5 2003-10-20 20:34:02 fillods Exp $
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,7 +29,6 @@
#include <hamlib/rig.h>
#include "register.h"
#include "microtune.h"
/*
@ -58,7 +57,7 @@ const struct rig_caps module_4937_caps = {
.rig_model = RIG_MODEL_MICROTUNE_4937,
.model_name = "4937 DI5 tuner module",
.mfg_name = "Microtune",
.version = "0.2",
.version = "0.2.1",
.copyright = "GPL",
.status = RIG_STATUS_UNTESTED,
.rig_type = RIG_TYPE_TUNER,
@ -94,22 +93,13 @@ const struct rig_caps module_4937_caps = {
.extparms = module_4937_ext_parms,
.priv = NULL, /* priv */
.rig_init = module_4937_init,
.rig_cleanup = module_4937_cleanup,
.rig_init = microtune_init,
.rig_cleanup = microtune_cleanup,
.rig_open = module_4937_open,
.rig_close = module_4937_close,
.rig_close = microtune_close,
.set_freq = module_4937_set_freq,
.get_freq = module_4937_get_freq,
.set_ext_level = module_4937_set_ext_level,
.set_freq = microtune_set_freq,
.get_freq = microtune_get_freq,
.set_ext_level = microtune_set_ext_level,
};
DECLARE_INITRIG_BACKEND(microtune)
{
rig_debug(RIG_DEBUG_VERBOSE, "microtune: _init called\n");
rig_register(&module_4937_caps);
return RIG_OK;
}