diff --git a/idf_component.yml b/idf_component.yml index 30f34ca..871056f 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -1,4 +1,4 @@ -version: "3.2.1" +version: "3.2.2" description: "Library for communication with RFID / NFC cards using MFRC522 module" url: "https://github.com/abobija/esp-idf-rc522" repository: "https://github.com/abobija/esp-idf-rc522.git" diff --git a/include/rc522_types.h b/include/rc522_types.h index 76874d5..cee9dcd 100644 --- a/include/rc522_types.h +++ b/include/rc522_types.h @@ -3,6 +3,7 @@ #include #include #include +#include "freertos/FreeRTOS.h" #include "rc522_driver.h" #include "rc522_picc.h" @@ -33,9 +34,10 @@ typedef struct rc522 *rc522_handle_t; typedef struct { rc522_driver_handle_t driver; - uint16_t poll_interval_ms; /*bits, RC522_TASK_STOPPED_BIT); while (!rc522->exit_requested) { + if (mutex_taken && rc522->config->task_mutex != NULL) { + if (xSemaphoreGive(rc522->config->task_mutex) == pdTRUE) { + mutex_taken = false; + } + else { + RC522_LOGW("failed to give mutex"); + } + } + if (rc522->state != RC522_STATE_POLLING) { // waiting for state change to polling rc522_delay_ms(100); @@ -224,6 +235,16 @@ void rc522_task(void *arg) rc522_delay_ms(task_delay_ms); + if (rc522->config->task_mutex != NULL) { + if (xSemaphoreTake(rc522->config->task_mutex, pdMS_TO_TICKS(mutex_take_timeout_ms)) == pdTRUE) { + mutex_taken = true; + } + else { + RC522_LOGW("failed to take mutex in %d ms", mutex_take_timeout_ms); + continue; + } + } + bool should_poll = (rc522_millis() - last_poll_ms) > rc522->config->poll_interval_ms; if (rc522->picc.state == RC522_PICC_STATE_IDLE || rc522->picc.state == RC522_PICC_STATE_HALT) {