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