Loading...
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 | /*****************************************************************************/ /* * sm.h -- soundcard radio modem driver internal header. * * Copyright (C) 1996 Thomas Sailer (sailer@ife.ee.ethz.ch) * * 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, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Please note that the GPL allows you to use the driver, NOT the radio. * In order to use the radio, you need a license from the communications * authority of your country. * */ #ifndef _SM_H #define _SM_H /* ---------------------------------------------------------------------- */ #include <linux/config.h> #include <linux/hdlcdrv.h> #include <linux/soundmodem.h> #define SM_DEBUG /* --------------------------------------------------------------------- */ #define DMA_MODE_AUTOINIT 0x10 /* ---------------------------------------------------------------------- */ /* * Information that need to be kept for each board. */ struct sm_state { struct hdlcdrv_state hdrv; const struct modem_tx_info *mode_tx; const struct modem_rx_info *mode_rx; const struct hardware_info *hwdrv; /* * Hardware (soundcard) access routines state */ union { long hw[32/sizeof(long)]; } hw; /* * state of the modem code */ union { long m[32/sizeof(long)]; } m; union { long d[256/sizeof(long)]; } d; #define DIAGDATALEN 64 struct diag_data { unsigned int mode; unsigned int flags; volatile int ptr; short data[DIAGDATALEN]; } diag; #ifdef SM_DEBUG struct debug_vals { unsigned long last_jiffies; unsigned cur_intcnt; unsigned last_intcnt; unsigned mod_cyc; unsigned demod_cyc; unsigned dma_residue; } debug_vals; #endif /* SM_DEBUG */ }; /* ---------------------------------------------------------------------- */ /* * Mode definition structure */ struct modem_tx_info { const char *name; unsigned int loc_storage; int srate; int bitrate; unsigned int dmabuflenmodulo; void (*modulator)(struct sm_state *, unsigned char *, int); void (*init)(struct sm_state *); }; struct modem_rx_info { const char *name; unsigned int loc_storage; int srate; int bitrate; unsigned int dmabuflenmodulo; unsigned int sperbit; void (*demodulator)(struct sm_state *, unsigned char *, int); void (*init)(struct sm_state *); }; /* ---------------------------------------------------------------------- */ /* * Soundcard driver definition structure */ struct hardware_info { char *hw_name; /* used for request_{region,irq,dma} */ unsigned int loc_storage; /* * mode specific open/close */ int (*open)(struct device *, struct sm_state *); int (*close)(struct device *, struct sm_state *); int (*ioctl)(struct device *, struct sm_state *, struct ifreq *, struct hdlcdrv_ioctl *, int); int (*sethw)(struct device *, struct sm_state *, char *); }; /* --------------------------------------------------------------------- */ #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) /* --------------------------------------------------------------------- */ extern const char sm_drvname[]; extern const char sm_drvinfo[]; /* --------------------------------------------------------------------- */ /* * ===================== diagnostics stuff =============================== */ extern inline void diag_trigger(struct sm_state *sm) { if (sm->diag.ptr < 0) if (!(sm->diag.flags & SM_DIAGFLAG_DCDGATE) || sm->hdrv.hdlcrx.dcd) sm->diag.ptr = 0; } /* --------------------------------------------------------------------- */ #define SHRT_MAX ((short)(((unsigned short)(~0U))>>1)) #define SHRT_MIN (-SHRT_MAX-1) extern inline void diag_add(struct sm_state *sm, int valinp, int valdemod) { int val; if ((sm->diag.mode != SM_DIAGMODE_INPUT && sm->diag.mode != SM_DIAGMODE_DEMOD) || sm->diag.ptr >= DIAGDATALEN || sm->diag.ptr < 0) return; val = (sm->diag.mode == SM_DIAGMODE_DEMOD) ? valdemod : valinp; /* clip */ if (val > SHRT_MAX) val = SHRT_MAX; if (val < SHRT_MIN) val = SHRT_MIN; sm->diag.data[sm->diag.ptr++] = val; } /* --------------------------------------------------------------------- */ extern inline void diag_add_one(struct sm_state *sm, int val) { if ((sm->diag.mode != SM_DIAGMODE_INPUT && sm->diag.mode != SM_DIAGMODE_DEMOD) || sm->diag.ptr >= DIAGDATALEN || sm->diag.ptr < 0) return; /* clip */ if (val > SHRT_MAX) val = SHRT_MAX; if (val < SHRT_MIN) val = SHRT_MIN; sm->diag.data[sm->diag.ptr++] = val; } /* --------------------------------------------------------------------- */ static inline void diag_add_constellation(struct sm_state *sm, int vali, int valq) { if ((sm->diag.mode != SM_DIAGMODE_CONSTELLATION) || sm->diag.ptr >= DIAGDATALEN-1 || sm->diag.ptr < 0) return; /* clip */ if (vali > SHRT_MAX) vali = SHRT_MAX; if (vali < SHRT_MIN) vali = SHRT_MIN; if (valq > SHRT_MAX) valq = SHRT_MAX; if (valq < SHRT_MIN) valq = SHRT_MIN; sm->diag.data[sm->diag.ptr++] = vali; sm->diag.data[sm->diag.ptr++] = valq; } /* --------------------------------------------------------------------- */ /* * ===================== utility functions =============================== */ extern inline unsigned int hweight32(unsigned int w) __attribute__ ((unused)); extern inline unsigned int hweight16(unsigned short w) __attribute__ ((unused)); extern inline unsigned int hweight8(unsigned char w) __attribute__ ((unused)); extern inline unsigned int hweight32(unsigned int w) { unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555); res = (res & 0x33333333) + ((res >> 2) & 0x33333333); res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F); res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF); return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF); } extern inline unsigned int hweight16(unsigned short w) { unsigned short res = (w & 0x5555) + ((w >> 1) & 0x5555); res = (res & 0x3333) + ((res >> 2) & 0x3333); res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F); return (res & 0x00FF) + ((res >> 8) & 0x00FF); } extern inline unsigned int hweight8(unsigned char w) { unsigned short res = (w & 0x55) + ((w >> 1) & 0x55); res = (res & 0x33) + ((res >> 2) & 0x33); return (res & 0x0F) + ((res >> 4) & 0x0F); } extern inline unsigned int gcd(unsigned int x, unsigned int y) __attribute__ ((unused)); extern inline unsigned int lcm(unsigned int x, unsigned int y) __attribute__ ((unused)); extern inline unsigned int gcd(unsigned int x, unsigned int y) { for (;;) { if (!x) return y; if (!y) return x; if (x > y) x %= y; else y %= x; } } extern inline unsigned int lcm(unsigned int x, unsigned int y) { return x * y / gcd(x, y); } /* --------------------------------------------------------------------- */ /* * ===================== profiling ======================================= */ #if defined(SM_DEBUG) && (defined(CONFIG_M586) || defined(CONFIG_M686)) /* * only do 32bit cycle counter arithmetic; we hope we won't overflow :-) * in fact, overflowing modems would require over 2THz clock speeds :-) */ #define time_exec(var,cmd) \ ({ \ unsigned int cnt1, cnt2, cnt3; \ __asm__(".byte 0x0f,0x31" : "=a" (cnt1), "=d" (cnt3)); \ cmd; \ __asm__(".byte 0x0f,0x31" : "=a" (cnt2), "=d" (cnt3)); \ var = cnt2-cnt1; \ }) #else /* defined(SM_DEBUG) && (defined(CONFIG_M586) || defined(CONFIG_M686)) */ #define time_exec(var,cmd) cmd #endif /* defined(SM_DEBUG) && (defined(CONFIG_M586) || defined(CONFIG_M686)) */ /* --------------------------------------------------------------------- */ extern const struct modem_tx_info sm_afsk1200_tx; extern const struct modem_tx_info sm_afsk2666_tx; extern const struct modem_tx_info sm_psk4800_tx; extern const struct modem_tx_info sm_hapn4800_8_tx; extern const struct modem_tx_info sm_hapn4800_10_tx; extern const struct modem_tx_info sm_hapn4800_pm8_tx; extern const struct modem_tx_info sm_hapn4800_pm10_tx; extern const struct modem_tx_info sm_fsk9600_4_tx; extern const struct modem_tx_info sm_fsk9600_5_tx; extern const struct modem_rx_info sm_afsk1200_rx; extern const struct modem_rx_info sm_afsk2666_rx; extern const struct modem_rx_info sm_psk4800_rx; extern const struct modem_rx_info sm_hapn4800_8_rx; extern const struct modem_rx_info sm_hapn4800_10_rx; extern const struct modem_rx_info sm_hapn4800_pm8_rx; extern const struct modem_rx_info sm_hapn4800_pm10_rx; extern const struct modem_rx_info sm_fsk9600_4_rx; extern const struct modem_rx_info sm_fsk9600_5_rx; extern const struct hardware_info sm_hw_sbc; extern const struct hardware_info sm_hw_wss; extern const struct hardware_info sm_hw_wssfdx; extern const struct modem_tx_info *sm_modem_tx_table[]; extern const struct modem_rx_info *sm_modem_rx_table[]; extern const struct hardware_info *sm_hardware_table[]; /* --------------------------------------------------------------------- */ void sm_output_status(struct sm_state *sm); /*void sm_output_open(struct sm_state *sm);*/ /*void sm_output_close(struct sm_state *sm);*/ /* --------------------------------------------------------------------- */ extern void inline sm_int_freq(struct sm_state *sm) { #ifdef SM_DEBUG unsigned long cur_jiffies = jiffies; /* * measure the interrupt frequency */ sm->debug_vals.cur_intcnt++; if ((cur_jiffies - sm->debug_vals.last_jiffies) >= HZ) { sm->debug_vals.last_jiffies = cur_jiffies; sm->debug_vals.last_intcnt = sm->debug_vals.cur_intcnt; sm->debug_vals.cur_intcnt = 0; } #endif /* SM_DEBUG */ } /* --------------------------------------------------------------------- */ #endif /* _SM_H */ |