1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
|
/*
* Hamlib KIT backend - Sat-Schneider DRT1/SAD1 DRM receiver description
* Copyright (c) 2004-2005 by Stephane Fillod
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <stdlib.h>
#include <stdio.h>
#include "hamlib/rig.h"
#include "serial.h"
#include "token.h"
#define DRT1_MODES (RIG_MODE_AM)
#define DRT1_FUNC (RIG_FUNC_NONE)
#define DRT1_LEVEL_ALL (RIG_LEVEL_NONE)
#define DRT1_PARM_ALL (RIG_PARM_NONE)
#define DRT1_VFO (RIG_VFO_A)
/* defaults */
#define OSCFREQ MHz(45.012)
#define IFMIXFREQ MHz(45)
#define REFMULT 8
#define CHARGE_PUMP_CURRENT 150
struct drt1_priv_data
{
freq_t osc_freq;
freq_t if_mix_freq;
unsigned ref_mult;
unsigned pump_crrnt;
};
#define TOK_OSCFREQ TOKEN_BACKEND(1)
#define TOK_IFMIXFREQ TOKEN_BACKEND(2)
#define TOK_REFMULT TOKEN_BACKEND(3)
#define TOK_PUMPCRNT TOKEN_BACKEND(4)
static const struct confparams drt1_cfg_params[] =
{
{
TOK_OSCFREQ, "osc_freq", "Oscillatorfreq", "Oscillator frequency in Hz",
"45012000", RIG_CONF_NUMERIC, { .n = { 0, MHz(400), 1 } }
},
{
TOK_IFMIXFREQ, "if_mix_freq", "IF", "IF mixing frequency in Hz",
"45000000", RIG_CONF_NUMERIC, { .n = { 0, MHz(400), 1 } }
},
{
TOK_REFMULT, "ref_mult", "REFCLK Multiplier", "REFCLK Multiplier",
"8", RIG_CONF_NUMERIC, { .n = { 4, 20, 1 } }
},
{
TOK_PUMPCRNT, "pump_current", "Charge pump current", "Charge pump current in uA",
"150", RIG_CONF_NUMERIC, { .n = { 75, 150, 25 } }
},
{ RIG_CONF_END, NULL, }
};
static int drt1_init(RIG *rig);
static int drt1_cleanup(RIG *rig);
static int drt1_set_freq(RIG *rig, vfo_t vfo, freq_t freq);
static int drt1_set_conf(RIG *rig, hamlib_token_t token, const char *val);
static int drt1_get_conf(RIG *rig, hamlib_token_t token, char *val);
/*
* SAT-Service Schneider DRM tuner.
*
* The receiver is controlled via the TX, RTS and DTR pins of the serial port.
*/
struct rig_caps drt1_caps =
{
RIG_MODEL(RIG_MODEL_DRT1),
.model_name = "DRT1",
.mfg_name = "SAT-Schneider",
.version = "20200112.0",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rig_type = RIG_TYPE_TUNER,
.ptt_type = RIG_PTT_NONE,
.dcd_type = RIG_DCD_NONE,
.port_type = RIG_PORT_SERIAL, /* bit banging */
.serial_rate_min = 9600, /* don't care */
.serial_rate_max = 9600,
.serial_data_bits = 8,
.serial_stop_bits = 1,
.serial_parity = RIG_PARITY_NONE,
.serial_handshake = RIG_HANDSHAKE_NONE,
.write_delay = 0,
.post_write_delay = 0,
.timeout = 200,
.retry = 0,
.has_get_func = DRT1_FUNC,
.has_set_func = DRT1_FUNC,
.has_get_level = DRT1_LEVEL_ALL,
.has_set_level = RIG_LEVEL_SET(DRT1_LEVEL_ALL),
.has_get_parm = DRT1_PARM_ALL,
.has_set_parm = RIG_PARM_SET(DRT1_PARM_ALL),
.level_gran = {},
.parm_gran = {},
.ctcss_list = NULL,
.dcs_list = NULL,
.preamp = { RIG_DBLST_END },
.attenuator = { RIG_DBLST_END },
.max_rit = Hz(0),
.max_xit = Hz(0),
.max_ifshift = Hz(0),
.targetable_vfo = 0,
.transceive = RIG_TRN_OFF,
.bank_qty = 0,
.chan_desc_sz = 0,
.chan_list = { RIG_CHAN_END, },
.rx_range_list1 = {
{kHz(50), MHz(30), DRT1_MODES, -1, -1, DRT1_VFO},
RIG_FRNG_END,
},
.tx_range_list1 = { RIG_FRNG_END, },
.rx_range_list2 = {
{kHz(50), MHz(30), DRT1_MODES, -1, -1, DRT1_VFO},
RIG_FRNG_END,
},
.tx_range_list2 = { RIG_FRNG_END, },
.tuning_steps = {
{DRT1_MODES, 1},
RIG_TS_END,
},
/* mode/filter list, remember: order matters! */
.filters = {
{DRT1_MODES, kHz(10)}, /* opt. 20 kHz */
RIG_FLT_END,
},
.cfgparams = drt1_cfg_params,
.rig_init = drt1_init,
.rig_cleanup = drt1_cleanup,
.set_conf = drt1_set_conf,
.get_conf = drt1_get_conf,
.set_freq = drt1_set_freq,
.hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS
};
int drt1_init(RIG *rig)
{
struct drt1_priv_data *priv;
STATE(rig)->priv = (struct drt1_priv_data *)calloc(1, sizeof(
struct drt1_priv_data));
if (!STATE(rig)->priv)
{
/* whoops! memory shortage! */
return -RIG_ENOMEM;
}
priv = STATE(rig)->priv;
priv->osc_freq = OSCFREQ;
priv->ref_mult = REFMULT;
priv->if_mix_freq = IFMIXFREQ;
priv->pump_crrnt = CHARGE_PUMP_CURRENT;
return RIG_OK;
}
int drt1_cleanup(RIG *rig)
{
if (!rig)
{
return -RIG_EINVAL;
}
if (STATE(rig)->priv)
{
free(STATE(rig)->priv);
}
STATE(rig)->priv = NULL;
return RIG_OK;
}
/*
* Assumes rig!=NULL, STATE(rig)->priv!=NULL
*/
int drt1_set_conf(RIG *rig, hamlib_token_t token, const char *val)
{
struct drt1_priv_data *priv;
priv = (struct drt1_priv_data *)STATE(rig)->priv;
switch (token)
{
case TOK_OSCFREQ:
sscanf(val, "%"SCNfreq, &priv->osc_freq);
break;
case TOK_REFMULT:
sscanf(val, "%u", &priv->ref_mult);
break;
case TOK_IFMIXFREQ:
sscanf(val, "%"SCNfreq, &priv->if_mix_freq);
break;
case TOK_PUMPCRNT:
sscanf(val, "%u", &priv->pump_crrnt);
break;
default:
return -RIG_EINVAL;
}
return RIG_OK;
}
/*
* assumes rig!=NULL,
* Assumes rig!=NULL, STATE(rig)->priv!=NULL
* and val points to a buffer big enough to hold the conf value.
*/
int drt1_get_conf2(RIG *rig, hamlib_token_t token, char *val, int val_len)
{
struct drt1_priv_data *priv;
priv = (struct drt1_priv_data *)STATE(rig)->priv;
switch (token)
{
case TOK_OSCFREQ:
SNPRINTF(val, val_len, "%"PRIfreq, priv->osc_freq);
break;
case TOK_REFMULT:
SNPRINTF(val, val_len, "%u", priv->ref_mult);
break;
case TOK_IFMIXFREQ:
SNPRINTF(val, val_len, "%"PRIfreq, priv->if_mix_freq);
break;
case TOK_PUMPCRNT:
SNPRINTF(val, val_len, "%u", priv->pump_crrnt);
break;
default:
return -RIG_EINVAL;
}
return RIG_OK;
}
int drt1_get_conf(RIG *rig, hamlib_token_t token, char *val)
{
return drt1_get_conf2(rig, token, val, 128);
}
/*
DDS is AD9951.
The clock input is 45,012 MHz (also 2nd LO frequency at the same time).
The clock multiplier should be set to 8x at start value (possible, that this
will change to lower clock multiplier).
The charge pump current to 75 A at start value (possible will change).
The VCO gain bit has to be set.
The IF offset for LO to the receiving frequency is + 45,000 MHz (fLO =
frec + 45,000 MHz)
Don't make the data clock too high, there are 1 KOhms decoupling resistors at
the input pins of the DDS.
Inputs (SDI(O)); SCLK und I/O UPDATE haves 5V TTL level, so that a
level converter from RS232 is needed.
I will use the attached motorola IC MC1489 as converter for amateur
application. This IC inverts the signals !
*/
#define AD_DELAY 4000
/*
* Introduce delay after changing the bit state
* FIXME: This implementation may not work for very fast computers,
* or smart compilers. However, nanosleep can have
* granularity > 10ms!
*/
static int ad_delay(int m)
{
long j;
for (j = 0; j <= m; j++) {}
return j;
}
static int ad_sdio(hamlib_port_t *port, int i)
{
int ret;
ret = ser_set_rts(port, i);
ad_delay(AD_DELAY);
if (ret != RIG_OK)
rig_debug(RIG_DEBUG_ERR, "%s: unable to set statusbits\n",
__func__);
return ret;
}
static int ad_sclk(const hamlib_port_t *port, int i)
{
int ret;
ret = ser_set_brk(port, i);
ad_delay(AD_DELAY);
if (ret != RIG_OK)
rig_debug(RIG_DEBUG_ERR, "%s: unable to set statusbits\n",
__func__);
return ret;
}
static int ad_ioupd(hamlib_port_t *port, int i)
{
int ret;
ret = ser_set_dtr(port, i);
ad_delay(AD_DELAY);
if (ret != RIG_OK)
rig_debug(RIG_DEBUG_ERR, "%s: unable to set statusbits\n",
__func__);
return ret;
}
static int ad_write_reg(hamlib_port_t *port, unsigned addr, unsigned nb_bytes,
unsigned data)
{
int i;
ad_sclk(port, 0); /* TXD 0 */
ad_ioupd(port, 1); /* DTR 1, CE */
/* Instruction byte, MSB Logic 0 = write */
addr &= 0x1f;
for (i = 7; i >= 0; i--)
{
ad_sdio(port, (addr & (1U << i)) ? 0 : 1); /* RTS 0 or 1 */
ad_sclk(port, 1); /* TXD 1, clock */
ad_sclk(port, 0); /* TXD 0 */
}
/* Data transfer */
for (i = nb_bytes * 8 - 1; i >= 0; i--)
{
ad_sdio(port, (data & (1U << i)) ? 0 : 1); /* RTS 0 or 1 */
ad_sclk(port, 1); /* TXD 1, clock */
ad_sclk(port, 0); /* TXD 0 */
}
ad_ioupd(port, 0); /* DTR 0 */
return RIG_OK;
}
/* Register serial addresses */
#define CFR1 0x0
#define CFR2 0x1
#define ASF 0x2
#define ARR 0x3
#define FTW0 0x4
#define POW0 0x5
int drt1_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
{
unsigned long frg;
unsigned cfr2;
struct drt1_priv_data *priv;
hamlib_port_t *port = RIGPORT(rig);
priv = (struct drt1_priv_data *)STATE(rig)->priv;
rig_flush(port);
/* Initialization */
ad_ioupd(port, 0);
ad_sdio(port, 0);
ad_sclk(port, 0);
/*
* CFR2:
* clock multiplier set to 8x, charge pump current to 75 A
* VCO gain bit has to be set
*/
cfr2 = ((priv->ref_mult << 3) & 0xf8) | 0x4 |
(((priv->pump_crrnt - 75) / 25) & 0x3);
ad_write_reg(port, CFR2, 3, cfr2);
/* all frequencies are in Hz */
frg = (unsigned long)(((double)freq + priv->if_mix_freq) /
(priv->osc_freq * priv->ref_mult)
* 4294967296.0);
rig_debug(RIG_DEBUG_VERBOSE, "%s: [%#lx]\n", __func__, frg);
ad_write_reg(port, FTW0, 4, frg);
return RIG_OK;
}
|