[374] | 1 | /** \addtogroup hal */
|
---|
| 2 | /** @{*/
|
---|
| 3 |
|
---|
| 4 | /* mbed Microcontroller Library
|
---|
| 5 | * Copyright (c) 2017 ARM Limited
|
---|
| 6 | *
|
---|
| 7 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 8 | * you may not use this file except in compliance with the License.
|
---|
| 9 | * You may obtain a copy of the License at
|
---|
| 10 | *
|
---|
| 11 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 12 | *
|
---|
| 13 | * Unless required by applicable law or agreed to in writing, software
|
---|
| 14 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 16 | * See the License for the specific language governing permissions and
|
---|
| 17 | * limitations under the License.
|
---|
| 18 | */
|
---|
| 19 | #ifndef MBED_FLASH_API_H
|
---|
| 20 | #define MBED_FLASH_API_H
|
---|
| 21 |
|
---|
| 22 | #include "device.h"
|
---|
| 23 | #include <stdint.h>
|
---|
| 24 |
|
---|
| 25 | #if DEVICE_FLASH
|
---|
| 26 |
|
---|
| 27 | #define MBED_FLASH_INVALID_SIZE 0xFFFFFFFF
|
---|
| 28 |
|
---|
| 29 | typedef struct flash_s flash_t;
|
---|
| 30 |
|
---|
| 31 | #if TARGET_FLASH_CMSIS_ALGO
|
---|
| 32 | #include "flash_data.h"
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #ifdef __cplusplus
|
---|
| 36 | extern "C" {
|
---|
| 37 | #endif
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | * \defgroup flash_hal Flash HAL API
|
---|
| 41 | * @{
|
---|
| 42 | */
|
---|
| 43 |
|
---|
| 44 | /** Initialize the flash peripheral and the flash_t object
|
---|
| 45 | *
|
---|
| 46 | * @param obj The flash object
|
---|
| 47 | * @return 0 for success, -1 for error
|
---|
| 48 | */
|
---|
| 49 | int32_t flash_init(flash_t *obj);
|
---|
| 50 |
|
---|
| 51 | /** Uninitialize the flash peripheral and the flash_t object
|
---|
| 52 | *
|
---|
| 53 | * @param obj The flash object
|
---|
| 54 | * @return 0 for success, -1 for error
|
---|
| 55 | */
|
---|
| 56 | int32_t flash_free(flash_t *obj);
|
---|
| 57 |
|
---|
| 58 | /** Erase one sector starting at defined address
|
---|
| 59 | *
|
---|
| 60 | * The address should be at sector boundary. This function does not do any check for address alignments
|
---|
| 61 | * @param obj The flash object
|
---|
| 62 | * @param address The sector starting address
|
---|
| 63 | * @return 0 for success, -1 for error
|
---|
| 64 | */
|
---|
| 65 | int32_t flash_erase_sector(flash_t *obj, uint32_t address);
|
---|
| 66 |
|
---|
| 67 | /** Read data starting at defined address
|
---|
| 68 | *
|
---|
| 69 | * This function has a WEAK implementation using memcpy for backwards compatibility.
|
---|
| 70 | * @param obj The flash object
|
---|
| 71 | * @param address Address to begin reading from
|
---|
| 72 | * @param data The buffer to read data into
|
---|
| 73 | * @param size The number of bytes to read
|
---|
| 74 | * @return 0 for success, -1 for error
|
---|
| 75 | */
|
---|
| 76 | int32_t flash_read(flash_t *obj, uint32_t address, uint8_t *data, uint32_t size);
|
---|
| 77 |
|
---|
| 78 | /** Program pages starting at defined address
|
---|
| 79 | *
|
---|
| 80 | * The pages should not cross multiple sectors.
|
---|
| 81 | * This function does not do any check for address alignments or if size is aligned to a page size.
|
---|
| 82 | * @param obj The flash object
|
---|
| 83 | * @param address The sector starting address
|
---|
| 84 | * @param data The data buffer to be programmed
|
---|
| 85 | * @param size The number of bytes to program
|
---|
| 86 | * @return 0 for success, -1 for error
|
---|
| 87 | */
|
---|
| 88 | int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size);
|
---|
| 89 |
|
---|
| 90 | /** Get sector size
|
---|
| 91 | *
|
---|
| 92 | * @param obj The flash object
|
---|
| 93 | * @param address The sector starting address
|
---|
| 94 | * @return The size of a sector
|
---|
| 95 | */
|
---|
| 96 | uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address);
|
---|
| 97 |
|
---|
| 98 | /** Get page size
|
---|
| 99 | *
|
---|
| 100 | * The page size defines the writable page size
|
---|
| 101 | * @param obj The flash object
|
---|
| 102 | * @return The size of a page
|
---|
| 103 | */
|
---|
| 104 | uint32_t flash_get_page_size(const flash_t *obj);
|
---|
| 105 |
|
---|
| 106 | /** Get start address for the flash region
|
---|
| 107 | *
|
---|
| 108 | * @param obj The flash object
|
---|
| 109 | * @return The start address for the flash region
|
---|
| 110 | */
|
---|
| 111 | uint32_t flash_get_start_address(const flash_t *obj);
|
---|
| 112 |
|
---|
| 113 | /** Get the flash region size
|
---|
| 114 | *
|
---|
| 115 | * @param obj The flash object
|
---|
| 116 | * @return The flash region size
|
---|
| 117 | */
|
---|
| 118 | uint32_t flash_get_size(const flash_t *obj);
|
---|
| 119 |
|
---|
| 120 | /**@}*/
|
---|
| 121 |
|
---|
| 122 | #ifdef __cplusplus
|
---|
| 123 | }
|
---|
| 124 | #endif
|
---|
| 125 |
|
---|
| 126 | #endif
|
---|
| 127 |
|
---|
| 128 | #endif
|
---|
| 129 |
|
---|
| 130 | /** @}*/
|
---|