mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Fri May 26 12:39:01 2017 +0100
Revision:
165:e614a9f1c9e2
Parent:
160:d5399cc887bb
Child:
167:e84263d55307
This updates the lib to the mbed lib v 143

Who changed what in which revision?

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