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