XM-01/CAN/XM-01/Core/Src/myCANBusDeal.c
2025-05-30 16:56:41 +08:00

60 lines
2.2 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.

#include "usart.h"
#include "can.h"
#include "gpio.h"
#include "math.h"
#include "rtthread.h"
#include "myCANBusDeal.h"
#include "myEdge_ai_app.h"
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
/* 定义线程栈与控制块(静态分配) */
#define CAN_THREAD_STACK_SIZE 512
static struct rt_thread can_thread;
static rt_uint8_t can_thread_stack[CAN_THREAD_STACK_SIZE];
/* 线程入口函数 */
static void can_thread_entry(void *parameter)
{
while (1)
{
if (CAN_RX_EVENT) // 如果接收标志位被置1则开展逻辑判断
{
rt_kprintf("Receive Succeed !\r\n");
CAN_TX_EVENT = CAN_Send_Msg(CAN_TX_BUFFER, 8); // 发送数据,根据返回值判定发送是否异常
if (CAN_TX_EVENT)
rt_kprintf("Send failed ,please check your data !\r\n"); // 返回1代表数据发送异常
else
rt_kprintf("Send completed !\r\n");
// 清空接收、发送数组保留Rxbuf内容
rt_memset(RxData, 0, sizeof(RxData));
rt_memset(CAN_TX_BUFFER, 0, sizeof(CAN_TX_BUFFER));
rt_thread_mdelay(50);
CAN_RX_EVENT = 0; // 标志位置0等待下一次中断
}
rt_thread_mdelay(50);
}
}
/* 初始化函数,使用静态线程启动 */
int can_thread_init(void)
{
rt_thread_init(&can_thread, // 线程控制块
"can_task", // 名称
can_thread_entry, // 入口函数
RT_NULL, // 参数
&can_thread_stack[0], // 栈起始地址
sizeof(can_thread_stack), // 栈大小
9, // 优先级(高)
10); // 时间片
rt_thread_startup(&can_thread); // 启动线程
return RT_EOK;
}
// INIT_APP_EXPORT(can_thread_init);
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////