-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdtmf.c
73 lines (54 loc) · 2.21 KB
/
dtmf.c
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
#include "dtmf.h"
#include "dial.h"
#include "gpio.h"
#include "extern.h"
//The followig are defined in extern.c
extern pthread_mutex_t dial_mutex ;
extern pthread_cond_t cond_dtmf_dial ;
extern pthread_cond_t cond_dialcomplete ;
extern uint8_t dial_status;
uint8_t gpio_port;
void *tf_dtmf()
{
struct sched_param para_dtmf;
para_dtmf.sched_priority = 40;
sched_setscheduler(0,SCHED_RR, ¶_dtmf);
//static dtmf_fsm_t dtmf_state = st_dtmf_idle;
static uint8_t loop_interrupt = 0;
static uint32_t tv_sec = 0;
static uint32_t tv_usec = 0;
static bool timeout = false;
while(1){ //loop and wait for interrupts
//loop only if cond_dial is true
/************************************************************************
* dtmf IDLE
***********************************************************************/
//Use wait_select until a DC_LOOP_INT occured (rising edgeof MCP Interrupt line)
// A timeout means the user blocks by leaving receiver of hook more than 30s
// loop_int > 0 load first pulse into number_dialed_accum then go to hangup
// In hangup it is checked, if another pulse comes
// wait for cond_dial
pthread_mutex_lock(&dial_mutex);
pthread_cond_wait(&cond_dtmf_dial, &dial_mutex);
pthread_mutex_unlock(&dial_mutex);
timeout = true;
tv_sec = 30;
tv_usec = 000000;
loop_interrupt = wait_select(tv_sec, tv_usec, DTMF_INT, timeout);
if (loop_interrupt > 0) {
// Normal detection of interrupt (only LSB 4 bits)
number_dialed = (0xf) & read_ctrl_register(DTMF_READ,MCP_GPIO, 5555);
dial_status = stat_compl_dtmf;
pthread_cond_signal(&cond_dialcomplete);
}
//if the receiver is lifted without dialing for 30s an Alarm is generated
else if (loop_interrupt == 0) {
dial_status = stat_nodial;
//Message to callling function that no dial occured
pthread_cond_signal(&cond_dialcomplete);
}
else {
usleep(10000);
}
}
}