Skip to content

Commit 91bb864

Browse files
committed
Improve slot read and write performance and reliability
1 parent 243da44 commit 91bb864

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Diff for: src/utility/ECC508.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,14 @@ int ECC508Class::readSlot(int slot, byte data[], int length)
185185
return 0;
186186
}
187187

188-
for (int i = 0; i < length; i += 4) {
189-
if (!read(2, addressForSlotOffset(slot, i), &data[i], 4)) {
188+
int chunkSize = 32;
189+
190+
for (int i = 0; i < length; i += chunkSize) {
191+
if ((length - i) < 32) {
192+
chunkSize = 4;
193+
}
194+
195+
if (!read(2, addressForSlotOffset(slot, i), &data[i], chunkSize)) {
190196
return 0;
191197
}
192198
}
@@ -204,8 +210,14 @@ int ECC508Class::writeSlot(int slot, const byte data[], int length)
204210
return 0;
205211
}
206212

207-
for (int i = 0; i < length; i += 4) {
208-
if (!write(2, addressForSlotOffset(slot, i), &data[i], 4)) {
213+
int chunkSize = 32;
214+
215+
for (int i = 0; i < length; i += chunkSize) {
216+
if ((length - i) < 32) {
217+
chunkSize = 4;
218+
}
219+
220+
if (!write(2, addressForSlotOffset(slot, i), &data[i], chunkSize)) {
209221
return 0;
210222
}
211223
}
@@ -440,7 +452,7 @@ int ECC508Class::read(int zone, int address, byte buffer[], int length)
440452
return 0;
441453
}
442454

443-
delay(1);
455+
delay(2);
444456

445457
if (!receiveResponse(buffer, length)) {
446458
return 0;
@@ -550,7 +562,7 @@ int ECC508Class::sendCommand(uint8_t opcode, uint8_t param1, uint16_t param2, co
550562

551563
int ECC508Class::receiveResponse(void* response, size_t length)
552564
{
553-
int retries = 25;
565+
int retries = 20;
554566
int responseSize = length + 3; // 1 for length header, 2 for CRC
555567
byte responseBuffer[responseSize];
556568

0 commit comments

Comments
 (0)