• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
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 #pragma once
16 
17 #include <components/log.h>
18 #include <driver/flash_types.h>
19 
20 #define FLASH_TAG "flash"
21 #define FLASH_LOGI(...) BK_LOGI(FLASH_TAG, ##__VA_ARGS__)
22 #define FLASH_LOGW(...) BK_LOGW(FLASH_TAG, ##__VA_ARGS__)
23 #define FLASH_LOGE(...) BK_LOGE(FLASH_TAG, ##__VA_ARGS__)
24 #define FLASH_LOGD(...) BK_LOGD(FLASH_TAG, ##__VA_ARGS__)
25 
26 #define FLASH_SIZE_1M                    0x100000
27 #define FLASH_SIZE_2M                    0x200000
28 #define FLASH_SIZE_4M                    0x400000
29 #define FLASH_SIZE_8M                    0x800000
30 #define FLASH_STATUS_REG_PROTECT_MASK    0xff
31 #define FLASH_STATUS_REG_PROTECT_OFFSET  8
32 #define FLASH_CMP_MASK                   0x1
33 #define FLASH_BUFFER_LEN                 8
34 #define FLASH_BYTES_CNT                  32
35 #define FLASH_ADDRESS_MASK               0x1f
36 #define FLASH_ERASE_SECTOR_MASK          0xFFF000
37 #define FLASH_SECTOR_SIZE_MASK           0x000FFF
38 #define FLASH_SECTOR_SIZE                0x1000 /* each sector has 4K bytes */
39 #define FLASH_SECTOR_SIZE_OFFSET         12
40 #define FLASH_PAGE_SIZE                  256 /* each page has 256 bytes */
41 #define FLASH_DPLL_DIV_VALUE_TEN         3
42 
43 typedef struct {
44 	uint32_t flash_id;
45 	uint8_t status_reg_size; /**< the byte count of status register */
46 	uint32_t flash_size;
47 	flash_line_mode_t line_mode;
48 	uint8_t cmp_post; /**< CMP bit position in status register */
49 	uint8_t protect_post; /**< block protect bits position in status register */
50 	uint8_t protect_mask; /**< block protect bits mask value in status register */
51 	uint16_t protect_all;
52 	uint16_t protect_none;
53 	uint16_t protect_half;
54 	uint16_t unprotect_last_block;
55 	uint8_t quad_en_post; /**< quad enable bit position in status register */
56 	uint8_t quad_en_val; /**< When the QE pin is set to quad_en_val(1 or 0), the Quad IO2 and IO3 pins are enabled */
57 	uint8_t coutinuous_read_mode_bits_val;
58 	uint8_t mode_sel;
59 } flash_config_t;
60