OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [net/] [soundmodem/] [sm.h] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*****************************************************************************/
2
 
3
/*
4
 *      sm.h  --  soundcard radio modem driver internal header.
5
 *
6
 *      Copyright (C) 1996-1998  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
 
28
#ifndef _SM_H
29
#define _SM_H
30
 
31
/* ---------------------------------------------------------------------- */
32
 
33
#include <linux/hdlcdrv.h>
34
#include <linux/soundmodem.h>
35
 
36
#define SM_DEBUG
37
 
38
/* ---------------------------------------------------------------------- */
39
/*
40
 * Information that need to be kept for each board.
41
 */
42
 
43
struct sm_state {
44
        struct hdlcdrv_state hdrv;
45
 
46
        const struct modem_tx_info *mode_tx;
47
        const struct modem_rx_info *mode_rx;
48
 
49
        const struct hardware_info *hwdrv;
50
 
51
        /*
52
         * Hardware (soundcard) access routines state
53
         */
54
        struct {
55
                void *ibuf;
56
                unsigned int ifragsz;
57
                unsigned int ifragptr;
58
                unsigned int i16bit;
59
                void *obuf;
60
                unsigned int ofragsz;
61
                unsigned int ofragptr;
62
                unsigned int o16bit;
63
                int ptt_cnt;
64
        } dma;
65
 
66
        union {
67
                long hw[32/sizeof(long)];
68
        } hw;
69
 
70
        /*
71
         * state of the modem code
72
         */
73
        union {
74
                long m[48/sizeof(long)];
75
        } m;
76
        union {
77
                long d[256/sizeof(long)];
78
        } d;
79
 
80
#define DIAGDATALEN 64
81
        struct diag_data {
82
                unsigned int mode;
83
                unsigned int flags;
84
                volatile int ptr;
85
                short data[DIAGDATALEN];
86
        } diag;
87
 
88
 
89
#ifdef SM_DEBUG
90
        struct debug_vals {
91
                unsigned long last_jiffies;
92
                unsigned cur_intcnt;
93
                unsigned last_intcnt;
94
                unsigned mod_cyc;
95
                unsigned demod_cyc;
96
                unsigned dma_residue;
97
        } debug_vals;
98
#endif /* SM_DEBUG */
99
};
100
 
101
/* ---------------------------------------------------------------------- */
102
/*
103
 * Mode definition structure
104
 */
105
 
106
struct modem_tx_info {
107
        const char *name;
108
        unsigned int loc_storage;
109
        int srate;
110
        int bitrate;
111
        void (*modulator_u8)(struct sm_state *, unsigned char *, unsigned int);
112
        void (*modulator_s16)(struct sm_state *, short *, unsigned int);
113
        void (*init)(struct sm_state *);
114
};
115
 
116
struct modem_rx_info {
117
        const char *name;
118
        unsigned int loc_storage;
119
        int srate;
120
        int bitrate;
121
        unsigned int overlap;
122
        unsigned int sperbit;
123
        void (*demodulator_u8)(struct sm_state *, const unsigned char *, unsigned int);
124
        void (*demodulator_s16)(struct sm_state *, const short *, unsigned int);
125
        void (*init)(struct sm_state *);
126
};
127
 
128
/* ---------------------------------------------------------------------- */
129
/*
130
 * Soundcard driver definition structure
131
 */
132
 
133
struct hardware_info {
134
        char *hw_name; /* used for request_{region,irq,dma} */
135
        unsigned int loc_storage;
136
        /*
137
         * mode specific open/close
138
         */
139
        int (*open)(struct device *, struct sm_state *);
140
        int (*close)(struct device *, struct sm_state *);
141
        int (*ioctl)(struct device *, struct sm_state *, struct ifreq *,
142
                     struct hdlcdrv_ioctl *, int);
143
        int (*sethw)(struct device *, struct sm_state *, char *);
144
};
145
 
146
/* --------------------------------------------------------------------- */
147
 
148
#define min(a, b) (((a) < (b)) ? (a) : (b))
149
#define max(a, b) (((a) > (b)) ? (a) : (b))
150
 
151
/* --------------------------------------------------------------------- */
152
 
153
extern const char sm_drvname[];
154
extern const char sm_drvinfo[];
155
 
156
/* --------------------------------------------------------------------- */
157
/*
158
 * ===================== diagnostics stuff ===============================
159
 */
160
 
161
extern inline void diag_trigger(struct sm_state *sm)
162
{
163
        if (sm->diag.ptr < 0)
164
                if (!(sm->diag.flags & SM_DIAGFLAG_DCDGATE) || sm->hdrv.hdlcrx.dcd)
165
                        sm->diag.ptr = 0;
166
}
167
 
