Mini_croe_Sick/User/task/mointor.c

44 lines
1.7 KiB
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.

/* Includes ----------------------------------------------------------------- */
#include "task\user_task.h"
#include "bsp\led.h"
#include "bsp\buzzer.h"
#include "device\can.h"
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* Private function --------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
extern CAN_t can;
void Task_Monitor(void *argument) {
(void)argument; // 消除未使用参数的警告
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_MONITOR; // 1000Hz
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
BSP_LED_Set(BSP_LED_RED, BSP_LED_ON, 0);
BSP_LED_Set(BSP_LED_BLUE, BSP_LED_ON, 0);
BSP_Buzzer_Set(0.1, 0.3f);
BSP_Buzzer_Start();
HAL_Delay(300);
BSP_Buzzer_Set(0.5, 0.5f);
HAL_Delay(300);
BSP_Buzzer_Set(0.9, 0.7f);
HAL_Delay(300);
BSP_Buzzer_Stop();
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
// 检测 mailbox 是否存在 0x04
if (can.mailbox.sick == 0x04) {
// 如果检测到 0x04重置 CAN 线程
osThreadTerminate(osThreadGetId()); // 终止当前线程
osThreadNew(Task_Can, NULL, NULL); // 创建新的 CAN 线程
}
// TODO: 监控任务的具体实现
BSP_LED_Set(BSP_LED_GREEN, BSP_LED_TAGGLE, 0);
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
}
}