Browse Source

PN5180 back in task + slight tweaks

master
Torsten Stauder 4 years ago
parent
commit
dd4150c450
  1. 1
      platformio.ini
  2. 3
      src/AudioPlayer.cpp
  3. 7
      src/Cmd.cpp
  4. 9
      src/Led.cpp
  5. 8
      src/RfidMfrc522.cpp
  6. 55
      src/RfidPn5180.cpp
  7. 12
      src/System.cpp
  8. 1
      src/System.h
  9. 14
      src/Web.cpp
  10. 3
      src/main.cpp
  11. 2
      src/revision.h
  12. 2
      src/settings.h
  13. 2
      src/values.h

1
platformio.ini

@ -32,6 +32,7 @@ lib_deps =
https://github.com/tueddy/PN5180-Library.git#0353104
platform_packages =
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#1.0.6
;platformio/framework-arduinoespressif32 @ https://github.com/tuniii/arduino-esp32-v1.0.6-wt#v1.0.6-patched
[env:esp32-a1s]

3
src/AudioPlayer.cpp

@ -687,7 +687,8 @@ void AudioPlayer_Task(void *parameter) {
}
}
esp_task_wdt_reset(); // Don't forget to feed the dog!
vTaskDelay(portTICK_PERIOD_MS * 3);
//esp_task_wdt_reset(); // Don't forget to feed the dog!
}
vTaskDelete(NULL);
}

7
src/Cmd.cpp

