1 |
1626 |
jcastillo |
/*****************************************************************************/
|
2 |
|
|
|
3 |
|
|
/*
|
4 |
|
|
* sm_hapn4800.c -- soundcard radio modem driver, 4800 baud HAPN modem
|
5 |
|
|
*
|
6 |
|
|
* Copyright (C) 1996 Thomas Sailer (sailer@ife.ee.ethz.ch)
|
7 |
|
|
*
|
8 |
|
|
* This program is free software; you can redistribute it and/or modify
|
9 |
|
|
* it under the terms of the GNU General Public License as published by
|
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
11 |
|
|
* (at your option) any later version.
|
12 |
|
|
*
|
13 |
|
|
* This program is distributed in the hope that it will be useful,
|
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
* GNU General Public License for more details.
|
17 |
|
|
*
|
18 |
|
|
* You should have received a copy of the GNU General Public License
|
19 |
|
|
* along with this program; if not, write to the Free Software
|
20 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
21 |
|
|
*
|
22 |
|
|
* Please note that the GPL allows you to use the driver, NOT the radio.
|
23 |
|
|
* In order to use the radio, you need a license from the communications
|
24 |
|
|
* authority of your country.
|
25 |
|
|
*
|
26 |
|
|
*
|
27 |
|
|
* This module implements a (hopefully) HAPN (Hamilton Area Packet
|
28 |
|
|
* Network) compatible 4800 baud modem.
|
29 |
|
|
* The HAPN modem uses kind of "duobinary signalling" (not really,
|
30 |
|
|
* duobinary signalling gives ... 0 0 -1 0 1 0 0 ... at the sampling
|
31 |
|
|
* instants, whereas HAPN signalling gives ... 0 0 -1 1 0 0 ..., see
|
32 |
|
|
* Proakis, Digital Communications).
|
33 |
|
|
* The code is untested. It is compatible with itself (i.e. it can decode
|
34 |
|
|
* the packets it sent), but I could not test if it is compatible with
|
35 |
|
|
* any "real" HAPN modem, since noone uses it in my region of the world.
|
36 |
|
|
* Feedback therefore welcome.
|
37 |
|
|
*/
|
38 |
|
|
|
39 |
|
|
#include "sm.h"
|
40 |
|
|
#include "sm_tbl_hapn4800.h"
|
41 |
|
|
|
42 |
|
|
/* --------------------------------------------------------------------- */
|
43 |
|
|
|
44 |
|
|
struct demod_state_hapn48 {
|
45 |
|
|
unsigned int shreg;
|
46 |
|
|
unsigned int bit_pll;
|
47 |
|
|
unsigned char last_bit;
|
48 |
|
|
unsigned char last_bit2;
|
49 |
|
|
unsigned int dcd_shreg;
|
50 |
|
|
int dcd_sum0, dcd_sum1, dcd_sum2;
|
51 |
|
|
unsigned int dcd_time;
|
52 |
|
|
int lvlhi, lvllo;
|
53 |
|
|
};
|
54 |
|
|
|
55 |
|
|
struct mod_state_hapn48 {
|
56 |
|
|
unsigned int shreg;
|
57 |
|
|
unsigned char tx_bit;
|
58 |
|
|
unsigned int tx_seq;
|
59 |
|
|
const unsigned char *tbl;
|
60 |
|
|
};
|
61 |
|
|
|
62 |
|
|
/* --------------------------------------------------------------------- */
|
63 |
|
|
|
64 |
|
|
static void modulator_hapn4800_10_u8(struct sm_state *sm, unsigned char *buf, unsigned int buflen)
|
65 |
|
|
{
|
66 |
|
|
struct mod_state_hapn48 *st = (struct mod_state_hapn48 *)(&sm->m);
|
67 |
|
|
|
68 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
69 |
|
|
if (!st->tx_seq++) {
|
70 |
|
|
if (st->shreg <= 1)
|
71 |
|
|
st->shreg = hdlcdrv_getbits(&sm->hdrv) | 0x10000;
|
72 |
|
|
st->tx_bit = ((st->tx_bit << 1) |
|
73 |
|
|
(st->tx_bit & 1));
|
74 |
|
|
st->tx_bit ^= (!(st->shreg & 1));
|
75 |
|
|
st->shreg >>= 1;
|
76 |
|
|
st->tbl = hapn48_txfilt_10 + (st->tx_bit & 0xf);
|
77 |
|
|
}
|
78 |
|
|
if (st->tx_seq >= 10)
|
79 |
|
|
st->tx_seq = 0;
|
80 |
|
|
*buf = *st->tbl;
|
81 |
|
|
st->tbl += 0x10;
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
/* --------------------------------------------------------------------- */
|
86 |
|
|
|
87 |
|
|
static void modulator_hapn4800_10_s16(struct sm_state *sm, short *buf, unsigned int buflen)
|
88 |
|
|
{
|
89 |
|
|
struct mod_state_hapn48 *st = (struct mod_state_hapn48 *)(&sm->m);
|
90 |
|
|
|
91 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
92 |
|
|
if (!st->tx_seq++) {
|
93 |
|
|
if (st->shreg <= 1)
|
94 |
|
|
st->shreg = hdlcdrv_getbits(&sm->hdrv) | 0x10000;
|
95 |
|
|
st->tx_bit = ((st->tx_bit << 1) |
|
96 |
|
|
(st->tx_bit & 1));
|
97 |
|
|
st->tx_bit ^= (!(st->shreg & 1));
|
98 |
|
|
st->shreg >>= 1;
|
99 |
|
|
st->tbl = hapn48_txfilt_10 + (st->tx_bit & 0xf);
|
100 |
|
|
}
|
101 |
|
|
if (st->tx_seq >= 10)
|
102 |
|
|
st->tx_seq = 0;
|
103 |
|
|
*buf = ((*st->tbl)-0x80)<<8;
|
104 |
|
|
st->tbl += 0x10;
|
105 |
|
|
}
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
/* --------------------------------------------------------------------- */
|
109 |
|
|
|
110 |
|
|
static void modulator_hapn4800_8_u8(struct sm_state *sm, unsigned char *buf, unsigned int buflen)
|
111 |
|
|
{
|
112 |
|
|
struct mod_state_hapn48 *st = (struct mod_state_hapn48 *)(&sm->m);
|
113 |
|
|
|
114 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
115 |
|
|
if (!st->tx_seq++) {
|
116 |
|
|
if (st->shreg <= 1)
|
117 |
|
|
st->shreg = hdlcdrv_getbits(&sm->hdrv) | 0x10000;
|
118 |
|
|
st->tx_bit = (st->tx_bit << 1) | (st->tx_bit & 1);
|
119 |
|
|
st->tx_bit ^= !(st->shreg & 1);
|
120 |
|
|
st->shreg >>= 1;
|
121 |
|
|
st->tbl = hapn48_txfilt_8 + (st->tx_bit & 0xf);
|
122 |
|
|
}
|
123 |
|
|
if (st->tx_seq >= 8)
|
124 |
|
|
st->tx_seq = 0;
|
125 |
|
|
*buf = *st->tbl;
|
126 |
|
|
st->tbl += 0x10;
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
/* --------------------------------------------------------------------- */
|
131 |
|
|
|
132 |
|
|
static void modulator_hapn4800_8_s16(struct sm_state *sm, short *buf, unsigned int buflen)
|
133 |
|
|
{
|
134 |
|
|
struct mod_state_hapn48 *st = (struct mod_state_hapn48 *)(&sm->m);
|
135 |
|
|
|
136 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
137 |
|
|
if (!st->tx_seq++) {
|
138 |
|
|
if (st->shreg <= 1)
|
139 |
|
|
st->shreg = hdlcdrv_getbits(&sm->hdrv) | 0x10000;
|
140 |
|
|
st->tx_bit = (st->tx_bit << 1) | (st->tx_bit & 1);
|
141 |
|
|
st->tx_bit ^= !(st->shreg & 1);
|
142 |
|
|
st->shreg >>= 1;
|
143 |
|
|
st->tbl = hapn48_txfilt_8 + (st->tx_bit & 0xf);
|
144 |
|
|
}
|
145 |
|
|
if (st->tx_seq >= 8)
|
146 |
|
|
st->tx_seq = 0;
|
147 |
|
|
*buf = ((*st->tbl)-0x80)<<8;
|
148 |
|
|
st->tbl += 0x10;
|
149 |
|
|
}
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
/* --------------------------------------------------------------------- */
|
153 |
|
|
|
154 |
|
|
static void modulator_hapn4800_pm10_u8(struct sm_state *sm, unsigned char *buf, unsigned int buflen)
|
155 |
|
|
{
|
156 |
|
|
struct mod_state_hapn48 *st = (struct mod_state_hapn48 *)(&sm->m);
|
157 |
|
|
|
158 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
159 |
|
|
if (!st->tx_seq++) {
|
160 |
|
|
if (st->shreg <= 1)
|
161 |
|
|
st->shreg = hdlcdrv_getbits(&sm->hdrv) | 0x10000;
|
162 |
|
|
st->tx_bit = ((st->tx_bit << 1) |
|
163 |
|
|
(st->tx_bit & 1));
|
164 |
|
|
st->tx_bit ^= (!(st->shreg & 1));
|
165 |
|
|
st->shreg >>= 1;
|
166 |
|
|
st->tbl = hapn48_txfilt_pm10 + (st->tx_bit & 0xf);
|
167 |
|
|
}
|
168 |
|
|
if (st->tx_seq >= 10)
|
169 |
|
|
st->tx_seq = 0;
|
170 |
|
|
*buf = *st->tbl;
|
171 |
|
|
st->tbl += 0x10;
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
/* --------------------------------------------------------------------- */
|
176 |
|
|
|
177 |
|
|
static void modulator_hapn4800_pm10_s16(struct sm_state *sm, short *buf, unsigned int buflen)
|
178 |
|
|
{
|
179 |
|
|
struct mod_state_hapn48 *st = (struct mod_state_hapn48 *)(&sm->m);
|
180 |
|
|
|
181 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
182 |
|
|
if (!st->tx_seq++) {
|
183 |
|
|
if (st->shreg <= 1)
|
184 |
|
|
st->shreg = hdlcdrv_getbits(&sm->hdrv) | 0x10000;
|
185 |
|
|
st->tx_bit = ((st->tx_bit << 1) |
|
186 |
|
|
(st->tx_bit & 1));
|
187 |
|
|
st->tx_bit ^= (!(st->shreg & 1));
|
188 |
|
|
st->shreg >>= 1;
|
189 |
|
|
st->tbl = hapn48_txfilt_pm10 + (st->tx_bit & 0xf);
|
190 |
|
|
}
|
191 |
|
|
if (st->tx_seq >= 10)
|
192 |
|
|
st->tx_seq = 0;
|
193 |
|
|
*buf = ((*st->tbl)-0x80)<<8;
|
194 |
|
|
st->tbl += 0x10;
|
195 |
|
|
}
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
/* --------------------------------------------------------------------- */
|
199 |
|
|
|
200 |
|
|
static void modulator_hapn4800_pm8_u8(struct sm_state *sm, unsigned char *buf, unsigned int buflen)
|
201 |
|
|
{
|
202 |
|
|
struct mod_state_hapn48 *st = (struct mod_state_hapn48 *)(&sm->m);
|
203 |
|
|
|
204 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
205 |
|
|
if (!st->tx_seq++) {
|
206 |
|
|
if (st->shreg <= 1)
|
207 |
|
|
st->shreg = hdlcdrv_getbits(&sm->hdrv) | 0x10000;
|
208 |
|
|
st->tx_bit = (st->tx_bit << 1) | (st->tx_bit & 1);
|
209 |
|
|
st->tx_bit ^= !(st->shreg & 1);
|
210 |
|
|
st->shreg >>= 1;
|
211 |
|
|
st->tbl = hapn48_txfilt_pm8 + (st->tx_bit & 0xf);
|
212 |
|
|
}
|
213 |
|
|
if (st->tx_seq >= 8)
|
214 |
|
|
st->tx_seq = 0;
|
215 |
|
|
*buf = *st->tbl;
|
216 |
|
|
st->tbl += 0x10;
|
217 |
|
|
}
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
/* --------------------------------------------------------------------- */
|
221 |
|
|
|
222 |
|
|
static void modulator_hapn4800_pm8_s16(struct sm_state *sm, short *buf, unsigned int buflen)
|
223 |
|
|
{
|
224 |
|
|
struct mod_state_hapn48 *st = (struct mod_state_hapn48 *)(&sm->m);
|
225 |
|
|
|
226 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
227 |
|
|
if (!st->tx_seq++) {
|
228 |
|
|
if (st->shreg <= 1)
|
229 |
|
|
st->shreg = hdlcdrv_getbits(&sm->hdrv) | 0x10000;
|
230 |
|
|
st->tx_bit = (st->tx_bit << 1) | (st->tx_bit & 1);
|
231 |
|
|
st->tx_bit ^= !(st->shreg & 1);
|
232 |
|
|
st->shreg >>= 1;
|
233 |
|
|
st->tbl = hapn48_txfilt_pm8 + (st->tx_bit & 0xf);
|
234 |
|
|
}
|
235 |
|
|
if (st->tx_seq >= 8)
|
236 |
|
|
st->tx_seq = 0;
|
237 |
|
|
*buf = ((*st->tbl)-0x80)<<8;
|
238 |
|
|
st->tbl += 0x10;
|
239 |
|
|
}
|
240 |
|
|
}
|
241 |
|
|
|
242 |
|
|
/* --------------------------------------------------------------------- */
|
243 |
|
|
|
244 |
|
|
static void demodulator_hapn4800_10_u8(struct sm_state *sm, const unsigned char *buf, unsigned int buflen)
|
245 |
|
|
{
|
246 |
|
|
struct demod_state_hapn48 *st = (struct demod_state_hapn48 *)(&sm->d);
|
247 |
|
|
static const int pll_corr[2] = { -0x800, 0x800 };
|
248 |
|
|
int curst, cursync;
|
249 |
|
|
int inv;
|
250 |
|
|
|
251 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
252 |
|
|
inv = ((int)(buf[-2])-0x80) << 8;
|
253 |
|
|
st->lvlhi = (st->lvlhi * 65309) >> 16; /* decay */
|
254 |
|
|
st->lvllo = (st->lvllo * 65309) >> 16; /* decay */
|
255 |
|
|
if (inv > st->lvlhi)
|
256 |
|
|
st->lvlhi = inv;
|
257 |
|
|
if (inv < st->lvllo)
|
258 |
|
|
st->lvllo = inv;
|
259 |
|
|
if (buflen & 1)
|
260 |
|
|
st->dcd_shreg <<= 1;
|
261 |
|
|
st->bit_pll += 0x199a;
|
262 |
|
|
curst = cursync = 0;
|
263 |
|
|
if (inv > st->lvlhi >> 1) {
|
264 |
|
|
curst = 1;
|
265 |
|
|
cursync = (buf[-2] > buf[-1] && buf[-2] > buf[-3] &&
|
266 |
|
|
buf[-2] > buf[-0] && buf[-2] > buf[-4]);
|
267 |
|
|
} else if (inv < st->lvllo >> 1) {
|
268 |
|
|
curst = -1;
|
269 |
|
|
cursync = (buf[-2] < buf[-1] && buf[-2] < buf[-3] &&
|
270 |
|
|
buf[-2] < buf[-0] && buf[-2] < buf[-4]);
|
271 |
|
|
}
|
272 |
|
|
if (cursync) {
|
273 |
|
|
st->dcd_shreg |= cursync;
|
274 |
|
|
st->bit_pll += pll_corr[((st->bit_pll - 0x8000u) & 0xffffu) < 0x8ccdu];
|
275 |
|
|
st->dcd_sum0 += 16 * hweight32(st->dcd_shreg & 0x18c6318c) -
|
276 |
|
|
hweight32(st->dcd_shreg & 0xe739ce70);
|
277 |
|
|
}
|
278 |
|
|
hdlcdrv_channelbit(&sm->hdrv, cursync);
|
279 |
|
|
if ((--st->dcd_time) <= 0) {
|
280 |
|
|
hdlcdrv_setdcd(&sm->hdrv, (st->dcd_sum0 +
|
281 |
|
|
st->dcd_sum1 +
|
282 |
|
|
st->dcd_sum2) < 0);
|
283 |
|
|
st->dcd_sum2 = st->dcd_sum1;
|
284 |
|
|
st->dcd_sum1 = st->dcd_sum0;
|
285 |
|
|
st->dcd_sum0 = 2; /* slight bias */
|
286 |
|
|
st->dcd_time = 240;
|
287 |
|
|
}
|
288 |
|
|
if (st->bit_pll >= 0x10000) {
|
289 |
|
|
st->bit_pll &= 0xffff;
|
290 |
|
|
st->last_bit2 = st->last_bit;
|
291 |
|
|
if (curst < 0)
|
292 |
|
|
st->last_bit = 0;
|
293 |
|
|
else if (curst > 0)
|
294 |
|
|
st->last_bit = 1;
|
295 |
|
|
st->shreg >>= 1;
|
296 |
|
|
st->shreg |= ((st->last_bit ^ st->last_bit2 ^ 1) & 1) << 16;
|
297 |
|
|
if (st->shreg & 1) {
|
298 |
|
|
hdlcdrv_putbits(&sm->hdrv, st->shreg >> 1);
|
299 |
|
|
st->shreg = 0x10000;
|
300 |
|
|
}
|
301 |
|
|
diag_trigger(sm);
|
302 |
|
|
}
|
303 |
|
|
diag_add_one(sm, inv);
|
304 |
|
|
}
|
305 |
|
|
}
|
306 |
|
|
|
307 |
|
|
/* --------------------------------------------------------------------- */
|
308 |
|
|
|
309 |
|
|
static void demodulator_hapn4800_10_s16(struct sm_state *sm, const short *buf, unsigned int buflen)
|
310 |
|
|
{
|
311 |
|
|
struct demod_state_hapn48 *st = (struct demod_state_hapn48 *)(&sm->d);
|
312 |
|
|
static const int pll_corr[2] = { -0x800, 0x800 };
|
313 |
|
|
int curst, cursync;
|
314 |
|
|
int inv;
|
315 |
|
|
|
316 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
317 |
|
|
inv = buf[-2];
|
318 |
|
|
st->lvlhi = (st->lvlhi * 65309) >> 16; /* decay */
|
319 |
|
|
st->lvllo = (st->lvllo * 65309) >> 16; /* decay */
|
320 |
|
|
if (inv > st->lvlhi)
|
321 |
|
|
st->lvlhi = inv;
|
322 |
|
|
if (inv < st->lvllo)
|
323 |
|
|
st->lvllo = inv;
|
324 |
|
|
if (buflen & 1)
|
325 |
|
|
st->dcd_shreg <<= 1;
|
326 |
|
|
st->bit_pll += 0x199a;
|
327 |
|
|
curst = cursync = 0;
|
328 |
|
|
if (inv > st->lvlhi >> 1) {
|
329 |
|
|
curst = 1;
|
330 |
|
|
cursync = (buf[-2] > buf[-1] && buf[-2] > buf[-3] &&
|
331 |
|
|
buf[-2] > buf[-0] && buf[-2] > buf[-4]);
|
332 |
|
|
} else if (inv < st->lvllo >> 1) {
|
333 |
|
|
curst = -1;
|
334 |
|
|
cursync = (buf[-2] < buf[-1] && buf[-2] < buf[-3] &&
|
335 |
|
|
buf[-2] < buf[-0] && buf[-2] < buf[-4]);
|
336 |
|
|
}
|
337 |
|
|
if (cursync) {
|
338 |
|
|
st->dcd_shreg |= cursync;
|
339 |
|
|
st->bit_pll += pll_corr[((st->bit_pll - 0x8000u) & 0xffffu) < 0x8ccdu];
|
340 |
|
|
st->dcd_sum0 += 16 * hweight32(st->dcd_shreg & 0x18c6318c) -
|
341 |
|
|
hweight32(st->dcd_shreg & 0xe739ce70);
|
342 |
|
|
}
|
343 |
|
|
hdlcdrv_channelbit(&sm->hdrv, cursync);
|
344 |
|
|
if ((--st->dcd_time) <= 0) {
|
345 |
|
|
hdlcdrv_setdcd(&sm->hdrv, (st->dcd_sum0 +
|
346 |
|
|
st->dcd_sum1 +
|
347 |
|
|
st->dcd_sum2) < 0);
|
348 |
|
|
st->dcd_sum2 = st->dcd_sum1;
|
349 |
|
|
st->dcd_sum1 = st->dcd_sum0;
|
350 |
|
|
st->dcd_sum0 = 2; /* slight bias */
|
351 |
|
|
st->dcd_time = 240;
|
352 |
|
|
}
|
353 |
|
|
if (st->bit_pll >= 0x10000) {
|
354 |
|
|
st->bit_pll &= 0xffff;
|
355 |
|
|
st->last_bit2 = st->last_bit;
|
356 |
|
|
if (curst < 0)
|
357 |
|
|
st->last_bit = 0;
|
358 |
|
|
else if (curst > 0)
|
359 |
|
|
st->last_bit = 1;
|
360 |
|
|
st->shreg >>= 1;
|
361 |
|
|
st->shreg |= ((st->last_bit ^ st->last_bit2 ^ 1) & 1) << 16;
|
362 |
|
|
if (st->shreg & 1) {
|
363 |
|
|
hdlcdrv_putbits(&sm->hdrv, st->shreg >> 1);
|
364 |
|
|
st->shreg = 0x10000;
|
365 |
|
|
}
|
366 |
|
|
diag_trigger(sm);
|
367 |
|
|
}
|
368 |
|
|
diag_add_one(sm, inv);
|
369 |
|
|
}
|
370 |
|
|
}
|
371 |
|
|
|
372 |
|
|
/* --------------------------------------------------------------------- */
|
373 |
|
|
|
374 |
|
|
static void demodulator_hapn4800_8_u8(struct sm_state *sm, const unsigned char *buf, unsigned int buflen)
|
375 |
|
|
{
|
376 |
|
|
struct demod_state_hapn48 *st = (struct demod_state_hapn48 *)(&sm->d);
|
377 |
|
|
static const int pll_corr[2] = { -0x800, 0x800 };
|
378 |
|
|
int curst, cursync;
|
379 |
|
|
int inv;
|
380 |
|
|
|
381 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
382 |
|
|
inv = ((int)(buf[-2])-0x80) << 8;
|
383 |
|
|
st->lvlhi = (st->lvlhi * 65309) >> 16; /* decay */
|
384 |
|
|
st->lvllo = (st->lvllo * 65309) >> 16; /* decay */
|
385 |
|
|
if (inv > st->lvlhi)
|
386 |
|
|
st->lvlhi = inv;
|
387 |
|
|
if (inv < st->lvllo)
|
388 |
|
|
st->lvllo = inv;
|
389 |
|
|
if (buflen & 1)
|
390 |
|
|
st->dcd_shreg <<= 1;
|
391 |
|
|
st->bit_pll += 0x2000;
|
392 |
|
|
curst = cursync = 0;
|
393 |
|
|
if (inv > st->lvlhi >> 1) {
|
394 |
|
|
curst = 1;
|
395 |
|
|
cursync = (buf[-2] > buf[-1] && buf[-2] > buf[-3] &&
|
396 |
|
|
buf[-2] > buf[-0] && buf[-2] > buf[-4]);
|
397 |
|
|
} else if (inv < st->lvllo >> 1) {
|
398 |
|
|
curst = -1;
|
399 |
|
|
cursync = (buf[-2] < buf[-1] && buf[-2] < buf[-3] &&
|
400 |
|
|
buf[-2] < buf[-0] && buf[-2] < buf[-4]);
|
401 |
|
|
}
|
402 |
|
|
if (cursync) {
|
403 |
|
|
st->dcd_shreg |= cursync;
|
404 |
|
|
st->bit_pll += pll_corr[((st->bit_pll - 0x8000u) & 0xffffu) < 0x9000u];
|
405 |
|
|
st->dcd_sum0 += 16 * hweight32(st->dcd_shreg & 0x44444444) -
|
406 |
|
|
hweight32(st->dcd_shreg & 0xbbbbbbbb);
|
407 |
|
|
}
|
408 |
|
|
hdlcdrv_channelbit(&sm->hdrv, cursync);
|
409 |
|
|
if ((--st->dcd_time) <= 0) {
|
410 |
|
|
hdlcdrv_setdcd(&sm->hdrv, (st->dcd_sum0 +
|
411 |
|
|
st->dcd_sum1 +
|
412 |
|
|
st->dcd_sum2) < 0);
|
413 |
|
|
st->dcd_sum2 = st->dcd_sum1;
|
414 |
|
|
st->dcd_sum1 = st->dcd_sum0;
|
415 |
|
|
st->dcd_sum0 = 2; /* slight bias */
|
416 |
|
|
st->dcd_time = 240;
|
417 |
|
|
}
|
418 |
|
|
if (st->bit_pll >= 0x10000) {
|
419 |
|
|
st->bit_pll &= 0xffff;
|
420 |
|
|
st->last_bit2 = st->last_bit;
|
421 |
|
|
if (curst < 0)
|
422 |
|
|
st->last_bit = 0;
|
423 |
|
|
else if (curst > 0)
|
424 |
|
|
st->last_bit = 1;
|
425 |
|
|
st->shreg >>= 1;
|
426 |
|
|
st->shreg |= ((st->last_bit ^ st->last_bit2 ^ 1) & 1) << 16;
|
427 |
|
|
if (st->shreg & 1) {
|
428 |
|
|
hdlcdrv_putbits(&sm->hdrv, st->shreg >> 1);
|
429 |
|
|
st->shreg = 0x10000;
|
430 |
|
|
}
|
431 |
|
|
diag_trigger(sm);
|
432 |
|
|
}
|
433 |
|
|
diag_add_one(sm, inv);
|
434 |
|
|
}
|
435 |
|
|
}
|
436 |
|
|
|
437 |
|
|
/* --------------------------------------------------------------------- */
|
438 |
|
|
|
439 |
|
|
static void demodulator_hapn4800_8_s16(struct sm_state *sm, const short *buf, unsigned int buflen)
|
440 |
|
|
{
|
441 |
|
|
struct demod_state_hapn48 *st = (struct demod_state_hapn48 *)(&sm->d);
|
442 |
|
|
static const int pll_corr[2] = { -0x800, 0x800 };
|
443 |
|
|
int curst, cursync;
|
444 |
|
|
int inv;
|
445 |
|
|
|
446 |
|
|
for (; buflen > 0; buflen--, buf++) {
|
447 |
|
|
inv = buf[-2];
|
448 |
|
|
st->lvlhi = (st->lvlhi * 65309) >> 16; /* decay */
|
449 |
|
|
st->lvllo = (st->lvllo * 65309) >> 16; /* decay */
|
450 |
|
|
if (inv > st->lvlhi)
|
451 |
|
|
st->lvlhi = inv;
|
452 |
|
|
if (inv < st->lvllo)
|
453 |
|
|
st->lvllo = inv;
|
454 |
|
|
if (buflen & 1)
|
455 |
|
|
st->dcd_shreg <<= 1;
|
456 |
|
|
st->bit_pll += 0x2000;
|
457 |
|
|
curst = cursync = 0;
|
458 |
|
|
if (inv > st->lvlhi >> 1) {
|
459 |
|
|
curst = 1;
|
460 |
|
|
cursync = (buf[-2] > buf[-1] && buf[-2] > buf[-3] &&
|
461 |
|
|
buf[-2] > buf[-0] && buf[-2] > buf[-4]);
|
462 |
|
|
} else if (inv < st->lvllo >> 1) {
|
463 |
|
|
curst = -1;
|
464 |
|
|
cursync = (buf[-2] < buf[-1] && buf[-2] < buf[-3] &&
|
465 |
|
|
buf[-2] < buf[-0] && buf[-2] < buf[-4]);
|
466 |
|
|
}
|
467 |
|
|
if (cursync) {
|
468 |
|
|
st->dcd_shreg |= cursync;
|
469 |
|
|
st->bit_pll += pll_corr[((st->bit_pll - 0x8000u) & 0xffffu) < 0x9000u];
|
470 |
|
|
st->dcd_sum0 += 16 * hweight32(st->dcd_shreg & 0x44444444) -
|
471 |
|
|
hweight32(st->dcd_shreg & 0xbbbbbbbb);
|
472 |
|
|
}
|
473 |
|
|
hdlcdrv_channelbit(&sm->hdrv, cursync);
|
474 |
|
|
if ((--st->dcd_time) <= 0) {
|
475 |
|
|
hdlcdrv_setdcd(&sm->hdrv, (st->dcd_sum0 +
|
476 |
|
|
st->dcd_sum1 +
|
477 |
|
|
st->dcd_sum2) < 0);
|
478 |
|
|
st->dcd_sum2 = st->dcd_sum1;
|
479 |
|
|
st->dcd_sum1 = st->dcd_sum0;
|
480 |
|
|
st->dcd_sum0 = 2; /* slight bias */
|
481 |
|
|
st->dcd_time = 240;
|
482 |
|
|
}
|
483 |
|
|
if (st->bit_pll >= 0x10000) {
|
484 |
|
|
st->bit_pll &= 0xffff;
|
485 |
|
|
st->last_bit2 = st->last_bit;
|
486 |
|
|
if (curst < 0)
|
487 |
|
|
st->last_bit = 0;
|
488 |
|
|
else if (curst > 0)
|
489 |
|
|
st->last_bit = 1;
|
490 |
|
|
st->shreg >>= 1;
|
491 |
|
|
st->shreg |= ((st->last_bit ^ st->last_bit2 ^ 1) & 1) << 16;
|
492 |
|
|
if (st->shreg & 1) {
|
493 |
|
|
hdlcdrv_putbits(&sm->hdrv, st->shreg >> 1);
|
494 |
|
|
st->shreg = 0x10000;
|
495 |
|
|
}
|
496 |
|
|
diag_trigger(sm);
|
497 |
|
|
}
|
498 |
|
|
diag_add_one(sm, inv);
|
499 |
|
|
}
|
500 |
|
|
}
|
501 |
|
|
|
502 |
|
|
/* --------------------------------------------------------------------- */
|
503 |
|
|
|
504 |
|
|
static void demod_init_hapn4800(struct sm_state *sm)
|
505 |
|
|
{
|
506 |
|
|
struct demod_state_hapn48 *st = (struct demod_state_hapn48 *)(&sm->d);
|
507 |
|
|
|
508 |
|
|
st->dcd_time = 120;
|
509 |
|
|
st->dcd_sum0 = 2;
|
510 |
|
|
}
|
511 |
|
|
|
512 |
|
|
/* --------------------------------------------------------------------- */
|
513 |
|
|
|
514 |
|
|
const struct modem_tx_info sm_hapn4800_8_tx = {
|
515 |
|
|
"hapn4800", sizeof(struct mod_state_hapn48), 38400, 4800,
|
516 |
|
|
modulator_hapn4800_8_u8, modulator_hapn4800_8_s16, NULL
|
517 |
|
|
};
|
518 |
|
|
|
519 |
|
|
const struct modem_rx_info sm_hapn4800_8_rx = {
|
520 |
|
|
"hapn4800", sizeof(struct demod_state_hapn48), 38400, 4800, 5, 8,
|
521 |
|
|
demodulator_hapn4800_8_u8, demodulator_hapn4800_8_s16, demod_init_hapn4800
|
522 |
|
|
};
|
523 |
|
|
|
524 |
|
|
/* --------------------------------------------------------------------- */
|
525 |
|
|
|
526 |
|
|
const struct modem_tx_info sm_hapn4800_10_tx = {
|
527 |
|
|
"hapn4800", sizeof(struct mod_state_hapn48), 48000, 4800,
|
528 |
|
|
modulator_hapn4800_10_u8, modulator_hapn4800_10_s16, NULL
|
529 |
|
|
};
|
530 |
|
|
|
531 |
|
|
const struct modem_rx_info sm_hapn4800_10_rx = {
|
532 |
|
|
"hapn4800", sizeof(struct demod_state_hapn48), 48000, 4800, 5, 10,
|
533 |
|
|
demodulator_hapn4800_10_u8, demodulator_hapn4800_10_s16, demod_init_hapn4800
|
534 |
|
|
};
|
535 |
|
|
|
536 |
|
|
/* --------------------------------------------------------------------- */
|
537 |
|
|
|
538 |
|
|
const struct modem_tx_info sm_hapn4800_pm8_tx = {
|
539 |
|
|
"hapn4800pm", sizeof(struct mod_state_hapn48), 38400, 4800,
|
540 |
|
|
modulator_hapn4800_pm8_u8, modulator_hapn4800_pm8_s16, NULL
|
541 |
|
|
};
|
542 |
|
|
|
543 |
|
|
const struct modem_rx_info sm_hapn4800_pm8_rx = {
|
544 |
|
|
"hapn4800pm", sizeof(struct demod_state_hapn48), 38400, 4800, 5, 8,
|
545 |
|
|
demodulator_hapn4800_8_u8, demodulator_hapn4800_8_s16, demod_init_hapn4800
|
546 |
|
|
};
|
547 |
|
|
|
548 |
|
|
/* --------------------------------------------------------------------- */
|
549 |
|
|
|
550 |
|
|
const struct modem_tx_info sm_hapn4800_pm10_tx = {
|
551 |
|
|
"hapn4800pm", sizeof(struct mod_state_hapn48), 48000, 4800,
|
552 |
|
|
modulator_hapn4800_pm10_u8, modulator_hapn4800_pm10_s16, NULL
|
553 |
|
|
};
|
554 |
|
|
|
555 |
|
|
const struct modem_rx_info sm_hapn4800_pm10_rx = {
|
556 |
|
|
"hapn4800pm", sizeof(struct demod_state_hapn48), 48000, 4800, 5, 10,
|
557 |
|
|
demodulator_hapn4800_10_u8, demodulator_hapn4800_10_s16, demod_init_hapn4800
|
558 |
|
|
};
|
559 |
|
|
|
560 |
|
|
/* --------------------------------------------------------------------- */
|