168
/* --------------------------------------------------------------------- */
169
 
170
#define SHRT_MAX ((short)(((unsigned short)(~0U))>>1))
171
#define SHRT_MIN (-SHRT_MAX-1)
172
 
173
extern inline void diag_add(struct sm_state *sm, int valinp, int valdemod)
174
{
175
        int val;
176
 
177
        if ((sm->diag.mode != SM_DIAGMODE_INPUT &&
178
             sm->diag.mode != SM_DIAGMODE_DEMOD) ||
179
            sm->diag.ptr >= DIAGDATALEN || sm->diag.ptr < 0)
180
                return;
181
        val = (sm->diag.mode == SM_DIAGMODE_DEMOD) ? valdemod : valinp;
182
        /* clip */
183
        if (val > SHRT_MAX)
184
                val = SHRT_MAX;
185
        if (val < SHRT_MIN)
186
                val = SHRT_MIN;
187
        sm->diag.data[sm->diag.ptr++] = val;
188
}
189
 
190
/* --------------------------------------------------------------------- */
191
 
192
extern inline void diag_add_one(struct sm_state *sm, int val)
193
{
194
        if ((sm->diag.mode != SM_DIAGMODE_INPUT &&
195
             sm->diag.mode != SM_DIAGMODE_DEMOD) ||
196
            sm->diag.ptr >= DIAGDATALEN || sm->diag.ptr < 0)
197
                return;
198
        /* clip */
199
        if (val > SHRT_MAX)
200
                val = SHRT_MAX;
201
        if (val < SHRT_MIN)
202
                val = SHRT_MIN;
203
        sm->diag.data[sm->diag.ptr++] = val;
204
}
205
 
206
/* --------------------------------------------------------------------- */
207
 
208
static inline void diag_add_constellation(struct sm_state *sm, int vali, int valq)
209
{
210
        if ((sm->diag.mode != SM_DIAGMODE_CONSTELLATION) ||
211
            sm->diag.ptr >= DIAGDATALEN-1 || sm->diag.ptr < 0)
212
                return;
213
        /* clip */
214
        if (vali > SHRT_MAX)
215
                vali = SHRT_MAX;
216
        if (vali < SHRT_MIN)
217
                vali = SHRT_MIN;
218
        if (valq > SHRT_MAX)
219
                valq = SHRT_MAX;
220
        if (valq < SHRT_MIN)
221
                valq = SHRT_MIN;
222
        sm->diag.data[sm->diag.ptr++] = vali;
223
        sm->diag.data[sm->diag.ptr++] = valq;
224
}
225
 
226
/* --------------------------------------------------------------------- */
227
/*
228
 * ===================== utility functions ===============================
229
 */
230
 
231
extern inline unsigned int hweight32(unsigned int w)
232
        __attribute__ ((unused));
233
extern inline unsigned int hweight16(unsigned short w)
234
        __attribute__ ((unused));
235
extern inline unsigned int hweight8(unsigned char w)
236
        __attribute__ ((unused));
237
 
238
extern inline unsigned int hweight32(unsigned int w)
239
{
240
        unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
241
        res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
242
        res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
243
        res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
244
        return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
245
}
246
 
247
extern inline unsigned int hweight16(unsigned short w)
248
{
249
        unsigned short res = (w & 0x5555) + ((w >> 1) & 0x5555);
250
        res = (res & 0x3333) + ((res >> 2) & 0x3333);
251
        res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F);
252
        return (res & 0x00FF) + ((res >> 8) & 0x00FF);
253
}
254
 
255
extern inline unsigned int hweight8(unsigned char w)
256
{
257
        unsigned short res = (w & 0x55) + ((w >> 1) & 0x55);
258
        res = (res & 0x33) + ((res >> 2) & 0x33);
259
        return (res & 0x0F) + ((res >> 4) & 0x0F);
260
}
261
 
262
extern inline unsigned int gcd(unsigned int x, unsigned int y)
263
        __attribute__ ((unused));
264
extern inline unsigned int lcm(unsigned int x, unsigned int y)
265
        __attribute__ ((unused));
266
 
267
extern inline unsigned int gcd(unsigned int x, unsigned int y)
268
{
269
        for (;;) {
270
                if (!x)
271
                        return y;
272
                if (!y)
273
                        return x;
274
                if (x > y)
275
                        x %= y;
276
                else
277
                        y %= x;
278
        }
279
}
280
 
