- uint16_t block;
- uint16_t this_len;
- uint8_t this_off;
-
- if (pos >= ao_storage_total || pos + len > ao_storage_total)
- return 0;
- while (len) {
-
- /* Compute portion of transfer within
- * a single block
- */
- this_off = pos;
- this_len = EE_BLOCK_SIZE - (uint16_t) this_off;
- block = (uint16_t) (pos >> 8);
- if (this_len > len)
- this_len = len;
- if (this_len & 0xff00)
- ao_panic(AO_PANIC_EE);
-
- /* Transfer the data */
- ao_mutex_get(&ao_ee_mutex); {
- if (this_len != EE_BLOCK_SIZE)
- ao_ee_fill(block);
- else {
- ao_ee_flush_internal();
- ao_ee_block = block;
- }
- memcpy(ao_ee_data + this_off, buf, this_len);
- ao_ee_block_dirty = 1;
- } ao_mutex_put(&ao_ee_mutex);
-
- /* See how much is left */
- buf += this_len;
- len -= this_len;
- pos += this_len;
- }
+ uint16_t block = (uint16_t) (pos >> EE_BLOCK_SHIFT);
+
+ /* Transfer the data */
+ ao_mutex_get(&ao_ee_mutex); {
+ if (len != EE_BLOCK_SIZE)
+ ao_ee_fill(block);
+ else {
+ ao_ee_flush_internal();
+ ao_ee_block = block;
+ }
+ memcpy(ao_ee_data + (uint16_t) (pos & 0xff), buf, len);
+ ao_ee_block_dirty = 1;
+ } ao_mutex_put(&ao_ee_mutex);