• 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 "hal_config.h"
18 #include "flash_hw.h"
19 #include "flash_ll.h"
20 #include <driver/hal/hal_flash_types.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 typedef struct {
27 	flash_hw_t *hw;
28 	flash_unit_t id;
29 } flash_hal_t;
30 
31 #define flash_hal_is_busy(hal) flash_ll_is_busy((hal)->hw)
32 #define flash_hal_get_id(hal) flash_ll_get_id((hal)->hw)
33 #define flash_hal_get_mid(hal) flash_ll_get_mid((hal)->hw)
34 #define flash_hal_read_status_reg(hal, sr_width) flash_ll_read_status_reg((hal)->hw, sr_width)
35 #define flash_hal_write_status_reg(hal, sr_width, sr_data) flash_ll_write_status_reg((hal)->hw, sr_width, sr_data)
36 #define flash_hal_disable_cpu_data_wr(hal) flash_ll_disable_cpu_data_wr((hal)->hw)
37 #define flash_hal_clear_qwfr(hal) flash_ll_clear_qwfr((hal)->hw)
38 #define flash_hal_set_mode(hal, mode_sel) flash_ll_set_mode((hal)->hw, mode_sel)
39 #define flash_hal_set_dual_mode(hal) flash_ll_set_dual_mode((hal)->hw)
40 #define flash_hal_set_quad_m_value(hal, m_value) flash_ll_set_quad_m_value((hal)->hw, m_value)
41 #define flash_hal_set_qe(hal, qe_bit, qe_bit_post) flash_ll_set_qe((hal)->hw, qe_bit, qe_bit_post)
42 #define flash_hal_set_clk(hal, clk_cfg) flash_ll_set_clk((hal)->hw, clk_cfg)
43 #define flash_hal_set_default_clk(hal) flash_ll_set_default_clk((hal)->hw)
44 #define flash_hal_set_clk_dpll(hal) flash_ll_set_clk_dpll((hal)->hw)
45 #define flash_hal_set_clk_dco(hal, ate_enabled) flash_ll_set_clk_dco((hal)->hw, ate_enabled)
46 #define flash_hal_erase_sector(hal, erase_addr) flash_ll_erase_sector((hal)->hw, erase_addr)
47 #define flash_hal_set_op_cmd_read(hal, read_addr) flash_ll_set_op_cmd_read((hal)->hw, read_addr)
48 #define flash_hal_read_data(hal) flash_ll_read_data((hal)->hw)
49 #define flash_hal_set_op_cmd_write(hal, write_addr) flash_ll_set_op_cmd_write((hal)->hw, write_addr)
50 #define flash_hal_write_data(hal, data) flash_ll_write_data((hal)->hw, data)
51 #define flash_hal_write_enable(hal) flash_ll_write_enable((hal)->hw)
52 #define flash_hal_write_disable(hal) flash_ll_write_disable((hal)->hw)
53 
54 bk_err_t flash_hal_init(flash_hal_t *hal);
55 uint16_t flash_hal_get_protect_value(flash_hal_t *hal, uint8_t status_reg_size,
56 									uint8_t protect_post, uint8_t protect_mask, uint8_t cmp_post);
57 
58 #if CFG_HAL_DEBUG_FLASH
59 void flash_struct_dump(void);
60 #else
61 #define flash_struct_dump()
62 #endif
63 
64 #ifdef __cplusplus
65 }
66 #endif
67 
68