修改can,添加看门狗monitor
This commit is contained in:
parent
9f7d7820ae
commit
e0367287ca
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"ads8864.h": "c"
|
"ads8864.h": "c",
|
||||||
|
"can.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because one or more lines are too long
@ -2,16 +2,11 @@
|
|||||||
#include "device/can.h"
|
#include "device/can.h"
|
||||||
#include "stm32f3xx_hal.h"
|
#include "stm32f3xx_hal.h"
|
||||||
// CAN 调试结构体实例
|
// CAN 调试结构体实例
|
||||||
can_t can_debug = {
|
|
||||||
.TxData = {0},
|
|
||||||
.TxID = 0x023,
|
|
||||||
.TxStatus = 0,
|
|
||||||
.DebugCounter = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
// 初始化 CAN
|
// 初始化 CAN
|
||||||
void CAN_Init(CAN_HandleTypeDef *hcan_Cur)
|
void CAN_Init(CAN_HandleTypeDef *hcan_Cur)
|
||||||
{
|
{ //重置CAN
|
||||||
|
HAL_CAN_Init(hcan_Cur); // 初始化CAN
|
||||||
// 仅初始化CAN,不配置接收过滤器
|
// 仅初始化CAN,不配置接收过滤器
|
||||||
HAL_CAN_Start(hcan_Cur); // 开启CAN
|
HAL_CAN_Start(hcan_Cur); // 开启CAN
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,12 @@
|
|||||||
|
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
/* Private define ----------------------------------------------------------- */
|
/* Private define ----------------------------------------------------------- */
|
||||||
|
can_t can_debug = {
|
||||||
|
.TxData = {0},
|
||||||
|
.TxID = 0x023,
|
||||||
|
.TxStatus = 0,
|
||||||
|
.DebugCounter = 0
|
||||||
|
};
|
||||||
|
|
||||||
/* Private variables -------------------------------------------------------- */
|
/* Private variables -------------------------------------------------------- */
|
||||||
|
|
||||||
|
@ -1,20 +1,36 @@
|
|||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
#include "device\can.h"
|
#include "device\can.h" // 确保包含 CAN_Debug_t 的定义
|
||||||
|
|
||||||
#include "task\user_task.h"
|
#include "task\user_task.h"
|
||||||
#include "bsp\led.h"
|
#include "bsp\led.h"
|
||||||
|
#include "cmsis_os.h" // 用于线程操作
|
||||||
|
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
/* Private define ----------------------------------------------------------- */
|
/* Private define ----------------------------------------------------------- */
|
||||||
/* Private macro ------------------------------------------------------------ */
|
/* Private macro ------------------------------------------------------------ */
|
||||||
/* Private variables -------------------------------------------------------- */
|
/* Private variables -------------------------------------------------------- */
|
||||||
|
extern can_t can_debug; // 引用 CAN 调试结构体
|
||||||
|
|
||||||
/* Private function --------------------------------------------------------- */
|
/* Private function --------------------------------------------------------- */
|
||||||
/* Exported functions ------------------------------------------------------- */
|
/* Exported functions ------------------------------------------------------- */
|
||||||
void Task_Monitor(void *argument) {
|
void Task_Monitor(void *argument) {
|
||||||
(void)argument; // 消除未使用参数的警告
|
(void)argument; // 消除未使用参数的警告
|
||||||
|
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_MONITOR; // 100Hz
|
||||||
|
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
||||||
|
|
||||||
|
uint32_t last_debug_counter = 0; // 上一次的 DebugCounter 值
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||||
BSP_LED_SET(BSP_LED1, BSP_LED_TAGGLE); // 切换 LED 状态
|
BSP_LED_SET(BSP_LED1, BSP_LED_TAGGLE); // 切换 LED 状态
|
||||||
HAL_Delay(1000); // 延时 1 秒
|
// 检查 DebugCounter 是否增加
|
||||||
|
if (can_debug.DebugCounter == last_debug_counter) {
|
||||||
|
// 如果 DebugCounter 没有增加,说明 Task_Can 可能卡住
|
||||||
|
osThreadTerminate(task_runtime.thread.can); // 终止 Task_Can 线程
|
||||||
|
task_runtime.thread.can = osThreadNew(Task_Can, NULL, NULL); // 重启 Task_Can 线程
|
||||||
|
} else {
|
||||||
|
// 如果 DebugCounter 增加,更新 last_debug_counter
|
||||||
|
last_debug_counter = can_debug.DebugCounter;
|
||||||
|
}
|
||||||
|
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user