|
@@ -1,5 +1,7 @@
|
|
|
#include "dev_can.h"
|
|
|
+#include "J1939.H"
|
|
|
#include "core_cmFunc.h"
|
|
|
+#include "dev_can_id.h"
|
|
|
#include "dev_iap.h"
|
|
|
#include "hal_can.h"
|
|
|
#include "hal_conf.h"
|
|
@@ -8,6 +10,14 @@
|
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
|
|
|
|
+queue_entry(pdu_tag, 40) can_rx_queue;
|
|
|
+
|
|
|
+queue_entry(pdu_tag, 40) can_tx_queue;
|
|
|
+
|
|
|
+uint8_t PGN_00B000H_Ary[20] = {0};
|
|
|
+
|
|
|
+extern void j1939_msg_push_queue(p_pdu_tag rec_msg);
|
|
|
+
|
|
|
double pow_branch(double x, long long N)
|
|
|
{
|
|
|
double ans = 1.0;
|
|
@@ -77,7 +87,8 @@ uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data)
|
|
|
|
|
|
#if 1
|
|
|
__disable_irq();
|
|
|
- result_status = en_queue(&can_tx_queue, response_msg);
|
|
|
+ en_queue(&can_tx_queue, response_msg, result_status);
|
|
|
+ // result_status = en_queue(&can_tx_queue, response_msg);
|
|
|
__enable_irq();
|
|
|
|
|
|
if (result_status != Q_OK)
|
|
@@ -126,7 +137,11 @@ void can_tx_callback(void)
|
|
|
{
|
|
|
pdu_tag tx_data;
|
|
|
// de_queue(can_tx, &tx_data);
|
|
|
- if (de_queue(&can_tx_queue, tx_data) == Q_OK) // 返回值为1代表读取成功
|
|
|
+ QUEUE_STATUS result_status;
|
|
|
+
|
|
|
+ de_queue(&can_tx_queue, tx_data, result_status);
|
|
|
+
|
|
|
+ if (result_status == Q_OK) // 返回值为1代表读取成功
|
|
|
{
|
|
|
can_tx_frame(tx_data);
|
|
|
CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
|
|
@@ -139,27 +154,32 @@ void can_tx_callback(void)
|
|
|
|
|
|
void can_rx_callback(CanRxMsg rx_message)
|
|
|
{
|
|
|
- pdu_tag data;
|
|
|
- uint8_t ps;
|
|
|
- uint8_t pf;
|
|
|
+ pdu_tag data;
|
|
|
+ uint8_t ps;
|
|
|
+ uint8_t pf;
|
|
|
+ QUEUE_STATUS result;
|
|
|
+
|
|
|
switch (rx_message.ExtId)
|
|
|
{
|
|
|
case 0x18011801:
|
|
|
data.id.r = 0x18011801;
|
|
|
data.reg.dlc = rx_message.DLC;
|
|
|
memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
|
|
|
- en_queue(&can_rx_queue, data);
|
|
|
- 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);
|
|
|
+ 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);
|
|
|
case 0x18011802:
|
|
|
data.id.r = 0x18011802;
|
|
|
data.reg.dlc = 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);
|
|
|
+ en_queue(&can_rx_queue, data, result);
|
|
|
#else
|
|
|
en_queue(can_rx, &data, 1);
|
|
|
#endif
|
|
@@ -171,23 +191,31 @@ void can_rx_callback(CanRxMsg rx_message)
|
|
|
data.id.r = rx_message.ExtId;
|
|
|
recv_can_id = data.id.b.sa;
|
|
|
memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
|
|
|
-#if 1
|
|
|
- en_queue(&can_rx_queue, data);
|
|
|
-#else
|
|
|
- en_queue(can_rx, &data, 1);
|
|
|
-#endif
|
|
|
+ en_queue(&can_rx_queue, data, result);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // ps = (rx_message.ExtId & CAN_PGN_PS) >> 8;
|
|
|
- // if (ps == 0xF4)
|
|
|
- // {
|
|
|
- // }
|
|
|
-#if 1
|
|
|
- en_queue(&can_rx_queue, data);
|
|
|
-#else
|
|
|
- en_queue(can_rx, &data, 1);
|
|
|
-#endif
|
|
|
+ ps = (rx_message.ExtId & CAN_PGN_PS) >> 8;
|
|
|
+ if (ps == 0xF4)
|
|
|
+ {
|
|
|
+ data.id.r = rx_message.ExtId;
|
|
|
+ recv_can_id = data.id.b.sa;
|
|
|
+ data.reg.dlc = rx_message.DLC;
|
|
|
+ memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
|
|
|
+
|
|
|
+ if (data.id.b.pf == g_can_iap)
|
|
|
+ {
|
|
|
+ en_queue(&can_rx_queue, data, result);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ en_queue(&can_rx_queue, data, result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ en_queue(&can_rx_queue, data, result);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -197,7 +225,7 @@ void can_rx_ctl(pdu_tag rec_msg)
|
|
|
{
|
|
|
// rec_msg.data.u8_buf[0];
|
|
|
// LED2 = !LED2;
|
|
|
- tx_flag = 1;
|
|
|
+ J1939_TP_TX_Message(0x00B300, 0xE1, PGN_00B000H_Ary, 20, 1);
|
|
|
}
|
|
|
uint8_t tx_data[8] = {0};
|
|
|
uint8_t flag = 0;
|
|
@@ -230,12 +258,13 @@ void can_rx_update(pdu_tag rec_msg)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#define ota_id 0xDF
|
|
|
can_rx_tab can_tab[] = {
|
|
|
0x18011802,
|
|
|
can_rx_param,
|
|
|
0x18011801,
|
|
|
can_rx_ctl,
|
|
|
- 0x18DFF4E1,
|
|
|
+ ota_id,
|
|
|
iap_rec_handler,
|
|
|
|
|
|
};
|
|
@@ -245,8 +274,10 @@ can_rx_tab can_tab[] = {
|
|
|
|
|
|
void can_start_send(void)
|
|
|
{
|
|
|
- pdu_tag tx_msg;
|
|
|
+ pdu_tag tx_msg;
|
|
|
+ QUEUE_STATUS result_status;
|
|
|
|
|
|
+ // if (RESET == CAN_GetITStatus(CAN1, CAN_IT_TME))
|
|
|
if (0 == ((CAN1->IER) & 0x1))
|
|
|
{
|
|
|
#if 0
|
|
@@ -257,7 +288,9 @@ void can_start_send(void)
|
|
|
CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
|
|
|
}
|
|
|
#else
|
|
|
- if (de_queue(&can_tx_queue, tx_msg) == Q_OK) // 返回值为1代表读取成功
|
|
|
+ de_queue(&can_tx_queue, tx_msg, result_status);
|
|
|
+
|
|
|
+ if (result_status == Q_OK) // 返回值为1代表读取成功
|
|
|
{
|
|
|
can_tx_frame(tx_msg);
|
|
|
CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
|
|
@@ -278,7 +311,9 @@ static uint8_t can_rx_process(void)
|
|
|
{
|
|
|
#if 1
|
|
|
__disable_irq();
|
|
|
- result = de_queue(&can_rx_queue, rec_msg);
|
|
|
+
|
|
|
+ de_queue(&can_rx_queue, rec_msg, result);
|
|
|
+ // result = de_queue(&can_rx_queue, rec_msg);
|
|
|
__enable_irq();
|
|
|
if (Q_OK == result)
|
|
|
{
|
|
@@ -306,7 +341,7 @@ static uint8_t can_rx_process(void)
|
|
|
|
|
|
if (flg == 0)
|
|
|
{
|
|
|
- // j1939_msg_push_queue(rec_msg);
|
|
|
+ j1939_msg_push_queue(&rec_msg);
|
|
|
}
|
|
|
flg = 0;
|
|
|
}
|
|
@@ -640,6 +675,28 @@ void can_tx_0x18011803_2_message(void)
|
|
|
push_can_message_to_queue(0x18011803, 8, data);
|
|
|
}
|
|
|
|
|
|
+void can_tx_0x18180003_message(void)
|
|
|
+{
|
|
|
+ uint8_t data[8] = {0};
|
|
|
+ data_bit_move(0, 16, 0);
|
|
|
+ data_bit_move(16, 16, 0x2710);
|
|
|
+ data_bit_move(32, 16, 0x4E20);
|
|
|
+ data_bit_move(48, 16, 0x7530);
|
|
|
+ product_array(data);
|
|
|
+ push_can_message_to_queue(0x18190006, 8, data);
|
|
|
+}
|
|
|
+
|
|
|
+void can_tx_0x18190007_message(void)
|
|
|
+{
|
|
|
+ uint8_t data[8] = {0};
|
|
|
+ data_bit_move(0, 16, 0xDFFF);
|
|
|
+ data_bit_move(16, 16, 0xF000);
|
|
|
+ data_bit_move(32, 16, 0xE800);
|
|
|
+ data_bit_move(48, 16, 0xE13D);
|
|
|
+ product_array(data);
|
|
|
+ push_can_message_to_queue(0x18190005, 8, data);
|
|
|
+}
|
|
|
+
|
|
|
void send_message(void)
|
|
|
{
|
|
|
static volatile uint8_t times = 0;
|
|
@@ -694,6 +751,8 @@ void send_message(void)
|
|
|
can_tx_0x18011802_message();
|
|
|
can_tx_0x18011803_message();
|
|
|
// can_tx_0x18011803_2_message();
|
|
|
+ can_tx_0x18180003_message();
|
|
|
+ can_tx_0x18190007_message();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -705,6 +764,8 @@ void send_message(void)
|
|
|
void dev_can_network_init(void)
|
|
|
{
|
|
|
hal_can_init();
|
|
|
+ queue_init(&can_rx_queue);
|
|
|
+ queue_init(&can_tx_queue);
|
|
|
hal_can_rx_back_init(can_rx_callback);
|
|
|
hal_can_tx_back_init(can_tx_callback);
|
|
|
}
|
|
@@ -712,6 +773,6 @@ void dev_can_network_init(void)
|
|
|
void can_process(void)
|
|
|
{
|
|
|
can_rx_process();
|
|
|
- send_message();
|
|
|
+ // send_message();
|
|
|
can_start_send();
|
|
|
}
|