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