首页 > 解决方案 > 免费 rtos 中 xTaskAbortDelay 函数的用途是什么?

问题描述

我有两个任务,我正在从蓝牙接收数据,如果我收到一个特定的十六进制值,我希望一个任务(即切换 LED 状态)根据接收到的数据运行。

如果没有收到数据,则两个任务都应按计划运行。

我一直在尝试使用 xTaskAbortDelay 函数,该任务确实从蓝牙数据的输入运行,但是,之后 LED 任务正在连续运行。

xTaskAbortDelay 会在这里造成一些问题吗?我应该使用其他东西来实现相同的功能吗?

TaskHandle_t  lora_send_data_handle;
TaskHandle_t  ble_send_data_handle;
TaskHandle_t  test_data_handle;

static void button_task_check(void * pvParameter)
{
    TickType_t xLastWakeTime;
    const TickType_t xFrequency = 1024;
    xLastWakeTime = xTaskGetTickCount();
    while(1)
    {
        nrf_delay_ms(100);
        SEGGER_RTT_printf(0,"%s","INSIDE SWITCHING\r\n");
        xTaskAbortDelay(test_data_handle);

        vTaskDelayUntil( &xLastWakeTime, (TickType_t) 1024);
    }
}


/*TASK TO RUN LEDS CHECK */
static void led_task_check(void * pvParameter)
{
    TickType_t xLastWakeTime;
    const TickType_t xFrequency = 122880;
    xLastWakeTime = xTaskGetTickCount();

    while(1)
    {
        SEGGER_RTT_printf(0,"%s","TEST TASK\r\n");
        nrf_gpio_pin_write(RED,1);
        nrf_gpio_pin_write(GREEN,1);
        nrf_gpio_pin_write(BLUE,1);

        nrf_gpio_pin_write(RED,0);
        nrf_gpio_pin_write(GREEN,1);
        nrf_gpio_pin_write(BLUE,1);
        nrf_delay_ms(1000);
        nrf_gpio_pin_write(RED,1);
        nrf_gpio_pin_write(GREEN,0);
        nrf_gpio_pin_write(BLUE,1);
        nrf_delay_ms(1000);
        nrf_gpio_pin_write(RED,1);
        nrf_gpio_pin_write(GREEN,1);
        nrf_gpio_pin_write(BLUE,0);
        nrf_delay_ms(1000);

        nrf_gpio_pin_write(RED,0);
        nrf_gpio_pin_write(GREEN,0);
        nrf_gpio_pin_write(BLUE,0);
        nrf_delay_ms(1000);

        vTaskDelayUntil( &xLastWakeTime, (TickType_t) 122880);
    }
}


int main(void)
{

    uint8_t rx_qspi[255];
    SEGGER_RTT_printf(0,"%s","reset\r\n");

    nrf_delay_ms(100);

    xQueue1 = xQueueCreate(1, 30);

    ret_code_t err_code;
    err_code = nrf_drv_clock_init();
    SEGGER_RTT_WriteString(0, err_code);

    UNUSED_VARIABLE(xTaskCreate( button_task_check, "t", \            
        configMINIMAL_STACK_SIZE + 200, NULL,3,  &lora_send_data_handle));
    UNUSED_VARIABLE(xTaskCreate(led_task_check, "et", \
        configMINIMAL_STACK_SIZE + 200, NULL, 2, &test_data_handle));

    vTaskStartScheduler();

    while(1);
}

标签: cfreertosrtos

解决方案


声誉低至评论。从你所说的来看,一切都如你所说。需要更多信息:

  1. LED 任务是什么样的?
  2. 您使用抢占式或协作式调度程序(#define configUSE_PREEMPTION 1在 freertosconfig.h 文件中)。
  3. 这三项任务的重点是什么?

其他需要考虑的事情是:您是否在任务完成后将任务重新置于 BLOCKED 状态?你应该先检查一下。您如何首先阻止任务?

也许尝试使用vTaskResume( <LED task handle> )蓝牙任务调用并vTaskSuspend()在完成工作后从 LED 任务调用。我个人认为这不是最好的方法,但它应该有效。


推荐阅读