Mercurial > public > ostc4
comparison OtherSources/firmwareEraseProgram.c @ 1051:4b6afe5551e1 GasConsumption tip
Refactors CalcFletcher32 in OtherSources/firmwareEraseProgram.c to iterate over 16-bit words via a pointer instead of an index-based loop. Removes unused variables and returns the computed 32-bit Fletcher checksum directly. (mikeller)
| author | heinrichsweikamp |
|---|---|
| date | Thu, 20 Nov 2025 16:47:21 +0100 |
| parents | 5924a2d1d3ba |
| children |
comparison
equal
deleted
inserted
replaced
| 1050:88b6ab90c55a | 1051:4b6afe5551e1 |
|---|---|
| 558 } | 558 } |
| 559 | 559 |
| 560 | 560 |
| 561 uint32_t CalcFletcher32(uint32_t startAddr, uint32_t endAddr) | 561 uint32_t CalcFletcher32(uint32_t startAddr, uint32_t endAddr) |
| 562 { | 562 { |
| 563 uint32_t fletcher = 0; | |
| 564 uint16_t* pData = (uint16_t*) startAddr; | |
| 565 uint32_t index = 0; | |
| 566 | |
| 567 uint16_t sum1 = 0; | 563 uint16_t sum1 = 0; |
| 568 uint16_t sum2 = 0; | 564 uint16_t sum2 = 0; |
| 569 for(index = startAddr; index <= endAddr; index +=2) | 565 for (uint16_t *index = (uint16_t *)startAddr; index <= (uint16_t *)endAddr; index++) { |
| 570 { | 566 sum1 = sum1 + *index; |
| 571 sum1 = sum1 + *pData++; | 567 sum2 = (sum2 + sum1); |
| 572 sum2 = (sum2 + sum1); | 568 } |
| 573 } | 569 return (sum2 << 16) | sum1; |
| 574 fletcher = (sum2 << 16) | sum1; | |
| 575 | |
| 576 return fletcher; | |
| 577 } | 570 } |
| 578 | 571 |
| 579 | 572 |
| 580 /* Private functions ---------------------------------------------------------*/ | 573 /* Private functions ---------------------------------------------------------*/ |
| 581 | 574 |
