mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
mdns: add configuration values for task priority, affinity and internal service timeouts
closes https://github.com/espressif/esp-idf/issues/4217
This commit is contained in:
parent
8b38d79dd3
commit
c6f38f04f8
@ -10,4 +10,52 @@ menu "mDNS"
|
|||||||
the maximum amount of services here. The valid value is from 1
|
the maximum amount of services here. The valid value is from 1
|
||||||
to 64.
|
to 64.
|
||||||
|
|
||||||
|
config MDNS_TASK_PRIORITY
|
||||||
|
int "mDNS task priority"
|
||||||
|
range 1 255
|
||||||
|
default 1
|
||||||
|
help
|
||||||
|
Allows setting mDNS task priority. Please do not set the task priority
|
||||||
|
higher than priorities of system tasks. Compile time warning/error
|
||||||
|
would be emitted if the chosen task priority were too high.
|
||||||
|
|
||||||
|
choice MDNS_TASK_AFFINITY
|
||||||
|
prompt "mDNS task affinity"
|
||||||
|
default MDNS_TASK_AFFINITY_CPU0
|
||||||
|
help
|
||||||
|
Allows setting mDNS tasks affinity, i.e. whether the task is pinned to
|
||||||
|
CPU0, pinned to CPU1, or allowed to run on any CPU.
|
||||||
|
|
||||||
|
config MDNS_TASK_AFFINITY_NO_AFFINITY
|
||||||
|
bool "No affinity"
|
||||||
|
config MDNS_TASK_AFFINITY_CPU0
|
||||||
|
bool "CPU0"
|
||||||
|
config MDNS_TASK_AFFINITY_CPU1
|
||||||
|
bool "CPU1"
|
||||||
|
depends on !FREERTOS_UNICORE
|
||||||
|
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
config MDNS_TASK_AFFINITY
|
||||||
|
hex
|
||||||
|
default FREERTOS_NO_AFFINITY if MDNS_TASK_AFFINITY_NO_AFFINITY
|
||||||
|
default 0x0 if MDNS_TASK_AFFINITY_CPU0
|
||||||
|
default 0x1 if MDNS_TASK_AFFINITY_CPU1
|
||||||
|
|
||||||
|
config MDNS_SERVICE_ADD_TIMEOUT_MS
|
||||||
|
int "mDNS adding service timeout (ms)"
|
||||||
|
range 10 30000
|
||||||
|
default 2000
|
||||||
|
help
|
||||||
|
Configures timeout for adding a new mDNS service. Adding a service
|
||||||
|
fails if could not be completed within this time.
|
||||||
|
|
||||||
|
config MDNS_TIMER_PERIOD_MS
|
||||||
|
int "mDNS timer period (ms)"
|
||||||
|
range 10 10000
|
||||||
|
default 100
|
||||||
|
help
|
||||||
|
Configures period of mDNS timer, which periodically transmits packets
|
||||||
|
and schedules mDNS searches.
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "mdns_networking.h"
|
#include "mdns_networking.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
#ifdef MDNS_ENABLE_DEBUG
|
#ifdef MDNS_ENABLE_DEBUG
|
||||||
void mdns_debug_packet(const uint8_t * data, size_t len);
|
void mdns_debug_packet(const uint8_t * data, size_t len);
|
||||||
@ -4095,7 +4096,8 @@ static esp_err_t _mdns_service_task_start(void)
|
|||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
if (!_mdns_service_task_handle) {
|
if (!_mdns_service_task_handle) {
|
||||||
xTaskCreatePinnedToCore(_mdns_service_task, "mdns", MDNS_SERVICE_STACK_DEPTH, NULL, 1, (TaskHandle_t * const)(&_mdns_service_task_handle), 0);
|
xTaskCreatePinnedToCore(_mdns_service_task, "mdns", MDNS_SERVICE_STACK_DEPTH, NULL, MDNS_TASK_PRIORITY,
|
||||||
|
(TaskHandle_t * const)(&_mdns_service_task_handle), MDNS_TASK_AFFINITY);
|
||||||
if (!_mdns_service_task_handle) {
|
if (!_mdns_service_task_handle) {
|
||||||
_mdns_stop_timer();
|
_mdns_stop_timer();
|
||||||
MDNS_SERVICE_UNLOCK();
|
MDNS_SERVICE_UNLOCK();
|
||||||
@ -4400,12 +4402,15 @@ esp_err_t mdns_service_add(const char * instance, const char * service, const ch
|
|||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t i = 0;
|
size_t start = xTaskGetTickCount();
|
||||||
while (_mdns_get_service_item(service, proto) == NULL && i++ < 200) {
|
size_t timeout_ticks = pdMS_TO_TICKS(MDNS_SERVICE_ADD_TIMEOUT_MS);
|
||||||
vTaskDelay(1);
|
while (_mdns_get_service_item(service, proto) == NULL)
|
||||||
}
|
{
|
||||||
if (i >= 200) {
|
uint32_t expired = xTaskGetTickCount() - start;
|
||||||
return ESP_FAIL;
|
if (expired >= timeout_ticks) {
|
||||||
|
return ESP_FAIL; // Timeout
|
||||||
|
}
|
||||||
|
vTaskDelay(MIN(10 / portTICK_RATE_MS, timeout_ticks - expired));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
@ -56,6 +56,15 @@
|
|||||||
|
|
||||||
#define MDNS_SERVICE_PORT 5353 // UDP port that the server runs on
|
#define MDNS_SERVICE_PORT 5353 // UDP port that the server runs on
|
||||||
#define MDNS_SERVICE_STACK_DEPTH 4096 // Stack size for the service thread
|
#define MDNS_SERVICE_STACK_DEPTH 4096 // Stack size for the service thread
|
||||||
|
#define MDNS_TASK_PRIORITY CONFIG_MDNS_TASK_PRIORITY
|
||||||
|
#if (MDNS_TASK_PRIORITY > ESP_TASK_PRIO_MAX)
|
||||||
|
#error "mDNS task priority is higher than ESP_TASK_PRIO_MAX"
|
||||||
|
#elif (MDNS_TASK_PRIORITY > ESP_TASKD_EVENT_PRIO)
|
||||||
|
#warning "mDNS task priority is higher than ESP_TASKD_EVENT_PRIO, mDNS library might not work correctly"
|
||||||
|
#endif
|
||||||
|
#define MDNS_TASK_AFFINITY CONFIG_MDNS_TASK_AFFINITY
|
||||||
|
#define MDNS_SERVICE_ADD_TIMEOUT_MS CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS
|
||||||
|
|
||||||
#define MDNS_PACKET_QUEUE_LEN 16 // Maximum packets that can be queued for parsing
|
#define MDNS_PACKET_QUEUE_LEN 16 // Maximum packets that can be queued for parsing
|
||||||
#define MDNS_ACTION_QUEUE_LEN 16 // Maximum actions pending to the server
|
#define MDNS_ACTION_QUEUE_LEN 16 // Maximum actions pending to the server
|
||||||
#define MDNS_TXT_MAX_LEN 1024 // Maximum string length of text data in TXT record
|
#define MDNS_TXT_MAX_LEN 1024 // Maximum string length of text data in TXT record
|
||||||
@ -82,7 +91,7 @@
|
|||||||
#define MDNS_SRV_PORT_OFFSET 4
|
#define MDNS_SRV_PORT_OFFSET 4
|
||||||
#define MDNS_SRV_FQDN_OFFSET 6
|
#define MDNS_SRV_FQDN_OFFSET 6
|
||||||
|
|
||||||
#define MDNS_TIMER_PERIOD_US 100000
|
#define MDNS_TIMER_PERIOD_US (CONFIG_MDNS_TIMER_PERIOD_MS*1000)
|
||||||
|
|
||||||
#define MDNS_SERVICE_LOCK() xSemaphoreTake(_mdns_service_semaphore, portMAX_DELAY)
|
#define MDNS_SERVICE_LOCK() xSemaphoreTake(_mdns_service_semaphore, portMAX_DELAY)
|
||||||
#define MDNS_SERVICE_UNLOCK() xSemaphoreGive(_mdns_service_semaphore)
|
#define MDNS_SERVICE_UNLOCK() xSemaphoreGive(_mdns_service_semaphore)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user