FreeRTOS Add Boot Time
This commit is contained in:
@@ -42,6 +42,7 @@ target_Sources(main PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/Source/ZE07CO.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/Source/MHZ14B.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/Source/HC-12.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/Source/boot_time.cpp
|
||||
)
|
||||
|
||||
target_include_directories(main PRIVATE
|
||||
@@ -76,6 +77,7 @@ target_link_libraries(
|
||||
hardware_pwm
|
||||
hardware_adc
|
||||
hardware_pio
|
||||
hardware_timer
|
||||
)
|
||||
|
||||
pico_enable_stdio_uart(main 1)
|
||||
|
||||
39
SOFTWARE-FreeRTOS/Source/boot_time.cpp
Normal file
39
SOFTWARE-FreeRTOS/Source/boot_time.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "HC-12.hpp"
|
||||
#include "boot_time.hpp"
|
||||
|
||||
|
||||
void BOOT_TIME(void *pvParameters)
|
||||
{
|
||||
(void)pvParameters;
|
||||
|
||||
_printTaskStackHighWaterMark("BOOT_TIME");
|
||||
|
||||
int _HC_12_SEND_NUM = 0;
|
||||
char BOOT_TIME_TEMP[BUFER] = { 0 };
|
||||
|
||||
|
||||
while (1) {
|
||||
// 获取自开机以来的微秒数
|
||||
uint64_t uptime_us = time_us_64();
|
||||
uint64_t total_uptime_sec = uptime_us / 1000000;
|
||||
|
||||
// 打印开机秒数
|
||||
printf("Boot Time: %llu seconds\n", total_uptime_sec);
|
||||
|
||||
{
|
||||
_HC_12_SEND_NUM++;
|
||||
if (_HC_12_SEND_NUM > 5) {
|
||||
sprintf(BOOT_TIME_TEMP, "Boot Time: %llu seconds\n", total_uptime_sec);
|
||||
_HC_12(BOOT_TIME_TEMP);
|
||||
memset(BOOT_TIME_TEMP, 0, BUFER);
|
||||
_HC_12_SEND_NUM = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_printTaskStackHighWaterMark("BOOT_TIME");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000)); // 每秒延迟
|
||||
}
|
||||
}
|
||||
17
SOFTWARE-FreeRTOS/Source/boot_time.hpp
Normal file
17
SOFTWARE-FreeRTOS/Source/boot_time.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef BOOT_TIME_H
|
||||
#define BOOT_TIME_H
|
||||
|
||||
/* Scheduler include files. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#include "queue.h"
|
||||
|
||||
#include <cstring>
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
#define BUFER 256
|
||||
|
||||
extern void BOOT_TIME(void *pvParameters);
|
||||
|
||||
#endif
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "ZE07CO.hpp"
|
||||
#include "MHZ14B.hpp"
|
||||
#include "HC-12.hpp"
|
||||
#include "boot_time.hpp"
|
||||
|
||||
#ifndef PICO_DEFAULT_LED_PIN
|
||||
#warning pio/hello_pio example requires a board with a regular LED
|
||||
@@ -109,6 +110,7 @@ int main(int argc, char *argv[])
|
||||
TaskHandle_t CH4_xHandle = NULL;
|
||||
TaskHandle_t CO_xHandle = NULL;
|
||||
TaskHandle_t CO2_xHandle = NULL;
|
||||
TaskHandle_t BOOT_TIME_xHandle = NULL;
|
||||
|
||||
|
||||
// 板载CPU温度
|
||||
@@ -146,6 +148,12 @@ int main(int argc, char *argv[])
|
||||
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) {
|
||||
printf("CO2() Task Error!");
|
||||
}
|
||||
|
||||
// Boot Time
|
||||
xReturned = xTaskCreate(BOOT_TIME, "BOOT_TIME task", 512, NULL, tskIDLE_PRIORITY, &BOOT_TIME_xHandle);
|
||||
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) {
|
||||
printf("CO2() Task Error!");
|
||||
}
|
||||
|
||||
|
||||
vTaskStartScheduler();
|
||||
|
||||
Reference in New Issue
Block a user