Skip to content

Commit

Permalink
fixup! fixup! drivers/mtd: introduce mtd_sector_needs_erase()
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Dec 14, 2023
1 parent 425a2db commit 1dd3c5c
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions drivers/include/mtd.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,16 +507,27 @@ int mtd_erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count);
int mtd_erase_sector(mtd_dev_t *mtd, uint32_t sector, uint32_t num);

/**
* @brief Check whether a sector needs to be erased before it can be written
* @brief Write data to a MTD device with whole sector writes
*
* @param mtd the device to erase
* @return true if an erase is needed, false if old data will be
* overwritten automatically.
* The MTD layer will take care of splitting up the transaction into multiple
* writes if it is required by the underlying storage media.
*
* The sectors will be erased before writing if needed.
*
* @param mtd the device to write to
* @param[in] src the buffer to write
* @param[in] sector Sector number to start writing to
* @param[in] num the number of sectors to write
*
* @retval n number of bytes written on success
* @retval <0 value on error
* @retval -ENODEV if @p mtd is not a valid device
* @retval -ENOTSUP if operation is not supported on @p mtd
* @retval -EOVERFLOW if @p addr or @p count are not valid, i.e. outside memory,
* @retval -EIO if I/O error occurred
* @retval -EINVAL if parameters are invalid
*/
static inline bool mtd_sector_needs_erase(mtd_dev_t *mtd)
{
return mtd->driver->flags & MTD_DRIVER_FLAG_DIRECT_WRITE;
}
int mtd_write_sector(mtd_dev_t *mtd, const void *src, uint32_t sector, uint32_t num);

/**
* @brief Set power mode on a MTD device
Expand Down

0 comments on commit 1dd3c5c

Please sign in to comment.