c - 免费 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);
}
解决方案
声誉低至评论。从你所说的来看,一切都如你所说。需要更多信息:
- LED 任务是什么样的?
- 您使用抢占式或协作式调度程序(
#define configUSE_PREEMPTION 1
在 freertosconfig.h 文件中)。 - 这三项任务的重点是什么?
其他需要考虑的事情是:您是否在任务完成后将任务重新置于 BLOCKED 状态?你应该先检查一下。您如何首先阻止任务?
也许尝试使用vTaskResume( <LED task handle> )
蓝牙任务调用并vTaskSuspend()
在完成工作后从 LED 任务调用。我个人认为这不是最好的方法,但它应该有效。
推荐阅读
- jquery - 我可以通过其他 jQuery 方法修改用作 insertAfter 参数的选择器吗?
- iphone - 快速比较两个 viewController
- ibm-mq - 读取 IBM MQ 文件内容的不同命令有哪些?
- python - Sympy 图:绘制具有多个自由变量的函数(python 3.6)
- windows-subsystem-for-linux - 如何在 Windows Subsystem for Linux (WSL) 中启用 Active Directory/LDAP/Kerberos?
- microsoft-dynamics - Dynamics 365:创建自定义 Web 应用程序 UI
- html - 适合没有定义父高度的图像
- r - ggplot 的 aes() 中的属性“color”破坏了我的 ggplot 代码的“geom_line()”部分
- java - 用于查找重复单词“\\b(\\w+)(\\s+\\1\\b)+”的 Java 正则表达式问题
- angular - 带有异步子路由器的命名路由器出口