c89: move variable declaration out from the for loop

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko 2023-08-08 11:18:19 +03:00 committed by Tiago Medicci Serrano
parent aa3eeaa62a
commit 1651bb476c
3 changed files with 152 additions and 154 deletions

View File

@ -281,13 +281,15 @@ static void slip_transmit(FAR struct slip_driver_s *self)
if (self->txlen > 0) if (self->txlen > 0)
{ {
int i;
/* Transmission of previous packet is still pending. This might happen /* Transmission of previous packet is still pending. This might happen
* in the 'slip_receive' -> 'slip_reply' -> 'slip_transmit' case. Try * in the 'slip_receive' -> 'slip_reply' -> 'slip_transmit' case. Try
* to forward pending packet into UART's transmit buffer. Timeout on * to forward pending packet into UART's transmit buffer. Timeout on
* packet if not forwarded within a second. * packet if not forwarded within a second.
*/ */
for (int i = 0; (i < 10) && (self->txsent != self->txlen); ) for (i = 0; (i < 10) && (self->txsent != self->txlen); )
{ {
ssz = file_write(&self->tty, ssz = file_write(&self->tty,
&self->txbuf[self->txsent], &self->txbuf[self->txsent],

View File

@ -53,35 +53,35 @@
/* Sub-sensor definitions */ /* Sub-sensor definitions */
#ifdef CONFIG_BME680_DISABLE_PRESS_MEAS #ifdef CONFIG_BME680_DISABLE_PRESS_MEAS
#define BME680_TEMP_IDX (0) # define BME680_TEMP_IDX (0)
#else #else
#define BME680_TEMP_IDX (-1) # define BME680_TEMP_IDX (-1)
#endif #endif
#define BME680_TEMP_IDX_OFF BME680_TEMP_IDX #define BME680_TEMP_IDX_OFF BME680_TEMP_IDX
#ifndef CONFIG_BME680_DISABLE_PRESS_MEAS #ifndef CONFIG_BME680_DISABLE_PRESS_MEAS
# define BME680_PRESS_IDX (BME680_TEMP_IDX_OFF + (1)) # define BME680_PRESS_IDX (BME680_TEMP_IDX_OFF + (1))
# define BME680_PRESS_IDX_OFF BME680_PRESS_IDX # define BME680_PRESS_IDX_OFF BME680_PRESS_IDX
#else #else
# define BME680_PRESS_IDX (-1) # define BME680_PRESS_IDX (-1)
# define BME680_PRESS_IDX_OFF BME680_TEMP_IDX_OFF # define BME680_PRESS_IDX_OFF BME680_TEMP_IDX_OFF
#endif #endif
#ifndef CONFIG_BME680_DISABLE_HUM_MEAS #ifndef CONFIG_BME680_DISABLE_HUM_MEAS
# define BME680_HUM_IDX (BME680_PRESS_IDX_OFF + (1)) # define BME680_HUM_IDX (BME680_PRESS_IDX_OFF + (1))
# define BME680_HUM_IDX_OFF BME680_HUM_IDX # define BME680_HUM_IDX_OFF BME680_HUM_IDX
#else #else
# define BME680_HUM_IDX (-1) # define BME680_HUM_IDX (-1)
# define BME680_HUM_IDX_OFF BME680_PRESS_IDX_OFF # define BME680_HUM_IDX_OFF BME680_PRESS_IDX_OFF
#endif #endif
#ifndef CONFIG_BME680_DISABLE_GAS_MEAS #ifndef CONFIG_BME680_DISABLE_GAS_MEAS
# define BME680_GAS_IDX (BME680_HUM_IDX_OFF + (1)) # define BME680_GAS_IDX (BME680_HUM_IDX_OFF + (1))
# define BME680_GAS_IDX_OFF BME680_GAS_IDX # define BME680_GAS_IDX_OFF BME680_GAS_IDX
#else #else
# define BME680_GAS_IDX (-1) # define BME680_GAS_IDX (-1)
# define BME680_GAS_IDX_OFF BME680_HUM_IDX_OFF # define BME680_GAS_IDX_OFF BME680_HUM_IDX_OFF
#endif #endif
#define BME680_SENSORS_COUNT (BME680_GAS_IDX_OFF + (1)) #define BME680_SENSORS_COUNT (BME680_GAS_IDX_OFF + (1))
@ -235,34 +235,36 @@
/* Possible gas range values */ /* Possible gas range values */
const uint32_t const_array1_int[16] = const uint32_t const_array1_int[16] =
{(2147483647), (2147483647), (2147483647), (2147483647), {
(2147483647), (2126008810), (2147483647), (2130303777), 2147483647, 2147483647, 2147483647, 2147483647,
(2147483647), (2147483647), (2143188679), (2136746228), 2147483647, 2126008810, 2147483647, 2130303777,
(2147483647), (2126008810), (2147483647), (2147483647) 2147483647, 2147483647, 2143188679, 2136746228,
}; 2147483647, 2126008810, 2147483647, 2147483647
};
const uint32_t const_array2_int[16] = const uint32_t const_array2_int[16] =
{(4096000000), (2048000000), (1024000000), (512000000), {
(255744255), (127110228), (64000000), (32258064), (16016016), 4096000000, 2048000000, 1024000000, 512000000,
(8000000), (4000000), (2000000), (1000000), (500000), 255744255, 127110228, 64000000, 32258064, 16016016,
(250000), (125000) 8000000, 4000000, 2000000, 1000000, 500000,
}; 250000, 125000
};
const float const_array1[16] = const float const_array1[16] =
{1.0, 1.0, 1.0, 1.0, 1.0, 0.99, 1.0, {
0.992, 1.0, 1.0, 0.998, 0.995, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.99, 1.0, 0.992, 1.0, 1.0,
0.99, 1.0, 1.0 0.998, 0.995, 1.0, 0.99, 1.0, 1.0
}; };
const float const_array2[16] = const float const_array2[16] =
{8000000.0, 4000000.0, 2000000.0, 1000000.0, {
499500.4995, 248262.1648, 125000.0, 63004.03226, 8000000.0, 4000000.0, 2000000.0, 1000000.0, 499500.4995,
31281.28128, 15625.0, 7812.5, 3906.25, 1953.125, 248262.1648, 125000.0, 63004.03226, 31281.28128, 15625.0,
976.5625, 488.28125, 244.140625 7812.5, 3906.25, 1953.125, 976.5625, 488.28125, 244.140625
}; };
#define CHECK_OS_BOUNDS(type) \ #define CHECK_OS_BOUNDS(type) \
(type >= BME680_OS_SKIPPED && type <= BME680_OS_16X) ((type) >= BME680_OS_SKIPPED && (type) <= BME680_OS_16X)
/**************************************************************************** /****************************************************************************
* Private Type Definitions * Private Type Definitions
@ -396,36 +398,34 @@ static int bme680_control(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/ ****************************************************************************/
static const push_data_func deliver_data[BME680_SENSORS_COUNT] = static const push_data_func deliver_data[BME680_SENSORS_COUNT] =
{ {
#ifndef CONFIG_BME680_DISABLE_PRESS_MEAS #ifndef CONFIG_BME680_DISABLE_PRESS_MEAS
bme680_push_press_data bme680_push_press_data
#else #else
bme680_push_temp_data bme680_push_temp_data
#endif #endif
#ifndef CONFIG_BME680_DISABLE_HUM_MEAS #ifndef CONFIG_BME680_DISABLE_HUM_MEAS
, , bme680_push_hum_data
bme680_push_hum_data
#endif #endif
#ifndef CONFIG_BME680_DISABLE_GAS_MEAS #ifndef CONFIG_BME680_DISABLE_GAS_MEAS
, , bme680_push_gas_data
bme680_push_gas_data
#endif #endif
}; };
static const struct sensor_ops_s g_sensor_ops = static const struct sensor_ops_s g_sensor_ops =
{ {
NULL, /* open */ NULL, /* open */
NULL, /* close */ NULL, /* close */
bme680_activate, /* activate */ bme680_activate, /* activate */
NULL, /* set_interval */ NULL, /* set_interval */
NULL, /* batch */ NULL, /* batch */
NULL, /* fetch */ NULL, /* fetch */
NULL, /* selftest */ NULL, /* selftest */
NULL, /* set_calibvalue */ NULL, /* set_calibvalue */
bme680_calibrate, /* calibrate */ bme680_calibrate, /* calibrate */
bme680_control /* control */ bme680_control /* control */
}; };
/**************************************************************************** /****************************************************************************
@ -814,8 +814,7 @@ static int bme680_push_temp_data(FAR struct bme680_dev_s *priv,
temp_data.timestamp = data->timestamp; temp_data.timestamp = data->timestamp;
temp_data.temperature = data->temperature; temp_data.temperature = data->temperature;
ret = lower.push_event(lower.priv, &temp_data, ret = lower.push_event(lower.priv, &temp_data, sizeof(struct sensor_temp));
sizeof(struct sensor_temp));
if (ret < 0) if (ret < 0)
{ {
@ -839,8 +838,7 @@ static int bme680_push_hum_data(FAR struct bme680_dev_s *priv,
hum_data.timestamp = data->timestamp; hum_data.timestamp = data->timestamp;
hum_data.humidity = data->humidity; hum_data.humidity = data->humidity;
ret = lower.push_event(lower.priv, &hum_data, ret = lower.push_event(lower.priv, &hum_data, sizeof(struct sensor_humi));
sizeof(struct sensor_humi));
if (ret < 0) if (ret < 0)
{ {
@ -864,8 +862,7 @@ static int bme680_push_gas_data(FAR struct bme680_dev_s *priv,
gas_data.timestamp = data->timestamp; gas_data.timestamp = data->timestamp;
gas_data.gas_resistance = data->gas_resistance / 1000.f; gas_data.gas_resistance = data->gas_resistance / 1000.f;
ret = lower.push_event(lower.priv, &gas_data, ret = lower.push_event(lower.priv, &gas_data, sizeof(struct sensor_gas));
sizeof(struct sensor_gas));
if (ret < 0) if (ret < 0)
{ {
@ -884,7 +881,7 @@ static int bme680_push_gas_data(FAR struct bme680_dev_s *priv,
* *
****************************************************************************/ ****************************************************************************/
static uint8_t calc_heater_res(const struct bme680_dev_s *priv) static uint8_t calc_heater_res(FAR const struct bme680_dev_s *priv)
{ {
uint8_t res_heat; uint8_t res_heat;
int32_t var1; int32_t var1;
@ -902,7 +899,9 @@ static uint8_t calc_heater_res(const struct bme680_dev_s *priv)
temp = dev.config.target_temp; temp = dev.config.target_temp;
if (temp > 400) if (temp > 400)
temp = 400; {
temp = 400;
}
amb_temp = dev.config.amb_temp; amb_temp = dev.config.amb_temp;
@ -926,7 +925,7 @@ static uint8_t calc_heater_res(const struct bme680_dev_s *priv)
* *
****************************************************************************/ ****************************************************************************/
static uint8_t calc_heater_dur(const struct bme680_dev_s *priv) static uint8_t calc_heater_dur(FAR const struct bme680_dev_s *priv)
{ {
uint16_t heat_dur = priv->dev.config.heater_duration; uint16_t heat_dur = priv->dev.config.heater_duration;
uint8_t gas_wait_val; uint8_t gas_wait_val;
@ -946,7 +945,7 @@ static uint8_t calc_heater_dur(const struct bme680_dev_s *priv)
while (heat_dur > 0x3f) while (heat_dur > 0x3f)
{ {
heat_dur = heat_dur / 4; heat_dur = heat_dur / 4;
factor += 1; factor++;
} }
gas_wait_val = (factor << 6) | heat_dur; gas_wait_val = (factor << 6) | heat_dur;
@ -1073,9 +1072,9 @@ err_out:
static float bme680_comp_temp(FAR struct bme680_dev_s *priv, static float bme680_comp_temp(FAR struct bme680_dev_s *priv,
uint32_t adc_temp) uint32_t adc_temp)
{ {
float var1 = 0; float var1 = 0.0f;
float var2 = 0; float var2 = 0.0f;
float calc_temp = 0; float calc_temp = 0.0f;
struct bme680_sensor_s dev = priv->dev; struct bme680_sensor_s dev = priv->dev;
@ -1090,7 +1089,7 @@ static float bme680_comp_temp(FAR struct bme680_dev_s *priv,
/* Compensated temperature data */ /* Compensated temperature data */
calc_temp = ((priv->dev.calib.t_fine) / 5120.0f); calc_temp = (priv->dev.calib.t_fine) / 5120.0f;
return calc_temp; return calc_temp;
} }
@ -1099,10 +1098,10 @@ static float bme680_comp_temp(FAR struct bme680_dev_s *priv,
static float bme680_comp_press(FAR struct bme680_dev_s *priv, static float bme680_comp_press(FAR struct bme680_dev_s *priv,
uint32_t adc_press) uint32_t adc_press)
{ {
float var1 = 0; float var1 = 0.0f;
float var2 = 0; float var2 = 0.0f;
float var3 = 0; float var3 = 0.0f;
float calc_pres = 0; float calc_pres = 0.0f;
struct bme680_sensor_s dev = priv->dev; struct bme680_sensor_s dev = priv->dev;
@ -1136,11 +1135,11 @@ static float bme680_comp_press(FAR struct bme680_dev_s *priv,
static float bme680_comp_hum(FAR struct bme680_dev_s *priv, static float bme680_comp_hum(FAR struct bme680_dev_s *priv,
uint16_t adc_hum) uint16_t adc_hum)
{ {
float calc_hum = 0; float calc_hum = 0.0f;
float var1 = 0; float var1 = 0.0f;
float var2 = 0; float var2 = 0.0f;
float var3 = 0; float var3 = 0.0f;
float var4 = 0; float var4 = 0.0f;
float temp_comp; float temp_comp;
struct bme680_sensor_s dev = priv->dev; struct bme680_sensor_s dev = priv->dev;
@ -1163,9 +1162,13 @@ static float bme680_comp_hum(FAR struct bme680_dev_s *priv,
calc_hum = var2 + ((var3 + (var4 * temp_comp)) * var2 * var2); calc_hum = var2 + ((var3 + (var4 * temp_comp)) * var2 * var2);
if (calc_hum > 100.0f) if (calc_hum > 100.0f)
calc_hum = 100.0f; {
calc_hum = 100.0f;
}
else if (calc_hum < 0.0f) else if (calc_hum < 0.0f)
calc_hum = 0.0f; {
calc_hum = 0.0f;
}
return calc_hum; return calc_hum;
} }
@ -1176,7 +1179,7 @@ static float bme680_calc_gas_res(FAR struct bme680_dev_s *priv,
uint16_t adc_gas_res, uint8_t gas_range) uint16_t adc_gas_res, uint8_t gas_range)
{ {
float calc_gas_res; float calc_gas_res;
float var1 = 0; float var1 = 0.0f;
struct bme680_sensor_s dev = priv->dev; struct bme680_sensor_s dev = priv->dev;
@ -1223,8 +1226,7 @@ static int bme680_read_measurements(FAR struct bme680_dev_s *priv,
uint8_t data_regs[BME680_DATA_LEN]; uint8_t data_regs[BME680_DATA_LEN];
ret = bme680_getregs(priv, BME680_DATA_ADDR, ret = bme680_getregs(priv, BME680_DATA_ADDR, data_regs, BME680_DATA_LEN);
data_regs, BME680_DATA_LEN);
if (ret < 0) if (ret < 0)
{ {
@ -1309,9 +1311,9 @@ static uint16_t bme680_get_tphg_dur(FAR struct bme680_dev_s *priv)
uint32_t meas_cycles; uint32_t meas_cycles;
uint16_t duration; uint16_t duration;
uint8_t os_to_meas_cycles[6] = uint8_t os_to_meas_cycles[6] =
{ {
0, 1, 2, 4, 8, 16 0, 1, 2, 4, 8, 16
}; };
meas_cycles = os_to_meas_cycles[priv->dev.config.temp_os]; meas_cycles = os_to_meas_cycles[priv->dev.config.temp_os];
@ -1325,17 +1327,17 @@ static uint16_t bme680_get_tphg_dur(FAR struct bme680_dev_s *priv)
/* TPH measurement duration */ /* TPH measurement duration */
tph_dur = meas_cycles * (1963); tph_dur = meas_cycles * 1963;
tph_dur += (477 * 4); /* TPH switching duration */ tph_dur += 477 * 4; /* TPH switching duration */
#ifndef CONFIG_BME680_DISABLE_GAS_MEAS #ifndef CONFIG_BME680_DISABLE_GAS_MEAS
tph_dur += (477 * 5); /* Gas measurement duration */ tph_dur += 477 * 5; /* Gas measurement duration */
#endif #endif
tph_dur += (500); tph_dur += 500;
tph_dur /= (1000); /* Convert to ms */ tph_dur /= 1000; /* Convert to ms */
tph_dur += (1); /* Wake up duration of 1ms */ tph_dur += 1; /* Wake up duration of 1ms */
duration = (uint16_t)tph_dur; duration = (uint16_t)tph_dur;
@ -1349,10 +1351,11 @@ static uint16_t bme680_get_tphg_dur(FAR struct bme680_dev_s *priv)
} }
static int bme680_activate(FAR struct sensor_lowerhalf_s *lower, static int bme680_activate(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep, FAR struct file *filep, bool enable)
bool enable)
{ {
int offset; int offset;
FAR struct bme680_sensor_s *dev;
FAR struct bme680_dev_s *priv;
/* Get offset inside array of lowerhalfs */ /* Get offset inside array of lowerhalfs */
@ -1360,38 +1363,35 @@ static int bme680_activate(FAR struct sensor_lowerhalf_s *lower,
{ {
case SENSOR_TYPE_AMBIENT_TEMPERATURE: case SENSOR_TYPE_AMBIENT_TEMPERATURE:
offset = BME680_TEMP_IDX; offset = BME680_TEMP_IDX;
break; break;
case SENSOR_TYPE_BAROMETER: case SENSOR_TYPE_BAROMETER:
offset = BME680_PRESS_IDX; offset = BME680_PRESS_IDX;
break; break;
case SENSOR_TYPE_RELATIVE_HUMIDITY: case SENSOR_TYPE_RELATIVE_HUMIDITY:
offset = BME680_HUM_IDX; offset = BME680_HUM_IDX;
break; break;
case SENSOR_TYPE_GAS: case SENSOR_TYPE_GAS:
offset = BME680_GAS_IDX; offset = BME680_GAS_IDX;
break; break;
default: default:
offset = 0; offset = 0;
break; break;
} }
FAR struct bme680_sensor_s *dev = dev = (FAR struct bme680_sensor_s *)
(FAR struct bme680_sensor_s *)
((uintptr_t)lower - offset * sizeof(*lower)); ((uintptr_t)lower - offset * sizeof(*lower));
FAR struct bme680_dev_s *priv = container_of(dev, priv = container_of(dev, FAR struct bme680_dev_s, dev);
FAR struct bme680_dev_s,
dev);
/* Wake the thread only once (the activate method will be called /* Wake the thread only once (the activate method will be called
* multiple times for the bme680 sub-sensors) * multiple times for the bme680 sub-sensors)
*/ */
if (priv->enabled == false && enable == true) if (!priv->enabled && enable)
{ {
dev->calibrated = false; dev->calibrated = false;
priv->enabled = enable; priv->enabled = enable;
@ -1409,10 +1409,13 @@ static int bme680_activate(FAR struct sensor_lowerhalf_s *lower,
} }
static int bme680_calibrate(FAR struct sensor_lowerhalf_s *lower, static int bme680_calibrate(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep, FAR struct file *filep, unsigned long arg)
unsigned long arg)
{ {
int offset; int offset;
FAR struct bme680_sensor_s *dev;
FAR struct bme680_dev_s *priv;
FAR struct bme680_config_s *calibval = (FAR struct bme680_config_s *)arg;
int ret;
/* Get offset inside array of lowerhalfs */ /* Get offset inside array of lowerhalfs */
@ -1420,36 +1423,29 @@ static int bme680_calibrate(FAR struct sensor_lowerhalf_s *lower,
{ {
case SENSOR_TYPE_AMBIENT_TEMPERATURE: case SENSOR_TYPE_AMBIENT_TEMPERATURE:
offset = BME680_TEMP_IDX; offset = BME680_TEMP_IDX;
break; break;
case SENSOR_TYPE_BAROMETER: case SENSOR_TYPE_BAROMETER:
offset = BME680_PRESS_IDX; offset = BME680_PRESS_IDX;
break; break;
case SENSOR_TYPE_RELATIVE_HUMIDITY: case SENSOR_TYPE_RELATIVE_HUMIDITY:
offset = BME680_HUM_IDX; offset = BME680_HUM_IDX;
break; break;
case SENSOR_TYPE_GAS: case SENSOR_TYPE_GAS:
offset = BME680_GAS_IDX; offset = BME680_GAS_IDX;
break; break;
default: default:
offset = 0; offset = 0;
break; break;
} }
FAR struct bme680_sensor_s *dev = dev = (FAR struct bme680_sensor_s *)
(FAR struct bme680_sensor_s *)
((uintptr_t)lower - offset * sizeof(*lower)); ((uintptr_t)lower - offset * sizeof(*lower));
FAR struct bme680_dev_s *priv = container_of(dev, priv = container_of(dev, FAR struct bme680_dev_s, dev);
FAR struct bme680_dev_s,
dev);
FAR struct bme680_config_s *calibval =
(FAR struct bme680_config_s *)arg;
int ret;
/* Sanity checks */ /* Sanity checks */
@ -1495,8 +1491,7 @@ static int bme680_calibrate(FAR struct sensor_lowerhalf_s *lower,
/* Update config in priv */ /* Update config in priv */
memcpy(&priv->dev.config, calibval, memcpy(&priv->dev.config, calibval, sizeof(struct bme680_config_s));
sizeof(struct bme680_config_s));
ret = bme680_write_config(priv); ret = bme680_write_config(priv);
@ -1559,7 +1554,9 @@ static int bme680_thread(int argc, char **argv)
while (true) while (true)
{ {
if (priv->enabled == false) int sensor;
if (!priv->enabled)
{ {
/* Wait for the sensor to be enabled */ /* Wait for the sensor to be enabled */
@ -1568,7 +1565,7 @@ static int bme680_thread(int argc, char **argv)
/* No measurements are done unless the sensor is calibrated */ /* No measurements are done unless the sensor is calibrated */
if (priv->dev.calibrated == false) if (!priv->dev.calibrated)
{ {
sninfo("The sensor is not calibrated!\n"); sninfo("The sensor is not calibrated!\n");
goto thread_sleep; goto thread_sleep;
@ -1593,7 +1590,7 @@ static int bme680_thread(int argc, char **argv)
data.timestamp = sensor_get_timestamp(); data.timestamp = sensor_get_timestamp();
for (int sensor = 0; sensor < BME680_SENSORS_COUNT; sensor++) for (sensor = 0; sensor < BME680_SENSORS_COUNT; sensor++)
{ {
deliver_data[sensor](priv, &data); deliver_data[sensor](priv, &data);
} }
@ -1629,6 +1626,7 @@ int bme680_register(int devno, FAR struct i2c_master_s *i2c)
FAR char *argv[2]; FAR char *argv[2];
char arg1[32]; char arg1[32];
int ret = OK; int ret = OK;
int i;
DEBUGASSERT(i2c != NULL); DEBUGASSERT(i2c != NULL);
@ -1675,8 +1673,7 @@ int bme680_register(int devno, FAR struct i2c_master_s *i2c)
ret = sensor_register(lower, devno); ret = sensor_register(lower, devno);
if (ret < 0) if (ret < 0)
{ {
snerr("ERROR: Failed to register barometer \ snerr("ERROR: Failed to register barometer driver (err = %d)\n",
driver (err = %d)\n",
ret); ret);
goto err_init; goto err_init;
} }
@ -1690,8 +1687,7 @@ int bme680_register(int devno, FAR struct i2c_master_s *i2c)
ret = sensor_register(lower, devno); ret = sensor_register(lower, devno);
if (ret < 0) if (ret < 0)
{ {
snerr("ERROR: Failed to register temperature \ snerr("ERROR: Failed to register temperature driver (err = %d)\n",
driver (err = %d)\n",
ret); ret);
goto err_init; goto err_init;
} }
@ -1707,8 +1703,7 @@ int bme680_register(int devno, FAR struct i2c_master_s *i2c)
ret = sensor_register(lower, devno); ret = sensor_register(lower, devno);
if (ret < 0) if (ret < 0)
{ {
snerr("ERROR: Failed to register humidity \ snerr("ERROR: Failed to register humidity driver (err = %d)\n",
driver (err = %d)\n",
ret); ret);
goto err_init; goto err_init;
} }
@ -1724,8 +1719,7 @@ int bme680_register(int devno, FAR struct i2c_master_s *i2c)
ret = sensor_register(lower, devno); ret = sensor_register(lower, devno);
if (ret < 0) if (ret < 0)
{ {
snerr("ERROR: Failed to register gas \ snerr("ERROR: Failed to register gas driver (err = %d)\n",
driver (err = %d)\n",
ret); ret);
goto err_init; goto err_init;
} }
@ -1749,7 +1743,7 @@ int bme680_register(int devno, FAR struct i2c_master_s *i2c)
return OK; return OK;
err_register: err_register:
for (int i = 0; i < BME680_SENSORS_COUNT; i++) for (i = 0; i < BME680_SENSORS_COUNT; i++)
{ {
sensor_unregister(&priv->dev.lower[i], devno); sensor_unregister(&priv->dev.lower[i], devno);
} }

View File

@ -306,20 +306,20 @@ struct ieee802154_privmac_s
****************************************************************************/ ****************************************************************************/
int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv, int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv,
FAR struct ieee802154_txdesc_s **txdesc); FAR struct ieee802154_txdesc_s **txdesc);
void mac802154_setupindirect(FAR struct ieee802154_privmac_s *priv, void mac802154_setupindirect(FAR struct ieee802154_privmac_s *priv,
FAR struct ieee802154_txdesc_s *txdesc); FAR struct ieee802154_txdesc_s *txdesc);
void mac802154_createdatareq(FAR struct ieee802154_privmac_s *priv, void mac802154_createdatareq(FAR struct ieee802154_privmac_s *priv,
FAR struct ieee802154_addr_s *coordaddr, FAR struct ieee802154_addr_s *coordaddr,
enum ieee802154_addrmode_e srcmode, enum ieee802154_addrmode_e srcmode,
FAR struct ieee802154_txdesc_s *txdesc); FAR struct ieee802154_txdesc_s *txdesc);
void mac802154_updatebeacon(FAR struct ieee802154_privmac_s *priv); void mac802154_updatebeacon(FAR struct ieee802154_privmac_s *priv);
void mac802154_notify(FAR struct ieee802154_privmac_s *priv, void mac802154_notify(FAR struct ieee802154_privmac_s *priv,
FAR struct ieee802154_primitive_s *primitive); FAR struct ieee802154_primitive_s *primitive);
/**************************************************************************** /****************************************************************************
* Helper Macros/Inline Functions * Helper Macros/Inline Functions
@ -349,7 +349,8 @@ void mac802154_notify(FAR struct ieee802154_privmac_s *priv,
#define mac802154_puteaddr(iob, eaddr) \ #define mac802154_puteaddr(iob, eaddr) \
do \ do \
{ \ { \
for (int index = IEEE802154_EADDRSIZE - 1; index >= 0; index--) \ int index; \
for (index = IEEE802154_EADDRSIZE - 1; index >= 0; index--) \
{ \ { \
iob->io_data[iob->io_len++] = eaddr[index]; \ iob->io_data[iob->io_len++] = eaddr[index]; \
} \ } \
@ -380,7 +381,8 @@ void mac802154_notify(FAR struct ieee802154_privmac_s *priv,
#define mac802154_takeeaddr(iob, eaddr) \ #define mac802154_takeeaddr(iob, eaddr) \
do \ do \
{ \ { \
for (int index = IEEE802154_EADDRSIZE - 1; index >= 0; index--) \ int index; \
for (index = IEEE802154_EADDRSIZE - 1; index >= 0; index--) \
{ \ { \
eaddr[index] = iob->io_data[iob->io_offset++]; \ eaddr[index] = iob->io_data[iob->io_offset++]; \
} \ } \
@ -542,7 +544,7 @@ mac802154_symtoticks(FAR struct ieee802154_privmac_s *priv, uint32_t symbols)
*/ */
priv->radio->getattr(priv->radio, IEEE802154_ATTR_PHY_SYMBOL_DURATION, priv->radio->getattr(priv->radio, IEEE802154_ATTR_PHY_SYMBOL_DURATION,
&attrval); &attrval);
/* After this step, ret represents microseconds */ /* After this step, ret represents microseconds */
@ -555,11 +557,11 @@ mac802154_symtoticks(FAR struct ieee802154_privmac_s *priv, uint32_t symbols)
if (ret % USEC_PER_TICK == 0) if (ret % USEC_PER_TICK == 0)
{ {
ret = ret / USEC_PER_TICK; ret /= USEC_PER_TICK;
} }
else else
{ {
ret = ret / USEC_PER_TICK; ret /= USEC_PER_TICK;
ret++; ret++;
} }
@ -645,7 +647,7 @@ mac802154_setchannel(FAR struct ieee802154_privmac_s *priv,
uint8_t channel) uint8_t channel)
{ {
priv->radio->setattr(priv->radio, IEEE802154_ATTR_PHY_CHAN, priv->radio->setattr(priv->radio, IEEE802154_ATTR_PHY_CHAN,
(FAR const union ieee802154_attr_u *)&channel); (FAR const union ieee802154_attr_u *)&channel);
} }
static inline void static inline void
@ -653,7 +655,7 @@ mac802154_setchpage(FAR struct ieee802154_privmac_s *priv,
uint8_t chpage) uint8_t chpage)
{ {
priv->radio->setattr(priv->radio, IEEE802154_ATTR_PHY_CURRENT_PAGE, priv->radio->setattr(priv->radio, IEEE802154_ATTR_PHY_CURRENT_PAGE,
(FAR const union ieee802154_attr_u *)&chpage); (FAR const union ieee802154_attr_u *)&chpage);
} }
static inline void static inline void
@ -662,7 +664,7 @@ mac802154_setpanid(FAR struct ieee802154_privmac_s *priv,
{ {
IEEE802154_PANIDCOPY(priv->addr.panid, panid); IEEE802154_PANIDCOPY(priv->addr.panid, panid);
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_PANID, priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_PANID,
(FAR const union ieee802154_attr_u *)panid); (FAR const union ieee802154_attr_u *)panid);
} }
static inline void static inline void
@ -671,7 +673,7 @@ mac802154_setsaddr(FAR struct ieee802154_privmac_s *priv,
{ {
IEEE802154_SADDRCOPY(priv->addr.saddr, saddr); IEEE802154_SADDRCOPY(priv->addr.saddr, saddr);
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_SADDR, priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_SADDR,
(FAR const union ieee802154_attr_u *)saddr); (FAR const union ieee802154_attr_u *)saddr);
} }
static inline void static inline void
@ -680,7 +682,7 @@ mac802154_setcoordsaddr(FAR struct ieee802154_privmac_s *priv,
{ {
IEEE802154_SADDRCOPY(priv->pandesc.coordaddr.saddr, saddr); IEEE802154_SADDRCOPY(priv->pandesc.coordaddr.saddr, saddr);
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_SADDR, priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_SADDR,
(FAR const union ieee802154_attr_u *)saddr); (FAR const union ieee802154_attr_u *)saddr);
} }
static inline void static inline void
@ -689,7 +691,7 @@ mac802154_setcoordeaddr(FAR struct ieee802154_privmac_s *priv,
{ {
IEEE802154_EADDRCOPY(priv->pandesc.coordaddr.eaddr, eaddr); IEEE802154_EADDRCOPY(priv->pandesc.coordaddr.eaddr, eaddr);
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_EADDR, priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_EADDR,
(FAR const union ieee802154_attr_u *)eaddr); (FAR const union ieee802154_attr_u *)eaddr);
} }
static inline void static inline void
@ -698,9 +700,9 @@ mac802154_setcoordaddr(FAR struct ieee802154_privmac_s *priv,
{ {
memcpy(&priv->pandesc.coordaddr, addr, sizeof(struct ieee802154_addr_s)); memcpy(&priv->pandesc.coordaddr, addr, sizeof(struct ieee802154_addr_s));
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_EADDR, priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_EADDR,
(FAR const union ieee802154_attr_u *)addr->eaddr); (FAR const union ieee802154_attr_u *)addr->eaddr);
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_SADDR, priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_SADDR,
(FAR const union ieee802154_attr_u *)addr->saddr); (FAR const union ieee802154_attr_u *)addr->saddr);
} }
static inline void static inline void
@ -717,7 +719,7 @@ mac802154_setrxonidle(FAR struct ieee802154_privmac_s *priv, bool rxonidle)
} }
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_RX_ON_WHEN_IDLE, priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_RX_ON_WHEN_IDLE,
(FAR const union ieee802154_attr_u *)&rxonidle); (FAR const union ieee802154_attr_u *)&rxonidle);
} }
static inline void static inline void
@ -725,7 +727,7 @@ mac802154_setdevmode(FAR struct ieee802154_privmac_s *priv, uint8_t mode)
{ {
priv->devmode = mode; priv->devmode = mode;
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_DEVMODE, priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_DEVMODE,
(FAR const union ieee802154_attr_u *)&mode); (FAR const union ieee802154_attr_u *)&mode);
} }
#endif /* __WIRELESS_IEEE802154__MAC802154_INTERNAL_H */ #endif /* __WIRELESS_IEEE802154__MAC802154_INTERNAL_H */