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