SDCard version

Fork of gr-peach-opencv-project-sd-card by the do

Committer:
thedo
Date:
Fri Jul 21 01:26:54 2017 +0000
Revision:
167:2ee3e82cb6f5
gr-peach-opencv-project-sd-card

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 167:2ee3e82cb6f5 1 /* mbed Microcontroller Library
thedo 167:2ee3e82cb6f5 2 * Copyright (c) 2017 ARM Limited
thedo 167:2ee3e82cb6f5 3 *
thedo 167:2ee3e82cb6f5 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
thedo 167:2ee3e82cb6f5 5 * of this software and associated documentation files (the "Software"), to deal
thedo 167:2ee3e82cb6f5 6 * in the Software without restriction, including without limitation the rights
thedo 167:2ee3e82cb6f5 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
thedo 167:2ee3e82cb6f5 8 * copies of the Software, and to permit persons to whom the Software is
thedo 167:2ee3e82cb6f5 9 * furnished to do so, subject to the following conditions:
thedo 167:2ee3e82cb6f5 10 *
thedo 167:2ee3e82cb6f5 11 * The above copyright notice and this permission notice shall be included in
thedo 167:2ee3e82cb6f5 12 * all copies or substantial portions of the Software.
thedo 167:2ee3e82cb6f5 13 *
thedo 167:2ee3e82cb6f5 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
thedo 167:2ee3e82cb6f5 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
thedo 167:2ee3e82cb6f5 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
thedo 167:2ee3e82cb6f5 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
thedo 167:2ee3e82cb6f5 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
thedo 167:2ee3e82cb6f5 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
thedo 167:2ee3e82cb6f5 20 * SOFTWARE.
thedo 167:2ee3e82cb6f5 21 */
thedo 167:2ee3e82cb6f5 22 #ifndef MBED_FLASHIAP_H
thedo 167:2ee3e82cb6f5 23 #define MBED_FLASHIAP_H
thedo 167:2ee3e82cb6f5 24
thedo 167:2ee3e82cb6f5 25 #if defined (DEVICE_FLASH) || defined(DOXYGEN_ONLY)
thedo 167:2ee3e82cb6f5 26
thedo 167:2ee3e82cb6f5 27 #include "flash_api.h"
thedo 167:2ee3e82cb6f5 28 #include "platform/SingletonPtr.h"
thedo 167:2ee3e82cb6f5 29 #include "platform/PlatformMutex.h"
thedo 167:2ee3e82cb6f5 30
thedo 167:2ee3e82cb6f5 31 namespace mbed {
thedo 167:2ee3e82cb6f5 32
thedo 167:2ee3e82cb6f5 33 /** \addtogroup drivers */
thedo 167:2ee3e82cb6f5 34
thedo 167:2ee3e82cb6f5 35 /** Flash IAP driver. It invokes flash HAL functions.
thedo 167:2ee3e82cb6f5 36 *
thedo 167:2ee3e82cb6f5 37 * @note Synchronization level: Thread safe
thedo 167:2ee3e82cb6f5 38 * @ingroup drivers
thedo 167:2ee3e82cb6f5 39 */
thedo 167:2ee3e82cb6f5 40 class FlashIAP {
thedo 167:2ee3e82cb6f5 41 public:
thedo 167:2ee3e82cb6f5 42 FlashIAP();
thedo 167:2ee3e82cb6f5 43 ~FlashIAP();
thedo 167:2ee3e82cb6f5 44
thedo 167:2ee3e82cb6f5 45 /** Initialize a flash IAP device
thedo 167:2ee3e82cb6f5 46 *
thedo 167:2ee3e82cb6f5 47 * Should be called once per lifetime of the object.
thedo 167:2ee3e82cb6f5 48 * @return 0 on success or a negative error code on failure
thedo 167:2ee3e82cb6f5 49 */
thedo 167:2ee3e82cb6f5 50 int init();
thedo 167:2ee3e82cb6f5 51
thedo 167:2ee3e82cb6f5 52 /** Deinitialize a flash IAP device
thedo 167:2ee3e82cb6f5 53 *
thedo 167:2ee3e82cb6f5 54 * @return 0 on success or a negative error code on failure
thedo 167:2ee3e82cb6f5 55 */
thedo 167:2ee3e82cb6f5 56 int deinit();
thedo 167:2ee3e82cb6f5 57
thedo 167:2ee3e82cb6f5 58 /** Read data from a flash device.
thedo 167:2ee3e82cb6f5 59 *
thedo 167:2ee3e82cb6f5 60 * This method invokes memcpy - reads number of bytes from the address
thedo 167:2ee3e82cb6f5 61 *
thedo 167:2ee3e82cb6f5 62 * @param buffer Buffer to write to
thedo 167:2ee3e82cb6f5 63 * @param addr Flash address to begin reading from
thedo 167:2ee3e82cb6f5 64 * @param size Size to read in bytes
thedo 167:2ee3e82cb6f5 65 * @return 0 on success, negative error code on failure
thedo 167:2ee3e82cb6f5 66 */
thedo 167:2ee3e82cb6f5 67 int read(void *buffer, uint32_t addr, uint32_t size);
thedo 167:2ee3e82cb6f5 68
thedo 167:2ee3e82cb6f5 69 /** Program data to pages
thedo 167:2ee3e82cb6f5 70 *
thedo 167:2ee3e82cb6f5 71 * The sectors must have been erased prior to being programmed
thedo 167:2ee3e82cb6f5 72 *
thedo 167:2ee3e82cb6f5 73 * @param buffer Buffer of data to be written
thedo 167:2ee3e82cb6f5 74 * @param addr Address of a page to begin writing to, must be a multiple of program and sector sizes
thedo 167:2ee3e82cb6f5 75 * @param size Size to write in bytes, must be a multiple of program and sector sizes
thedo 167:2ee3e82cb6f5 76 * @return 0 on success, negative error code on failure
thedo 167:2ee3e82cb6f5 77 */
thedo 167:2ee3e82cb6f5 78 int program(const void *buffer, uint32_t addr, uint32_t size);
thedo 167:2ee3e82cb6f5 79
thedo 167:2ee3e82cb6f5 80 /** Erase sectors
thedo 167:2ee3e82cb6f5 81 *
thedo 167:2ee3e82cb6f5 82 * The state of an erased sector is undefined until it has been programmed
thedo 167:2ee3e82cb6f5 83 *
thedo 167:2ee3e82cb6f5 84 * @param addr Address of a sector to begin erasing, must be a multiple of the sector size
thedo 167:2ee3e82cb6f5 85 * @param size Size to erase in bytes, must be a multiple of the sector size
thedo 167:2ee3e82cb6f5 86 * @return 0 on success, negative error code on failure
thedo 167:2ee3e82cb6f5 87 */
thedo 167:2ee3e82cb6f5 88 int erase(uint32_t addr, uint32_t size);
thedo 167:2ee3e82cb6f5 89
thedo 167:2ee3e82cb6f5 90 /** Get the sector size at the defined address
thedo 167:2ee3e82cb6f5 91 *
thedo 167:2ee3e82cb6f5 92 * Sector size might differ at address ranges.
thedo 167:2ee3e82cb6f5 93 * An example <0-0x1000, sector size=1024; 0x10000-0x20000, size=2048>
thedo 167:2ee3e82cb6f5 94 *
thedo 167:2ee3e82cb6f5 95 * @param addr Address of or inside the sector to query
thedo 167:2ee3e82cb6f5 96 * @return Size of a sector in bytes or MBED_FLASH_INVALID_SIZE if not mapped
thedo 167:2ee3e82cb6f5 97 */
thedo 167:2ee3e82cb6f5 98 uint32_t get_sector_size(uint32_t addr) const;
thedo 167:2ee3e82cb6f5 99
thedo 167:2ee3e82cb6f5 100 /** Get the flash start address
thedo 167:2ee3e82cb6f5 101 *
thedo 167:2ee3e82cb6f5 102 * @return Flash start address
thedo 167:2ee3e82cb6f5 103 */
thedo 167:2ee3e82cb6f5 104 uint32_t get_flash_start() const;
thedo 167:2ee3e82cb6f5 105
thedo 167:2ee3e82cb6f5 106 /** Get the flash size
thedo 167:2ee3e82cb6f5 107 *
thedo 167:2ee3e82cb6f5 108 * @return Flash size
thedo 167:2ee3e82cb6f5 109 */
thedo 167:2ee3e82cb6f5 110 uint32_t get_flash_size() const;
thedo 167:2ee3e82cb6f5 111
thedo 167:2ee3e82cb6f5 112 /** Get the program page size
thedo 167:2ee3e82cb6f5 113 *
thedo 167:2ee3e82cb6f5 114 * @return Size of a program page in bytes
thedo 167:2ee3e82cb6f5 115 */
thedo 167:2ee3e82cb6f5 116 uint32_t get_page_size() const;
thedo 167:2ee3e82cb6f5 117
thedo 167:2ee3e82cb6f5 118 private:
thedo 167:2ee3e82cb6f5 119
thedo 167:2ee3e82cb6f5 120 /* Check if address and size are aligned to a sector
thedo 167:2ee3e82cb6f5 121 *
thedo 167:2ee3e82cb6f5 122 * @param addr Address of block to check for alignment
thedo 167:2ee3e82cb6f5 123 * @param size Size of block to check for alignment
thedo 167:2ee3e82cb6f5 124 * @return true if the block is sector aligned, false otherwise
thedo 167:2ee3e82cb6f5 125 */
thedo 167:2ee3e82cb6f5 126 bool is_aligned_to_sector(uint32_t addr, uint32_t size);
thedo 167:2ee3e82cb6f5 127
thedo 167:2ee3e82cb6f5 128 flash_t _flash;
thedo 167:2ee3e82cb6f5 129 static SingletonPtr<PlatformMutex> _mutex;
thedo 167:2ee3e82cb6f5 130 };
thedo 167:2ee3e82cb6f5 131
thedo 167:2ee3e82cb6f5 132 } /* namespace mbed */
thedo 167:2ee3e82cb6f5 133
thedo 167:2ee3e82cb6f5 134 #endif /* DEVICE_FLASH */
thedo 167:2ee3e82cb6f5 135
thedo 167:2ee3e82cb6f5 136 #endif /* MBED_FLASHIAP_H */
thedo 167:2ee3e82cb6f5 137