UniversalCanCore/Src/CanReceiveTask.cpp
2025-12-15 21:21:12 +08:00

28 lines
666 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "CanReceiveTask.h"
// 一个任务函数C 风格
void Task1(void* param) {
while (true) {
std::cout << "Task1 running\n";
vTaskDelay(1000); // 延时 1000ms
}
}
// 另一个任务函数
void Task2(void* param) {
while (true) {
std::cout << "Task2 running\n";
vTaskDelay(500); // 延时 500ms
}
}
void CanRecive(void)
{
// 创建“任务”,用 std::thread 代替 FreeRTOS 任务
std::thread t1(Task1, nullptr);
std::thread t2(Task2, nullptr);
// 如果想模拟 FreeRTOS通常任务一直运行主函数也可以阻塞
t1.join();
t2.join();
}