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 * A ticker encapsulates the timing information of some
44 * abstract tick source. The following tickers are used:
45 * - Each xbus has an embedded ticker.
46 * - There is one global dahdi_ticker to represent ticks
47 * of external dahdi card (in case we want to sync
48 * from other dahdi devices).
49 */
50 struct xpp_ticker { /* for rate calculation */
51 int count;
52 int cycle;
53 ktime_t first_sample;
54 ktime_t last_sample;
55 int tick_period; /* usec/tick */
56 spinlock_t lock;
57 };
58
59 /*
60 * xpp_drift represent the measurements of the offset between an
61 * xbus ticker to a reference ticker.
62 */
63 struct xpp_drift {
64 int delta_tick; /* from ref_ticker */
65 int lost_ticks; /* occurances */
66 int lost_tick_count;
67 int sync_inaccuracy;
68 ktime_t last_lost_tick;
69 long delta_sum;
70 int offset_prev;
71 int offset_range;
72 int offset_min;
73 int offset_max;
74 int min_speed;
75 int max_speed;
76 spinlock_t lock;
77 };
78
79 void xpp_drift_init(xbus_t *xbus);
80
81 static inline long usec_diff(const ktime_t *tv1,
82 const ktime_t *tv2)
83 {
84 return ktime_us_delta(*tv1, *tv2);
85 }
86
87 int xbus_pcm_init(void *top);
88 void xbus_pcm_shutdown(void);
89 int send_pcm_frame(xbus_t *xbus, xframe_t *xframe);
90 void pcm_recompute(xpd_t *xpd, xpp_line_t tmp_pcm_mask);
91 void xframe_receive_pcm(xbus_t *xbus, xframe_t *xframe);
92 void update_wanted_pcm_mask(xpd_t *xpd, xpp_line_t new_mask, uint new_pcm_len);
93 void generic_card_pcm_recompute(xpd_t *xpd, xpp_line_t pcm_mask);
94 void generic_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack);
95 void generic_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack);
96 int generic_timing_priority(xpd_t *xpd);
97 int generic_echocancel_timeslot(xpd_t *xpd, int pos);
98 int generic_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask);
99 void fill_beep(u_char *buf, int num, int duration);
100 const char *sync_mode_name(enum sync_mode mode);
101 void xbus_set_command_timer(xbus_t *xbus, bool on);
102 void xbus_request_sync(xbus_t *xbus, enum sync_mode mode);
103 void got_new_syncer(xbus_t *xbus, enum sync_mode mode, int drift);
104 int xbus_command_queue_tick(xbus_t *xbus);
105 void xbus_reset_counters(xbus_t *xbus);
106 void elect_syncer(const char *msg);
107 int exec_sync_command(const char *buf, size_t count);
108 int fill_sync_string(char *buf, size_t count);
109 #ifdef DAHDI_SYNC_TICK
110 void dahdi_sync_tick(struct dahdi_span *span, int is_master);
111 #endif
112
113 #ifdef DEBUG_PCMTX
114 extern int pcmtx;
115 extern int pcmtx_chan;
116 #endif
117
118 #endif /* __KERNEL__ */
119
120 #endif /* XBUS_PCM_H */