- result =
- twi_start_w(EEPROM_ADDR(blk_addr))
- && twi_send(&blk_offs, sizeof blk_offs)
- && twi_send(buf, size);
+ twi_stop();
+
+ /* Update count and addr for next operation */
+ size -= count;
+ fd->fd.seek_pos += count;
+ buf = ((const char *)buf) + count;
+ wr_len += count;
+ }
+
+ return wr_len;
+}
+
+/**
+ * Copy \a size bytes from buffer \a _buf to
+ * eeprom.
+ * \note Writes are verified and if buffer content
+ * is not matching we retry 5 times max.
+ */
+static size_t eeprom_writeVerify(struct KFile *_fd, const void *_buf, size_t size)
+{
+ Eeprom *fd = EEPROM_CAST(_fd);
+ int retries = 5;
+ size_t wr_len;
+
+ while (retries--)
+ {
+ wr_len = eeprom_writeRaw(_fd, _buf, size);
+ /* rewind to verify what we have just written */
+ kfile_seek(_fd, -(kfile_off_t)wr_len, KSM_SEEK_CUR);
+ if (wr_len == size
+ && eeprom_verify(fd, _buf, wr_len))
+ {
+ /* Forward to go after what we have written*/
+ kfile_seek(_fd, wr_len, KSM_SEEK_CUR);
+ return wr_len;
+ }
+ }
+ return wr_len;
+}