|
@@ -1,48 +1,20 @@
|
|
-#include "dev_can.h"
|
|
|
|
|
|
+#include "can_task.h"
|
|
#include "J1939.H"
|
|
#include "J1939.H"
|
|
-#include "can.h"
|
|
|
|
-#include "core_cmFunc.h"
|
|
|
|
-#include "dev_can_cali.h"
|
|
|
|
-#include "dev_can_id.h"
|
|
|
|
-#include "hal_math.h"
|
|
|
|
|
|
+#include "can_cali.h"
|
|
|
|
+#include "can_id_deal.h"
|
|
|
|
+#include "can_interface.h"
|
|
#include "iap.h"
|
|
#include "iap.h"
|
|
#include "queue.h"
|
|
#include "queue.h"
|
|
|
|
+#include "utils.h"
|
|
#include <stdint.h>
|
|
#include <stdint.h>
|
|
-#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
queue_entry(pdu_tag, 40) can_rx_queue;
|
|
queue_entry(pdu_tag, 40) can_rx_queue;
|
|
-
|
|
|
|
queue_entry(pdu_tag, 40) can_tx_queue;
|
|
queue_entry(pdu_tag, 40) can_tx_queue;
|
|
|
|
|
|
-uint8_t PGN_00B000H_Ary[20] = {0};
|
|
|
|
-
|
|
|
|
|
|
+uint8_t PGN_00B000H_Ary[20] = {0};
|
|
extern void j1939_msg_push_queue(p_pdu_tag rec_msg);
|
|
extern void j1939_msg_push_queue(p_pdu_tag rec_msg);
|
|
-
|
|
|
|
-uint8_t recv_can_id = 0;
|
|
|
|
-
|
|
|
|
-static uint64_t base_data;
|
|
|
|
-
|
|
|
|
-void data_bit_move(uint8_t start_bit, uint8_t bit_len, uint64_t data)
|
|
|
|
-{
|
|
|
|
- uint64_t mask = 0;
|
|
|
|
- uint64_t source_data = (uint64_t)data;
|
|
|
|
- mask = hal_pow(2, bit_len) - 1;
|
|
|
|
- base_data |= (mask & source_data) << start_bit;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void product_array(uint8_t send_array[8])
|
|
|
|
-{
|
|
|
|
- send_array[0] = (uint8_t)base_data;
|
|
|
|
- send_array[1] = (uint8_t)(base_data >> 8);
|
|
|
|
- send_array[2] = (uint8_t)(base_data >> 16);
|
|
|
|
- send_array[3] = (uint8_t)(base_data >> 24);
|
|
|
|
- send_array[4] = (uint8_t)(base_data >> 32);
|
|
|
|
- send_array[5] = (uint8_t)(base_data >> 40);
|
|
|
|
- send_array[6] = (uint8_t)(base_data >> 48);
|
|
|
|
- send_array[7] = (uint8_t)(base_data >> 56);
|
|
|
|
- base_data = 0;
|
|
|
|
-}
|
|
|
|
|
|
+uint8_t recv_can_id = 0;
|
|
|
|
|
|
uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data)
|
|
uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data)
|
|
{
|
|
{
|
|
@@ -54,77 +26,47 @@ uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data)
|
|
|
|
|
|
if (id > 0x7FF)
|
|
if (id > 0x7FF)
|
|
{
|
|
{
|
|
- response_msg.reg.ide = CAN_Id_Extended;
|
|
|
|
|
|
+ response_msg.reg.ide = CAN_ID_EXT;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- response_msg.reg.ide = CAN_Id_Standard;
|
|
|
|
|
|
+ response_msg.reg.ide = CAN_ID_STD;
|
|
}
|
|
}
|
|
|
|
|
|
-#if 1
|
|
|
|
__disable_irq();
|
|
__disable_irq();
|
|
en_queue(&can_tx_queue, response_msg, result_status);
|
|
en_queue(&can_tx_queue, response_msg, result_status);
|
|
- // result_status = en_queue(&can_tx_queue, response_msg);
|
|
|
|
__enable_irq();
|
|
__enable_irq();
|
|
|
|
|
|
if (result_status != Q_OK)
|
|
if (result_status != Q_OK)
|
|
{
|
|
{
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
-#else
|
|
|
|
- en_queue(can_tx, &response_msg, 1);
|
|
|
|
-#endif
|
|
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
static uint8_t can_tx_frame(pdu_tag can_message)
|
|
static uint8_t can_tx_frame(pdu_tag can_message)
|
|
{
|
|
{
|
|
- uint8_t result = CAN_TxStatus_NoMailBox;
|
|
|
|
- result = can_msg_tx(can_message.id.r, can_message.reg.ide, can_message.data.u8_buf, can_message.reg.dlc);
|
|
|
|
- return result;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// void can_tx_stop(CAN_TypeDef *can_perpiph, u8 mailbox_number)
|
|
|
|
-// {
|
|
|
|
-// can_tx_mail_box_stop(can_perpiph, mailbox_number);
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// QUEUE_STATUS can_tx_process(p_can_queue_tag p_queue)
|
|
|
|
-// {
|
|
|
|
-// u8 mailbox_number = 0;
|
|
|
|
-// u8 query_result = CAN_TxStatus_NoMailBox;
|
|
|
|
-
|
|
|
|
-// if (queue_empty(p_queue))
|
|
|
|
-// return Q_OK;
|
|
|
|
-// mailbox_number = can_tx_frame(p_queue->can_message[p_queue->tail]);
|
|
|
|
-// if (mailbox_number == CAN_TxStatus_NoMailBox)
|
|
|
|
-// return Q_OK;
|
|
|
|
-// query_result = can_tx_mail_box_state(CAN1, mailbox_number);
|
|
|
|
-// if (query_result == CAN_TxStatus_Ok || query_result == CAN_TxStatus_Pending)
|
|
|
|
-// {
|
|
|
|
-// p_queue->tail = (p_queue->tail + 1) % MAX_QSIZE;
|
|
|
|
-// p_queue->count--;
|
|
|
|
-// return Q_OK;
|
|
|
|
-// }
|
|
|
|
-// return Q_ERR;
|
|
|
|
-// }
|
|
|
|
|
|
+
|
|
|
|
+ can_msg_tx(can_message.id.r, can_message.reg.ide, can_message.data.u8_buf, can_message.reg.dlc);
|
|
|
|
+ return 1;
|
|
|
|
+}
|
|
|
|
|
|
void can_tx_callback(void)
|
|
void can_tx_callback(void)
|
|
{
|
|
{
|
|
- pdu_tag tx_data;
|
|
|
|
- // de_queue(can_tx, &tx_data);
|
|
|
|
|
|
+ pdu_tag tx_data;
|
|
QUEUE_STATUS result_status;
|
|
QUEUE_STATUS result_status;
|
|
|
|
|
|
de_queue(&can_tx_queue, tx_data, result_status);
|
|
de_queue(&can_tx_queue, tx_data, result_status);
|
|
|
|
|
|
- if (result_status == Q_OK) // 返回值为1代表读取成功
|
|
|
|
|
|
+ // 返回值为1代表读取成功
|
|
|
|
+ if (result_status == Q_OK)
|
|
{
|
|
{
|
|
can_tx_frame(tx_data);
|
|
can_tx_frame(tx_data);
|
|
- CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
|
|
|
|
|
|
+ CAN_IT_TME_ENABLE();
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- CAN_ITConfig(CAN1, CAN_IT_TME, DISABLE);
|
|
|
|
|
|
+ CAN_IT_TME_DISABLE();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -141,24 +83,12 @@ void can_rx_callback(CanRxMsg rx_message)
|
|
data.id.r = 0x18011801;
|
|
data.id.r = 0x18011801;
|
|
data.reg.dlc = rx_message.DLC;
|
|
data.reg.dlc = rx_message.DLC;
|
|
memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
|
|
memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
|
|
- // en_queue(&can_rx_queue, data);
|
|
|
|
en_queue(&can_rx_queue, data, result);
|
|
en_queue(&can_rx_queue, data, result);
|
|
- // case 0x18DFF4E1:
|
|
|
|
- // data.id.r = 0x18DFF4E1;
|
|
|
|
- // data.reg.dlc = rx_message.DLC;
|
|
|
|
- // memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
|
|
|
|
- // // en_queue(&can_rx_queue, data);
|
|
|
|
- // en_queue(&can_rx_queue, data, result);
|
|
|
|
|
|
+ break;
|
|
case 0x18011802:
|
|
case 0x18011802:
|
|
data.id.r = 0x18011802;
|
|
data.id.r = 0x18011802;
|
|
data.reg.dlc = rx_message.DLC;
|
|
data.reg.dlc = rx_message.DLC;
|
|
memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
|
|
memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
|
|
-#if 1
|
|
|
|
- // en_queue(&can_rx_queue, data);
|
|
|
|
- en_queue(&can_rx_queue, data, result);
|
|
|
|
-#else
|
|
|
|
- en_queue(can_rx, &data, 1);
|
|
|
|
-#endif
|
|
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
pf = (rx_message.ExtId & CAN_PGN_PF) >> 16;
|
|
pf = (rx_message.ExtId & CAN_PGN_PF) >> 16;
|
|
@@ -179,7 +109,7 @@ void can_rx_callback(CanRxMsg rx_message)
|
|
data.reg.dlc = rx_message.DLC;
|
|
data.reg.dlc = rx_message.DLC;
|
|
memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
|
|
memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
|
|
|
|
|
|
- if (data.id.b.pf == CAN_IAP)
|
|
|
|
|
|
+ if (data.id.b.pf == 0xDF)
|
|
{
|
|
{
|
|
en_queue(&can_rx_queue, data, result);
|
|
en_queue(&can_rx_queue, data, result);
|
|
}
|
|
}
|
|
@@ -195,20 +125,18 @@ void can_rx_callback(CanRxMsg rx_message)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
uint8_t tx_flag = 0;
|
|
uint8_t tx_flag = 0;
|
|
|
|
|
|
void can_rx_ctl(pdu_tag rec_msg)
|
|
void can_rx_ctl(pdu_tag rec_msg)
|
|
{
|
|
{
|
|
- // rec_msg.data.u8_buf[0];
|
|
|
|
- // LED2 = !LED2;
|
|
|
|
J1939_TP_TX_Message(0x00B300, 0xE1, PGN_00B000H_Ary, 20, 1);
|
|
J1939_TP_TX_Message(0x00B300, 0xE1, PGN_00B000H_Ary, 20, 1);
|
|
}
|
|
}
|
|
|
|
+
|
|
uint8_t tx_data[8] = {0};
|
|
uint8_t tx_data[8] = {0};
|
|
uint8_t flag = 0;
|
|
uint8_t flag = 0;
|
|
void can_rx_param(pdu_tag rec_msg)
|
|
void can_rx_param(pdu_tag rec_msg)
|
|
{
|
|
{
|
|
- // LED2 = !LED2;
|
|
|
|
-
|
|
|
|
tx_data[0] = rec_msg.data.u8_buf[0];
|
|
tx_data[0] = rec_msg.data.u8_buf[0];
|
|
tx_data[1] = rec_msg.data.u8_buf[1];
|
|
tx_data[1] = rec_msg.data.u8_buf[1];
|
|
tx_data[2] = rec_msg.data.u8_buf[2];
|
|
tx_data[2] = rec_msg.data.u8_buf[2];
|
|
@@ -221,8 +149,6 @@ void can_rx_param(pdu_tag rec_msg)
|
|
{
|
|
{
|
|
flag = 1;
|
|
flag = 1;
|
|
}
|
|
}
|
|
-
|
|
|
|
- // push_can_message_to_queue(rec_msg.id.r, rec_msg.reg.dlc, rec_msg.data.u8_buf);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void can_rx_update(pdu_tag rec_msg)
|
|
void can_rx_update(pdu_tag rec_msg)
|
|
@@ -235,49 +161,31 @@ void can_rx_update(pdu_tag rec_msg)
|
|
}
|
|
}
|
|
|
|
|
|
can_rx_tab can_tab[] = {
|
|
can_rx_tab can_tab[] = {
|
|
- 0x18011802,
|
|
|
|
- can_rx_param,
|
|
|
|
- 0x18011801,
|
|
|
|
- can_rx_ctl,
|
|
|
|
- CAN_IAP,
|
|
|
|
- iap_rec_handler,
|
|
|
|
- CAN_CALI,
|
|
|
|
- can_cali_msg_analysis,
|
|
|
|
|
|
+ {0x18011802, can_rx_param},
|
|
|
|
+ {0x18011801, can_rx_ctl},
|
|
|
|
+ {CAN_IAP, iap_rec_handler},
|
|
|
|
+ {CAN_CALI, can_cali_msg_analysis}
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
-#define REG32(addr) (*(volatile uint32_t *)(uint32_t)(addr))
|
|
|
|
-#define CAN_INTEN(canx) REG32((canx) + 0x14U)
|
|
|
|
-
|
|
|
|
void can_start_send(void)
|
|
void can_start_send(void)
|
|
{
|
|
{
|
|
pdu_tag tx_msg;
|
|
pdu_tag tx_msg;
|
|
QUEUE_STATUS result_status;
|
|
QUEUE_STATUS result_status;
|
|
|
|
|
|
- // if (RESET == CAN_GetITStatus(CAN1, CAN_IT_TME))
|
|
|
|
- if (0 == ((CAN1->IER) & 0x1))
|
|
|
|
|
|
+ if (0 == ((CAN_IER) & 0x1))
|
|
{
|
|
{
|
|
-#if 0
|
|
|
|
- de_queue(can_tx, &tx_msg);
|
|
|
|
- if (can_tx.ret == 1) // 返回值为1代表读取成功
|
|
|
|
- {
|
|
|
|
- can_tx_frame(tx_msg);
|
|
|
|
- CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
|
|
|
|
- }
|
|
|
|
-#else
|
|
|
|
de_queue(&can_tx_queue, tx_msg, result_status);
|
|
de_queue(&can_tx_queue, tx_msg, result_status);
|
|
|
|
|
|
if (result_status == Q_OK) // 返回值为1代表读取成功
|
|
if (result_status == Q_OK) // 返回值为1代表读取成功
|
|
{
|
|
{
|
|
can_tx_frame(tx_msg);
|
|
can_tx_frame(tx_msg);
|
|
- CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
|
|
|
|
|
|
+ CAN_IT_TME_ENABLE();
|
|
}
|
|
}
|
|
-
|
|
|
|
-#endif
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static uint8_t can_rx_process(void)
|
|
|
|
|
|
+static void can_rx_process(void)
|
|
{
|
|
{
|
|
uint8_t i;
|
|
uint8_t i;
|
|
uint8_t flg = 0;
|
|
uint8_t flg = 0;
|
|
@@ -286,12 +194,10 @@ static uint8_t can_rx_process(void)
|
|
|
|
|
|
for (uint8_t j = 0; j < 15; j++)
|
|
for (uint8_t j = 0; j < 15; j++)
|
|
{
|
|
{
|
|
-#if 1
|
|
|
|
__disable_irq();
|
|
__disable_irq();
|
|
-
|
|
|
|
de_queue(&can_rx_queue, rec_msg, result);
|
|
de_queue(&can_rx_queue, rec_msg, result);
|
|
- // result = de_queue(&can_rx_queue, rec_msg);
|
|
|
|
__enable_irq();
|
|
__enable_irq();
|
|
|
|
+
|
|
if (Q_OK == result)
|
|
if (Q_OK == result)
|
|
{
|
|
{
|
|
for (i = 0; i < ARR_SIZE(can_tab); i++)
|
|
for (i = 0; i < ARR_SIZE(can_tab); i++)
|
|
@@ -302,7 +208,7 @@ static uint8_t can_rx_process(void)
|
|
flg = 1;
|
|
flg = 1;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- else if (can_tab[i].id == (rec_msg.id.b.pf << 8 | rec_msg.id.b.ps))
|
|
|
|
|
|
+ else if (can_tab[i].id == (uint32_t)(rec_msg.id.b.pf << 8 | rec_msg.id.b.ps))
|
|
{
|
|
{
|
|
can_tab[i].p_func(rec_msg);
|
|
can_tab[i].p_func(rec_msg);
|
|
flg = 1;
|
|
flg = 1;
|
|
@@ -322,20 +228,6 @@ static uint8_t can_rx_process(void)
|
|
}
|
|
}
|
|
flg = 0;
|
|
flg = 0;
|
|
}
|
|
}
|
|
-#else
|
|
|
|
- de_queue(can_rx, &rec_msg);
|
|
|
|
- if (can_rx.ret == 1) // 返回值为1代表读取成功
|
|
|
|
- {
|
|
|
|
- for (i = 0; i < ARR_SIZE(can_tab); i++)
|
|
|
|
- {
|
|
|
|
- if (can_tab[i].id == rec_msg.id.r)
|
|
|
|
- {
|
|
|
|
- can_tab[i].p_func(rec_msg);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -437,19 +329,10 @@ void can_tx_0x1801000F_message(void)
|
|
void can_tx_0x18010010_message(void)
|
|
void can_tx_0x18010010_message(void)
|
|
{
|
|
{
|
|
uint8_t data[8] = {0};
|
|
uint8_t data[8] = {0};
|
|
- // data_bit_move(0, 8, 1);
|
|
|
|
- // data_bit_move(8, 8, 1);
|
|
|
|
- // data_bit_move(32, 8, 0);
|
|
|
|
- // data_bit_move(40, 8, 0);
|
|
|
|
- // product_array(data);
|
|
|
|
- data[0] = 1;
|
|
|
|
- data[1] = 1;
|
|
|
|
- data[4] = 0;
|
|
|
|
- data[5] = 0;
|
|
|
|
- // push_can_message_to_queue(0x18010010, 8, data);
|
|
|
|
- // data[1] = 5;
|
|
|
|
- // push_can_message_to_queue(0x18010010, 8, data);
|
|
|
|
- // data[1] = 10;
|
|
|
|
|
|
+ data[0] = 1;
|
|
|
|
+ data[1] = 1;
|
|
|
|
+ data[4] = 0;
|
|
|
|
+ data[5] = 0;
|
|
push_can_message_to_queue(0x18010010, 8, data);
|
|
push_can_message_to_queue(0x18010010, 8, data);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -569,14 +452,6 @@ void can_tx_0x1801001D_message(void)
|
|
void can_tx_0x18010023_message(void)
|
|
void can_tx_0x18010023_message(void)
|
|
{
|
|
{
|
|
uint8_t send_data[8] = {0};
|
|
uint8_t send_data[8] = {0};
|
|
- // data[0] = 'A';
|
|
|
|
- // data[1] = 'A';
|
|
|
|
- // data[2] = 'A';
|
|
|
|
- // data[3] = 'A';
|
|
|
|
- // data[4] = 'A';
|
|
|
|
- // data[5] = 'A';
|
|
|
|
- // data[6] = 'A';
|
|
|
|
- // data[7] = 'A';
|
|
|
|
data_bit_move(0, 8, 'A');
|
|
data_bit_move(0, 8, 'A');
|
|
data_bit_move(8, 8, 'A');
|
|
data_bit_move(8, 8, 'A');
|
|
data_bit_move(16, 8, 'A');
|
|
data_bit_move(16, 8, 'A');
|
|
@@ -603,8 +478,8 @@ void can_tx_0x18011802_message(void)
|
|
{
|
|
{
|
|
data[0] = (addr + fdf) & 0xFF;
|
|
data[0] = (addr + fdf) & 0xFF;
|
|
data[1] = (addr + fdf) >> 8;
|
|
data[1] = (addr + fdf) >> 8;
|
|
- data[2] = rand() & 0xFF;
|
|
|
|
- data[3] = rand() >> 8;
|
|
|
|
|
|
+ data[2] = 0xFF;
|
|
|
|
+ data[3] = 8;
|
|
fdf++;
|
|
fdf++;
|
|
if (fdf == 80)
|
|
if (fdf == 80)
|
|
{
|
|
{
|
|
@@ -738,7 +613,7 @@ void send_message(void)
|
|
can_tx_0x18010012_message();
|
|
can_tx_0x18010012_message();
|
|
can_tx_0x18011802_message();
|
|
can_tx_0x18011802_message();
|
|
can_tx_0x18011803_message();
|
|
can_tx_0x18011803_message();
|
|
- // can_tx_0x18011803_2_message();
|
|
|
|
|
|
+ can_tx_0x18011803_2_message();
|
|
can_tx_0x18180003_message();
|
|
can_tx_0x18180003_message();
|
|
can_tx_0x18190007_message();
|
|
can_tx_0x18190007_message();
|
|
}
|
|
}
|
|
@@ -749,9 +624,8 @@ void send_message(void)
|
|
times++;
|
|
times++;
|
|
}
|
|
}
|
|
|
|
|
|
-void dev_can_network_init(void)
|
|
|
|
|
|
+void can_network_init(void)
|
|
{
|
|
{
|
|
- can_init();
|
|
|
|
queue_init(&can_rx_queue);
|
|
queue_init(&can_rx_queue);
|
|
queue_init(&can_tx_queue);
|
|
queue_init(&can_tx_queue);
|
|
can_rx_back_init(can_rx_callback);
|
|
can_rx_back_init(can_rx_callback);
|
|
@@ -761,7 +635,6 @@ void dev_can_network_init(void)
|
|
void can_process(void)
|
|
void can_process(void)
|
|
{
|
|
{
|
|
can_rx_process();
|
|
can_rx_process();
|
|
- // send_message();
|
|
|
|
- // can_tx_0x18190009_message();
|
|
|
|
|
|
+ send_message();
|
|
can_start_send();
|
|
can_start_send();
|
|
-}
|
|
|
|
|
|
+}
|