From 81e1412a1ff733c803bd2551bfbe44eb16db51a2 Mon Sep 17 00:00:00 2001 From: Rahix <rahix@rahix.de> Date: Sat, 24 Aug 2019 09:18:05 +0200 Subject: [PATCH] fix(pmic): Relax lock requirements to prevent busy lock Signed-off-by: Rahix <rahix@rahix.de> --- epicardium/modules/pmic.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/epicardium/modules/pmic.c b/epicardium/modules/pmic.c index 89365ffb..4df12ea9 100644 --- a/epicardium/modules/pmic.c +++ b/epicardium/modules/pmic.c @@ -18,6 +18,8 @@ #include <stdio.h> #include <string.h> +#define LOCK_WAIT pdMS_TO_TICKS(1000) + /* Task ID for the pmic handler */ static TaskHandle_t pmic_task_id = NULL; @@ -51,12 +53,12 @@ int pmic_read_amux(enum pmic_amux_signal sig, float *result) return -EINVAL; } - int adc_ret = hwlock_acquire(HWLOCK_ADC, pdMS_TO_TICKS(100)); + int adc_ret = hwlock_acquire(HWLOCK_ADC, LOCK_WAIT); if (adc_ret < 0) { ret = adc_ret; goto done; } - i2c_ret = hwlock_acquire(HWLOCK_I2C, pdMS_TO_TICKS(100)); + i2c_ret = hwlock_acquire(HWLOCK_I2C, LOCK_WAIT); if (i2c_ret < 0) { ret = i2c_ret; goto done; @@ -71,10 +73,9 @@ int pmic_read_amux(enum pmic_amux_signal sig, float *result) * release the I2C mutex. */ hwlock_release(HWLOCK_I2C); - i2c_ret = 0; vTaskDelay(pdMS_TO_TICKS(5)); - i2c_ret = hwlock_acquire(HWLOCK_I2C, pdMS_TO_TICKS(100)); + i2c_ret = hwlock_acquire(HWLOCK_I2C, LOCK_WAIT); if (i2c_ret < 0) { ret = i2c_ret; goto done; @@ -138,7 +139,7 @@ done: static void pmic_poll_interrupts(TickType_t *button_start_tick, TickType_t duration) { - while (hwlock_acquire(HWLOCK_I2C, pdMS_TO_TICKS(500)) < 0) { + while (hwlock_acquire(HWLOCK_I2C, LOCK_WAIT) < 0) { LOG_WARN("pmic", "Failed to acquire I2C. Retrying ..."); xTaskNotify(pmic_task_id, PMIC_NOTIFY_IRQ, eSetBits); return; -- GitLab