distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
distortos::devices::BlockDevice Class Referenceabstract

#include "distortos/devices/memory/BlockDevice.hpp"

Inheritance diagram for distortos::devices::BlockDevice:
[legend]

Public Member Functions

virtual ~BlockDevice ()=default
 BlockDevice's destructor. More...
 
virtual int close ()=0
 Closes device. More...
 
virtual int erase (uint64_t address, uint64_t size)=0
 Erases blocks on a device. More...
 
virtual size_t getBlockSize () const =0
 
virtual uint64_t getSize () const =0
 
virtual void lock ()=0
 Locks the device for exclusive use by current thread. More...
 
virtual int open ()=0
 Opens device. More...
 
virtual int read (uint64_t address, void *buffer, size_t size)=0
 Reads data from a device. More...
 
virtual int synchronize ()=0
 Synchronizes state of a device, ensuring all cached writes are finished. More...
 
virtual void unlock ()=0
 Unlocks the device which was previously locked by current thread. More...
 
virtual int write (uint64_t address, const void *buffer, size_t size)=0
 Writes data to a device. More...
 
 BlockDevice (const BlockDevice &)=delete
 
BlockDeviceoperator= (const BlockDevice &)=delete
 

Detailed Description

BlockDevice class is an interface for a block device.

Constructor & Destructor Documentation

◆ ~BlockDevice()

virtual distortos::devices::BlockDevice::~BlockDevice ( )
virtualdefault

BlockDevice's destructor.

Precondition
Device is closed.

Member Function Documentation

◆ close()

virtual int distortos::devices::BlockDevice::close ( )
pure virtual

Closes device.

Note
Even if error code is returned, the device must not be used from the context which opened it (until it is successfully opened again).
Precondition
Device is opened.
Returns
0 on success, error code otherwise

Implemented in distortos::devices::SpiEeprom, distortos::devices::SdCard, and distortos::devices::SdCardSpiBased.

Here is the caller graph for this function:

◆ erase()

virtual int distortos::devices::BlockDevice::erase ( uint64_t  address,
uint64_t  size 
)
pure virtual

Erases blocks on a device.

Precondition
Device is opened.
address and size are valid.
Selected range is within address space of device.
Parameters
[in]addressis the address of range that will be erased, must be a multiple of block size
[in]sizeis the size of erased range, bytes, must be a multiple of block size
Returns
0 on success, error code otherwise

Implemented in distortos::devices::SpiEeprom, distortos::devices::SdCard, and distortos::devices::SdCardSpiBased.

Here is the caller graph for this function:

◆ getBlockSize()

virtual size_t distortos::devices::BlockDevice::getBlockSize ( ) const
pure virtual
Returns
block size, bytes

Implemented in distortos::devices::SpiEeprom, distortos::devices::SdCard, and distortos::devices::SdCardSpiBased.

Here is the caller graph for this function:

◆ getSize()

virtual uint64_t distortos::devices::BlockDevice::getSize ( ) const
pure virtual
Returns
size of block device, bytes

Implemented in distortos::devices::SpiEeprom, distortos::devices::SdCard, and distortos::devices::SdCardSpiBased.

Here is the caller graph for this function:

◆ lock()

virtual void distortos::devices::BlockDevice::lock ( )
pure virtual

Locks the device for exclusive use by current thread.

When the object is locked, any call to any member function from other thread will be blocked until the object is unlocked. Locking is optional, but may be useful when more than one transaction must be done atomically.

Note
Locks are recursive.
Warning
This function must not be called from interrupt context!
Precondition
The number of recursive locks of device is less than 65535.
Postcondition
Device is locked.

Implemented in distortos::devices::SpiEeprom, distortos::devices::SdCard, and distortos::devices::SdCardSpiBased.

Here is the caller graph for this function:

◆ open()

virtual int distortos::devices::BlockDevice::open ( )
pure virtual

Opens device.

Precondition
The number of times the device is opened is less than 255.
Returns
0 on success, error code otherwise

Implemented in distortos::devices::SpiEeprom, distortos::devices::SdCard, and distortos::devices::SdCardSpiBased.

Here is the caller graph for this function:

◆ read()

virtual int distortos::devices::BlockDevice::read ( uint64_t  address,
void *  buffer,
size_t  size 
)
pure virtual

Reads data from a device.

Precondition
Device is opened.
address and buffer and size are valid.
Selected range is within address space of device.
Parameters
[in]addressis the address of data that will be read, must be a multiple of block size
[out]bufferis the buffer into which the data will be read, must be valid
[in]sizeis the size of buffer, bytes, must be a multiple of block size
Returns
0 on success, error code otherwise

Implemented in distortos::devices::SpiEeprom, distortos::devices::SdCard, and distortos::devices::SdCardSpiBased.

Here is the caller graph for this function:

◆ synchronize()

virtual int distortos::devices::BlockDevice::synchronize ( )
pure virtual

Synchronizes state of a device, ensuring all cached writes are finished.

Precondition
Device is opened.
Returns
0 on success, error code otherwise

Implemented in distortos::devices::SpiEeprom, distortos::devices::SdCard, and distortos::devices::SdCardSpiBased.

Here is the caller graph for this function:

◆ unlock()

virtual void distortos::devices::BlockDevice::unlock ( )
pure virtual

Unlocks the device which was previously locked by current thread.

Note
Locks are recursive.
Warning
This function must not be called from interrupt context!
Precondition
This function is called by the thread that locked the device.

Implemented in distortos::devices::SpiEeprom, distortos::devices::SdCard, and distortos::devices::SdCardSpiBased.

Here is the caller graph for this function:

◆ write()

virtual int distortos::devices::BlockDevice::write ( uint64_t  address,
const void *  buffer,
size_t  size 
)
pure virtual

Writes data to a device.

Precondition
Device is opened.
address and buffer and size are valid.
Selected range is within address space of device.
Parameters
[in]addressis the address of data that will be written, must be a multiple of block size
[in]bufferis the buffer with data that will be written, must be valid
[in]sizeis the size of buffer, bytes, must be a multiple of block size
Returns
0 on success, error code otherwise

Implemented in distortos::devices::SpiEeprom, distortos::devices::SdCard, and distortos::devices::SdCardSpiBased.

Here is the caller graph for this function:

The documentation for this class was generated from the following file: