FreeRTOS Add Boot Time
This commit is contained in:
parent
dbfdce8ec9
commit
f4f1772db6
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -4,7 +4,9 @@
|
||||
"files.associations": {
|
||||
"cstring": "cpp",
|
||||
"random": "cpp",
|
||||
"system_error": "c"
|
||||
"system_error": "c",
|
||||
"*.tcc": "cpp",
|
||||
"streambuf": "cpp"
|
||||
},
|
||||
"cmake.ignoreCMakeListsMissing": true
|
||||
}
|
@ -189,6 +189,7 @@ int loop(int fd, CONF *conf, DATA *DATA)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// CO
|
||||
if (strstr(receivedString, "CO")) {
|
||||
|
||||
@ -246,6 +247,14 @@ int loop(int fd, CONF *conf, DATA *DATA)
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
// Boot Time
|
||||
if (strstr(receivedString, "Boot Time")) {
|
||||
if (1 == (sscanf(receivedString, "Boot Time: %llu seconds\n", &DATA->boot_time_))) {
|
||||
printf("Boot Time: %llu seconds\n", DATA->boot_time_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
receivedString[0] = '\0';
|
||||
@ -360,6 +369,7 @@ int main()
|
||||
data->co_1st = 1;
|
||||
data->co2_1st = 1;
|
||||
data->_time = 180;
|
||||
data->boot_time_ = 0;
|
||||
|
||||
redirect_stdout_to_file(logfd, "hc-12.log");
|
||||
pthread_mutex_init(&mutex, NULL); // 初始化互斥锁
|
||||
|
@ -48,6 +48,9 @@ typedef struct DATA {
|
||||
float co2;
|
||||
float ch4_;
|
||||
|
||||
// boot time
|
||||
long long unsigned int boot_time_;
|
||||
|
||||
// 超过阈值次数
|
||||
int ds18b20_num;
|
||||
int ch4_num;
|
||||
|
@ -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温度
|
||||
@ -147,6 +149,12 @@ int main(int argc, char *argv[])
|
||||
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();
|
||||
while (1) {};
|
||||
|
@ -304,6 +304,7 @@ int wifi_connect() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// 主程序
|
||||
int main(int argc, char *argv[]) {
|
||||
stdio_init_all();
|
||||
@ -349,10 +350,8 @@ int main(int argc, char *argv[]) {
|
||||
cyw43_arch_deinit();
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
stdio_init_all();
|
||||
@ -470,4 +469,3 @@ int main(int argc, char *argv[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
Loading…
Reference in New Issue
Block a user