#include <stdio.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/ledc.h" #include "esp_err.h" #include "string.h" #include "esp_log.h" #include "freertos/queue.h" #define LEDC_TIMER LEDC_TIMER_0 //LEDC定时器 #define LEDC_MODE LEDC_LOW_SPEED_MODE //LEDC的速度模式 #define LEDC_OUTPUT_IO (12) //LEDC绑定引脚 #define LEDC_CHANNEL LEDC_CHANNEL_0 //LEDC通道 #define LEDC_DUTY_RES LEDC_TIMER_13_BIT //LEDC占空比分辨率 #define LEDC_DUTY (4095) //LEDC占空比 #define LEDC_FREQUENCY (5000) //LEDC频率 5 kHz static void example_ledc_init(void) { //LEDC定时器配置 ledc_timer_config_t ledc_timer = { .speed_mode = LEDC_MODE, //设置定时器低速模式 .timer_num = LEDC_TIMER, //设置定时器0 .duty_resolution = LEDC_DUTY_RES, //设置定时器分辨率 13位 .freq_hz = LEDC_FREQUENCY, //设置定时器频率 5kHz .clk_cfg = LEDC_AUTO_CLK //设置定时器时钟选择 }; ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer)); //设置定时器配置 //配置LEDC通道 ledc_channel_config_t ledc_channel = { .speed_mode = LEDC_MODE, //设置通道模式低速模式 .channel = LEDC_CHANNEL, //设置LEDC通道0 .timer_sel = LEDC_TIMER, //设置LEDC定时器 .intr_type = LEDC_INTR_DISABLE, //设置LEDC中断类型 .gpio_num = LEDC_OUTPUT_IO, //设置LEDCGPIO引脚 .duty = 0, // Set duty to 0% //设置占空比 .hpoint = 0 //LEDC通道hpoint值 }; ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));//配置LEDC通道参数 } void cpu_task(void *ptr){ uint8_t cpu_info[400]; while (1) { memset(cpu_info,0,400); vTaskList((char *)&cpu_info); printf("%s",cpu_info); printf("--------------\r\n"); memset(cpu_info,0,400); vTaskGetRunTimeStats((char*)&cpu_info); printf("%s",cpu_info); printf("--------------\r\n"); vTaskDelay(5000/portTICK_PERIOD_MS); } } QueueHandle_t test_queue_handle = NULL; void test_queue(){ test_queue_handle = xQueueCreate(20,50); if(test_queue_handle!=NULL){ ESP_LOGI("YCP","创建成功"); }else{ ESP_LOGI("YCP","空间不足"); } } char *str = "消息队列发送测试"; void test_queue_send(void *ptr){ while (1){ xQueueSend(test_queue_handle,(void *)str,0); vTaskDelay(1000/portTICK_PERIOD_MS); } } void test_queue_receive(void *ptr){ char queue_receive[50]; while (1){ int ret = xQueueReceive(test_queue_handle,(void *)queue_receive,500); if(ret){ ESP_LOGE("消息队列接收","%s",queue_receive); }else{ ESP_LOGE("消息队列接收","没收到"); } vTaskDelay(1000/portTICK_PERIOD_MS); } } void app_main(void) { test_queue(); // 配置LEDC外设 example_ledc_init(); // 设置占空比(LEDC的速度模式,LEDC通道,4095+1) 50% 2^13 = 8192 4096即占一半,占空比50% ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY)); // 更新占空比 ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL)); xTaskCreate(cpu_task,"cpu_task_name",4096,NULL,1,NULL); xTaskCreate(test_queue_send,"test_queue_send_name",4096,NULL,1,NULL); xTaskCreate(test_queue_receive,"test_queue_receive_name",4096,NULL,1,NULL); }
标签:队列,void,ledc,queue,LEDC,消息,test,cpu From: https://www.cnblogs.com/ycp666/p/17017254.html