Commit b4a75801 authored by Rahix's avatar Rahix

Merge 'Remove legacy HW lock interface'

See merge request !379
parents 77ee86e4 77a2d514
Pipeline #4554 passed with stages
in 2 minutes and 16 seconds
......@@ -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);
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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();
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment