Skip to content
Snippets Groups Projects
Commit 585144d2 authored by swym's avatar swym
Browse files

Merge branch 'rahix/fix-start-lock' into 'master'

Relax lock requirements to prevent busy lock

See merge request card10/firmware!241
parents c8dbb334 e2e5a259
No related branches found
No related tags found
No related merge requests found
......@@ -412,6 +412,11 @@ void vBhi160Task(void *pvParameters)
bhi160_task_id = xTaskGetCurrentTaskHandle();
bhi160_mutex = xSemaphoreCreateMutexStatic(&bhi160_mutex_data);
/*
* Wait a little before initializing BHI160.
*/
vTaskDelay(pdMS_TO_TICKS(500));
int lockret = hwlock_acquire(HWLOCK_I2C, pdMS_TO_TICKS(100));
if (lockret < 0) {
LOG_CRIT("bhi160", "Failed to acquire I2C lock!");
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment