1/*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
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#ifndef __CFIFLASH_H__
16#define __CFIFLASH_H__
17
18#include "stdint.h"
19
20#define CFIFLASH_MAX_NUM            2
21#define CFIFLASH_CAPACITY           (32 * 1024 * 1024)
22#define CFIFLASH_ERASEBLK_SIZE      (128 * 1024 * 2)    /* fit QEMU of 2 banks  */
23#define CFIFLASH_ERASEBLK_WORDS     (CFIFLASH_ERASEBLK_SIZE / sizeof(uint32_t))
24#define CFIFLASH_ERASEBLK_WORDMASK  (~(CFIFLASH_ERASEBLK_WORDS - 1))
25
26/* Results of Flash Functions */
27typedef enum {
28    FLASH_OK = 0,     /* 0: Successful */
29    FLASH_ERROR       /* 1: R/W Error */
30} FLASH_DRESULT;
31
32unsigned CfiFlashSec2Bytes(unsigned sector);
33
34int CfiFlashQuery(uint32_t pdrv);
35int32_t CfiFlashRead(uint32_t pdrv, uint32_t *buffer, uint32_t offset, uint32_t nbytes);
36int32_t CfiFlashWrite(uint32_t pdrv, const uint32_t *buffer, uint32_t offset, uint32_t nbytes);
37int32_t CfiFlashErase(uint32_t pdrv, uint32_t offset);
38
39#if (LOSCFG_SUPPORT_FATFS == 1)
40#include "fatfs.h"
41#include "ff_gen_drv.h"
42
43DiskioDrvTypeDef *GetCfiBlkOps(void);
44#endif /* LOSCFG_SUPPORT_FATFS == 1 */
45
46#if (LOSCFG_SUPPORT_LITTLEFS == 1)
47#include "lfs.h"
48
49int LittlefsDriverInit(void);
50struct lfs_config* GetCfiLfsCfg(void);
51#endif /* LOSCFG_SUPPORT_LITTLEFS == 1 */
52
53#endif /* __CFIFLASH_H__ */
54