The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Kojto
Date:
Wed Jul 19 16:46:19 2017 +0100
Revision:
147:a97add6d7e64
Parent:
146:22da6e220af6
Child:
152:235179ab3f27
Release 147 of the mbed library.

Who changed what in which revision?

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