diff options
Diffstat (limited to 'chip/npcx/cec.c')
-rw-r--r-- | chip/npcx/cec.c | 17 |
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: |