【问题标题】:Using semaphore in FreeRTOS在 FreeRTOS 中使用信号量
【发布时间】:2018-07-09 08:55:32
【问题描述】:

我正在尝试使用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 标志设置了必要的freeRTOS configuration

任何建议为什么这不能编译?

【问题讨论】:

    标签: arduino freertos esp32


    【解决方案1】:

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

    【讨论】:

    • 非常感谢!如果这需要我使用已弃用的 API,我可能应该重新考虑我的设计。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 2022-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多