mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 05:42:05 +08:00
eeprom/spi_xx25xx: Add IOCTL to set Block Protect
Build Documentation / build-html (push) Has been cancelled
Build Documentation / build-html (push) Has been cancelled
Add IOCTL to set Block Protect, because we need a way to set Block Protect of an EEPROM. Signed-off-by: Jiri Vlasak <jvlasak@elektroline.cz>
This commit is contained in:
@@ -184,6 +184,17 @@ The full list of ``ioctl()`` commands can be found in
|
||||
Erase the full EEPROM, a dedicated command is used if supported by the
|
||||
device.
|
||||
|
||||
- ``EEPIOC_BLOCKPROTECT``
|
||||
*Argument:* ``uint8_t``
|
||||
|
||||
Set EEPROM's Block Protect bits. For 25AA160-compatible EEPROM with
|
||||
two Block Protect bits in Status Register, the argument may be:
|
||||
|
||||
- ``0`` for no write protect,
|
||||
- ``1`` to set Block Protection 0 bit of Status Register,
|
||||
- ``2`` to set Block Protection 1 bit of Status Register,
|
||||
- ``3`` to set both Block Protection bits 0 and 1.
|
||||
|
||||
File Systems
|
||||
============
|
||||
|
||||
|
||||
@@ -964,6 +964,8 @@ static int ee24xx_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
ret = ee24xx_eraseall(eedev);
|
||||
break;
|
||||
|
||||
/* TODO: add "case EEPIOC_BLOCKPROTECT:" */
|
||||
|
||||
default:
|
||||
ret = -ENOTTY;
|
||||
}
|
||||
|
||||
@@ -731,6 +731,50 @@ static int ee25xx_erasesector(FAR struct ee25xx_dev_s *eedev,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ee25xx_rdsr
|
||||
*
|
||||
* Description: Read status register.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static uint8_t ee25xx_rdsr(FAR struct ee25xx_dev_s *eedev)
|
||||
{
|
||||
uint8_t tx[2];
|
||||
uint8_t rx[2];
|
||||
|
||||
tx[0] = EE25XX_CMD_RDSR;
|
||||
tx[1] = EE25XX_DUMMY;
|
||||
|
||||
ee25xx_lock(eedev);
|
||||
SPI_SELECT(eedev->spi, SPIDEV_EEPROM(eedev->devid), true);
|
||||
SPI_EXCHANGE(eedev->spi, tx, rx, 2);
|
||||
SPI_SELECT(eedev->spi, SPIDEV_EEPROM(eedev->devid), false);
|
||||
ee25xx_unlock(eedev);
|
||||
return rx[1];
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ee25xx_wrsr
|
||||
*
|
||||
* Description: Write status register.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void ee25xx_wrsr(FAR struct ee25xx_dev_s *eedev, uint8_t what)
|
||||
{
|
||||
uint8_t tx[2];
|
||||
|
||||
tx[0] = EE25XX_CMD_WRSR;
|
||||
tx[1] = what;
|
||||
|
||||
ee25xx_lock(eedev);
|
||||
SPI_SELECT(eedev->spi, SPIDEV_EEPROM(eedev->devid), true);
|
||||
SPI_EXCHANGE(eedev->spi, tx, NULL, 2);
|
||||
SPI_SELECT(eedev->spi, SPIDEV_EEPROM(eedev->devid), false);
|
||||
ee25xx_unlock(eedev);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Driver Functions
|
||||
****************************************************************************/
|
||||
@@ -1094,6 +1138,29 @@ static int ee25xx_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
ret = ee25xx_eraseall(eedev);
|
||||
break;
|
||||
|
||||
case EEPIOC_BLOCKPROTECT:
|
||||
{
|
||||
/* Get current value of status register. */
|
||||
|
||||
ret = ee25xx_rdsr(eedev);
|
||||
|
||||
/* Clear Block Protection bits. */
|
||||
|
||||
ret &= ~(EE25XX_SR_BP0 | EE25XX_SR_BP1);
|
||||
|
||||
/* Set Block Protection bits. */
|
||||
|
||||
ret |= ((uint8_t)arg << 2) & (EE25XX_SR_BP0 | EE25XX_SR_BP1);
|
||||
|
||||
/* Write status register. */
|
||||
|
||||
ee25xx_writeenable(eedev, true);
|
||||
ee25xx_wrsr(eedev, ret);
|
||||
ee25xx_waitwritecomplete(eedev);
|
||||
ret = OK;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = -ENOTTY;
|
||||
}
|
||||
|
||||
@@ -84,6 +84,11 @@
|
||||
* provides success/failure
|
||||
* indication). */
|
||||
|
||||
#define EEPIOC_BLOCKPROTECT _EEPIOC(0x005) /* Set which memory blocks to
|
||||
* protect.
|
||||
* IN: Which blocks as integer.
|
||||
* OUT: OK (0) on success. */
|
||||
|
||||
/************************************************************************************
|
||||
* Type Definitions
|
||||
************************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user