static ssize_t progmem_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, FAR uint8_t *buffer)
{
+ FAR struct progmem_dev_s *priv = (FAR struct progmem_dev_s *)dev;
FAR const uint8_t *src;
+ off_t block;
/* Read the specified bytes into the provided user buffer and return
* status (The positive, number of bytes actually read or a negated
* errno)
*/
- src = (FAR const uint8_t *)up_progmem_getaddress(offset);
+ block = offset >> priv->blkshift;
+ src = (FAR const uint8_t *)up_progmem_getaddress(block) +
+ (offset & ((1 << priv->blkshift) - 1));
memcpy(buffer, src, nbytes);
return nbytes;
}
{
FAR struct progmem_dev_s *priv = (FAR struct progmem_dev_s *)dev;
ssize_t result;
+ off_t block;
/* Write the specified blocks from the provided user buffer and return status
* (The positive, number of blocks actually written or a negated errno)
*/
- result = up_progmem_write(up_progmem_getaddress(offset), buffer, nbytes);
+ block = offset >> priv->blkshift;
+ result = up_progmem_write(up_progmem_getaddress(block) +
+ (offset & ((1 << priv->blkshift) - 1)), buffer, nbytes);
return result < 0 ? result : nbytes;
}
#endif