Skip to content

Commit

Permalink
samples: demo buttons fix atomic var access
Browse files Browse the repository at this point in the history
fix for coverity issue array vs singleton

Signed-off-by: Krzysztof Taborowski <[email protected]>
  • Loading branch information
ktaborowski authored and RobertGalatNordic committed Feb 15, 2024
1 parent b11146b commit f38c67b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions samples/template/src/sensor_monitoring/app_buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <zephyr/sys/atomic.h>

static uint8_t button_id_arr[] = { 0, 1, 2, 3 };
static atomic_t button_press_mask = ATOMIC_INIT(0);
ATOMIC_DEFINE(button_press_mask, sizeof(button_id_arr));
static uint32_t button_notify_mask;
static uint32_t button_press_time_in_sec_id_arr[APP_BUTTONS_MAX];
static atomic_t button_event_pending_processing = ATOMIC_INIT(false);
Expand All @@ -19,8 +19,8 @@ void app_btn_event_handler(uint32_t btn_id)
return;
}

if (!atomic_test_bit(&button_press_mask, button_id_arr[btn_id])) {
atomic_set_bit(&button_press_mask, button_id_arr[btn_id]);
if (!atomic_test_bit(button_press_mask, button_id_arr[btn_id])) {
atomic_set_bit(button_press_mask, button_id_arr[btn_id]);
}

atomic_set(&button_event_pending_processing, true);
Expand Down Expand Up @@ -61,14 +61,14 @@ bool app_btn_notify_mask_bit_is_set(uint8_t btn_id)
void app_btn_press_mask_bit_clear(uint8_t btn_id)
{
if (btn_id < APP_BUTTONS_MAX) {
atomic_clear_bit(&button_press_mask, button_id_arr[btn_id]);
atomic_clear_bit(button_press_mask, button_id_arr[btn_id]);
}
}

bool app_btn_press_mask_bit_is_set(uint8_t btn_id)
{
if (btn_id < APP_BUTTONS_MAX) {
return atomic_test_bit(&button_press_mask, button_id_arr[btn_id]);
return atomic_test_bit(button_press_mask, button_id_arr[btn_id]);
}
return false;
}
Expand Down

0 comments on commit f38c67b

Please sign in to comment.