|
@@ -50,6 +50,11 @@
|
|
#define ADDRESS_CLAIM_TX 1 /**< 进入地址竞争发送处理模式*/
|
|
#define ADDRESS_CLAIM_TX 1 /**< 进入地址竞争发送处理模式*/
|
|
#define ADDRESS_CLAIM_RX 2 /**< 进入地址竞争接受处理模式*/
|
|
#define ADDRESS_CLAIM_RX 2 /**< 进入地址竞争接受处理模式*/
|
|
|
|
|
|
|
|
+// queue_entry(J1939_MESSAGE, 10)
|
|
|
|
+// j1939_rx_queue;
|
|
|
|
+
|
|
|
|
+extern uint8_t PGN_00B000H_Ary[20];
|
|
|
|
+
|
|
// 全局变量。
|
|
// 全局变量。
|
|
/** 设备的标称符
|
|
/** 设备的标称符
|
|
*
|
|
*
|
|
@@ -111,6 +116,9 @@ J1939_MESSAGE TXQueue_4[J1939_TX_QUEUE_SIZE];
|
|
|
|
|
|
struct Request_List REQUEST_LIST;
|
|
struct Request_List REQUEST_LIST;
|
|
|
|
|
|
|
|
+// #define REQUEST_PGN_MAX (10)
|
|
|
|
+// struct Request_List RequestListArray[REQUEST_PGN_MAX];
|
|
|
|
+
|
|
#if J1939_TP_RX_TX
|
|
#if J1939_TP_RX_TX
|
|
// TP协议全局变量
|
|
// TP协议全局变量
|
|
J1939_TP_Flags J1939_TP_Flags_t;
|
|
J1939_TP_Flags J1939_TP_Flags_t;
|
|
@@ -422,6 +430,7 @@ j1939_uint8_t J1939_Send_Message(J1939_MESSAGE *MsgPtr, CAN_NODE _Can_Node)
|
|
void j1939_msg_push_queue(p_pdu_tag rec_msg)
|
|
void j1939_msg_push_queue(p_pdu_tag rec_msg)
|
|
{
|
|
{
|
|
J1939_MESSAGE _msg;
|
|
J1939_MESSAGE _msg;
|
|
|
|
+ QUEUE_STATUS status;
|
|
|
|
|
|
_msg.Mxe.DataPage = rec_msg->id.b.dp;
|
|
_msg.Mxe.DataPage = rec_msg->id.b.dp;
|
|
_msg.Mxe.Priority = rec_msg->id.b.p;
|
|
_msg.Mxe.Priority = rec_msg->id.b.p;
|
|
@@ -435,7 +444,7 @@ void j1939_msg_push_queue(p_pdu_tag rec_msg)
|
|
{
|
|
{
|
|
_msg.Mxe.Data[index] = rec_msg->data.u8_buf[index];
|
|
_msg.Mxe.Data[index] = rec_msg->data.u8_buf[index];
|
|
}
|
|
}
|
|
- // en_queue(&j1939_rx_queue, _msg);
|
|
|
|
|
|
+ en_queue(&j1939_rx_queue, _msg, status);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -486,7 +495,7 @@ void J1939_Initialization()
|
|
REQUEST_LIST.update = J1939_NULL;
|
|
REQUEST_LIST.update = J1939_NULL;
|
|
REQUEST_LIST.lenght = 0;
|
|
REQUEST_LIST.lenght = 0;
|
|
REQUEST_LIST.Can_Node = Select_CAN_NODE_Null;
|
|
REQUEST_LIST.Can_Node = Select_CAN_NODE_Null;
|
|
- REQUEST_LIST.next = J1939_NULL;
|
|
|
|
|
|
+ // REQUEST_LIST.next = J1939_NULL;
|
|
/*将TP协议置为空闲*/
|
|
/*将TP协议置为空闲*/
|
|
#if J1939_TP_RX_TX
|
|
#if J1939_TP_RX_TX
|
|
J1939_TP_Flags_t.state = J1939_TP_NULL;
|
|
J1939_TP_Flags_t.state = J1939_TP_NULL;
|
|
@@ -506,6 +515,26 @@ void J1939_Initialization()
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#define PGN_00B000 0x00B000
|
|
|
|
+
|
|
|
|
+void PGN0_ResponseDataUpdate(void)
|
|
|
|
+{
|
|
|
|
+ PGN_00B000H_Ary[0] = 1;
|
|
|
|
+ PGN_00B000H_Ary[1] = 1;
|
|
|
|
+ PGN_00B000H_Ary[2] = 1;
|
|
|
|
+ PGN_00B000H_Ary[3] = 1;
|
|
|
|
+ PGN_00B000H_Ary[4] = 1;
|
|
|
|
+ PGN_00B000H_Ary[5] = 1;
|
|
|
|
+ PGN_00B000H_Ary[5] = 1;
|
|
|
|
+ PGN_00B000H_Ary[6] = 1;
|
|
|
|
+ PGN_00B000H_Ary[7] = 1;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void J1939_InitResponsePGN(void)
|
|
|
|
+{
|
|
|
|
+ J1939_Create_Response(PGN_00B000H_Ary, 23, PGN_00B000, PGN0_ResponseDataUpdate, Select_CAN_NODE_1);
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @note 这个函数被调用,当设备产生CAN中断(可能是接受中断,也可能是发送中断)\n
|
|
* @note 这个函数被调用,当设备产生CAN中断(可能是接受中断,也可能是发送中断)\n
|
|
首先我们要清除中断标识位\n
|
|
首先我们要清除中断标识位\n
|
|
@@ -545,24 +574,33 @@ void J1939_ISR(void)
|
|
void J1939_TP_Poll();
|
|
void J1939_TP_Poll();
|
|
void J1939_Poll()
|
|
void J1939_Poll()
|
|
{
|
|
{
|
|
|
|
+ static j1939_uint8_t gpn_init_flg = 0;
|
|
|
|
+
|
|
|
|
+ if (!gpn_init_flg)
|
|
|
|
+ {
|
|
|
|
+ gpn_init_flg = 1;
|
|
|
|
+ queue_init(&j1939_rx_queue);
|
|
|
|
+ J1939_Initialization();
|
|
|
|
+ J1939_InitResponsePGN();
|
|
|
|
+ }
|
|
// 我们必须调用J1939_ReceiveMessages接受函数,在时间被重置为0之前。
|
|
// 我们必须调用J1939_ReceiveMessages接受函数,在时间被重置为0之前。
|
|
#if J1939_POLL_ECAN == J1939_TRUE
|
|
#if J1939_POLL_ECAN == J1939_TRUE
|
|
Can_Node = Select_CAN_NODE_1;
|
|
Can_Node = Select_CAN_NODE_1;
|
|
J1939_Address = NodeAddress_1;
|
|
J1939_Address = NodeAddress_1;
|
|
J1939_ReceiveMessages();
|
|
J1939_ReceiveMessages();
|
|
- J1939_TransmitMessages();
|
|
|
|
- Can_Node = Select_CAN_NODE_2;
|
|
|
|
- J1939_Address = NodeAddress_2;
|
|
|
|
- J1939_ReceiveMessages();
|
|
|
|
- J1939_TransmitMessages();
|
|
|
|
- Can_Node = Select_CAN_NODE_3;
|
|
|
|
- J1939_Address = NodeAddress_3;
|
|
|
|
- J1939_ReceiveMessages();
|
|
|
|
- J1939_TransmitMessages();
|
|
|
|
- Can_Node = Select_CAN_NODE_4;
|
|
|
|
- J1939_Address = NodeAddress_4;
|
|
|
|
- J1939_ReceiveMessages();
|
|
|
|
- J1939_TransmitMessages();
|
|
|
|
|
|
+ // J1939_TransmitMessages();
|
|
|
|
+ // Can_Node = Select_CAN_NODE_2;
|
|
|
|
+ // J1939_Address = NodeAddress_2;
|
|
|
|
+ // J1939_ReceiveMessages();
|
|
|
|
+ // J1939_TransmitMessages();
|
|
|
|
+ // Can_Node = Select_CAN_NODE_3;
|
|
|
|
+ // J1939_Address = NodeAddress_3;
|
|
|
|
+ // J1939_ReceiveMessages();
|
|
|
|
+ // J1939_TransmitMessages();
|
|
|
|
+ // Can_Node = Select_CAN_NODE_4;
|
|
|
|
+ // J1939_Address = NodeAddress_4;
|
|
|
|
+ // J1939_ReceiveMessages();
|
|
|
|
+ // J1939_TransmitMessages();
|
|
#if J1939_TP_RX_TX
|
|
#if J1939_TP_RX_TX
|
|
J1939_TP_Poll();
|
|
J1939_TP_Poll();
|
|
#endif // J1939_TP_RX_TX
|
|
#endif // J1939_TP_RX_TX
|
|
@@ -1128,7 +1166,11 @@ void J1939_TP_DT_Packet_send(void)
|
|
}
|
|
}
|
|
|
|
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
- J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
|
|
+ // J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
+ {
|
|
|
|
+ _msg.Mxe.SourceAddress = J1939_Address;
|
|
|
|
+ Port_CAN_Transmit(&_msg);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -1164,7 +1206,12 @@ void J1939_CM_Start(void)
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
|
|
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
- J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
|
|
+ // J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
+
|
|
|
|
+ {
|
|
|
|
+ _msg.Mxe.SourceAddress = J1939_Address;
|
|
|
|
+ Port_CAN_Transmit(&_msg);
|
|
|
|
+ }
|
|
|
|
|
|
/*刷新等待时间,触发下一个步骤()*/
|
|
/*刷新等待时间,触发下一个步骤()*/
|
|
TP_TX_MSG.time = J1939_TP_T3;
|
|
TP_TX_MSG.time = J1939_TP_T3;
|
|
@@ -1195,7 +1242,11 @@ void J1939_TP_TX_Abort(void)
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
|
|
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
- J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
|
|
+ // J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
+ {
|
|
|
|
+ _msg.Mxe.SourceAddress = J1939_Address;
|
|
|
|
+ Port_CAN_Transmit(&_msg);
|
|
|
|
+ }
|
|
/*结束发送*/
|
|
/*结束发送*/
|
|
TP_TX_MSG.state = J1939_TX_DONE;
|
|
TP_TX_MSG.state = J1939_TX_DONE;
|
|
}
|
|
}
|
|
@@ -1224,7 +1275,11 @@ void J1939_TP_RX_Abort(void)
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
|
|
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
- J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
|
|
+ // J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
+ {
|
|
|
|
+ _msg.Mxe.SourceAddress = J1939_Address;
|
|
|
|
+ Port_CAN_Transmit(&_msg);
|
|
|
|
+ }
|
|
/*结束发送*/
|
|
/*结束发送*/
|
|
TP_RX_MSG.state = J1939_RX_DONE;
|
|
TP_RX_MSG.state = J1939_RX_DONE;
|
|
}
|
|
}
|
|
@@ -1303,7 +1358,11 @@ void J1939_read_DT_Packet()
|
|
_msg.Mxe.Data[6] = (j1939_uint8_t)(pgn_num >> 8 & 0xff);
|
|
_msg.Mxe.Data[6] = (j1939_uint8_t)(pgn_num >> 8 & 0xff);
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
- J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
|
|
+ // J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
+ {
|
|
|
|
+ _msg.Mxe.SourceAddress = J1939_Address;
|
|
|
|
+ Port_CAN_Transmit(&_msg);
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
if (TP_RX_MSG.packets_total > TP_RX_MSG.packets_ok_num)
|
|
if (TP_RX_MSG.packets_total > TP_RX_MSG.packets_ok_num)
|
|
@@ -1320,7 +1379,11 @@ void J1939_read_DT_Packet()
|
|
_msg.Mxe.Data[6] = (j1939_uint8_t)(pgn_num >> 8 & 0xff);
|
|
_msg.Mxe.Data[6] = (j1939_uint8_t)(pgn_num >> 8 & 0xff);
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
- J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
|
|
+ // J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
+ {
|
|
|
|
+ _msg.Mxe.SourceAddress = J1939_Address;
|
|
|
|
+ Port_CAN_Transmit(&_msg);
|
|
|
|
+ }
|
|
TP_RX_MSG.state = J1939_TP_RX_DATA_WAIT;
|
|
TP_RX_MSG.state = J1939_TP_RX_DATA_WAIT;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -1334,7 +1397,11 @@ void J1939_read_DT_Packet()
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
|
|
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
- J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
|
|
+ // J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
+ {
|
|
|
|
+ _msg.Mxe.SourceAddress = J1939_Address;
|
|
|
|
+ Port_CAN_Transmit(&_msg);
|
|
|
|
+ }
|
|
TP_RX_MSG.state = J1939_TP_RX_DATA_WAIT;
|
|
TP_RX_MSG.state = J1939_TP_RX_DATA_WAIT;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -1350,7 +1417,11 @@ void J1939_read_DT_Packet()
|
|
_msg.Mxe.Data[6] = (j1939_uint8_t)(pgn_num >> 8 & 0xff);
|
|
_msg.Mxe.Data[6] = (j1939_uint8_t)(pgn_num >> 8 & 0xff);
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
_msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
/*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
|
|
- J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
|
|
+ // J1939_EnqueueMessage(&_msg, Can_Node);
|
|
|
|
+ {
|
|
|
|
+ _msg.Mxe.SourceAddress = J1939_Address;
|
|
|
|
+ Port_CAN_Transmit(&_msg);
|
|
|
|
+ }
|
|
TP_RX_MSG.state = J1939_RX_DONE;
|
|
TP_RX_MSG.state = J1939_RX_DONE;
|
|
return;
|
|
return;
|
|
}
|
|
}
|