Преглед изворни кода

support read chip id

Signed-off-by: FuangCao <cavan.cao@foxmail.com>
FuangCao пре 3 година
родитељ
комит
cebc698778
3 измењених фајлова са 32 додато и 2 уклоњено
  1. 16 2
      Application/app/iap.c
  2. 15 0
      Application/libs/shark_utils.c
  3. 1 0
      Application/libs/shark_utils.h

+ 16 - 2
Application/app/iap.c

@@ -13,6 +13,17 @@ static u8 _write_success = 0;
 static int _write_position = 0;
 static shark_timer_t _reboot_timer = {.handler = _reboot_timer_handler,};
 
+void iap_read_chip_id(can_frame_t *frame)
+{
+	u8 buff[24];
+	u8 len;
+
+	buff[0] = buff[1] = 0x00;
+	len = shark_read_chip_id(buff + 2) + 2;
+
+	protocol_send_bms_info(frame->head.can_addr, frame->key, buff, len);
+}
+
 void process_iap_message(can_frame_t *frame, int len){
 	uint8_t *data = NULL;
 	int data_len = 0;
@@ -58,7 +69,11 @@ void process_iap_message(can_frame_t *frame, int len){
 			}
 			break;
 		case CAN_KEY_IAP_STAT:
-			protocol_send_ack(frame->head.can_addr, frame->key, 0);
+			if (len > 0 && frame->data[0] == 0x01) {
+				iap_read_chip_id(frame);
+			} else {
+				protocol_send_ack(frame->head.can_addr, frame->key, 0);
+			}
 			break;
 		case CAN_EEY_IAP_READ_STRING:
 			iap_read_string(frame);
@@ -129,7 +144,6 @@ void iap_read_string(can_frame_t *frame)
 	protocol_send_bms_info(frame->head.can_addr, frame->key, buff, len + 4);
 }
 
-
 static int iap_check_image(uint8_t *data, int len) {
 	uint32_t size, checksum;
 	size = shark_decode_u24(data);

+ 15 - 0
Application/libs/shark_utils.c

@@ -1,4 +1,6 @@
 #include "shark_utils.h"
+#include "bsp/shark_bsp.h"
+#include "string.h"
 
 const u16 shark_crc16_table[] = {
 	0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1,
@@ -117,3 +119,16 @@ void shark_encode_u32(u8 *buff, u32 value)
 	buff[3] = value >> 24;
 }
 
+u8 shark_read_chip_id(u8 *buff)
+{
+#ifdef GD32F3x0
+	u32 values[] = { REG32(0x1FFFF7AC), REG32(0x1FFFF7B0), REG32(0x1FFFF7B4), REG32(0x1FFFF7E0) };
+#else
+	u32 values[] = { REG32(0x1FFFF7E8), REG32(0x1FFFF7EC), REG32(0x1FFFF7F0), REG32(0x1FFFF7E0) };
+#endif
+
+	memcpy(buff, values, sizeof(values));
+
+	return sizeof(values);
+}
+

+ 1 - 0
Application/libs/shark_utils.h

@@ -20,6 +20,7 @@ u32 shark_decode_u32(const u8 *buff);
 void shark_encode_u16(u8 *buff, u16 value);
 void shark_encode_u24(u8 *buff, u32 value);
 void shark_encode_u32(u8 *buff, u32 value);
+u8 shark_read_chip_id(u8 *buff);
 u32 shark_iap_checksum_put(u32 crc, const u8 *buff, u32 length);
 u32 shark_iap_checksum_finish(u32 crc);
 u32 shark_iap_checksum_init(void);