@@ -173,6 +173,44 @@ int ECC508Class::ecSign(int slot, const byte message[], byte signature[])
173
173
return 1 ;
174
174
}
175
175
176
+ int ECC508Class::readSlot (int slot, byte data[], int length)
177
+ {
178
+ if (slot < 0 || slot > 15 ) {
179
+ return -1 ;
180
+ }
181
+
182
+ if (length % 4 != 0 ) {
183
+ return 0 ;
184
+ }
185
+
186
+ for (int i = 0 ; i < length; i += 4 ) {
187
+ if (!read (2 , addressForSlotOffset (slot, i), &data[i], 4 )) {
188
+ return 0 ;
189
+ }
190
+ }
191
+
192
+ return 1 ;
193
+ }
194
+
195
+ int ECC508Class::writeSlot (int slot, const byte data[], int length)
196
+ {
197
+ if (slot < 0 || slot > 15 ) {
198
+ return -1 ;
199
+ }
200
+
201
+ if (length % 4 != 0 ) {
202
+ return 0 ;
203
+ }
204
+
205
+ for (int i = 0 ; i < length; i += 4 ) {
206
+ if (!write (2 , addressForSlotOffset (slot, i), &data[i], 4 )) {
207
+ return 0 ;
208
+ }
209
+ }
210
+
211
+ return 1 ;
212
+ }
213
+
176
214
int ECC508Class::locked ()
177
215
{
178
216
byte config[4 ];
@@ -476,6 +514,14 @@ int ECC508Class::lock(int zone)
476
514
return 1 ;
477
515
}
478
516
517
+ int ECC508Class::addressForSlotOffset (int slot, int offset)
518
+ {
519
+ int block = offset / 32 ;
520
+ offset = (offset % 32 ) / 4 ;
521
+
522
+ return (slot << 3 ) | (block << 8 ) | (offset);
523
+ }
524
+
479
525
int ECC508Class::sendCommand (uint8_t opcode, uint8_t param1, uint16_t param2, const byte data[], size_t dataLength)
480
526
{
481
527
int commandLength = 8 + dataLength; // 1 for type, 1 for length, 1 for opcode, 1 for param1, 2 for param2, 2 for crc
@@ -502,7 +548,7 @@ int ECC508Class::sendCommand(uint8_t opcode, uint8_t param1, uint16_t param2, co
502
548
503
549
int ECC508Class::receiveResponse (void * response, size_t length)
504
550
{
505
- int retries = 20 ;
551
+ int retries = 25 ;
506
552
int responseSize = length + 3 ; // 1 for length header, 2 for CRC
507
553
byte responseBuffer[responseSize];
508
554
0 commit comments