281
extern inline unsigned int lcm(unsigned int x, unsigned int y)
282
{
283
        return x * y / gcd(x, y);
284
}
285
 
286
/* --------------------------------------------------------------------- */
287
/*
288
 * ===================== profiling =======================================
289
 */
290
 
291
 
292
#ifdef __i386__
293
 
294
extern int sm_x86_capability;
295
 
296
#define HAS_RDTSC (sm_x86_capability & 0x10)
297
 
298
/*
299
 * only do 32bit cycle counter arithmetic; we hope we won't overflow.
300
 * in fact, overflowing modems would require over 2THz CPU clock speeds :-)
301
 */
302
 
303
#define time_exec(var,cmd)                                              \
304
({                                                                      \
305
        if (HAS_RDTSC) {                                                \
306
                unsigned int cnt1, cnt2, cnt3;                          \
307
                __asm__(".byte 0x0f,0x31" : "=a" (cnt1), "=d" (cnt3));  \
308
                cmd;                                                    \
309
                __asm__(".byte 0x0f,0x31" : "=a" (cnt2), "=d" (cnt3));  \
310
                var = cnt2-cnt1;                                        \
311
        } else {                                                        \
312
                cmd;                                                    \
313
        }                                                               \
314
})
315
 
316
#else /* __i386__ */
317
 
318
#define time_exec(var,cmd) cmd
319
 
320
#endif /* __i386__ */
321
 
322
/* --------------------------------------------------------------------- */
323
 
324
extern const struct modem_tx_info sm_afsk1200_tx;
325
extern const struct modem_tx_info sm_afsk2400_7_tx;
326
extern const struct modem_tx_info sm_afsk2400_8_tx;
327
extern const struct modem_tx_info sm_afsk2666_tx;
328
extern const struct modem_tx_info sm_psk4800_tx;
329
extern const struct modem_tx_info sm_hapn4800_8_tx;
330
extern const struct modem_tx_info sm_hapn4800_10_tx;
331
extern const struct modem_tx_info sm_hapn4800_pm8_tx;
332
extern const struct modem_tx_info sm_hapn4800_pm10_tx;
333
extern const struct modem_tx_info sm_fsk9600_4_tx;
334
extern const struct modem_tx_info sm_fsk9600_5_tx;
335
 
336
extern const struct modem_rx_info sm_afsk1200_rx;
337
extern const struct modem_rx_info sm_afsk2400_7_rx;
338
extern const struct modem_rx_info sm_afsk2400_8_rx;
339
extern const struct modem_rx_info sm_afsk2666_rx;
340
extern const struct modem_rx_info sm_psk4800_rx;
341
extern const struct modem_rx_info sm_hapn4800_8_rx;
342
extern const struct modem_rx_info sm_hapn4800_10_rx;
343
extern const struct modem_rx_info sm_hapn4800_pm8_rx;
344
extern const struct modem_rx_info sm_hapn4800_pm10_rx;
345
extern const struct modem_rx_info sm_fsk9600_4_rx;
346
extern const struct modem_rx_info sm_fsk9600_5_rx;
347
 
348
extern const struct hardware_info sm_hw_sbc;
349
extern const struct hardware_info sm_hw_sbcfdx;
350
extern const struct hardware_info sm_hw_wss;
351
extern const struct hardware_info sm_hw_wssfdx;
352
 
353
extern const struct modem_tx_info *sm_modem_tx_table[];
354
extern const struct modem_rx_info *sm_modem_rx_table[];
355
extern const struct hardware_info *sm_hardware_table[];
356
 
357
/* --------------------------------------------------------------------- */
358
 
359
void sm_output_status(struct sm_state *sm);
360
/*void sm_output_open(struct sm_state *sm);*/
361
/*void sm_output_close(struct sm_state *sm);*/
362
 
363
/* --------------------------------------------------------------------- */
364
 
365
extern void inline sm_int_freq(struct sm_state *sm)
366
{
367
#ifdef SM_DEBUG
368
        unsigned long cur_jiffies = jiffies;
369
        /*
370
         * measure the interrupt frequency
371
         */
372
        sm->debug_vals.cur_intcnt++;
373
        if ((cur_jiffies - sm->debug_vals.last_jiffies) >= HZ) {
374
                sm->debug_vals.last_jiffies = cur_jiffies;
375
                sm->debug_vals.last_intcnt = sm->debug_vals.cur_intcnt;
376
                sm->debug_vals.cur_intcnt = 0;
377
        }
378
#endif /* SM_DEBUG */
379
}
380
 
381
/* --------------------------------------------------------------------- */
382
#endif /* _SM_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.