summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Adolfsson <sadolfsson@google.com>2018-05-06 21:57:02 +0200
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-06-19 20:02:08 +0000
commit528d6adda9997b45af62f598d298bf674357c066 (patch)
treecbbff7d9371d638b1a98d865aa49a03a4e16a485
parent8a9203dd06d8f6f20db823c9038f506dc29cebce (diff)
downloadchrome-ec-528d6adda9997b45af62f598d298bf674357c066.tar.gz
npcx: CEC: Improve pulse-width measurements
Take into account the time from the interrupt is triggered until the timer is set when recharging the timer. Signed-off-by: Stefan Adolfsson <sadolfsson@chromium.org> BUG=b:76467407 BRANCH=none TEST=Using temprorary debug-prints. CQ-DEPEND=CL:1030227 Reviewed-on: https://chromium-review.googlesource.com/1030228 Reviewed-by: Randall Spangler <rspangler@chromium.org> Change-Id: Ia36bd73ff5efcff719db7b7915212f30a8e555f3 Reviewed-on: https://chromium-review.googlesource.com/1055827 Tested-by: Stefan Adolfsson <sadolfsson@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Stefan Adolfsson <sadolfsson@chromium.org>
-rw-r--r--chip/npcx/cec.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/chip/npcx/cec.c b/chip/npcx/cec.c
index 231c4f367e..9b94b281d2 100644
--- a/chip/npcx/cec.c
+++ b/chip/npcx/cec.c
@@ -229,6 +229,12 @@ static struct cec_rx_cb cec_rx_cb;
/* Parameters and buffer for initiator (sender) state */
static struct cec_tx cec_tx;
+/*
+ * Time between interrupt triggered and the next timer was
+ * set when measuring pulse width
+ */
+static int cap_delay;
+
/* Value charged into the capture timer on last capture start */
static int cap_charge;
@@ -273,7 +279,13 @@ static void tmr_cap_start(enum cap_edge edge, int timeout)
* the edge change.
*/
if (timeout > 0) {
- cap_charge = timeout;
+ /*
+ * Store the time it takes from the interrupts starts to when we
+ * actually get here. This part of the pulse-width needs to be
+ * taken into account
+ */
+ cap_delay = (0xffff - NPCX_TCNT1(mdl));
+ cap_charge = timeout - cap_delay;
NPCX_TCNT1(mdl) = cap_charge;
SET_BIT(NPCX_TIEN(mdl), NPCX_TIEN_TCIEN);
} else {
@@ -301,7 +313,7 @@ static int tmr_cap_get(void)
{
int mdl = NPCX_MFT_MODULE_1;
- return (cap_charge - NPCX_TCRA(mdl));
+ return (cap_charge + cap_delay - NPCX_TCRA(mdl));
}
static void tmr_oneshot_start(int timeout)
@@ -447,6 +459,7 @@ void enter_state(enum cec_state new_state)
memset(&cec_tx, 0, sizeof(struct cec_tx));
memset(&cec_rx_cb, 0, sizeof(struct cec_rx_cb));
cap_charge = 0;
+ cap_delay = 0;
cec_events = 0;
break;
case CEC_STATE_IDLE: