1 /* 2 * Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup Lockzhiner 18 * 19 * @file flash.h 20 */ 21 22 #ifndef LZ_HARDWARE_FLASH_H 23 #define LZ_HARDWARE_FLASH_H 24 25 /** 26 * @brief Get flash block size. 27 * 28 * This function get flash block size. 29 * 30 * @return Returns flash block size if the size is got successfully; 31 * returns 0 otherwise. For details about other return values, see the chip description. 32 */ 33 unsigned int FlashGetBlockSize(void); 34 35 /** 36 * @brief Reads data from a flash memory address. 37 * 38 * This function reads a specified length of data from a specified flash memory address. 39 * 40 * @param flashOffset Indicates the address of the flash memory from which data is to read. 41 * @param size Indicates the length of the data to read. 42 * @param ramData Indicates the pointer to the RAM for storing the read data. 43 * @return Returns {@link LZ_HARDWARE_SUCCESS} if the data is read successfully; 44 * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description. 45 */ 46 unsigned int FlashRead(unsigned int flashOffset, unsigned int size, unsigned char *ramData); 47 48 /** 49 * @brief Writes data to a flash memory address. 50 * 51 * This function writes a specified length of data to a specified flash memory address. 52 * 53 * @param flashOffset Indicates the address of the flash memory to which data is to be written. 54 * @param size Indicates the length of the data to write. 55 * @param ramData Indicates the pointer to the RAM for storing the data to write. 56 * @param doErase Specifies whether to automatically erase existing data. 57 * Note: if doErase is set, size should be divided by block size(4K). 58 * @return Returns {@link LZ_HARDWARE_SUCCESS} if the data is written successfully; 59 * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description. 60 */ 61 unsigned int FlashWrite(unsigned int flashOffset, unsigned int size, 62 const unsigned char *ramData, unsigned char doErase); 63 64 /** 65 * @brief Erases data in a specified flash memory address. 66 * 67 * @param flashOffset Indicates the flash memory address. 68 * @param size Indicates the data length in bytes. 69 * Note: size should be divided by block size(4K). 70 * @return Returns {@link LZ_HARDWARE_SUCCESS} if the data is erased successfully; 71 * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description. 72 */ 73 unsigned int FlashErase(unsigned int flashOffset, unsigned int size); 74 75 /** 76 * @brief Initializes a flash device. 77 * 78 * @return Returns {@link LZ_HARDWARE_SUCCESS} if the flash device is initialized; 79 * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description. 80 */ 81 unsigned int FlashInit(void); 82 83 /** 84 * @brief Deinitializes a flash device. 85 * 86 * @return Returns {@link LZ_HARDWARE_SUCCESS} if the flash device is deinitialized; 87 * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description. 88 */ 89 unsigned int FlashDeinit(void); 90 91 void FlashSetResidentFlag(int flag); 92 93 #endif 94 95