2024-04-25 22:31:01 +08:00
|
|
|
|
#include "by_can.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
#include "dwt_delay.h"
|
|
|
|
|
|
#include "by_utils.h"
|
|
|
|
|
|
#include "by_debug.h"
|
|
|
|
|
|
|
|
|
|
|
|
by_error_status by_can_send_stdd(uint32_t id, const uint8_t *data, uint8_t len, uint16_t timeout)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
assert(id < 0x7FF);
|
|
|
|
|
|
|
|
|
|
|
|
if (len > 8) {
|
|
|
|
|
|
len = 8;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t transmit_mailbox;
|
|
|
|
|
|
can_tx_message_type tx_message_struct;
|
|
|
|
|
|
tx_message_struct.standard_id = id; /* 设置发送数据帧的 ID=0x400 */
|
|
|
|
|
|
tx_message_struct.extended_id = 0; /* 不设置 */
|
|
|
|
|
|
tx_message_struct.id_type = CAN_ID_STANDARD; /* 发送数据帧类型(标准/扩展):标准数据帧 */
|
|
|
|
|
|
tx_message_struct.frame_type = CAN_TFT_DATA; /* 发送帧类型(远程/数据):数据帧 */
|
|
|
|
|
|
tx_message_struct.dlc = len; /* 发送数据长度(0~8):8 */
|
|
|
|
|
|
memcpy(tx_message_struct.data, data, len); /* 复制发送数据 */
|
|
|
|
|
|
transmit_mailbox = can_message_transmit(CAN1, &tx_message_struct); /* 将以上待发送报文写入发送邮箱并请求发送 */
|
|
|
|
|
|
|
|
|
|
|
|
/* 等待该邮箱发送成功—对应邮箱发送成功标志置起 */
|
2024-05-01 12:16:55 +08:00
|
|
|
|
if (timeout) {
|
|
|
|
|
|
while (can_transmit_status_get(CAN1, (can_tx_mailbox_num_type)transmit_mailbox) != CAN_TX_STATUS_SUCCESSFUL) {
|
|
|
|
|
|
// LOGD("CAN#SEND: timeout=%d", timeout);
|
|
|
|
|
|
if (0 == timeout--) {
|
|
|
|
|
|
LOGW("CAN#TIMEOUT: ID=0x%x", id);
|
|
|
|
|
|
|
|
|
|
|
|
return BY_ERROR;
|
|
|
|
|
|
}
|
|
|
|
|
|
DWT_Delay(10);
|
2024-04-25 22:31:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return BY_SUCCESS;
|
|
|
|
|
|
}
|