Debian Codegraph @

drivers/dahdi/xpp/xbus-pcm.h

raw symbols SCIP
1 /*
2 * Written by Oron Peled <[email protected]>
3 * Copyright (C) 2004-2007, Xorcom
4 *
5 * All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22
23 /*
24 * This source module contains all the PCM and SYNC handling code.
25 */
26 #ifndef XBUS_PCM_H
27 #define XBUS_PCM_H
28
29 #include "xdefs.h"
30 #include <linux/proc_fs.h>
31 #include <dahdi/kernel.h>
32
33 #ifdef __KERNEL__
34
35 enum sync_mode {
36 SYNC_MODE_NONE = 0x00,
37 SYNC_MODE_AB = 0x01, /* Astribank sync */
38 SYNC_MODE_PLL = 0x03, /* Adjust XPD's PLL according to HOST */
39 SYNC_MODE_QUERY = 0x80,
40 };
41
42 /*
43 * Abstract representation of timestamp.
44 * It would (eventually) replace the hard-coded
45 * timeval structs so we can migrate to better
46 * time representations.
47 */
48 struct xpp_timestamp {
49 struct timeval tv;
50 };
51
52 /*
53 * A ticker encapsulates the timing information of some
54 * abstract tick source. The following tickers are used:
55 * - Each xbus has an embedded ticker.
56 * - There is one global dahdi_ticker to represent ticks
57 * of external dahdi card (in case we want to sync
58 * from other dahdi devices).
59 */
60 struct xpp_ticker { /* for rate calculation */
61 int count;
62 int cycle;
63 struct xpp_timestamp first_sample;
64 struct xpp_timestamp last_sample;
65 int tick_period; /* usec/tick */
66 spinlock_t lock;
67 };
68
69 /*
70 * xpp_drift represent the measurements of the offset between an
71 * xbus ticker to a reference ticker.
72 */
73 struct xpp_drift {
74 int delta_tick; /* from ref_ticker */
75 int lost_ticks; /* occurances */
76 int lost_tick_count;
77 int sync_inaccuracy;
78 struct xpp_timestamp last_lost_tick;
79 long delta_sum;
80 int offset_prev;
81 int offset_range;
82 int offset_min;
83 int offset_max;
84 int min_speed;
85 int max_speed;
86 spinlock_t lock;
87 };
88
89 void xpp_drift_init(xbus_t *xbus);
90
91 static inline long usec_diff(const struct timeval *tv1,
92 const struct timeval *tv2)
93 {
94 long diff_sec;
95 long diff_usec;
96
97 diff_sec = tv1->tv_sec - tv2->tv_sec;
98 diff_usec = tv1->tv_usec - tv2->tv_usec;
99 return diff_sec * 1000000 + diff_usec;
100 }
101
102 int xbus_pcm_init(void *top);
103 void xbus_pcm_shutdown(void);
104 int send_pcm_frame(xbus_t *xbus, xframe_t *xframe);
105 void pcm_recompute(xpd_t *xpd, xpp_line_t tmp_pcm_mask);
106 void xframe_receive_pcm(xbus_t *xbus, xframe_t *xframe);
107 void update_wanted_pcm_mask(xpd_t *xpd, xpp_line_t new_mask, uint new_pcm_len);
108 void generic_card_pcm_recompute(xpd_t *xpd, xpp_line_t pcm_mask);
109 void generic_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack);
110 void generic_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack);
111 int generic_timing_priority(xpd_t *xpd);
112 int generic_echocancel_timeslot(xpd_t *xpd, int pos);
113 int generic_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask);
114 void fill_beep(u_char *buf, int num, int duration);
115 const char *sync_mode_name(enum sync_mode mode);
116 void xbus_set_command_timer(xbus_t *xbus, bool on);
117 void xbus_request_sync(xbus_t *xbus, enum sync_mode mode);
118 void got_new_syncer(xbus_t *xbus, enum sync_mode mode, int drift);
119 int xbus_command_queue_tick(xbus_t *xbus);
120 void xbus_reset_counters(xbus_t *xbus);
121 void elect_syncer(const char *msg);
122 int exec_sync_command(const char *buf, size_t count);
123 int fill_sync_string(char *buf, size_t count);
124 #ifdef DAHDI_SYNC_TICK
125 void dahdi_sync_tick(struct dahdi_span *span, int is_master);
126 #endif
127
128 #ifdef DEBUG_PCMTX
129 extern int pcmtx;
130 extern int pcmtx_chan;
131 #endif
132
133 #endif /* __KERNEL__ */
134
135 #endif /* XBUS_PCM_H */