Skip to content

Commit e575eea

Browse files
Jeppe Odgaardhenrikbrixandersen
authored andcommitted
drivers: sensor: explorir_m: improve transceive
During calibration feature development the following loop was used for testing: ```shell CMD="sensor attr_set explorir_m co2 calibration 1234" while : ; do echo "$CMD" > /dev/ttyACM0; sleep .8; done ``` At some point calibration would fail and all following calibration commands would fail. Reset buffer and semaphore just before terminating the command to better mitigate disturbance from previous failed command. Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
1 parent f624486 commit e575eea

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

drivers/sensor/explorir_m/explorir_m.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,6 @@ static void explorir_m_uart_terminate(const struct device *uart_dev)
198198
uart_poll_out(uart_dev, EXPLORIR_M_END_CHAR);
199199
}
200200

201-
static int explorir_m_await_receive(struct explorir_m_data *data)
202-
{
203-
int rc = k_sem_take(&data->uart_rx_sem, K_MSEC(EXPLORIR_M_MAX_RESPONSE_DELAY));
204-
205-
/* Reset semaphore if sensor did not respond within maximum specified response time */
206-
if (rc == -EAGAIN) {
207-
k_sem_reset(&data->uart_rx_sem);
208-
}
209-
210-
return rc;
211-
}
212-
213201
static int explorir_m_uart_transceive(const struct device *dev, char type, struct sensor_value *val,
214202
enum explorir_m_uart_set_usage set)
215203
{
@@ -225,8 +213,6 @@ static int explorir_m_uart_transceive(const struct device *dev, char type, struc
225213

226214
k_mutex_lock(&data->uart_mutex, K_FOREVER);
227215

228-
explorir_m_buffer_reset(data);
229-
230216
uart_poll_out(cfg->uart_dev, type);
231217

232218
if (set == EXPLORIR_M_SET_VAL_ONE) {
@@ -246,9 +232,12 @@ static int explorir_m_uart_transceive(const struct device *dev, char type, struc
246232
uart_poll_out(cfg->uart_dev, buf[i]);
247233
}
248234

235+
explorir_m_buffer_reset(data);
236+
k_sem_reset(&data->uart_rx_sem);
237+
249238
explorir_m_uart_terminate(cfg->uart_dev);
250239

251-
rc = explorir_m_await_receive(data);
240+
rc = k_sem_take(&data->uart_rx_sem, K_MSEC(EXPLORIR_M_MAX_RESPONSE_DELAY));
252241
if (rc != 0) {
253242
LOG_WRN("%c did not receive a response: %d", type, rc);
254243
}

0 commit comments

Comments
 (0)