Olle Sköld / BD_DISCO_F746NG
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BD_DISCO_F746NG.h Source File

BD_DISCO_F746NG.h

00001 #include "BlockDevice.h"
00002 #include "stm32746g_discovery_sd.h"
00003 #include "mbed.h"
00004 
00005 
00006 class BD_DISCO_F746NG : public BlockDevice
00007 {
00008 public:
00009     BD_DISCO_F746NG(bd_size_t block=512);
00010     /** Lifetime of the memory block device
00011      *
00012      * @param size      Size of the Block Device in bytes
00013      * @param read      Minimum read size required in bytes
00014      * @param program   Minimum program size required in bytes
00015      * @param erase     Minimum erase size required in bytes
00016      */
00017     BD_DISCO_F746NG(bd_size_t read, bd_size_t program, bd_size_t erase);
00018     virtual ~BD_DISCO_F746NG();
00019 
00020     /** Initialize a block device
00021      *
00022      *  @return         0 on success or a negative error code on failure
00023      */
00024     virtual int init();
00025 
00026     /** Deinitialize a block device
00027      *
00028      *  @return         0 on success or a negative error code on failure
00029      */
00030     virtual int deinit();
00031 
00032     /** Read blocks from a block device
00033      *
00034      *  @param buffer   Buffer to read blocks into
00035      *  @param addr     Address of block to begin reading from
00036      *  @param size     Size to read in bytes, must be a multiple of read block size
00037      *  @return         0 on success, negative error code on failure
00038      */
00039     virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
00040 
00041     /** Program blocks to a block device
00042      *
00043      *  The blocks must have been erased prior to being programmed
00044      *
00045      *  @param buffer   Buffer of data to write to blocks
00046      *  @param addr     Address of block to begin writing to
00047      *  @param size     Size to write in bytes, must be a multiple of program block size
00048      *  @return         0 on success, negative error code on failure
00049      */
00050     virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
00051 
00052     /** Erase blocks on a block device
00053      *
00054      *  The state of an erased block is undefined until it has been programmed
00055      *
00056      *  @param addr     Address of block to begin erasing
00057      *  @param size     Size to erase in bytes, must be a multiple of erase block size
00058      *  @return         0 on success, negative error code on failure
00059      */
00060     virtual int erase(bd_addr_t addr, bd_size_t size);
00061 
00062     /** Get the size of a readable block
00063      *
00064      *  @return         Size of a readable block in bytes
00065      */
00066     virtual bd_size_t get_read_size() const;
00067 
00068     /** Get the size of a programable block
00069      *
00070      *  @return         Size of a programable block in bytes
00071      */
00072     virtual bd_size_t get_program_size() const;
00073 
00074     /** Get the size of a eraseable block
00075      *
00076      *  @return         Size of a eraseable block in bytes
00077      */
00078     virtual bd_size_t get_erase_size() const;
00079 
00080     /** Get the total size of the underlying device
00081      *
00082      *  @return         Size of the underlying device in bytes
00083      */
00084     virtual bd_size_t size() const;
00085 
00086 private:
00087     uint32_t Timeout; 
00088     bd_size_t _read_size;
00089     bd_size_t _program_size;
00090     bd_size_t _erase_size;
00091     bd_size_t _count;
00092     bd_size_t _blocksize;
00093     bd_size_t _size;
00094     BSP_SD_CardInfo _currentCardInfo;
00095     uint8_t _SD_state;
00096     uint8_t **_blocks;
00097 };