1 /**
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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 * Description: Provides iot_flash driver source \n
16 *
17 * History: \n
18 * 2024-01-09, Create file. \n
19 */
20 #include "iot_errno.h"
21 #include "sfc.h"
22 #include "iot_flash.h"
23
24 const sfc_flash_config_t sfc_cfg = {
25 .read_type = FAST_READ_QUAD_OUTPUT,
26 .write_type = PAGE_PROGRAM,
27 .mapping_addr = 0x200000,
28 .mapping_size = 0x800000,
29 };
30
IoTFlashInit(void)31 unsigned int IoTFlashInit(void)
32 {
33 return uapi_sfc_init((sfc_flash_config_t *)&sfc_cfg);
34 }
35
IoTFlashDeinit(void)36 unsigned int IoTFlashDeinit(void)
37 {
38 uapi_sfc_deinit();
39 return IOT_SUCCESS;
40 }
41
IoTFlashWrite(unsigned int flashOffset,unsigned int size,const unsigned char * ramData,unsigned char doErase)42 unsigned int IoTFlashWrite(unsigned int flashOffset, unsigned int size, const unsigned char *ramData,
43 unsigned char doErase)
44 {
45 if (doErase != 0) {
46 uapi_sfc_reg_erase(flashOffset, size);
47 }
48 return uapi_sfc_reg_write(flashOffset, (uint8_t *)ramData, size);
49 }
50
IoTFlashRead(unsigned int flashOffset,unsigned int size,unsigned char * ramData)51 unsigned int IoTFlashRead(unsigned int flashOffset, unsigned int size, unsigned char *ramData)
52 {
53 return uapi_sfc_reg_read(flashOffset, ramData, size);
54 }
55
IoTFlashErase(unsigned int flashOffset,unsigned int size)56 unsigned int IoTFlashErase(unsigned int flashOffset, unsigned int size)
57 {
58 return uapi_sfc_reg_erase(flashOffset, size);
59 }