@ -328,6 +328,13 @@ void Cmd_Action(const uint16_t mod) {
break;
}
#ifdef ENABLE_ESPUINO_DEBUG
case PRINT_TASK_STATS: {
System_esp_print_tasks();
break;
}
#endif
default: {
snprintf(Log_Buffer, Log_BufferLength, "%s %d !", (char *) FPSTR(modificatorDoesNotExist), mod);
Log_Println(Log_Buffer, LOGLEVEL_ERROR);

9
src/Led.cpp

@ -64,7 +64,7 @@ void Led_Init(void) {
xTaskCreatePinnedToCore(
Led_Task, /* Function to implement the task */
"Led_Task", /* Name of the task */
2000, /* Stack size in words */
1512, /* Stack size in words */
NULL, /* Task input parameter */
1, /* Priority of the task */
NULL, /* Task handle. */
@ -191,7 +191,6 @@ static void Led_Task(void *parameter) {
FastLED.show();
showEvenError = !showEvenError;
vTaskDelay(portTICK_RATE_MS * 500);
esp_task_wdt_reset();
continue;
}
@ -203,6 +202,8 @@ static void Led_Task(void *parameter) {
// Multi-LED: growing red as long button for sleepmode is pressed.
// Single-LED: red when pressed and flashing red when long interval-duration is reached
if (gShutdownButton < (sizeof(gButtons) / sizeof(gButtons[0])) - 1) { // Only show animation, if CMD_SLEEPMODE was assigned to BUTTON_n_LONG + button is pressed
//snprintf(Log_Buffer, Log_BufferLength, "%u", uxTaskGetStackHighWaterMark(NULL));
//Log_Println(Log_Buffer, LOGLEVEL_DEBUG);
if (!gButtons[gShutdownButton].currentState && (millis() - gButtons[gShutdownButton].firstPressedTimestamp >= 150) && gButtonInitComplete) {
if (NUM_LEDS == 1) {
FastLED.clear();
@ -636,8 +637,8 @@ static void Led_Task(void *parameter) {
vTaskDelay(portTICK_RATE_MS * 5);
}
}
//vTaskDelay(portTICK_RATE_MS * 10);
esp_task_wdt_reset();
vTaskDelay(portTICK_RATE_MS * 1);
//esp_task_wdt_reset();
}
vTaskDelete(NULL);
#endif

8
src/RfidMfrc522.cpp

@ -60,9 +60,9 @@
for (;;) {
if (RFID_SCAN_INTERVAL/2 >= 20) {
vTaskDelay(RFID_SCAN_INTERVAL/2);
vTaskDelay(portTICK_RATE_MS * (RFID_SCAN_INTERVAL/2));
} else {
vTaskDelay(20);
vTaskDelay(portTICK_RATE_MS * 20);
}
byte cardId[cardIdSize];
String cardIdString;
@ -133,9 +133,9 @@
// https://github.com/miguelbalboa/rfid/issues/188; voodoo! :-)
while (true) {
if (RFID_SCAN_INTERVAL/2 >= 20) {
vTaskDelay(RFID_SCAN_INTERVAL/2);
vTaskDelay(portTICK_RATE_MS * (RFID_SCAN_INTERVAL/2));
} else {
vTaskDelay(20);
vTaskDelay(portTICK_RATE_MS * 20);
}
control=0;
for (uint8_t i=0u; i<3; i++) {

55
src/RfidPn5180.cpp

@ -8,6 +8,7 @@
#include "Queues.h"
#include "System.h"
#include "Port.h"
#include <esp_task_wdt.h>
#include "AudioPlayer.h"
#ifdef RFID_READER_TYPE_PN5180
@ -32,7 +33,7 @@
extern unsigned long Rfid_LastRfidCheckTimestamp;
#ifdef RFID_READER_TYPE_PN5180
static void Rfid_Read(void);
static void Rfid_Task(void *parameter);
void Rfid_Init(void) {
#ifdef PN5180_ENABLE_LPCD
@ -42,29 +43,43 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
gpio_hold_dis(gpio_num_t(RFID_RST)); // RST
pinMode(RFID_IRQ, INPUT);
#endif
xTaskCreatePinnedToCore(
Rfid_Task, /* Function to implement the task */
"rfid", /* Name of the task */
1536, /* Stack size in words */
NULL, /* Task input parameter */
2 | portPRIVILEGE_BIT, /* Priority of the task */
NULL, /* Task handle. */
0 /* Core where the task should run */
);
}
void Rfid_Cyclic(void) {
Rfid_Read();
vTaskDelay(5u);
// Not necessary as cyclic stuff performed by task Rfid_Task()
}
void Rfid_Read(void) {
void Rfid_Task(void *parameter) {
static PN5180ISO14443 nfc14443(RFID_CS, RFID_BUSY, RFID_RST);
static PN5180ISO15693 nfc15693(RFID_CS, RFID_BUSY, RFID_RST);
static uint32_t lastTimeDetected14443 = 0;
static uint32_t lastTimeDetected15693 = 0;
uint32_t lastTimeDetected14443 = 0;
uint32_t lastTimeDetected15693 = 0;
#ifdef PAUSE_WHEN_RFID_REMOVED
static byte lastValidcardId[cardIdSize];
static bool cardAppliedCurrentRun = false;
static bool cardAppliedLastRun = false;
bool sameCardReapplied = false;
byte lastValidcardId[cardIdSize];
bool cardAppliedCurrentRun = false;
bool cardAppliedLastRun = false;
#endif
static uint8_t stateMachine = RFID_PN5180_STATE_INIT;
uint8_t stateMachine = RFID_PN5180_STATE_INIT;
static byte cardId[cardIdSize], lastCardId[cardIdSize];
uint8_t uid[10];
for (;;) {
vTaskDelay(portTICK_RATE_MS * 10u);
String cardIdString;
bool cardReceived = false;
#ifdef PAUSE_WHEN_RFID_REMOVED
bool sameCardReapplied = false;
#endif
if (RFID_PN5180_STATE_INIT == stateMachine) {
nfc14443.begin();
@ -84,6 +99,8 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
// 1. check for an ISO-14443 card
} else if (RFID_PN5180_NFC14443_STATE_RESET == stateMachine) {
nfc14443.reset();
//snprintf(Log_Buffer, Log_BufferLength, "%u", uxTaskGetStackHighWaterMark(NULL));
//Log_Println(Log_Buffer, LOGLEVEL_DEBUG);
} else if (RFID_PN5180_NFC14443_STATE_SETUPRF == stateMachine) {
nfc14443.setupRF();
} else if (RFID_PN5180_NFC14443_STATE_READCARD == stateMachine) {
@ -152,8 +169,9 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
}
#ifdef PAUSE_WHEN_RFID_REMOVED
if (!cardAppliedCurrentRun && cardAppliedLastRun && !gPlayProperties.pausePlay) { // Card removed => pause
if (!cardAppliedCurrentRun && cardAppliedLastRun && !gPlayProperties.pausePlay && System_GetOperationMode() != OPMODE_BLUETOOTH) { // Card removed => pause
AudioPlayer_TrackControlToQueueSender(PAUSEPLAY);
Log_Println((char *) FPSTR(rfidTagRemoved), LOGLEVEL_NOTICE);
}
cardAppliedLastRun = cardAppliedCurrentRun;
#endif
@ -167,10 +185,10 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
// reset state machine
if (RFID_PN5180_NFC14443_STATE_ACTIVE == stateMachine) {
stateMachine = RFID_PN5180_NFC14443_STATE_RESET;
return;
continue;
} else if (RFID_PN5180_NFC15693_STATE_ACTIVE == stateMachine) {
stateMachine = RFID_PN5180_NFC15693_STATE_RESET;
return;
continue;
}
}
@ -202,8 +220,9 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
xQueueSend(gRfidCardQueue, cardIdString.c_str(), 0);
} else {
// If pause-button was pressed while card was not applied, playback could be active. If so: don't pause when card is reapplied again as the desired functionality would be reversed in this case.
if (gPlayProperties.pausePlay) {
if (gPlayProperties.pausePlay && System_GetOperationMode() != OPMODE_BLUETOOTH) {
AudioPlayer_TrackControlToQueueSender(PAUSEPLAY); // ... play/pause instead
Log_Println((char *) FPSTR(rfidTagReapplied), LOGLEVEL_NOTICE);
}
}
memcpy(lastValidcardId, uid, cardIdSize);
@ -212,9 +231,9 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
#endif
}
if (stateMachine == RFID_PN5180_NFC14443_STATE_ACTIVE) { // If 14443 is active, bypass 15693 as next check (performance)
if (RFID_PN5180_NFC14443_STATE_ACTIVE == stateMachine) { // If 14443 is active, bypass 15693 as next check (performance)
stateMachine = RFID_PN5180_NFC14443_STATE_RESET;
} else if (stateMachine == RFID_PN5180_NFC15693_STATE_ACTIVE) { // If 15693 is active, bypass 14443 as next check (performance)
} else if (RFID_PN5180_NFC15693_STATE_ACTIVE == stateMachine) { // If 15693 is active, bypass 14443 as next check (performance)
stateMachine = RFID_PN5180_NFC15693_STATE_RESET;
} else {
stateMachine++;
@ -223,6 +242,7 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
}
}
}
}
void Rfid_Exit(void) {
// goto low power card detection mode
@ -292,5 +312,4 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
}
#endif
}
#endif

12
src/System.cpp

@ -8,6 +8,9 @@
#include "Mqtt.h"
#include "SdCard.h"
#include "Port.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
constexpr const char prefsRfidNamespace[] PROGMEM = "rfidTags"; // Namespace used to save IDs of rfid-tags
constexpr const char prefsSettingsNamespace[] PROGMEM = "settings"; // Namespace used for generic settings
@ -227,3 +230,12 @@ void System_ShowUpgradeWarning(void) {
Log_Println((char *) FPSTR(warningRefactoring), LOGLEVEL_ERROR);
}
}
#ifdef ENABLE_ESPUINO_DEBUG
void System_esp_print_tasks(void) {
char *pbuffer = (char *)calloc(2048, 1);
vTaskGetRunTimeStats(pbuffer);
Serial.printf("=====\n%s\n=====", pbuffer);
free(pbuffer);
}
#endif

1
src/System.h

@ -24,3 +24,4 @@ void System_SetOperationMode(uint8_t opMode);
uint8_t System_GetOperationMode(void);
uint8_t System_GetOperationModeFromNvs(void);
void System_ShowUpgradeWarning(void);
void System_esp_print_tasks(void);

14
src/Web.cpp

@ -609,13 +609,14 @@ void explorerHandleFileUpload(AsyncWebServerRequest *request, String filename, s
}
// Create Task for handling the storage of the data
xTaskCreate(
xTaskCreatePinnedToCore(
explorerHandleFileStorageTask, /* Function to implement the task */
"fileStorageTask", /* Name of the task */
4000, /* Stack size in words */
filePath, /* Task input parameter */
2 | portPRIVILEGE_BIT, /* Priority of the task */
&fileStorageTaskHandle /* Task handle. */
&fileStorageTaskHandle, /* Task handle. */
1 /* Core where the task should run */
);
}
@ -674,7 +675,7 @@ void explorerHandleFileStorageTask(void *parameter) {
// done exit loop to terminate
break;
}
vTaskDelay(portTICK_PERIOD_MS * 100);
vTaskDelay(portTICK_PERIOD_MS * 20);
}
#ifdef SD_MMC_1BIT_MODE
vTaskDelay(portTICK_PERIOD_MS * 1);
@ -737,7 +738,12 @@ void explorerHandleListRequest(AsyncWebServerRequest *request) {
}
file = root.openNextFile();
esp_task_wdt_reset();
// If playback is active this can (at least sometimes) prevent scattering
if (!gPlayProperties.pausePlay) {
vTaskDelay(portTICK_PERIOD_MS * 5);
} else {
vTaskDelay(portTICK_PERIOD_MS * 1);
}
}
serializeJson(obj, serializedJsonString);

3
src/main.cpp

@ -273,6 +273,5 @@ void loop() {
#endif
IrReceiver_Cyclic();
vTaskDelay(5u);
vTaskDelay(portTICK_RATE_MS * 5u);
}

2
src/revision.h

@ -1,4 +1,4 @@
#ifndef __REVISION_H__
#define __REVISION_H__
constexpr const char softwareRevision[] PROGMEM = "Software-revision: 20210930-1";
constexpr const char softwareRevision[] PROGMEM = "Software-revision: 20211002-1";
#endif

2
src/settings.h

@ -238,4 +238,6 @@
#include "settings-custom.h" // Contains all user-relevant settings custom-board
#endif
//#define ENABLE_ESPUINO_DEBUG // Needs modification of platformio.ini (https://forum.espuino.de/t/rfid-mit-oder-ohne-task/353/21); better don't enable unless you know what you're doing :-)
#endif

2
src/values.h

@ -74,4 +74,6 @@
#define DE 1
#define EN 2
// Debug
#define PRINT_TASK_STATS 900 // Prints task stats (only debugging; needs modification of platformio.ini (https://forum.espuino.de/t/rfid-mit-oder-ohne-task/353/21))
#endif
Loading…
Cancel
Save