在 FreeRTOS 中使用信号量

Using semaphore in FreeRTOS

我正在尝试使用 arduino core for ESP32 的信号量。我的代码如下:

#include <Arduino.h>
#include <freertos/task.h>
#include <freertos/queue.h>
#define configUSE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
void vTaskExample(void *pvParameters);
void accessSharedResource{}
volatile SemaphoreHandle_t xResourceSemaphore = NULL;
void setup()
{
    xTaskCreatePinnedToCore(&vTaskExample, "example task", 1024, NULL, 2, NULL, 1);
}

void loop()
{
    // Do nothing
}

void vTaskExample(void *pvParameters)
{
    vSemaphoreCreateBinary(xResourceSemaphore);
    while (true)
    {
        if (xSemaphoreAltTake(xResourceSemaphore, (TickType_t)0))
        {
            accessSharedResource();
            xSemaphoreAltGive(xResourceSemaphore);
        }
    }
}

不幸的是,在编译期间(准确地说是在链接阶段),我收到以下错误消息:

main.cpp:(.text._Z12vTaskExamplePv+0x37): undefined reference to `xQueueAltGenericReceive'
main.cpp:(.text._Z12vTaskExamplePv+0x4b): undefined reference to `xQueueAltGenericSend'

我查了freeRTOS的文档,说这两个函数在queue.h;因此,应该可用。另外,我通过设置 configUSE_MUTEXES and configUSE_COUNTING_SEMAPHORES flags

设置了必要的 freeRTOS configuration

为什么这不能编译有什么建议吗?

queue.h 中仅提供了原型 - 没有可执行文件。如果您查看 FreeRTOS documentation,您会注意到替代方案 API 已被弃用很长时间,并且仅当 configUSE_ALTERNATIVE_API 设置为 1 时才包含在构建中。