13d0407baSopenharmony_ci/* 23d0407baSopenharmony_ci * Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. 33d0407baSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43d0407baSopenharmony_ci * you may not use this file except in compliance with the License. 53d0407baSopenharmony_ci * You may obtain a copy of the License at 63d0407baSopenharmony_ci * 73d0407baSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83d0407baSopenharmony_ci * 93d0407baSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103d0407baSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113d0407baSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123d0407baSopenharmony_ci * See the License for the specific language governing permissions and 133d0407baSopenharmony_ci * limitations under the License. 143d0407baSopenharmony_ci */ 153d0407baSopenharmony_ci 163d0407baSopenharmony_ci/** 173d0407baSopenharmony_ci * @addtogroup Lockzhiner 183d0407baSopenharmony_ci * 193d0407baSopenharmony_ci * @file flash.h 203d0407baSopenharmony_ci */ 213d0407baSopenharmony_ci 223d0407baSopenharmony_ci#ifndef LZ_HARDWARE_FLASH_H 233d0407baSopenharmony_ci#define LZ_HARDWARE_FLASH_H 243d0407baSopenharmony_ci 253d0407baSopenharmony_ci/** 263d0407baSopenharmony_ci * @brief Get flash block size. 273d0407baSopenharmony_ci * 283d0407baSopenharmony_ci * This function get flash block size. 293d0407baSopenharmony_ci * 303d0407baSopenharmony_ci * @return Returns flash block size if the size is got successfully; 313d0407baSopenharmony_ci * returns 0 otherwise. For details about other return values, see the chip description. 323d0407baSopenharmony_ci */ 333d0407baSopenharmony_ciunsigned int FlashGetBlockSize(void); 343d0407baSopenharmony_ci 353d0407baSopenharmony_ci/** 363d0407baSopenharmony_ci * @brief Reads data from a flash memory address. 373d0407baSopenharmony_ci * 383d0407baSopenharmony_ci * This function reads a specified length of data from a specified flash memory address. 393d0407baSopenharmony_ci * 403d0407baSopenharmony_ci * @param flashOffset Indicates the address of the flash memory from which data is to read. 413d0407baSopenharmony_ci * @param size Indicates the length of the data to read. 423d0407baSopenharmony_ci * @param ramData Indicates the pointer to the RAM for storing the read data. 433d0407baSopenharmony_ci * @return Returns {@link LZ_HARDWARE_SUCCESS} if the data is read successfully; 443d0407baSopenharmony_ci * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description. 453d0407baSopenharmony_ci */ 463d0407baSopenharmony_ciunsigned int FlashRead(unsigned int flashOffset, unsigned int size, unsigned char *ramData); 473d0407baSopenharmony_ci 483d0407baSopenharmony_ci/** 493d0407baSopenharmony_ci * @brief Writes data to a flash memory address. 503d0407baSopenharmony_ci * 513d0407baSopenharmony_ci * This function writes a specified length of data to a specified flash memory address. 523d0407baSopenharmony_ci * 533d0407baSopenharmony_ci * @param flashOffset Indicates the address of the flash memory to which data is to be written. 543d0407baSopenharmony_ci * @param size Indicates the length of the data to write. 553d0407baSopenharmony_ci * @param ramData Indicates the pointer to the RAM for storing the data to write. 563d0407baSopenharmony_ci * @param doErase Specifies whether to automatically erase existing data. 573d0407baSopenharmony_ci * Note: if doErase is set, size should be divided by block size(4K). 583d0407baSopenharmony_ci * @return Returns {@link LZ_HARDWARE_SUCCESS} if the data is written successfully; 593d0407baSopenharmony_ci * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description. 603d0407baSopenharmony_ci */ 613d0407baSopenharmony_ciunsigned int FlashWrite(unsigned int flashOffset, unsigned int size, 623d0407baSopenharmony_ci const unsigned char *ramData, unsigned char doErase); 633d0407baSopenharmony_ci 643d0407baSopenharmony_ci/** 653d0407baSopenharmony_ci * @brief Erases data in a specified flash memory address. 663d0407baSopenharmony_ci * 673d0407baSopenharmony_ci * @param flashOffset Indicates the flash memory address. 683d0407baSopenharmony_ci * @param size Indicates the data length in bytes. 693d0407baSopenharmony_ci * Note: size should be divided by block size(4K). 703d0407baSopenharmony_ci * @return Returns {@link LZ_HARDWARE_SUCCESS} if the data is erased successfully; 713d0407baSopenharmony_ci * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description. 723d0407baSopenharmony_ci */ 733d0407baSopenharmony_ciunsigned int FlashErase(unsigned int flashOffset, unsigned int size); 743d0407baSopenharmony_ci 753d0407baSopenharmony_ci/** 763d0407baSopenharmony_ci * @brief Initializes a flash device. 773d0407baSopenharmony_ci * 783d0407baSopenharmony_ci * @return Returns {@link LZ_HARDWARE_SUCCESS} if the flash device is initialized; 793d0407baSopenharmony_ci * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description. 803d0407baSopenharmony_ci */ 813d0407baSopenharmony_ciunsigned int FlashInit(void); 823d0407baSopenharmony_ci 833d0407baSopenharmony_ci/** 843d0407baSopenharmony_ci * @brief Deinitializes a flash device. 853d0407baSopenharmony_ci * 863d0407baSopenharmony_ci * @return Returns {@link LZ_HARDWARE_SUCCESS} if the flash device is deinitialized; 873d0407baSopenharmony_ci * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description. 883d0407baSopenharmony_ci */ 893d0407baSopenharmony_ciunsigned int FlashDeinit(void); 903d0407baSopenharmony_ci 913d0407baSopenharmony_civoid FlashSetResidentFlag(int flag); 923d0407baSopenharmony_ci 933d0407baSopenharmony_ci#endif 943d0407baSopenharmony_ci 95