001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

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