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