freertos入门之queue

该文展示了如何在ESP32平台上使用FreeRTOS实时操作系统进行任务调度。创建了两个任务,一个负责发送数据到队列,另一个从队列接收数据,通过延时函数实现周期性执行。同时,定义了一个空闲钩子函数vApplicationIdleHook。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基于esp32 平台 。
参考:
https://www.freertos.org/fr-content-src/uploads/2018/07/161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf

#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/event_groups.h"

QueueHandle_t   queue;

void send(void *p) {
	printf("xQueueSend\n");
	BaseType_t a = 0;
	while (1) {
		a++;
		vTaskDelay(pdMS_TO_TICKS(1000));
		xQueueSend(queue,&a,pdMS_TO_TICKS(1000*1000));
		printf("send:%d\n",a);
	}
}

void receive(void *p) {
	printf("receive\n");
	BaseType_t a = 0;
	while (1) {
		xQueueReceive(queue,&a,pdMS_TO_TICKS(1000*1000));
		printf("received:%d\n",a);

	}
}

void vApplicationIdleHook( void ){
	printf("vApplicationIdleHook\n");
}

void app_main(void) {
	queue = xQueueCreate(10,sizeof(BaseType_t));
	xTaskCreate(&send, "hid_task", 2048, NULL, configMAX_PRIORITIES-1, NULL);
	xTaskCreate(&receive, "hid_task", 2048, NULL, 0, NULL);
	return;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值