1 /*
2 # Copyright (C) 2024 HiHope Open Source Organization .
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 #include "iot_errno.h"
16 #include "sfc.h"
17 #include "iot_flash.h"
18
19 const sfc_flash_config_t sfc_cfg = {
20 .read_type = FAST_READ_QUAD_OUTPUT,
21 .write_type = PAGE_PROGRAM,
22 .mapping_addr = 0x200000,
23 .mapping_size = 0x800000,
24 };
25
IoTFlashInit(void)26 unsigned int IoTFlashInit(void)
27 {
28 return uapi_sfc_init((sfc_flash_config_t *)&sfc_cfg);
29 }
30
IoTFlashDeinit(void)31 unsigned int IoTFlashDeinit(void)
32 {
33 uapi_sfc_deinit();
34 return IOT_SUCCESS;
35 }
36
IoTFlashWrite(unsigned int flashOffset,unsigned int size,const unsigned char * ramData,unsigned char doErase)37 unsigned int IoTFlashWrite(unsigned int flashOffset, unsigned int size, const unsigned char *ramData,
38 unsigned char doErase)
39 {
40 if (doErase != 0) {
41 uapi_sfc_reg_erase(flashOffset, size);
42 }
43 return uapi_sfc_reg_write(flashOffset, (uint8_t *)ramData, size);
44 }
45
IoTFlashRead(unsigned int flashOffset,unsigned int size,unsigned char * ramData)46 unsigned int IoTFlashRead(unsigned int flashOffset, unsigned int size, unsigned char *ramData)
47 {
48 return uapi_sfc_reg_read(flashOffset, ramData, size);
49 }
50
IoTFlashErase(unsigned int flashOffset,unsigned int size)51 unsigned int IoTFlashErase(unsigned int flashOffset, unsigned int size)
52 {
53 return uapi_sfc_reg_erase(flashOffset, size);
54 }
55