Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

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