Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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