Gradually migrate to FreeRTOS

This commit is contained in:
2024-06-04 09:54:09 +08:00
parent db774bfd76
commit 92c0ee6bd8
15 changed files with 143 additions and 161 deletions

View File

@@ -19,8 +19,8 @@
#include "MHZ14B.hpp"
#ifndef PICO_DEFAULT_LED_PIN
#warning pio/hello_pio example requires a board with a regular LED
#define PICO_DEFAULT_LED_PIN 25
#warning pio/hello_pio example requires a board with a regular LED
#define PICO_DEFAULT_LED_PIN 25
#endif
void Led_Blinky(void *pvParameters)
@@ -30,24 +30,23 @@ void Led_Blinky(void *pvParameters)
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
_printTaskStackHighWaterMark("Led_Blinky");
float TEMPERATURE;
while (1) {
vTaskDelay(pdMS_TO_TICKS(500));
gpio_put(LED_PIN, 1);
vTaskDelay(pdMS_TO_TICKS(500));
gpio_put(LED_PIN, 0);
// 从队列接收数据
if (xQueueReceive(xQueue, &TEMPERATURE, portMAX_DELAY) == pdPASS) {
// 处理接收到的数据
printf("%f\n", TEMPERATURE);
}
//_printTaskStackHighWaterMark("Led_Blinky");
}
@@ -60,7 +59,7 @@ void Read_Onboard_Temperature(void *pvParameters)
adc_init();
adc_set_temp_sensor_enabled(true);
adc_select_input(4); // Input 4 is the onboard temperature sensor.
//_printTaskStackHighWaterMark("Read_Onboard_Temperature");
while (1) {
@@ -70,9 +69,9 @@ void Read_Onboard_Temperature(void *pvParameters)
float tempC = 27.0f - (adc - 0.706f) / 0.001721f;
printf("Onboard temperature %.02f°C %.02f°F\n", tempC, (tempC * 9 / 5 + 32));
//_printTaskStackHighWaterMark("Read_Onboard_Temperature");
vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时
}
}
@@ -82,12 +81,10 @@ int main(void)
stdio_init_all();
sleep_ms(3000);
//set_sys_clock_khz(250000, true);
// 创建队列
xQueue = xQueueCreate(10, sizeof(long));
// 创建任务
BaseType_t xReturned;
TaskHandle_t Led_Blinky_xHandle = NULL;
@@ -97,31 +94,25 @@ int main(void)
// 板载LED闪烁
xReturned = xTaskCreate(Led_Blinky, "Blinky task", 512, NULL, tskIDLE_PRIORITY, &Led_Blinky_xHandle);
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY)
{
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) {
printf("Blinky Task Error!");
}
// DS18B20
xReturned = xTaskCreate(DS18B20, "DS18B20 task", 1024, NULL, tskIDLE_PRIORITY, &DS18B20_xHandle);
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY)
{
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) {
printf("DS18B20() Task Error!");
}
// CH4
xReturned = xTaskCreate(CH4, "CH4 task", 1024, NULL, tskIDLE_PRIORITY, &CH4_xHandle);
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY)
{
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) {
printf("CH4() Task Error!");
}
// CO2
xReturned = xTaskCreate(CO2, "CO2 task", 1024, NULL, tskIDLE_PRIORITY, &CO2_xHandle);
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY)
{
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) {
printf("CO2() Task Error!");
}
vTaskStartScheduler();
return 0;