ZDBMS/output/IapIsp.lst

856 lines
50 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 1
C51 COMPILER V9.01, COMPILATION OF MODULE IAPISP
OBJECT MODULE PLACED IN .\output\IapIsp.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE code_bootloader\IapIsp.c OPTIMIZE(8,SPEED) BROWSE INCDIR(.\header_bootlo
-ader) DEBUG OBJECTEXTEND PRINT(.\output\IapIsp.lst) OBJECT(.\output\IapIsp.obj)
line level source
1 /********************************************************************************
2 Copyright (C), Sinowealth Electronic. Ltd.
3 Author: Sino
4 Version: V0.0
5 Date: 2020/04/26
6 History:
7 V2.0 2020/04/26 Preliminary
8 ********************************************************************************/
9 #include "MCURegister.h"
10 #include "C51_TYPE.H"
11 #include "Flash.h"
12 #include "IapIsp.h"
13
14 BOOL bIapIspFlg; //0表示当前执行IAP操作1表示当前执行ISP操作
15 BOOL bHandsheakOkFlg;
16 BOOL bUartSndOverFlg;
17 U16 uiUartRcvChkSum;
18 U8 ucUartErrCode;
19 U8 ucUartBufPT;
20 U32 ulIapDataPtr;
21 U32 ulIapChksum;
22 U32 ulIapRecDataLen;
23 U8 ucIapIndexBk;
24 U8 ucIapRestCommand;
25 U8 xdata ucUartBuf[150];
26 U8 xdata ucIapBuf[MCU_CODE_SECTOR_SIZE];
27
28 extern void UARTInit(void);
29 /*************************************************************************************************
30 * 函数名: UartSendAck
31 * 参 数: 无
32 * 返回值: 无
33 * 描 述: 当Slave接收完数据并处理完成后开始返回数据
34 *************************************************************************************************/
35 void UartSendAck(void)
36 {
37 1 U8 i, DataBak;
38 1 U16 CheckSum = 0;
39 1
40 1 ucUartBuf[LENGTH] = 0x00;
41 1 ucUartBuf[COMMAND] = 0x0B;
42 1
43 1 DataBak = ucUartBuf[SOURCE]; //交换源ID和目标ID
44 1 ucUartBuf[SOURCE] = ucUartBuf[TARGET];
45 1 ucUartBuf[TARGET] = DataBak;
46 1
47 1 for(i=2; i<(ucUartBuf[LENGTH]+7); i++)
48 1 {
49 2 CheckSum += ucUartBuf[i];
50 2 }
51 1
52 1 ucUartBuf[7+ucUartBuf[LENGTH]] = (U8)CheckSum;
53 1 ucUartBuf[8+ucUartBuf[LENGTH]] = (U8)(CheckSum>>8);
54 1
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 2
55 1 bUartSndOverFlg = 0;
56 1 UartTxEn(ucUartBuf[ucUartBufPT]);
57 1 }
58
59
60 /*************************************************************************************************
61 * 函数名: IapHandShake
62 * 参 数: 无
63 * 返回值: 无
64 * 描 述: 握手协议进入IAP或者ISP烧写流程
65 bIapIspFlg: 0--IAP操作1--ISP操作
66 *************************************************************************************************/
67 void IapHandShake(void)
68 {
69 1 ucUartBuf[INDEXES] = 0;
70 1 if(ucUartBuf[DATA]=='I' && ucUartBuf[DATA+1]=='A' && ucUartBuf[DATA+2]=='P')
71 1 {
72 2 bIapIspFlg = IAP_MODE;
73 2 bHandsheakOkFlg = 1;
74 2 }
75 1 else if(ucUartBuf[DATA]=='I' && ucUartBuf[DATA+1]=='S' && ucUartBuf[DATA+2]=='P')
76 1 {
77 2 bIapIspFlg = ISP_MODE;
78 2 bHandsheakOkFlg = 1;
79 2 }
80 1 else
81 1 {
82 2 ucUartBuf[INDEXES] = IAPERROR_HANDSHAKE; //握手失败
83 2 bHandsheakOkFlg = 0;
84 2 }
85 1 }
86
87
88 /*************************************************************************************************
89 * 函数名: IapBeginAck
90 * 参 数: 无
91 * 返回值: 无
92 * 描 述: IAP或ISP开始操作擦除CODE的备份区30K
93 *************************************************************************************************/
94 void IapBeginAck(void)
95 {
96 1 U8 i, SectorNum, McuFlashType;
97 1 U32 McuFlashAddr;
98 1
99 1 ulIapDataPtr = 0;
100 1 ulIapChksum = 0;
101 1 ulIapRecDataLen = 0;
102 1 ulIapRecDataLen = ((U32)ucUartBuf[DATA+3]<<24) //数据长度
103 1 | ((U32)ucUartBuf[DATA+2]<<16)
104 1 | ((U32)ucUartBuf[DATA+1]<<8)
105 1 | (U32)ucUartBuf[DATA];
106 1
107 1 if(!bHandsheakOkFlg)
108 1 {
109 2 ucUartBuf[INDEXES] = IAPERROR_HANDSHAKE; //握手失败
110 2 }
111 1
112 1 if((ulIapRecDataLen > IAP_BK_CODE_SIZE) && (bIapIspFlg == IAP_MODE))
113 1 {
114 2 ucUartBuf[INDEXES] = IAPERROR_SIZE; //如果数据长度不等于IAP和ISP长度
-默认为长度异常
115 2 }
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 3
116 1 else if((ulIapRecDataLen > ISP_CODE_SIZE) && (bIapIspFlg == ISP_MODE))
117 1 {
118 2 ucUartBuf[INDEXES] = IAPERROR_SIZE; //如果数据长度不等于IAP和ISP长度
-默认为长度异常
119 2 }
120 1 else
121 1 {
122 2 ucUartBuf[INDEXES] = 0; //先预设回复成功
123 2 ucIapIndexBk = 0;
124 2
125 2 //1. 如果当前操作是ISP则先擦除BOOT区的标志然后在BOOT_FLG_ISP_ADD中写ISP_FLG标志0xA5
126 2 ucMcuFlashWrValid = 0x55; //设置MCU Code区可操作标志
-止误写
127 2 McuFlashEraseSector(BOOT_FLG_START_ADDR, MCU_TYPE_CODE);
128 2 if(McuFlashBlankCheck(BOOT_FLG_START_ADDR, MCU_TYPE_CODE)) //擦除结束后,需要查空
129 2 {
130 3 if(bIapIspFlg == ISP_MODE)
131 3 {
132 4 McuFlashWrOneByte(BOOT_FLG_ISP_ADDR, ISP_FLG, MCU_TYPE_CODE);
133 4 if(McuFlashRdOneByte(BOOT_FLG_ISP_ADDR, MCU_TYPE_CODE) != ISP_FLG)
134 4 {
135 5 ucUartBuf[INDEXES] = IAPERROR_WR; //Write失败
136 5 }
137 4 }
138 3 }
139 2 else
140 2 {
141 3 ucUartBuf[INDEXES] = IAPERROR_ERASE; //Erase失败
142 3 }
143 2 ucMcuFlashWrValid = 0;
144 2
145 2 //2. 不管是IAP还是ISP都先擦除程序的所有Sector如果是ISP则还需要擦除EEPROM区
146 2 if(ucUartBuf[INDEXES] == 0) //检查ucUartBuf[INDEXES]
147 2 {
148 3 SectorNum = ulIapRecDataLen/MCU_CODE_SECTOR_SIZE;
149 3 for(i=0; i<SectorNum; i++) //先擦除CODE备份区的Sector
150 3 {
151 4 McuFlashType = MCU_TYPE_CODE; //先默认擦除flash
152 4 if(bIapIspFlg == ISP_MODE)
153 4 {
154 5 McuFlashAddr = ISP_CODE_START_ADDR; //ISP起始地址
155 5 }
156 4 else
157 4 {
158 5 McuFlashAddr = IAP_BK_CODE_START_ADDR; //IAP起始地址
159 5 }
160 4 McuFlashAddr += (U16)i*512; //确定被擦除页起始地址
161 4
162 4 if(bIapIspFlg == ISP_MODE) //ISP模式下直接擦除EEPROM
163 4 {
164 5 if(i>=(SectorNum-APP_PARA_SIZE/MCU_CODE_SECTOR_SIZE)) //EEPROM按sector擦除
165 5 {
166 6 McuFlashType = MCU_TYPE_E2P;
167 6 McuFlashAddr = (U16)(i+APP_PARA_SIZE/MCU_CODE_SECTOR_SIZE-SectorNum)*512;
168 6 }
169 5 }
170 4
171 4 ucMcuFlashWrValid = 0x55; //设置MCU Code区可操作标志防止误写
172 4 McuFlashEraseSector(McuFlashAddr, McuFlashType);
173 4 if(!McuFlashBlankCheck(McuFlashAddr, McuFlashType)) //擦除结束后,需要查空
174 4 {
175 5 ucUartBuf[INDEXES] = IAPERROR_ERASE; //Erase失败
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 4
176 5 }
177 4 ucMcuFlashWrValid = 0;
178 4 }
179 3 }
180 2 else
181 2 {
182 3 ucUartBuf[INDEXES] = IAPERROR_INDEX;
183 3 }
184 2 }
185 1 }
186
187
188 /*************************************************************************************************
189 * 函数名: IapWrSector
190 * 参 数: 无
191 * 返回值: 无
192 * 描 述: 写入1个Sector数据
193 *************************************************************************************************/
194 BOOL IapWrSector(void)
195 {
196 1 BOOL Result = 1;
197 1 U16 i;
198 1 U32 McuFlashAddr;
199 1 U8 McuFlashType;
200 1
201 1 for(i=0; i<MCU_CODE_SECTOR_SIZE; i++) //连续写1个sector
202 1 {
203 2 McuFlashType = MCU_TYPE_CODE;
204 2 if(bIapIspFlg == ISP_MODE) //ISP
205 2 {
206 3 McuFlashAddr = ISP_CODE_START_ADDR + ulIapDataPtr;
207 3 if(McuFlashAddr >= (ulIapRecDataLen+BOOT_CODE_SIZE-APP_PARA_SIZE))
208 3 {
209 4 McuFlashAddr = McuFlashAddr - (ulIapRecDataLen+BOOT_CODE_SIZE-APP_PARA_SIZE);
210 4 McuFlashType = MCU_TYPE_E2P; //ISP更新EEPROM区
211 4 }
212 3 }
213 2 else
214 2 {
215 3 McuFlashAddr = IAP_BK_CODE_START_ADDR + ulIapDataPtr;
216 3 }
217 2 McuFlashWrOneByte(McuFlashAddr, ucIapBuf[i], McuFlashType);
218 2 if(ucIapBuf[i] != McuFlashRdOneByte(McuFlashAddr, McuFlashType))
219 2 {
220 3 Result = 0;
221 3 break;
222 3 }
223 2 ulIapDataPtr++;
224 2 }
225 1
226 1 return Result;
227 1 }
228
229
230 /*************************************************************************************************
231 * 函数名: IapReceiveData
232 * 参 数: 无
233 * 返回值: 无
234 * 描 述: 接收数据同时将数据写入的MCU CODE区
235 *************************************************************************************************/
236 void IapReceiveData(void)
237 {
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 5
238 1 U16 i;
239 1 U8 j;
240 1 U32 McuFlashAddr;
241 1 U8 McuFlashType;
242 1
243 1 bHandsheakOkFlg = 0;
244 1
245 1 if( ((ucUartBuf[INDEXES]<ucIapIndexBk) || (ucUartBuf[INDEXES]>(ucIapIndexBk+4))) && (ucUartBuf[INDEXES
-] != 0) ) //yangweilei
246 1 {
247 2 ucUartBuf[INDEXES] = IAPERROR_INDEX; //数据索引错误,首先判断是否连续,其
-次判断是否超出范围
248 2 }
249 1 else
250 1 {
251 2 ucIapIndexBk = ucUartBuf[INDEXES];
252 2 ucUartBuf[INDEXES] = 0;
253 2 if(ucUartBuf[LENGTH] == 0)
254 2 {
255 3 ulIapDataPtr += 512; //如果传递的长度为0表示当前128个字节<E5AD97>
-<2D>0指针加但不写(增加150mS/1K)
256 3 }
257 2 else
258 2 {
259 3 j = ucIapIndexBk % 4; //目前暂定sector长度为512bytes每次传<E6ACA1>
-<2D>128bytes所以定义为4
260 3 for(i=0; i<ucUartBuf[LENGTH]; i++)
261 3 {
262 4 ucIapBuf[i+(U16)j*ucUartBuf[LENGTH]] = ucUartBuf[DATA+i];
263 4 }
264 3 if(j == 3) //连续接收满1个sector才进行写入操作
265 3 {
266 4 ucMcuFlashWrValid = 0x55; //设置MCU Code区可操作标志
-止误写
267 4 if(!IapWrSector()) //第一次写sector错误则擦除后再写一次
268 4 {
269 5 if(ulIapDataPtr >= MCU_CODE_SECTOR_SIZE)
270 5 {
271 6 ulIapDataPtr -= MCU_CODE_SECTOR_SIZE; //指针返回到该Sector起始
272 6 }
273 5 else
274 5 {
275 6 ulIapDataPtr = 0;
276 6 }
277 5
278 5 McuFlashType = MCU_TYPE_CODE; //默认是CODE区
279 5 if(bIapIspFlg == ISP_MODE) //ISP
280 5 {
281 6 McuFlashAddr = ISP_CODE_START_ADDR + ulIapDataPtr;
282 6 if(McuFlashAddr >= (ulIapRecDataLen+BOOT_CODE_SIZE-APP_PARA_SIZE))
283 6 {
284 7 McuFlashAddr = McuFlashAddr - (ulIapRecDataLen+BOOT_CODE_SIZE-APP_PARA_SIZE);
285 7 McuFlashType = MCU_TYPE_E2P; //ISP更新EEPROM区
286 7 }
287 6 }
288 5 else
289 5 {
290 6 McuFlashAddr = IAP_BK_CODE_START_ADDR + ulIapDataPtr;
291 6 }
292 5 ucMcuFlashWrValid = 0x55;
293 5 McuFlashEraseSector(McuFlashAddr, McuFlashType);
294 5 if(McuFlashBlankCheck(McuFlashAddr, McuFlashType)) //擦除结束后,需要查空
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 6
295 5 {
296 6 if(!IapWrSector()) //如果连续写两次错误,则返回给上位机异常
297 6 {
298 7 ucUartBuf[INDEXES] = IAPERROR_WR; //写入错误
299 7 }
300 6 else
301 6 {
302 7 goto UpdateChksum;
303 7 }
304 6 }
305 5 else
306 5 {
307 6 ucUartBuf[INDEXES] = IAPERROR_ERASE; //擦除错误
308 6 }
309 5 }
310 4 else //512Bytes写入正确才更新checksum值
311 4 {
312 5 UpdateChksum:
313 5 for(j=0; j<MCU_CODE_SECTOR_SIZE/4; j++) //计算checksum需要按照32bit尽量兼容STM32
314 5 {
315 6 ulIapChksum += (((U32)ucIapBuf[j*4+3]<<24)
316 6 | ((U32)ucIapBuf[j*4+2]<<16)
317 6 | ((U32)ucIapBuf[j*4+1]<<8)
318 6 | ((U32)ucIapBuf[j*4+0]));
319 6 }
320 5 }
321 4
322 4 ucMcuFlashWrValid = 0;
323 4 }
324 3 }
325 2 }
326 1 }
327
328
329 /*************************************************************************************************
330 * 函数名: IapRDataVerify
331 * 参 数: 无
332 * 返回值: 无
333 * 描 述: 验证CheckSum是否正确
334 *************************************************************************************************/
335 void IapRDataVerify(void)
336 {
337 1 U32 CheckSum = 0;
338 1
339 1 CheckSum = ((U32)ucUartBuf[DATA+3]<<24) //获取上位机下发的校验和
340 1 | ((U32)ucUartBuf[DATA+2]<<16)
341 1 | ((U32)ucUartBuf[DATA+1]<<8)
342 1 | ((U32)ucUartBuf[DATA+0]);
343 1
344 1 if(ulIapChksum != CheckSum) //数据校验失败
345 1 {
346 2 ucUartBuf[INDEXES] = IAPERROR_CRC;
347 2 }
348 1 else
349 1 {
350 2 ucUartBuf[INDEXES] = 0; //数据校验成功
351 2 }
352 1 }
353
354
355 /*************************************************************************************************
356 * 函数名: IapCmdReset
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 7
357 * 参 数: 无
358 * 返回值: 无
359 * 描 述: 当IAP和ISP正常Program结束之后上位机发送复位指令程序会跳转到0x0000地址
360 ISP程序会擦除BOOT区的标志区ISP结束
361 IAP程序会擦除BOOT区的标志区同时将标志区的最后一个字节写0x5AAPP会自动升级
362 *************************************************************************************************/
363 void IapCmdReset(void)
364 {
365 1 ucUartBuf[INDEXES] = 0;
366 1 ucIapRestCommand = IAP_CMD_RESET;
367 1
368 1 ucMcuFlashWrValid = 0x55; //设置MCU Code区可操作标志防止<E998B2>
-笮<>
369 1 McuFlashEraseSector(BOOT_FLG_START_ADDR, MCU_TYPE_CODE);
370 1 if(McuFlashBlankCheck(BOOT_FLG_START_ADDR, MCU_TYPE_CODE)) //擦除结束后,需要查空
371 1 {
372 2 if(bIapIspFlg == IAP_MODE) //IAP升级结束后需要将BOOT区的标志<E6A087>
-<2D>詈笠桓鲎纸谛<E7BAB8>0x5A
373 2 {
374 3 McuFlashWrOneByte(BOOT_FLG_IAP_ADDR, IAP_FLG, MCU_TYPE_CODE);
375 3 if(McuFlashRdOneByte(BOOT_FLG_IAP_ADDR, MCU_TYPE_CODE) != IAP_FLG)
376 3 {
377 4 ucUartBuf[INDEXES] = IAPERROR_WR; //Write失败
378 4 ucIapRestCommand = 0;
379 4 }
380 3 }
381 2 }
382 1 else
383 1 {
384 2 ucUartBuf[INDEXES] = IAPERROR_ERASE; //擦除失败
385 2 ucIapRestCommand = 0;
386 2 }
387 1 ucMcuFlashWrValid = 0;
388 1 }
389
390
391 /*************************************************************************************************
392 * 函数名: UartCmdProcess
393 * 参 数: 无
394 * 返回值: 无
395 * 描 述: 处理IAP和ISP的四条命令
396 *************************************************************************************************/
397 void UartCmdProcess(void)
398 {
399 1 ucUartBufPT = 0;
400 1 if(uiUartRcvChkSum != ((ucUartBuf[ucUartBuf[LENGTH]+8]<<8) + ucUartBuf[ucUartBuf[LENGTH]+7]))
401 1 {
402 2 ucUartErrCode |= IAPERROR_CHECKSUM;
403 2 }
404 1
405 1 if(ucUartErrCode != 0) //如果有错误代码则不执行命令处理
406 1 {
407 2 ucUartBuf[INDEXES] = ucUartErrCode;
408 2 }
409 1 else
410 1 {
411 2 if(ucUartBuf[COMMAND] == IAP_CMD_HANDSHAKE) //IAP和ISP握手协议上位机连续发两次
412 2 {
413 3 IapHandShake();
414 3 }
415 2 else if(ucUartBuf[COMMAND] == IAP_CMD_BEGIN) //开始IAP或ISP并将CODE区/EEP区全部
-擦除
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 8
416 2 {
417 3 IapBeginAck();
418 3 }
419 2 else if(ucUartBuf[COMMAND] == IAP_CMD_TRANS) //接收数据、写入、校验
420 2 {
421 3 IapReceiveData();
422 3 }
423 2 else if(ucUartBuf[COMMAND] == IAP_CMD_VERIFY) //
424 2 {
425 3 IapRDataVerify();
426 3 }
427 2 else if(ucUartBuf[COMMAND] == IAP_CMD_RESET)
428 2 {
429 3 IapCmdReset();
430 3 }
431 2 }
432 1
433 1 UartSendAck();
434 1 }
435
436
437 /*************************************************************************************************
438 * 函数名: BootIapIsp
439 * 参 数: 无
440 * 返回值: 无
441 * 描 述: IAP和ISP函数处理
442 *************************************************************************************************/
443 void BootIapIsp(void)
444 {
445 1 ulIapDataPtr = 0;
446 1 ulIapChksum = 0;
447 1 ucIapRestCommand = 0;
448 1 UARTInit();
449 1 while(1)
450 1 {
451 2 #if ((UART_DEFINE >= 1)&&(UART_DEFINE<= 30))
452 2 {
453 3 if(RI)
454 3 {
455 4 //BootMcuWdtClear(); //在该程序循环中未接收到UART通讯
-则判定通讯异常,触发看门狗
456 4 ucUartBuf[ucUartBufPT] = SBUF;
457 4 ucUartBufPT++;
458 4 if(ucUartBufPT >= 140) //该指针不会超过140
459 4 {
460 5 ucUartBufPT = 0;
461 5 }
462 4 if(ucUartBufPT == 1)
463 4 {
464 5 if(ucUartBuf[HEARD1] != 0x5A) //检查帧头是否Wie0x5AA5
465 5 {
466 6 ucUartBufPT = 0;
467 6 }
468 5
469 5 }
470 4 else if(ucUartBufPT == 2)
471 4 {
472 5
473 5 if(ucUartBuf[HEARD2] != 0xA5)
474 5 {
475 6 ucUartBufPT = 0;
476 6 }
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 9
477 5 else
478 5 {
479 6 uiUartRcvChkSum = 0; //帧头判断正确
480 6 ucUartErrCode = 0;
481 6 }
482 5 }
483 4 else
484 4 {
485 5
486 5 if(ucUartBufPT < (ucUartBuf[LENGTH]+9))
487 5 {
488 6 if(ucUartBufPT <= (ucUartBuf[LENGTH]+7))
489 6 {
490 7 uiUartRcvChkSum += ucUartBuf[ucUartBufPT-1];
491 7 }
492 6
493 6 if(ucUartBufPT == (TARGET+1)) //检查ID
494 6 {
495 7
496 7 if(ucUartBuf[TARGET] != IAP_BMSID)
497 7 {
498 8 ucUartBufPT = 0;
499 8 }
500 7 }
501 6 else if(ucUartBufPT == (COMMAND+1)) //检测COMMAND
502 6 {
503 7 if((ucUartBuf[COMMAND] != IAP_CMD_HANDSHAKE)
504 7 && (ucUartBuf[COMMAND] != IAP_CMD_BEGIN)
505 7 && (ucUartBuf[COMMAND] != IAP_CMD_TRANS)
506 7 && (ucUartBuf[COMMAND] != IAP_CMD_VERIFY)
507 7 && (ucUartBuf[COMMAND] != IAP_CMD_RESET))
508 7 {
509 8 ucUartErrCode |= IAPERROR_CMD;
510 8 }
511 7 }
512 6 }
513 5 else
514 5 {
515 6 BootMcuWdtClear();
516 6 UartCmdProcess();
517 6 }
518 5 }
519 4 RI = 0;
520 4 }
521 3
522 3 if(TI)
523 3 {
524 4 BootMcuWdtClear(); //在该程序循环中未接收到UART通讯
-判定通讯异常,触发看门狗
525 4
526 4 if(ucUartBufPT >= (ucUartBuf[LENGTH]+8))
527 4 {
528 5 UartRxEn(); //Allow UART receive data
529 5 ucUartBufPT = 0;
530 5 ucUartBuf[0] = 0;
531 5 ucUartBuf[1] = 0;
532 5 ucUartBuf[2] = 0;
533 5 bUartSndOverFlg = 1;
534 5 }
535 4 else
536 4 {
537 5 ucUartBufPT++;
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 10
538 5 UartTxEn(ucUartBuf[ucUartBufPT]);
539 5 }
540 4
541 4 TI = 0;
542 4 }
543 3
544 3 if(ucIapRestCommand == IAP_CMD_RESET)
545 3 {
546 4 BootMcuWdtClear();
547 4 if(bUartSndOverFlg) //Reset帧回复结束
548 4 {
549 5 bUartSndOverFlg = 0;
550 5 ucIapRestCommand = 0;
551 5 ((void(code*)(void))0x0000)();
552 5 }
553 4 }
554 3 }
555 2 #elif ((UART_DEFINE >= 31)&&(UART_DEFINE<= 60))
{
INSCON = 0x40;
if(RI1)
{
//BootMcuWdtClear(); //在该程序循环中未接收到UART通讯
-则判定通讯异常,触发看门狗
ucUartBuf[ucUartBufPT] = SBUF1;
INSCON = 0x00;
ucUartBufPT++;
if(ucUartBufPT >= 140) //该指针不会超过140
{
ucUartBufPT = 0;
}
if(ucUartBufPT == 1)
{
if(ucUartBuf[HEARD1] != 0x5A) //检查帧头是否Wie0x5AA5
{
ucUartBufPT = 0;
}
}
else if(ucUartBufPT == 2)
{
if(ucUartBuf[HEARD2] != 0xA5)
{
ucUartBufPT = 0;
}
else
{
uiUartRcvChkSum = 0; //帧头判断正确
ucUartErrCode = 0;
}
}
else
{
if(ucUartBufPT < (ucUartBuf[LENGTH]+9))
{
if(ucUartBufPT <= (ucUartBuf[LENGTH]+7))
{
uiUartRcvChkSum += ucUartBuf[ucUartBufPT-1];
}
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 11
if(ucUartBufPT == (TARGET+1)) //检查ID
{
if(ucUartBuf[TARGET] != IAP_BMSID)
{
ucUartBufPT = 0;
}
}
else if(ucUartBufPT == (COMMAND+1)) //检测COMMAND
{
if((ucUartBuf[COMMAND] != IAP_CMD_HANDSHAKE)
&& (ucUartBuf[COMMAND] != IAP_CMD_BEGIN)
&& (ucUartBuf[COMMAND] != IAP_CMD_TRANS)
&& (ucUartBuf[COMMAND] != IAP_CMD_VERIFY)
&& (ucUartBuf[COMMAND] != IAP_CMD_RESET))
{
ucUartErrCode |= IAPERROR_CMD;
}
}
}
else
{
BootMcuWdtClear();
UartCmdProcess();
}
}
INSCON = 0x40;
RI1 = 0;
INSCON = 0x00;
}
INSCON = 0x40;
if(TI1)
{
INSCON = 0x00;
BootMcuWdtClear(); //在该程序循环中未接收到UART通讯
-判定通讯异常,触发看门狗
if(ucUartBufPT >= (ucUartBuf[LENGTH]+8))
{
UartRxEn(); //Allow UART receive data
ucUartBufPT = 0;
ucUartBuf[0] = 0;
ucUartBuf[1] = 0;
ucUartBuf[2] = 0;
bUartSndOverFlg = 1;
}
else
{
ucUartBufPT++;
UartTxEn(ucUartBuf[ucUartBufPT]);
}
INSCON = 0x40;
TI1 = 0;
INSCON = 0x00;
}
if(ucIapRestCommand == IAP_CMD_RESET)
{
BootMcuWdtClear();
if(bUartSndOverFlg) //Reset帧回复结束
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 12
{
bUartSndOverFlg = 0;
ucIapRestCommand = 0;
((void(code*)(void))0x0000)();
}
}
}
#elif ( UART_DEFINE == 61)
{
INSCON = 0x40;
if(RI2)
{
//BootMcuWdtClear(); //在该程序循环中未接收到UART通讯
-则判定通讯异常,触发看门狗
ucUartBuf[ucUartBufPT] = SBUF2;
INSCON = 0x00;
ucUartBufPT++;
if(ucUartBufPT >= 140) //该指针不会超过140
{
ucUartBufPT = 0;
}
if(ucUartBufPT == 1)
{
if(ucUartBuf[HEARD1] != 0x5A) //检查帧头是否Wie0x5AA5
{
ucUartBufPT = 0;
}
}
else if(ucUartBufPT == 2)
{
if(ucUartBuf[HEARD2] != 0xA5)
{
ucUartBufPT = 0;
}
else
{
uiUartRcvChkSum = 0; //帧头判断正确
ucUartErrCode = 0;
}
}
else
{
if(ucUartBufPT < (ucUartBuf[LENGTH]+9))
{
if(ucUartBufPT <= (ucUartBuf[LENGTH]+7))
{
uiUartRcvChkSum += ucUartBuf[ucUartBufPT-1];
}
if(ucUartBufPT == (TARGET+1)) //检查ID
{
if(ucUartBuf[TARGET] != IAP_BMSID)
{
ucUartBufPT = 0;
}
}
else if(ucUartBufPT == (COMMAND+1)) //检测COMMAND
{
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 13
if((ucUartBuf[COMMAND] != IAP_CMD_HANDSHAKE)
&& (ucUartBuf[COMMAND] != IAP_CMD_BEGIN)
&& (ucUartBuf[COMMAND] != IAP_CMD_TRANS)
&& (ucUartBuf[COMMAND] != IAP_CMD_VERIFY)
&& (ucUartBuf[COMMAND] != IAP_CMD_RESET))
{
ucUartErrCode |= IAPERROR_CMD;
}
}
}
else
{
BootMcuWdtClear();
UartCmdProcess();
}
}
INSCON = 0x40;
RI2 = 0;
INSCON = 0x00;
}
INSCON = 0x40;
if(TI2)
{
INSCON = 0x00;
BootMcuWdtClear(); //在该程序循环中未接收到UART通讯
-判定通讯异常,触发看门狗
if(ucUartBufPT >= (ucUartBuf[LENGTH]+8))
{
UartRxEn(); //Allow UART receive data
ucUartBufPT = 0;
ucUartBuf[0] = 0;
ucUartBuf[1] = 0;
ucUartBuf[2] = 0;
bUartSndOverFlg = 1;
}
else
{
ucUartBufPT++;
UartTxEn(ucUartBuf[ucUartBufPT]);
}
INSCON = 0x40;
TI2 = 0;
INSCON = 0x00;
}
if(ucIapRestCommand == IAP_CMD_RESET)
{
BootMcuWdtClear();
if(bUartSndOverFlg) //Reset帧回复结束
{
bUartSndOverFlg = 0;
ucIapRestCommand = 0;
((void(code*)(void))0x0000)();
}
}
}
#endif
780 2 }
781 1 }
C51 COMPILER V9.01 IAPISP 12/22/2023 12:15:06 PAGE 14
782
783
784
785
786
787
788
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2211 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 662 ----
PDATA SIZE = ---- ----
DATA SIZE = 18 24
IDATA SIZE = ---- ----
BIT SIZE = 3 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)