flash: implement flash_write0() to write a sequence of zeroes

tags/0.1.0
S.J.R. van Schaik 8 years ago
parent 22028021ca
commit cd67577f35
  1. 1
      include/flash.h
  2. 22
      source/core/flash.c

@ -34,6 +34,7 @@ size_t flash_get_capacity(struct flash_dev *dev);
size_t flash_read(struct flash_dev *dev, uint32_t addr, void *data, size_t len);
size_t flash_write(struct flash_dev *dev, uint32_t addr, const void *data,
size_t len);
size_t flash_write0(struct flash_dev *dev, uint32_t addr, size_t len);
size_t flash_copy(struct flash_dev *dev, uint32_t dst, uint32_t src, size_t len);
int flash_is_erased(struct flash_dev *dev, uint32_t addr, size_t len);
int flash_erase(struct flash_dev *dev, uint32_t addr, size_t len);

@ -1,5 +1,6 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <flash.h>
#include <macros.h>
@ -96,6 +97,27 @@ size_t flash_write(struct flash_dev *dev, uint32_t addr, const void *data,
return dev->ops->write(dev, addr, data, len);
}
size_t flash_write0(struct flash_dev *dev, uint32_t addr, size_t len)
{
uint8_t data[32];
size_t nbytes, ret = 0;
memset(data, 0, 32);
while (len) {
nbytes = min(sizeof data, len);
if (flash_write(dev, addr, data, nbytes) == 0)
return -1;
addr += nbytes;
len -= nbytes;
ret += nbytes;
}
return ret;
}
size_t flash_copy(struct flash_dev *dev, uint32_t dst, uint32_t src, size_t len)
{
if (!dev)

Loading…
Cancel
Save