summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Adolfsson <sadolfsson@google.com>2018-05-06 21:57:02 +0200
committerchrome-bot <chrome-bot@chromium.org>2018-05-11 09:30:34 -0700
commit394ede0e6e011498ba78b5f9a98c3d6fbe0d7376 (patch)
treee7ffafb0e07022ba4cd95359e14f3f9d86392402
parent38d90756cbb979937c3fc06b362dc048d853ca98 (diff)
downloadchrome-ec-394ede0e6e011498ba78b5f9a98c3d6fbe0d7376.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 Change-Id: Ia36bd73ff5efcff719db7b7915212f30a8e555f3 Reviewed-on: https://chromium-review.googlesource.com/1030228 Commit-Ready: Stefan Adolfsson <sadolfsson@chromium.org> Tested-by: Stefan Adolfsson <sadolfsson@chromium.org> Reviewed-by: Randall Spangler <rspangler@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: