11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
4475be4d85a274d0961593db41cf85689db1d583cJoe Perches Copyright (c) Eicon Networks, 2002.
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
6475be4d85a274d0961593db41cf85689db1d583cJoe Perches This source file is supplied for the use with
7475be4d85a274d0961593db41cf85689db1d583cJoe Perches Eicon Networks range of DIVA Server Adapters.
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
9475be4d85a274d0961593db41cf85689db1d583cJoe Perches Eicon File Revision :    2.1
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
11475be4d85a274d0961593db41cf85689db1d583cJoe Perches This program is free software; you can redistribute it and/or modify
12475be4d85a274d0961593db41cf85689db1d583cJoe Perches it under the terms of the GNU General Public License as published by
13475be4d85a274d0961593db41cf85689db1d583cJoe Perches the Free Software Foundation; either version 2, or (at your option)
14475be4d85a274d0961593db41cf85689db1d583cJoe Perches any later version.
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
16475be4d85a274d0961593db41cf85689db1d583cJoe Perches This program is distributed in the hope that it will be useful,
17475be4d85a274d0961593db41cf85689db1d583cJoe Perches but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
18475be4d85a274d0961593db41cf85689db1d583cJoe Perches implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19475be4d85a274d0961593db41cf85689db1d583cJoe Perches See the GNU General Public License for more details.
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
21475be4d85a274d0961593db41cf85689db1d583cJoe Perches You should have received a copy of the GNU General Public License
22475be4d85a274d0961593db41cf85689db1d583cJoe Perches along with this program; if not, write to the Free Software
23475be4d85a274d0961593db41cf85689db1d583cJoe Perches Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
26475be4d85a274d0961593db41cf85689db1d583cJoe Perches#ifndef CAPIDTMF_H_
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_H_
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*---------------------------------------------------------------------------*/
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*---------------------------------------------------------------------------*/
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_TONE_GROUP_COUNT            2
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_LOW_GROUP_FREQUENCIES       4
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_HIGH_GROUP_FREQUENCIES      4
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DSPDTMF_RX_SENSITIVITY_LOW_DEFAULT	50	/* -52 dBm */
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DSPDTMF_RX_SENSITIVITY_HIGH_DEFAULT	50	/* -52 dBm */
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DSPDTMF_RX_HIGH_EXCEEDING_LOW_DEFAULT	10	/* dB */
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DSPDTMF_RX_LOW_EXCEEDING_HIGH_DEFAULT	10	/* dB */
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DSPDTMF_RX_HARMONICS_SEL_DEFAULT	12	/* dB */
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_RECV_BASE_FREQUENCY_COUNT   (CAPIDTMF_LOW_GROUP_FREQUENCIES + CAPIDTMF_HIGH_GROUP_FREQUENCIES)
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_RECV_GUARD_FREQUENCY_COUNT  8
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT  (CAPIDTMF_RECV_BASE_FREQUENCY_COUNT + CAPIDTMF_RECV_GUARD_FREQUENCY_COUNT)
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_RECV_POSITIVE_COEFF_COUNT   16
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_RECV_NEGATIVE_COEFF_COUNT   (CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT - CAPIDTMF_RECV_POSITIVE_COEFF_COUNT)
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_RECV_ACCUMULATE_CYCLES      205
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_RECV_FUNDAMENTAL_OFFSET     (0xff35L * 2)
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_RECV_FUNDAMENTAL_DECREMENT  (0x0028L * 2)
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_RECV_DIGIT_BUFFER_SIZE      32
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_RECV_STATE_IDLE             0x00
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CAPIDTMF_RECV_STATE_DTMF_ACTIVE      0x01
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldstypedef struct tag_capidtmf_recv_state
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
51475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte digit_buffer[CAPIDTMF_RECV_DIGIT_BUFFER_SIZE];
52475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word digit_write_pos;
53475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word digit_read_pos;
54475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word indication_state;
55475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word indication_state_ack;
56475be4d85a274d0961593db41cf85689db1d583cJoe Perches	long goertzel_buffer[2][CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
57475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word min_gap_duration;
58475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word min_digit_duration;
59475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word cycle_counter;
60475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word current_digit_on_time;
61475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word current_digit_off_time;
62475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte current_digit_value;
63475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte state;
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} t_capidtmf_recv_state;
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldstypedef struct tag_capidtmf_state
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
67475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte ulaw;
68475be4d85a274d0961593db41cf85689db1d583cJoe Perches	t_capidtmf_recv_state recv;
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} t_capidtmf_state;
70475be4d85a274d0961593db41cf85689db1d583cJoe Perchesword capidtmf_recv_indication(t_capidtmf_state *p_state, byte *buffer);
71475be4d85a274d0961593db41cf85689db1d583cJoe Perchesvoid capidtmf_recv_block(t_capidtmf_state *p_state, byte *buffer, word length);
72475be4d85a274d0961593db41cf85689db1d583cJoe Perchesvoid capidtmf_init(t_capidtmf_state *p_state, byte ulaw);
73475be4d85a274d0961593db41cf85689db1d583cJoe Perchesvoid capidtmf_recv_enable(t_capidtmf_state *p_state, word min_digit_duration, word min_gap_duration);
74475be4d85a274d0961593db41cf85689db1d583cJoe Perchesvoid capidtmf_recv_disable(t_capidtmf_state *p_state);
75475be4d85a274d0961593db41cf85689db1d583cJoe Perches#define capidtmf_indication(p_state, buffer)  (((p_state)->recv.indication_state != (p_state)->recv.indication_state_ack) ? capidtmf_recv_indication(p_state, buffer) : 0)
76475be4d85a274d0961593db41cf85689db1d583cJoe Perches#define capidtmf_recv_process_block(p_state, buffer, length)  { if ((p_state)->recv.state != CAPIDTMF_RECV_STATE_IDLE) capidtmf_recv_block(p_state, buffer, length); }
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*---------------------------------------------------------------------------*/
781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*---------------------------------------------------------------------------*/
79475be4d85a274d0961593db41cf85689db1d583cJoe Perches#endif
80