diff --git a/epicardium/modules/bme680.c b/epicardium/modules/bme680.c index caadf68b9fa5ba9f2a0d5395db610a56c1237410..8cda3a6e28d52a3dfa92aa33796ae91cb77f25d3 100644 --- a/epicardium/modules/bme680.c +++ b/epicardium/modules/bme680.c @@ -43,9 +43,7 @@ int epic_bme680_init() return 0; } - if (hwlock_acquire_timeout(HWLOCK_I2C, portMAX_DELAY) < 0) { - return -EBUSY; - } + hwlock_acquire(HWLOCK_I2C); bme.dev_id = BME680_I2C_ADDR_PRIMARY; bme.intf = BME680_I2C_INTF; @@ -110,9 +108,7 @@ int epic_bme680_deinit() return 0; } - if (hwlock_acquire_timeout(HWLOCK_I2C, portMAX_DELAY) < 0) { - return -EBUSY; - } + hwlock_acquire(HWLOCK_I2C); int8_t result = bme680_soft_reset(&bme); if (result != BME680_OK) { @@ -133,9 +129,7 @@ int epic_bme680_read_sensors(struct bme680_sensor_data *data) return -EINVAL; } - if (hwlock_acquire_timeout(HWLOCK_I2C, portMAX_DELAY) < 0) { - return -EBUSY; - } + hwlock_acquire(HWLOCK_I2C); uint16_t profile_dur = 0; bme680_get_profile_dur(&profile_dur, &bme); @@ -152,9 +146,7 @@ int epic_bme680_read_sensors(struct bme680_sensor_data *data) */ hwlock_release(HWLOCK_I2C); vTaskDelay(pdMS_TO_TICKS(profile_dur)); - if (hwlock_acquire_timeout(HWLOCK_I2C, portMAX_DELAY) < 0) { - return -EBUSY; - } + hwlock_acquire(HWLOCK_I2C); struct bme680_field_data raw_data; result = bme680_get_sensor_data(&raw_data, &bme); diff --git a/epicardium/modules/gpio.c b/epicardium/modules/gpio.c index 872aaee7a1d31b9f3c341ea2c0b67e3323b8a4ce..72ce3ba6a83f3b492e63f2837f3aa3369e004e24 100644 --- a/epicardium/modules/gpio.c +++ b/epicardium/modules/gpio.c @@ -137,18 +137,15 @@ int epic_gpio_read_pin(uint8_t pin) } else if (cfg->func == GPIO_FUNC_IN) { return GPIO_InGet(cfg) != 0; } else if (cfg->func == GPIO_FUNC_ALT1) { - int rc = hwlock_acquire_timeout(HWLOCK_ADC, portMAX_DELAY); - if (!rc) { - ADC_StartConvert(s_adc_channels[pin], 0, 0); - uint16_t value; - int rc = ADC_GetData(&value); - hwlock_release(HWLOCK_ADC); - if (rc < 0) { - return -EIO; - } - return (int)value; + hwlock_acquire(HWLOCK_ADC); + ADC_StartConvert(s_adc_channels[pin], 0, 0); + uint16_t value; + int rc = ADC_GetData(&value); + hwlock_release(HWLOCK_ADC); + if (rc < 0) { + return -EIO; } - return rc; + return (int)value; } else { return -EINVAL; } diff --git a/epicardium/modules/hw-lock.c b/epicardium/modules/hw-lock.c index 47929fe06cf80c263168be59de1265aa5c87daec..529963e352edae97d8b377f5e3c7eb57ef4a47f7 100644 --- a/epicardium/modules/hw-lock.c +++ b/epicardium/modules/hw-lock.c @@ -37,40 +37,6 @@ int hwlock_acquire_nonblock(enum hwlock_periph p) } } -int hwlock_acquire_timeout(enum hwlock_periph p, TickType_t wait) -{ - assert(p < _HWLOCK_MAX); - - /* - * Check for code still defining a timeout. It will be ignored in the - * new implementation but a warning is emitted so someone hopefully - * eventually fixes the offending code ... - * - * At some point, the signature of this function should be changed. - * Alternatively it could be split into two, similar to the mutex API. - */ - if (wait != 0 && wait != portMAX_DELAY) { - LOG_WARN( - "hwlock", - "Attempting to lock %d with a timeout (from %p).", - p, - __builtin_return_address(0) - ); - } - - /* Non-blocking lock attempt */ - if (wait == 0) { - if (mutex_trylock(&hwlock_mutex[p]) == true) { - return 0; - } else { - return -EBUSY; - } - } - - mutex_lock(&hwlock_mutex[p]); - return 0; -} - void hwlock_release(enum hwlock_periph p) { assert(p < _HWLOCK_MAX); diff --git a/epicardium/modules/light_sensor.c b/epicardium/modules/light_sensor.c index a0f997ac1d88e1b1e60822ea1309f06879b3ee65..ea8d74c36c92e381dd8239a2bd9b02617fd92b6a 100644 --- a/epicardium/modules/light_sensor.c +++ b/epicardium/modules/light_sensor.c @@ -29,9 +29,7 @@ static int light_sensor_init() uint16_t epic_light_sensor_read() { - if (hwlock_acquire_timeout(HWLOCK_ADC, portMAX_DELAY) != 0) { - return 0; - } + hwlock_acquire(HWLOCK_ADC); ADC_StartConvert(ADC_CH_7, 0, 0); ADC_GetData(&last_value); @@ -42,7 +40,7 @@ uint16_t epic_light_sensor_read() static void readAdcCallback() { - if (hwlock_acquire_timeout(HWLOCK_ADC, 0) != 0) { + if (hwlock_acquire_nonblock(HWLOCK_ADC) != 0) { /* Can't do much about this here ... Retry next time */ return; } @@ -57,9 +55,7 @@ int epic_light_sensor_run() { int ret = 0; - if (hwlock_acquire_timeout(HWLOCK_ADC, portMAX_DELAY) != 0) { - return -EBUSY; - } + hwlock_acquire(HWLOCK_ADC); light_sensor_init(); diff --git a/epicardium/modules/modules.h b/epicardium/modules/modules.h index 0444b688f33cb879e3cca9f59cb1eb365999eb17..67557ad4f226aa6ad9a116aa0b940b09889ed2a2 100644 --- a/epicardium/modules/modules.h +++ b/epicardium/modules/modules.h @@ -97,7 +97,6 @@ enum hwlock_periph { _HWLOCK_MAX, }; -int hwlock_acquire_timeout(enum hwlock_periph p, TickType_t wait); void hwlock_acquire(enum hwlock_periph p); int hwlock_acquire_nonblock(enum hwlock_periph p); void hwlock_release(enum hwlock_periph p); diff --git a/epicardium/modules/pmic.c b/epicardium/modules/pmic.c index f9deaff7c4d4ad142b362d90dfe1f1be2bbc319f..1c996b2313fd3c37e864b7eb896ebf4adb9c9b07 100644 --- a/epicardium/modules/pmic.c +++ b/epicardium/modules/pmic.c @@ -18,8 +18,6 @@ #include <stdio.h> #include <string.h> -#define LOCK_WAIT portMAX_DELAY - /* Task ID for the pmic handler */ static TaskHandle_t pmic_task_id = NULL; @@ -46,23 +44,14 @@ void pmic_interrupt_callback(void *_) int pmic_read_amux(enum pmic_amux_signal sig, float *result) { - int ret = 0; - int i2c_ret = 0; + int ret = 0; if (sig > _PMIC_AMUX_MAX) { return -EINVAL; } - int adc_ret = hwlock_acquire_timeout(HWLOCK_ADC, LOCK_WAIT); - if (adc_ret < 0) { - ret = adc_ret; - goto done; - } - i2c_ret = hwlock_acquire_timeout(HWLOCK_I2C, LOCK_WAIT); - if (i2c_ret < 0) { - ret = i2c_ret; - goto done; - } + hwlock_acquire(HWLOCK_ADC); + hwlock_acquire(HWLOCK_I2C); /* Select the correct channel for this measurement. */ MAX77650_setMUX_SEL(sig); @@ -75,11 +64,7 @@ int pmic_read_amux(enum pmic_amux_signal sig, float *result) hwlock_release(HWLOCK_I2C); vTaskDelay(pdMS_TO_TICKS(5)); - i2c_ret = hwlock_acquire_timeout(HWLOCK_I2C, LOCK_WAIT); - if (i2c_ret < 0) { - ret = i2c_ret; - goto done; - } + hwlock_acquire(HWLOCK_I2C); uint16_t adc_data; ADC_StartConvert(ADC_CH_0, 0, 0); @@ -120,14 +105,8 @@ int pmic_read_amux(enum pmic_amux_signal sig, float *result) ret = -EINVAL; } -done: - if (i2c_ret == 0) { - hwlock_release(HWLOCK_I2C); - } - - if (adc_ret == 0) { - hwlock_release(HWLOCK_ADC); - } + hwlock_release(HWLOCK_I2C); + hwlock_release(HWLOCK_ADC); return ret; } @@ -138,10 +117,7 @@ done: */ static uint8_t pmic_poll_interrupts(void) { - while (hwlock_acquire_timeout(HWLOCK_I2C, LOCK_WAIT) < 0) { - LOG_WARN("pmic", "Failed to acquire I2C. Retrying ..."); - vTaskDelay(pdMS_TO_TICKS(100)); - } + hwlock_acquire(HWLOCK_I2C); uint8_t int_flag = MAX77650_getINT_GLBL(); hwlock_release(HWLOCK_I2C);