11bd4fe43Sopenharmony_ci/*
21bd4fe43Sopenharmony_ci * @file hi_flash.h
31bd4fe43Sopenharmony_ci *
41bd4fe43Sopenharmony_ci * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
51bd4fe43Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
61bd4fe43Sopenharmony_ci * you may not use this file except in compliance with the License.
71bd4fe43Sopenharmony_ci * You may obtain a copy of the License at
81bd4fe43Sopenharmony_ci *
91bd4fe43Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
101bd4fe43Sopenharmony_ci *
111bd4fe43Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
121bd4fe43Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
131bd4fe43Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141bd4fe43Sopenharmony_ci * See the License for the specific language governing permissions and
151bd4fe43Sopenharmony_ci * limitations under the License.
161bd4fe43Sopenharmony_ci */
171bd4fe43Sopenharmony_ci
181bd4fe43Sopenharmony_ci/** @defgroup iot_flash  Flash
191bd4fe43Sopenharmony_ci *  @ingroup drivers
201bd4fe43Sopenharmony_ci */
211bd4fe43Sopenharmony_ci#ifndef __HI_FLASH_H__
221bd4fe43Sopenharmony_ci#define __HI_FLASH_H__
231bd4fe43Sopenharmony_ci
241bd4fe43Sopenharmony_ci#include <hi_types.h>
251bd4fe43Sopenharmony_ci#include <hi_flash_base.h>
261bd4fe43Sopenharmony_ci/**
271bd4fe43Sopenharmony_ci* @ingroup  iot_flash
281bd4fe43Sopenharmony_ci* @brief  Reads the flash data to the specified cache. CNcomment:读出Flash数据到指定缓存区域。CNend
291bd4fe43Sopenharmony_ci*
301bd4fe43Sopenharmony_ci* @par 描述:
311bd4fe43Sopenharmony_ci*           Reads the flash data to the specified cache. CNcomment:读出Flash数据到指定缓存区域。CNend
321bd4fe43Sopenharmony_ci*
331bd4fe43Sopenharmony_ci* @attention None
341bd4fe43Sopenharmony_ci* @param  flash_offset      [IN] type #const hi_u32,Offset of the flash address.CNcomment:指定的Flash地址偏移。CNend
351bd4fe43Sopenharmony_ci* @param  size              [IN] type #const hi_u32,Read length (unit: byte).
361bd4fe43Sopenharmony_ciCNcomment:指定读取的长度(单位:byte)。CNend
371bd4fe43Sopenharmony_ci* @param  ram_data          [OUT] type #hi_u8*,Destination cache address.CNcomment:目的缓存地址。CNend
381bd4fe43Sopenharmony_ci*
391bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
401bd4fe43Sopenharmony_ci* @retval #Other           Failure. For details, see hi_errno.h.
411bd4fe43Sopenharmony_ci* @par 依赖:
421bd4fe43Sopenharmony_ci*            @li hi_flash.h:FLASH driver APIs.CNcomment:该接口声明所在的头文件。CNend
431bd4fe43Sopenharmony_ci* @see  None
441bd4fe43Sopenharmony_ci*/
451bd4fe43Sopenharmony_cihi_u32 hi_flash_read(const hi_u32 flash_offset, const hi_u32 size, hi_u8 *ram_data);
461bd4fe43Sopenharmony_ci
471bd4fe43Sopenharmony_ci/**
481bd4fe43Sopenharmony_ci* @ingroup  iot_flash
491bd4fe43Sopenharmony_ci* @brief  Writes data to the specified flash partition.CNcomment:把数据写入指定的Flash区。CNend
501bd4fe43Sopenharmony_ci*
511bd4fe43Sopenharmony_ci* @par 描述:
521bd4fe43Sopenharmony_ci*           Writes data to the specified flash partition.CNcomment:把数据写入指定的Flash区域。CNend
531bd4fe43Sopenharmony_ci*
541bd4fe43Sopenharmony_ci* @attention
551bd4fe43Sopenharmony_ci*           @li Restriction protection for the relative address of the flash memory.
561bd4fe43Sopenharmony_ciCNcomment:Flash相对地址的限制保护。CNend
571bd4fe43Sopenharmony_ci*           @li The number of flash erase times must comply with the device data sheet.
581bd4fe43Sopenharmony_ciCNcomment:Flash擦写次数限制。CNend
591bd4fe43Sopenharmony_ci*           @li Determine whether to erase the flash before the write based on the actual control scenario.
601bd4fe43Sopenharmony_ciCNcomment:根据用户实际控制场景决定是否先擦后写。CNend
611bd4fe43Sopenharmony_ci* @param  flash_offset    [IN] type #const hi_u32,Offset address for writing data to the flash memory.
621bd4fe43Sopenharmony_ciCNcomment:指定写入Flash偏移地址。CNend
631bd4fe43Sopenharmony_ci* @param  size            [IN] type #hi_u32,Length of the data to be written (unit: byte).
641bd4fe43Sopenharmony_ciCNcomment:需要写入的长度(单位:byte)。CNend
651bd4fe43Sopenharmony_ci* @param  ram_data        [IN] type #const hi_u8*,Cache address of the data to be written.
661bd4fe43Sopenharmony_ciCNcomment:需要写入的数据的缓存地址。CNend
671bd4fe43Sopenharmony_ci* @param  do_erase        [IN] type #hi_bool,HI_FALSE: Write data to the flash memory directly.
681bd4fe43Sopenharmony_ci*                                             HI_TRUE:  Erase the sector space before write.
691bd4fe43Sopenharmony_ci*                         The user data is written to the user operation space and the historical
701bd4fe43Sopenharmony_ci*                         data is written back to other spaces.CNcomment:表示是否自动擦除并覆盖写入。
711bd4fe43Sopenharmony_ci*                         @li HI_TRUE:本接口中先擦后写。
721bd4fe43Sopenharmony_ci*                         @li HI_FALSE:用户已经擦除本接口,可直接写入。CNend
731bd4fe43Sopenharmony_ci*
741bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
751bd4fe43Sopenharmony_ci* @retval #Other           Failure. For details, see hi_errno.h.
761bd4fe43Sopenharmony_ci* @par 依赖:
771bd4fe43Sopenharmony_ci*            @li hi_flash.h:FLASH driver APIs.CNcomment:该接口声明所在的头文件。CNend
781bd4fe43Sopenharmony_ci* @see  None
791bd4fe43Sopenharmony_ci*/
801bd4fe43Sopenharmony_cihi_u32 hi_flash_write(const hi_u32 flash_offset, hi_u32 size, const hi_u8 *ram_data, hi_bool do_erase);
811bd4fe43Sopenharmony_ci
821bd4fe43Sopenharmony_ci/**
831bd4fe43Sopenharmony_ci* @ingroup  iot_flash
841bd4fe43Sopenharmony_ci* @brief  Erases the data in the specified flash partition.CNcomment:把指定的Flash区域数据擦除。CNend
851bd4fe43Sopenharmony_ci*
861bd4fe43Sopenharmony_ci* @par 描述:
871bd4fe43Sopenharmony_ci*           Erases the data in the specified flash partition.CNcomment:把指定的Flash区域数据擦除。CNend
881bd4fe43Sopenharmony_ci*
891bd4fe43Sopenharmony_ci* @attention
901bd4fe43Sopenharmony_ci*           @li Restriction protection for the relative address of the flash memory.
911bd4fe43Sopenharmony_ciCNcomment:Flash相对地址的限制保护。CNend
921bd4fe43Sopenharmony_ci*           @li The number of flash erase times must comply with the device data sheet.
931bd4fe43Sopenharmony_ciCNcomment:Flash擦写次数限制。CNend
941bd4fe43Sopenharmony_ci*
951bd4fe43Sopenharmony_ci* @param  flash_offset    [IN] type #const hi_u32,Address offset of the flash memory to be erased.
961bd4fe43Sopenharmony_ciCNcomment:指定要擦除Flash的地址偏移。CNend
971bd4fe43Sopenharmony_ci* @param  size            [IN] type #const hi_u32,Length of the data to be erased (unit: byte).
981bd4fe43Sopenharmony_ci*                         The value must be a multiple of 4 KB.
991bd4fe43Sopenharmony_ciCNcomment:需要擦除的长度(单位:byte),必须是4K的倍数。CNend
1001bd4fe43Sopenharmony_ci*
1011bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
1021bd4fe43Sopenharmony_ci* @retval #Other           Failure. For details, see hi_errno.h.
1031bd4fe43Sopenharmony_ci* @par 依赖:
1041bd4fe43Sopenharmony_ci*            @li hi_flash.h:FLASH driver APIs.CNcomment:该接口声明所在的头文件。CNend
1051bd4fe43Sopenharmony_ci* @see  None
1061bd4fe43Sopenharmony_ci*/
1071bd4fe43Sopenharmony_cihi_u32 hi_flash_erase(const hi_u32 flash_offset, const hi_u32 size);
1081bd4fe43Sopenharmony_ci
1091bd4fe43Sopenharmony_ci/**
1101bd4fe43Sopenharmony_ci* @ingroup  iot_flash
1111bd4fe43Sopenharmony_ci* @brief   Initializes the flash device. CNcomment:初始化Flash设备。CNend
1121bd4fe43Sopenharmony_ci*
1131bd4fe43Sopenharmony_ci* @par 描述:
1141bd4fe43Sopenharmony_ci*           Initializes the flash device. CNcomment:初始化Flash设备。CNend
1151bd4fe43Sopenharmony_ci*
1161bd4fe43Sopenharmony_ci* @attention Initialize the flash module during system boot.
1171bd4fe43Sopenharmony_ciCNcomment:Flash模块初始化,一般在系统启动时调用。CNend
1181bd4fe43Sopenharmony_ci* @param  None
1191bd4fe43Sopenharmony_ci*
1201bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
1211bd4fe43Sopenharmony_ci* @retval #Other           Failure. For details, see hi_errno.h.
1221bd4fe43Sopenharmony_ci* @par 依赖:
1231bd4fe43Sopenharmony_ci*            @li hi_flash.h:FLASH driver APIs.CNcomment:该接口声明所在的头文件。CNend
1241bd4fe43Sopenharmony_ci* @see  None
1251bd4fe43Sopenharmony_ci*/
1261bd4fe43Sopenharmony_cihi_u32 hi_flash_init(hi_void);
1271bd4fe43Sopenharmony_ci
1281bd4fe43Sopenharmony_ci/**
1291bd4fe43Sopenharmony_ci* @ingroup  iot_flash
1301bd4fe43Sopenharmony_ci* @brief  Deinitializes the flash device.CNcomment:去初始化Flash设备。CNend
1311bd4fe43Sopenharmony_ci*
1321bd4fe43Sopenharmony_ci* @par 描述:
1331bd4fe43Sopenharmony_ci*           Deinitializes the flash device.CNcomment:去初始化Flash设备。CNend
1341bd4fe43Sopenharmony_ci*
1351bd4fe43Sopenharmony_ci* @attention None
1361bd4fe43Sopenharmony_ci* @param  None
1371bd4fe43Sopenharmony_ci*
1381bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
1391bd4fe43Sopenharmony_ci* @retval #Other           Failure. For details, see hi_errno.h.
1401bd4fe43Sopenharmony_ci* @par 依赖:
1411bd4fe43Sopenharmony_ci*            @li hi_flash.h:FLASH driver APIs.CNcomment:该接口声明所在的头文件。CNend
1421bd4fe43Sopenharmony_ci* @see  None
1431bd4fe43Sopenharmony_ci*/
1441bd4fe43Sopenharmony_cihi_u32 hi_flash_deinit(hi_void);
1451bd4fe43Sopenharmony_ci/**
1461bd4fe43Sopenharmony_ci* @ingroup  iot_flash
1471bd4fe43Sopenharmony_ci* @brief  Sets or reads flash information.CNcomment:获取Flash信息。CNend
1481bd4fe43Sopenharmony_ci*
1491bd4fe43Sopenharmony_ci* @par 描述:
1501bd4fe43Sopenharmony_ci*          Sets or reads flash information.CNcomment:获取Flash信息。CNend
1511bd4fe43Sopenharmony_ci*
1521bd4fe43Sopenharmony_ci* @attention None
1531bd4fe43Sopenharmony_ci* @param  cmd             [IN]     type #hi_u16,Command ID, currently supports HI_FLASH_CMD_GET_INFO and
1541bd4fe43Sopenharmony_ci*                         HI_FLASHI_FLASH_CMD_IS_BUSY.
1551bd4fe43Sopenharmony_ciCNcomment:命令ID,当前支持HI_FLASH_CMD_GET_INFO 和 HI_FLASH_CMD_IS_BUSY。CNend
1561bd4fe43Sopenharmony_ci* @param  data            [IN/OUT] type #hi_void*, Information set or obtained. cmd is HI_FLASH_CMD_GET_INFO, data is
1571bd4fe43Sopenharmony_ci*                         a pointer of hi_flash_info struct; cmd is HI_FLASH_CMD_IS_BUSY, data is a pointer of type
1581bd4fe43Sopenharmony_ci*                         hi_bool.CNcomment:数据信息,cmd参数为HI_FLASH_CMD_GET_INFO,data为hi_flash_info结构指针;
1591bd4fe43Sopenharmony_ci*                         cmd为HI_FLASH_CMD_IS_BUSY,data为hi_bool类型指针。CNend
1601bd4fe43Sopenharmony_ci*
1611bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS  Success.
1621bd4fe43Sopenharmony_ci* @retval #Other           Failure. For details, see hi_errno.h.
1631bd4fe43Sopenharmony_ci* @par 依赖:
1641bd4fe43Sopenharmony_ci*            @li hi_flash.h:FLASH driver APIs.CNcomment:该接口声明所在的头文件。CNend
1651bd4fe43Sopenharmony_ci* @see  None
1661bd4fe43Sopenharmony_ci*/
1671bd4fe43Sopenharmony_cihi_u32 hi_flash_ioctl(HI_IN hi_u16 cmd, HI_INOUT hi_void *data);
1681bd4fe43Sopenharmony_ci
1691bd4fe43Sopenharmony_ci#endif
1701bd4fe43Sopenharmony_ci
171