fix(CAN): 使用DMA优化CAN通信数据收发

重新配置CAN引脚映射并实现基于DMA的数据收发机制,提升通信效率。增加了DMA通道4和5的中断处理函数,用于接收和发送CAN消息。修改了CAN发送函数以支持DMA传输,并去除了原有的轮询等待机制。

feat(ADC): 重新实现ADC与DMA初始化配置
将ADC和DMA的配置迁移至ADC.cpp文件中,完善了DMA循环采样模式配置及ADC多通道扫描功能。删除了initial.cpp中重复的初始化代码,并修正了相关头文件包含。

chore(headers): 清理冗余头文件引用
多个源文件中删除了不必要的标准库和硬件无关头文件引用,减少编译依赖,提高代码清晰度。
This commit is contained in:
cbb
2025-11-01 20:29:11 +08:00
parent 867a37ff79
commit 71a92fa68e
12 changed files with 258 additions and 171 deletions
+15 -14
View File
@@ -1,7 +1,6 @@
#include "Timer.h"
#include "Can.h"
#include "DengFOC.h"
#include "ang_sensor.h"
#include "Timer.h"
#include "adc.h"
#include "gd32c10x.h"
@@ -9,8 +8,6 @@
#include "gd32c10x_misc.h"
#include "gd32c10x_rcu.h"
#include "gd32c10x_timer.h"
#include "systick.h"
#include <cstdio>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
@@ -176,40 +173,43 @@ void TIMER2_IRQHandler(void) {
// 每100us执行一次的操作
sampler.update_current();
// 每1ms执行的代码 (100us * 10 = 1ms)
if (total_us100_counter >= 10) {
// 每1ms执行的代码
total_us100_counter = 0; // 重置计数器
// 设置CAN发送标志
CAN0_transmiter.can0_send_flag = SET;
if (sampler.get_current('U') > 2000 ||
sampler.get_current('V') > 2000 ||
sampler.get_current('W') > 2000) {
FOC.over_current++;
} else {
FOC.over_current = 0;
}
// 更新各种传感器数据
sampler.update_mcu_temp();
sampler.update_drv_temp();
sampler.update_vbus_voltage();
// 每10ms执行的代码 (1ms * 10 = 10ms)
// 停机判断及冷却
if (FOC.over_current > 10) {
FOC.is_shut_down = 10;
}
static u8 ms10_counter = 0;
ms10_counter++;
if (ms10_counter >= 10) {
ms10_counter = 0;
// 可以添加每10ms执行的代码
// 每100ms执行的代码 (10ms * 10 = 100ms)
static u8 ms100_counter = 0;
ms100_counter++;
if (ms100_counter >= 10) {
ms100_counter = 0;
// 可以添加每100ms执行的代码
// if (sampler.get_current('U') > 1.0 ||
// sampler.get_current('V') > 1.0 ||
// sampler.get_current('W') > 1.0) {
// if (FOC.is_shut_down == 0) {
// FOC.shut_down();
// }
// }
// 每1s执行的代码 (100ms * 10 = 1s)
static u8 sec_counter = 0;
sec_counter++;
if (sec_counter >= 10) {
@@ -233,6 +233,7 @@ void TIMER3_IRQHandler(void) {
timer_interrupt_flag_clear(TIMER3, TIMER_INT_UP);
static u8 count = 0;
count++;
if (FOC.is_shut_down > 0)
FOC.is_shut_down--;
else