diff options
author | Shaun Ruffell <sruffell@digium.com> | 2011-08-30 16:38:41 +0000 |
---|---|---|
committer | Shaun Ruffell <sruffell@digium.com> | 2011-08-30 16:38:41 +0000 |
commit | cd95077826aa2b3348f384b6972c9619efc7b00c (patch) | |
tree | ced099548bc53c46d4afbc8c5e64006a4b586ea1 /drivers/dahdi/wctdm24xxp/base.c | |
parent | ed9d6ec1e397916c69cee2dd1ebd3c7e3e18793b (diff) |
wctdm24xxp: Use interval for debouncing FXO polarity detection.
Eliminate the assumption that the check function is going to be called
for every frame. Also use a state machine to make polarity debouncing
similar to the other debouncing code.
Signed-off-by: Shaun Ruffell <sruffell@digium.com>
Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@10170 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'drivers/dahdi/wctdm24xxp/base.c')
-rw-r--r-- | drivers/dahdi/wctdm24xxp/base.c | 110 |
1 files changed, 80 insertions, 30 deletions
diff --git a/drivers/dahdi/wctdm24xxp/base.c b/drivers/dahdi/wctdm24xxp/base.c index aa6a2b6..fc79b73 100644 --- a/drivers/dahdi/wctdm24xxp/base.c +++ b/drivers/dahdi/wctdm24xxp/base.c @@ -2071,6 +2071,83 @@ wctdm_check_battery_present(struct wctdm *wc, struct wctdm_module *const mod) } static void +wctdm_fxo_stop_debouncing_polarity(struct wctdm *wc, + struct wctdm_module *const mod) +{ + struct fxo *const fxo = &mod->mod.fxo; + switch (fxo->polarity_state) { + case UNKNOWN_POLARITY: + break; + case POLARITY_DEBOUNCE_POSITIVE: + fxo->polarity_state = POLARITY_NEGATIVE; + break; + case POLARITY_POSITIVE: + break; + case POLARITY_DEBOUNCE_NEGATIVE: + fxo->polarity_state = POLARITY_POSITIVE; + break; + case POLARITY_NEGATIVE: + break; + }; +} + +static void +wctdm_fxo_check_polarity(struct wctdm *wc, struct wctdm_module *const mod, + const bool positive_polarity) +{ + struct fxo *const fxo = &mod->mod.fxo; + + switch (fxo->polarity_state) { + case UNKNOWN_POLARITY: + fxo->polarity_state = (positive_polarity) ? POLARITY_POSITIVE : + POLARITY_NEGATIVE; + break; + case POLARITY_DEBOUNCE_POSITIVE: + if (!positive_polarity) { + fxo->polarity_state = POLARITY_NEGATIVE; + } else if (time_after(wc->framecount, fxo->poldebounce_timer)) { + fxo->polarity_state = POLARITY_POSITIVE; + dahdi_qevent_lock(get_dahdi_chan(wc, mod), + DAHDI_EVENT_POLARITY); + if (debug & DEBUG_CARD) { + dev_info(&wc->vb.pdev->dev, + "%s: Polarity NEGATIVE -> POSITIVE\n", + get_dahdi_chan(wc, mod)->name); + } + } + break; + case POLARITY_POSITIVE: + if (!positive_polarity) { + fxo->polarity_state = POLARITY_DEBOUNCE_NEGATIVE; + fxo->poldebounce_timer = wc->framecount + + POLARITY_DEBOUNCE; + } + break; + case POLARITY_DEBOUNCE_NEGATIVE: + if (positive_polarity) { + fxo->polarity_state = POLARITY_POSITIVE; + } else if (time_after(wc->framecount, fxo->poldebounce_timer)) { + dahdi_qevent_lock(get_dahdi_chan(wc, mod), + DAHDI_EVENT_POLARITY); + if (debug & DEBUG_CARD) { + dev_info(&wc->vb.pdev->dev, + "%s: Polarity POSITIVE -> NEGATIVE\n", + get_dahdi_chan(wc, mod)->name); + } + fxo->polarity_state = POLARITY_NEGATIVE; + } + break; + case POLARITY_NEGATIVE: + if (positive_polarity) { + fxo->polarity_state = POLARITY_DEBOUNCE_POSITIVE; + fxo->poldebounce_timer = wc->framecount + + POLARITY_DEBOUNCE; + } + break; + }; +} + +static void wctdm_voicedaa_check_hook(struct wctdm *wc, struct wctdm_module *const mod) { signed char b; @@ -2116,41 +2193,14 @@ wctdm_voicedaa_check_hook(struct wctdm *wc, struct wctdm_module *const mod) } if (abs_voltage < battthresh) { - fxo->lastpol = fxo->polarity; - fxo->polaritydebounce = 0; - + wctdm_fxo_stop_debouncing_polarity(wc, mod); wctdm_check_battery_lost(wc, mod); } else { wctdm_check_battery_present(wc, mod); - - if (fxo->lastpol >= 0) { - if (fxo->line_voltage_status < 0) { - fxo->lastpol = -1; - fxo->polaritydebounce = POLARITY_DEBOUNCE / MS_PER_CHECK_HOOK; - } - } - if (fxo->lastpol <= 0) { - if (fxo->line_voltage_status > 0) { - fxo->lastpol = 1; - fxo->polaritydebounce = POLARITY_DEBOUNCE / MS_PER_CHECK_HOOK; - } - } + wctdm_fxo_check_polarity(wc, mod, + (fxo->line_voltage_status > 0)); } - if (fxo->polaritydebounce) { - fxo->polaritydebounce--; - if (fxo->polaritydebounce < 1) { - if (fxo->lastpol != fxo->polarity) { - if (debug & DEBUG_CARD) - dev_info(&wc->vb.pdev->dev, "%lu Polarity reversed (%d -> %d)\n", jiffies, - fxo->polarity, - fxo->lastpol); - if (fxo->polarity) - dahdi_qevent_lock(get_dahdi_chan(wc, mod), DAHDI_EVENT_POLARITY); - fxo->polarity = fxo->lastpol; - } - } - } /* Look for neon mwi pulse */ if (neonmwi_monitor && !fxo->offhook) { /* Look for 4 consecutive voltage readings |