inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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