feat(CAN): 实现多节点CAN总线通信与节点ID管理功能

- 添加CAN调试宏定义,支持条件编译调试信息输出
- 实现节点ID相关功能,包括构建CAN ID、消息过滤、获取/设置节点ID
- 支持Flash存储节点ID,提供加载和保存功能
- 实现节点ID设置和查询命令处理
- 更新CANFD发送函数使用节点ID构建发送ID
- 添加消息过滤逻辑,只处理目标节点的消息
- 重构DMA中断服务程序,优化数据传输处理
- 替换printf为调试宏,便于生产环境控制调试输出
This commit is contained in:
cbb
2026-03-15 02:38:50 +08:00
parent 2b93a4537c
commit 9f56ab394e
10 changed files with 751 additions and 461 deletions
+15 -14
View File
@@ -44,6 +44,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "motor.h"
#include <cstdio>
// SLEEP 调试宏定义
#if SLEEP_DEBUG
#define SLEEP_DEBUG_PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define SLEEP_DEBUG_PRINT(fmt, ...) ((void)0)
#endif
volatile static uint32_t delay;
extern CAN_transmiter CAN0_transmiter;
extern FlashEEPROM flashEEP;
@@ -131,7 +138,7 @@ void app_prepare_deep_sleep(bool save_data) {
if (save_data) {
flashEEP.save_system_config(true);
}
// 将SIT1044设置为低功耗待机模式
// 将 SIT1044 设置为低功耗待机模式
// CAN0_transmiter.CAN_Sleep();
motor_sleep();
// 在睡眠前调整看门狗超时时间为最大值,使其在唤醒前不会触发
@@ -140,7 +147,7 @@ void app_prepare_deep_sleep(bool save_data) {
fwdgt_write_disable();
__disable_irq();
// 遍历最后一个数字,后一个地址写+1
// 遍历最后一个数字,后一个地址写 +1
for (u32 address = SLEEP_CONFIG_END - SIZE_U32;
address >= SLEEP_CONFIG_START; address -= SIZE_U32) { // 遍历睡眠存储区
volatile u32 *flash_ptr = (volatile u32 *)address;
@@ -149,9 +156,7 @@ void app_prepare_deep_sleep(bool save_data) {
address > SLEEP_CONFIG_START) { // 空数据且未到头跳过
continue;
} else { // 有数据的话读取
#if SLEEP_DEBUG
printf("app sleep found %08x at %08x\r\n", sleep_enable, address);
#endif
SLEEP_DEBUG_PRINT("app sleep found %08x at %08x\r\n", sleep_enable, address);
if (address == SLEEP_CONFIG_END - SIZE_U32) {
fmc_unlock();
fmc_state_enum fmc_status =
@@ -164,27 +169,23 @@ void app_prepare_deep_sleep(bool save_data) {
address = SLEEP_CONFIG_START - SIZE_U32; // 重新开始写入
}
address += SIZE_U32;
#if SLEEP_DEBUG
printf("app sleep prepare write %08x at %08x\r\n", SLEEP_ENABLE,
SLEEP_DEBUG_PRINT("app sleep prepare write %08x at %08x\r\n", SLEEP_ENABLE,
address);
#endif
fmc_state_enum fmc_status =
write_ADDRESS(address, SLEEP_ENABLE); // 写入数据
#if SLEEP_DEBUG
volatile u32 *flash_ptr = (volatile u32 *)address;
u32 sleep_check = *flash_ptr;
printf("app sleep wrote %08x at %08x\r\n", sleep_check, address);
SLEEP_DEBUG_PRINT("app sleep wrote %08x at %08x\r\n", sleep_check, address);
#endif
if (fmc_status != FMC_READY) { // 写入失败报错
flashEEP.EEPROMStatus = FLASH_EEPROM_WRITE_ERROR;
#if SLEEP_DEBUG
printf("app wrote %08x at %08x ERROR\r\n", SLEEP_ENABLE,
SLEEP_DEBUG_PRINT("app wrote %08x at %08x ERROR\r\n", SLEEP_ENABLE,
address);
#endif
return;
}
break;
}
}
jumpToBOOT(); // 跳转到bootloader正式休眠,进入低功耗待机模式
}
jumpToBOOT(); // 跳转到 bootloader 正式休眠,进入低功耗待机模式
}