ZDBMS/output/ExtE2PRom.lst

610 lines
29 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 EXTE2PROM 02/19/2025 10:42:27 PAGE 1
C51 COMPILER V9.01, COMPILATION OF MODULE EXTE2PROM
OBJECT MODULE PLACED IN .\output\ExtE2PRom.obj
COMPILER INVOKED BY: D:\Tool\Keil\C51\BIN\C51.EXE code_drv\ExtE2PRom.c LARGE OPTIMIZE(7,SIZE) REGFILE(.\output\MCUCore_L
-oad.ORC) BROWSE INTVECTOR(0X1000) INCDIR(.\header_app;.\header_drv;.\code_gasguage;.\code_classb\iec60730_lib\include;.\
-code_classb\iec60730_proc\Include;.\code_classb\config) DEBUG OBJECTEXTEND PRINT(.\output\ExtE2PRom.lst) OBJECT(.\output
-\ExtE2PRom.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 "Main.h"
10
11 BOOL bE2PProcessFlg; //EEPROM处理标志
12 BOOL bE2PBKDsgEnd; //放电结束标志需要备份信息到外挂EEPROM
13 BOOL bE2PBKDsgEndValid;
14 BOOL bE2PBKChgStop; //充电结束标志需要备份信息到外挂EEPROM
15 BOOL bE2PBKChgStart; //充电开始标志需要备份信息到外挂EEPROM
16 BOOL bE2PBKRtc; //RTC定时备份标志需要备份信息到外挂EEPRO
-M
17 BOOL bE2PErase; //擦除外挂EEPROM标志
18 U8 xdata bUart0E2PRdData; //读取外挂EEPROM标志
19 U8 xdata bUart1E2PRdData; //读取外挂EEPROM标志
20 U8 xdata bUart2E2PRdData; //读取外挂EEPROM标志
21 BOOL bE2PRErr;
22 BOOL bE2PTwiRWErrFlg;
23 U8 xdata bUart0RTCRdTime; //读取RTC时间标志
24 U8 xdata bUart1RTCRdTime; //读取RTC时间标志
25 U8 xdata bUart2RTCRdTime; //读取RTC时间标志
26 BOOL bDsgToChgFlg; //放电转换为充电,需要备份数据
27 BOOL bChgToDsgFlg; //充电转换为放电,需要备份数据
28 U16 xdata uiE2PDataAddr;
29 U8 xdata ucE2PTwiRWErrDelayCnt;
30 U8 xdata ucRTCBKTime1;
31 U16 xdata uiRTCBKTime2;
32 U8 idata ucUpDataLimitTime;
33 U16 xdata uiCHGValidTime;
34 U8 xdata ucRTCBuf[7];
35
36
37 /*************************************************************************************************
38 * 函数名: AFEI2CCheck
39 * 参 数: 无
40 * 返回值: 无
41 * 描 述: 连续5S检测到AFE的I2C通讯错误则置位bAfeErr=1
42 *************************************************************************************************/
43 void E2PRomTwiCheck(void)
44 {
45 1 if(bEnEEPRomBK)
46 1 {
47 2 if(bE2PTwiRWErrFlg)
48 2 {
49 3 if(++ucE2PTwiRWErrDelayCnt >= TIME_1S_5S)
50 3 {
51 4 bE2PRErr = 1;
C51 COMPILER V9.01 EXTE2PROM 02/19/2025 10:42:27 PAGE 2
52 4 ucE2PTwiRWErrDelayCnt = TIME_1S_5S;
53 4 }
54 3 }
55 2 else
56 2 {
57 3 ucE2PTwiRWErrDelayCnt = 0;
58 3 }
59 2 }
60 1 }
61
62
63 /*************************************************************************************************
64 * 函数名: E2PRomWrite
65 * 参 数: Addr地址Length长度WrBuf写入存放的Buf
66 * 返回值: 无
67 * 描 述: 写入EEPROm
68 *************************************************************************************************/
69 BOOL E2PRomWrite(U16 WrAddr, U8 Length, U8 xdata *WrBuf)
70 {
71 1 BOOL Result = 0;
72 1 U8 i;
73 1
74 1 if(!bE2PRErr)
75 1 {
76 2 for(i=0; i<5; i++)
77 2 {
78 3 #ifdef TWI_Hardware_Module
79 3 if(TwiWrite(E2PROM_ID, WrAddr, TWI_ADDR_2B, Length, TWI_CRC_NO, WrBuf))
80 3 {
81 4 Result = 1;
82 4 break;
83 4 }
84 3 #else
if(TwiWrite(E2PROM_ID, WrAddr, Length, WrBuf))
{
Result = 1;
break;
}
#endif
91 3 Delay1ms(1);
92 3 }
93 2 }
94 1 bE2PTwiRWErrFlg = !Result; //标记通讯是否正常
95 1
96 1 return Result;
97 1 }
98
99
100 /*************************************************************************************************
101 * 函数名: E2PRomRead
102 * 参 数: Addr地址Length长度RdBuf读取存放的Buf
103 * 返回值: 无
104 * 描 述: 读取EEPROm
105 *************************************************************************************************/
106 BOOL E2PRomRead(U16 RdAddr, U8 Length, U8 xdata *RdBuf)
107 {
108 1 BOOL Result = 0;
109 1 U8 i;
110 1
111 1 if(!bE2PRErr)
112 1 {
113 2 for(i=0; i<5; i++)
C51 COMPILER V9.01 EXTE2PROM 02/19/2025 10:42:27 PAGE 3
114 2 {
115 3 #ifdef TWI_Hardware_Module
116 3 if(TwiRead(E2PROM_ID, RdAddr, TWI_ADDR_2B, Length, TWI_CRC_NO, RdBuf))
117 3 {
118 4 Result = 1;
119 4 break;
120 4 }
121 3 #else
if(TwiRead(E2PROM_ID, RdAddr, Length, RdBuf))
{
Result = 1;
break;
}
#endif
128 3 Delay1ms(1);
129 3 }
130 2 }
131 1 bE2PTwiRWErrFlg = !Result; //标记通讯是否正常
132 1
133 1 return Result;
134 1 }
135
136
137
138 /*************************************************************************************************
139 * 函数名: E2PRomErase
140 * 参 数: 无
141 * 返回值: 无
142 * 描 述: 擦除EEPROM
143 *************************************************************************************************/
144 void E2PRomErase(void)
145 {
146 1 U16 i;
147 1 U8 xdata WrBuf[8];
148 1
149 1 MemorySet(WrBuf, 0, 8); //clr Info.uiVCell[]
150 1
151 1 for(i=0; i<(E2PROM_SIZE/32-1); i++)
152 1 {
153 2 McuWDTClear();
154 2 E2PRomWrite(i*32+31, 1, WrBuf);
155 2 }
156 1
157 1 E2PRomWrite(E2PROM_BOOT_ADDR, 8, WrBuf);
158 1 uiE2PDataAddr = 0;
159 1 }
160
161
162 /*************************************************************************************************
163 * 函数名: InitE2PRom
164 * 参 数: 无
165 * 返回值: 无
166 * 描 述: 初始化EEPROM的地址
167 *************************************************************************************************/
168 BOOL E2PRomInit(void)
169 {
170 1 BOOL Result = 0;
171 1
172 1 U8 xdata RdBuf[8];
173 1
174 1 Result = E2PRomRead(E2PROM_BOOT_ADDR, 8, RdBuf);
175 1
C51 COMPILER V9.01 EXTE2PROM 02/19/2025 10:42:27 PAGE 4
176 1 RdBuf[2] = RdBuf[0]+RdBuf[1];
177 1 RdBuf[6] = RdBuf[4]+RdBuf[5];
178 1
179 1 if(RdBuf[2] == RdBuf[3])
180 1 {
181 2 uiE2PDataAddr = ((U16)RdBuf[0]<<8) + RdBuf[1];
182 2 }
183 1 else if(RdBuf[6] == RdBuf[7])
184 1 {
185 2 uiE2PDataAddr = ((U16)RdBuf[4]<<8) + RdBuf[5];
186 2 }
187 1 else
188 1 {
189 2 uiE2PDataAddr = 0;
190 2 }
191 1
192 1 return Result;
193 1 }
194
195
196 /*************************************************************************************************
197 * 函数名: E2PRomBKRTC
198 * 参 数: 无
199 * 返回值: 无
200 * 描 述: 备份RTC
201 *************************************************************************************************/
202 void E2PRomBKRTC(void)
203 {
204 1 U8 xdata WrBuf[9];
205 1 U8 i, checksum = 0;
206 1
207 1 RTCReadTime(&RTC);
208 1 MemoryCopy((U8 xdata *)&(RTC.Second), WrBuf, 7);
209 1 for(i=0; i<7; i++)
210 1 {
211 2 checksum += WrBuf[i];
212 2 }
213 1 WrBuf[7] = checksum;
214 1 WrBuf[8] = 0x5A;
215 1
216 1 E2PRomWrite(E2PROM_RTC_ADDR, 9, WrBuf);
217 1 }
218
219
220 /*************************************************************************************************
221 * 函数名: E2PRomBKBoot
222 * 参 数: 无
223 * 返回值: 无
224 * 描 述: 备份EEPROM的Boot区
225 *************************************************************************************************/
226 void E2PRomBKBoot(void)
227 {
228 1 U8 xdata WrBuf[8];
229 1
230 1 WrBuf[0] = (uiE2PDataAddr>>8);
231 1 WrBuf[1] = uiE2PDataAddr;
232 1 WrBuf[3] = WrBuf[0]+WrBuf[1]; //Calculate checksum
233 1
234 1 WrBuf[4] = WrBuf[0];
235 1 WrBuf[5] = WrBuf[1];
236 1 WrBuf[7] = WrBuf[3];
237 1
C51 COMPILER V9.01 EXTE2PROM 02/19/2025 10:42:27 PAGE 5
238 1 E2PRomWrite(E2PROM_BOOT_ADDR, 8, WrBuf);
239 1 }
240
241
242 /*************************************************************************************************
243 * 函数名: E2PRomBKData
244 * 参 数: BKType备份类型
245 * 返回值: 无
246 * 描 述: 读取外挂EEPROM
247 *************************************************************************************************/
248 void E2PRomBKData(U8 BKType)
249 {
250 1 U8 xdata WrBuf[32];
251 1
252 1 if(BKType == E2PROM_BKTYPE_CHG_START) //充电开始
253 1 {
254 2 MemoryCopy((U8 xdata *)&ucRTCBuf[0], WrBuf, 3);
255 2 MemoryCopy((U8 xdata *)&ucRTCBuf[4], WrBuf + 3, 3);
256 2 }
257 1 else
258 1 {
259 2 RTCReadTime(&RTC);
260 2 MemoryCopy((U8 xdata *)&(RTC.Second), WrBuf, 3);
261 2 MemoryCopy((U8 xdata *)&(RTC.Date), WrBuf + 3, 3);
262 2 }
263 1
264 1 WrBuf[6] = (Info.uiPackStatus>>8);
265 1 WrBuf[7] = Info.uiPackStatus;
266 1 WrBuf[8] = (Info.uiBatStatus>>8);
267 1 WrBuf[9] = Info.uiBatStatus;
268 1 WrBuf[10] = (Info.ulFCC>>24);
269 1 WrBuf[11] = (Info.ulFCC>>16);
270 1 WrBuf[12] = (Info.ulFCC>>8);
271 1 WrBuf[13] = Info.ulFCC;
272 1 WrBuf[14] = (Info.ulRC>>24);
273 1 WrBuf[15] = (Info.ulRC>>16);
274 1 WrBuf[16] = (Info.ulRC>>8);
275 1 WrBuf[17] = Info.ulRC;
276 1 WrBuf[18] = (Info.ulVoltage>>24);
277 1 WrBuf[19] = (Info.ulVoltage>>16);
278 1 WrBuf[20] = (Info.ulVoltage>>8);
279 1 WrBuf[21] = Info.ulVoltage;
280 1 WrBuf[22] = (Info.slCurr>>24);
281 1 WrBuf[23] = (Info.slCurr>>16);
282 1 WrBuf[24] = (Info.slCurr>>8);
283 1 WrBuf[25] = Info.slCurr;
284 1 WrBuf[26] = (Info.uiTS[0]>>8);
285 1 WrBuf[27] = Info.uiTS[0];
286 1 WrBuf[28] = (Info.uiCycleCount>>8);
287 1 WrBuf[29] = Info.uiCycleCount;
288 1 WrBuf[30] = BKType;
289 1 WrBuf[31] = 0x5A;
290 1
291 1 E2PRomWrite(uiE2PDataAddr, 32, WrBuf);
292 1
293 1 uiE2PDataAddr += 32;
294 1 if(uiE2PDataAddr >= E2PROM_BOOT_ADDR)
295 1 {
296 2 uiE2PDataAddr = 0;
297 2 }
298 1
299 1 E2PRomBKBoot();
C51 COMPILER V9.01 EXTE2PROM 02/19/2025 10:42:27 PAGE 6
300 1 }
301
302
303 /*************************************************************************************************
304 * 函数名: Uart0RdE2PRom
305 * 参 数: 无
306 * 返回值: 无
307 * 描 述: 读取外挂EEPROM
308 *************************************************************************************************/
309 void Uart0RdE2PRom(void)
310 {
311 1 U16 RdAddr;
312 1
313 1 RdAddr = ((U16)ucUart0Buf[UART_CMD_NO]-CMD_RD_EEPROM)*128+((U16)ucSubClassID-0x80)*4096;
314 1 E2PRomRead(RdAddr, ucUart0Buf[UART_LENGTH], &ucUart0Buf[UART_DATA]);
315 1
316 1 ucUart0Buf[UART_DATA+ucUart0Buf[UART_LENGTH]] = CRC8cal(&ucUart0Buf,ucUart0Buf[UART_LENGTH]+UART_DATA)
-;
317 1 Uart0SendData(); //Start Send Data; Set UART REG
318 1 }
319
320 /*************************************************************************************************
321 * 函数名: Uart1RdE2PRom
322 * 参 数: 无
323 * 返回值: 无
324 * 描 述: 读取外挂EEPROM
325 *************************************************************************************************/
326 void Uart1RdE2PRom(void)
327 {
328 1 U16 RdAddr;
329 1
330 1 RdAddr = ((U16)ucUart1Buf[UART_CMD_NO]-CMD_RD_EEPROM)*128+((U16)ucSubClassID-0x80)*4096;
331 1 E2PRomRead(RdAddr, ucUart1Buf[UART_LENGTH], &ucUart1Buf[UART_DATA]);
332 1
333 1 ucUart1Buf[UART_DATA+ucUart1Buf[UART_LENGTH]] = CRC8cal(&ucUart1Buf,ucUart1Buf[UART_LENGTH]+UART_DATA)
-;
334 1 Uart1SendData(); //Start Send Data; Set UART REG
335 1 }
336
337 /*************************************************************************************************
338 * 函数名: Uart2RdE2PRom
339 * 参 数: 无
340 * 返回值: 无
341 * 描 述: 读取外挂EEPROM
342 *************************************************************************************************/
343 void Uart2RdE2PRom(void)
344 {
345 1 U16 RdAddr;
346 1
347 1 RdAddr = ((U16)ucUart2Buf[UART_CMD_NO]-CMD_RD_EEPROM)*128+((U16)ucSubClassID-0x80)*4096;
348 1 E2PRomRead(RdAddr, ucUart2Buf[UART_LENGTH], &ucUart2Buf[UART_DATA]);
349 1
350 1 ucUart2Buf[UART_DATA+ucUart2Buf[UART_LENGTH]] = CRC8cal(&ucUart2Buf,ucUart2Buf[UART_LENGTH]+UART_DATA)
-;
351 1 Uart2SendData(); //Start Send Data; Set UART REG
352 1 }
353
354
355 /*************************************************************************************************
356 * 函数名: UartRdRTC
357 * 参 数: 无
358 * 返回值: 无
C51 COMPILER V9.01 EXTE2PROM 02/19/2025 10:42:27 PAGE 7
359 * 描 述: 读取RTC时间秒、分、时、日、月、年并返回给UART
360 *************************************************************************************************/
361 void Uart0RdRTC(void)
362 {
363 1 RTCReadTime(&RTC);
364 1 MemoryCopy((U8 xdata *)&(RTC.Second), &ucUart0Buf[UART_DATA], 7);
365 1
366 1 ucUart0Buf[UART_DATA+ucUart0Buf[UART_LENGTH]] = CRC8cal(&ucUart0Buf,ucUart0Buf[UART_LENGTH]+UART_DATA);
367 1 Uart0SendData(); //Start Send Data; Set UART REG
368 1 }
369
370
371 /*************************************************************************************************
372 * 函数名: Uart1RdRTC
373 * 参 数: 无
374 * 返回值: 无
375 * 描 述: 读取RTC时间秒、分、时、日、月、年并返回给UART
376 *************************************************************************************************/
377 void Uart1RdRTC(void)
378 {
379 1 RTCReadTime(&RTC);
380 1 MemoryCopy((U8 xdata *)&(RTC.Second), &ucUart1Buf[UART_DATA], 7);
381 1
382 1 ucUart1Buf[UART_DATA+ucUart1Buf[UART_LENGTH]] = CRC8cal(&ucUart1Buf,ucUart1Buf[UART_LENGTH]+UART_DATA);
383 1 Uart1SendData(); //Start Send Data; Set UART REG
384 1 }
385
386 /*************************************************************************************************
387 * 函数名: Uart2RdRTC
388 * 参 数: 无
389 * 返回值: 无
390 * 描 述: 读取RTC时间秒、分、时、日、月、年并返回给UART
391 *************************************************************************************************/
392 void Uart2RdRTC(void)
393 {
394 1 RTCReadTime(&RTC);
395 1 MemoryCopy((U8 xdata *)&(RTC.Second), &ucUart2Buf[UART_DATA], 7);
396 1
397 1 ucUart2Buf[UART_DATA+ucUart2Buf[UART_LENGTH]] = CRC8cal(&ucUart2Buf,ucUart2Buf[UART_LENGTH]+UART_DATA);
398 1 Uart2SendData(); //Start Send Data; Set UART REG
399 1 }
400
401 /*************************************************************************************************
402 * 函数名: E2PRomBKProcess
403 * 参 数: 无
404 * 返回值: 无
405 * 描 述: 对外挂EEPROM进行相应处理
406 *************************************************************************************************/
407 void E2PRomBKProcess(void)
408 {
409 1 U8 BKType;
410 1
411 1 if(bEnEEPRomBK && bE2PProcessFlg)
412 1 {
413 2 bE2PProcessFlg = 0;
414 2 // E2PRomInit();
415 2 // RTCInitTime(&RTC);
416 2
417 2 if(bE2PErase)
418 2 {
419 3 bE2PErase = 0;
420 3 E2PRomErase();
C51 COMPILER V9.01 EXTE2PROM 02/19/2025 10:42:27 PAGE 8
421 3 }
422 2
423 2 if(bUart0E2PRdData||bUart1E2PRdData||bUart2E2PRdData)
424 2 {
425 3 if(bUart0E2PRdData )
426 3 {
427 4 bUart0E2PRdData = 0;
428 4 Uart0RdE2PRom();
429 4 }
430 3 if(bUart1E2PRdData)
431 3 {
432 4 bUart1E2PRdData = 0;
433 4 Uart2RdE2PRom();
434 4 }
435 3 if(bUart2E2PRdData)
436 3 {
437 4 bUart2E2PRdData = 0;
438 4 Uart2RdE2PRom();
439 4 }
440 3
441 3 }
442 2
443 2 if(bUart0RTCRdTime||bUart1RTCRdTime||bUart2RTCRdTime)
444 2 {
445 3 if(bUart0RTCRdTime)
446 3 {
447 4 bUart0RTCRdTime = 0;
448 4 Uart0RdRTC();
449 4 }
450 3 if(bUart1RTCRdTime)
451 3 {
452 4 bUart1RTCRdTime = 0;
453 4 Uart1RdRTC();
454 4 }
455 3 if(bUart2RTCRdTime)
456 3 {
457 4 bUart2RTCRdTime = 0;
458 4 Uart2RdRTC();
459 4 }
460 3 }
461 2
462 2 if(bE2PBKRtc)
463 2 {
464 3 bE2PBKRtc = 0;
465 3 E2PRomBKRTC();
466 3 }
467 2
468 2 if(bE2PBKChgStart)
469 2 {
470 3 bE2PBKChgStart = 0;
471 3 BKType = E2PROM_BKTYPE_CHG_START;
472 3 E2PRomBKData(BKType);
473 3 }
474 2
475 2 if(bE2PBKChgStop)
476 2 {
477 3 bE2PBKChgStop = 0;
478 3 BKType = E2PROM_BKTYPE_CHG_END;
479 3 E2PRomBKData(BKType);
480 3 }
481 2
482 2 if(bE2PBKDsgEnd)
C51 COMPILER V9.01 EXTE2PROM 02/19/2025 10:42:27 PAGE 9
483 2 {
484 3 bE2PBKDsgEnd = 0;
485 3 BKType = E2PROM_BKTYPE_DSG_END;
486 3 E2PRomBKData(BKType);
487 3 }
488 2 }
489 1 }
490
491
492 /*************************************************************************************************
493 * 函数名: E2PRomBKCheck
494 * 参 数: 无
495 * 返回值: 无
496 * 描 述: 每1s检测是否需要备份RTC及EEPROM数据
497 *************************************************************************************************/
498 void E2PRomBKCheck(void)
499 {
500 1 if(bEnEEPRomBK)
501 1 {
502 2 // E2PRomInit();
503 2 // RTCInitTime(&RTC);
504 2
505 2 if(++ucRTCBKTime1 >= E2ucRTCBKDelay)
506 2 {
507 3 ucRTCBKTime1 = 0;
508 3 RTCReadTime(&RTC);
509 3 }
510 2
511 2 if(++uiRTCBKTime2 >= 3600) //1h
512 2 {
513 3 uiRTCBKTime2 = 0;
514 3 bE2PProcessFlg = 1;
515 3 bE2PBKRtc = 1;
516 3 }
517 2
518 2 if(!bCHGING)
519 2 {
520 3 bDsgToChgFlg = 1;
521 3 if(bChgToDsgFlg)
522 3 {
523 4 bChgToDsgFlg = 0;
524 4 bE2PProcessFlg = 1;
525 4 bE2PBKChgStop = 1;
526 4 }
527 3 if(bUV && bE2PBKDsgEndValid)
528 3 {
529 4 bE2PBKDsgEndValid = 0;
530 4 bE2PProcessFlg = 1;
531 4 bE2PBKDsgEnd = 1;
532 4 }
533 3 else if(!bUV)
534 3 {
535 4 bE2PBKDsgEndValid = 1;
536 4 }
537 3 }
538 2
539 2 if((bDsgToChgFlg && Info.slCurr>=E2siChgBKCur))
540 2 {
541 3 if(!uiCHGValidTime)
542 3 {
543 4 RTCReadTime(&RTC);
544 4 MemoryCopy((U8 xdata *)&RTC, ucRTCBuf, 7);
C51 COMPILER V9.01 EXTE2PROM 02/19/2025 10:42:27 PAGE 10
545 4 }
546 3
547 3 if(++uiCHGValidTime > ((U16)E2ucChgBKDelay*60)) //1分钟
548 3 {
549 4 uiCHGValidTime = 0;
550 4 bChgToDsgFlg = 1;
551 4 bDsgToChgFlg = 0;
552 4 bE2PProcessFlg = 1;
553 4 bE2PBKChgStart = 1;
554 4 }
555 3 }
556 2 else
557 2 {
558 3 uiCHGValidTime = 0;
559 3 }
560 2 }
561 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1964 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 21 82
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = 1 ----
BIT SIZE = 11 3
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)