Erste version der Software für der Prototyp

Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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