| 
					
				 | 
			
			
				@@ -5,6 +5,9 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #include <stdlib.h> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #include <string.h> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+queue_entry(pdu_tag, 30) can_tx_queue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+queue_entry(pdu_tag, 30) can_rx_queue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 double pow_branch(double x, long long N) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     double ans = 1.0; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -57,7 +60,8 @@ void product_array(uint8_t send_array[8]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pdu_tag response_msg; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pdu_tag      response_msg; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    QUEUE_STATUS result_status; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     response_msg.id.r    = id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     response_msg.reg.dlc = len; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     memcpy(&response_msg.data.u8_buf[0], p_data, len); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -71,7 +75,10 @@ uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         response_msg.reg.ide = CAN_Id_Standard; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (en_queue(&can_tx_queue, response_msg) != Q_OK) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    __disable_irq(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    en_queue(&can_tx_queue, response_msg, result_status); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    __enable_irq(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (result_status != Q_OK) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -88,9 +95,12 @@ static uint8_t can_tx_frame(pdu_tag can_message) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 void can_tx_callback(void) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pdu_tag tx_data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pdu_tag      tx_data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    QUEUE_STATUS result_status; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    de_queue(&can_tx_queue, tx_data, result_status); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (de_queue(&can_tx_queue, &tx_data) == Q_OK) // 返回值为1代表读取成功 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (result_status == Q_OK) // 返回值为1代表读取成功 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         can_tx_frame(tx_data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -103,16 +113,15 @@ void can_tx_callback(void) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 void can_rx_callback(CanRxMsg rx_message) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pdu_tag data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    uint8_t ps; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    uint8_t pf; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pdu_tag      data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    QUEUE_STATUS result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     switch (rx_message.ExtId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     default: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -127,11 +136,13 @@ can_rx_tab can_tab[] = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 void can_start_send(void) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pdu_tag tx_msg; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (RESET == CAN_GetITStatus(CAN1, CAN_IT_TME)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pdu_tag      tx_msg; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    QUEUE_STATUS result_status; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (de_queue(&can_tx_queue, &tx_msg) == Q_OK) // 返回值为1代表读取成功 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (0 == ((CAN1->IER) & 0x1)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        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); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -141,13 +152,18 @@ void can_start_send(void) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 static uint8_t can_rx_process(void) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    uint8_t i; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    uint8_t flg = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pdu_tag rec_msg; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    uint8_t      i; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    uint8_t      flg = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pdu_tag      rec_msg; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    QUEUE_STATUS result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for (uint8_t j = 0; j < 15; j++) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (Q_OK == de_queue(&can_rx_queue, &rec_msg)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        __disable_irq(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        de_queue(&can_rx_queue, rec_msg, result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        __enable_irq(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (Q_OK == result) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for (i = 0; i < ARR_SIZE(can_tab); i++) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -164,6 +180,8 @@ static uint8_t can_rx_process(void) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 void dev_can_network_init(void) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     drv_can_init(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    queue_init(&can_rx_queue); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    queue_init(&can_tx_queue); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     drv_can_rx_back_init(can_rx_callback); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     drv_can_tx_back_init(can_tx_callback); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |